netx.jnlp

Class Parser


(package private) class Parser
extends java.lang.Object

Contains methods to parse an XML document into a JNLPFile. Implements JNLP specification version 1.0.
Version:
$Revision: 1.13 $
Author:
Jon A. Maxwell (JAM) - initial author

Constructor Summary

Parser(JNLPFile file, URL base, Node root, boolean strict, boolean allowExtensions)
Create a parser for the JNLP file.

Method Summary

protected void
addInfo(InformationDesc info, Node node, String mod, Object value)
Adds a key,value pair to the information object.
AppletDesc
getApplet(Node node)
Returns the applet descriptor.
ApplicationDesc
getApplication(Node node)
Returns the application descriptor.
String
getAttribute(Node node, String name, String defaultValue)
Retuns an attribute or the specified defaultValue if there is no such attribute.
static Node
getChildNode(Node node, String name)
Returns the first child node with the specified name.
static Node[]
getChildNodes(Node node, String name)
Returns all child nodes with the specified name.
URL
getCodeBase()
Returns the codebase.
ComponentDesc
getComponent(Node node)
Returns the component descriptor.
ExtensionDesc
getExtension(Node node)
Returns the Extension element at the specified node.
URL
getFileLocation()
Returns the file location.
Version
getFileVersion()
Returns the file version.
IconDesc
getIcon(Node node)
Returns the icon element at the specified node.
List
getInfo(Node parent)
Returns all of the information elements under the specified node.
InformationDesc
getInformationDesc(Node node)
Returns the information element at the specified node.
InstallerDesc
getInstaller(Node node)
Returns the installer descriptor.
JARDesc
getJAR(Node node)
Returns the JAR element at the specified node.
JREDesc
getJRE(Node node)
Returns the JRE element at the specified node.
Object
getLauncher(Node parent)
Returns the launch descriptor element, either AppletDesc, ApplicationDesc, ComponentDesc, or InstallerDesc.
Locale
getLocale(String localeStr)
Returns a Locale from a single locale.
Locale[]
getLocales(Node node)
Returns the Locale object(s) from a node's locale attribute.
PackageDesc
getPackage(Node node)
Returns the Package element at the specified node.
PropertyDesc
getProperty(Node node)
Returns the Property element at the specified node.
String
getRequiredAttribute(Node node, String name, String defaultValue)
Returns the same result as getAttribute except that if strict mode is enabled or the default value is null a parse exception is thrown instead of returning the default value.
URL
getRequiredURL(Node node, String name, URL base)
Returns the same result as getURL except that a ParseException is thrown if the attribute is null or empty.
List
getResources(Node parent, boolean j2se)
Returns all of the ResourcesDesc elements under the specified node (jnlp or j2se).
ResourcesDesc
getResourcesDesc(Node node, boolean j2se)
Returns the ResourcesDesc element at the specified node.
static Node
getRootNode(InputStream input)
Return the root node from the XML document in the specified input stream.
SecurityDesc
getSecurity(Node parent)
Returns the security descriptor element.
String
getSpanText(Node node)
Returns the implied text under a node, for example "text" in "text".
Version
getSpecVersion()
Returns the specification version.
static Version
getSupportedVersions()
Return the JNLP specification versions supported.
URL
getURL(Node node, String name, URL base)
Returns a URL object from a href string relative to the code base.
Version
getVersion(Node node, String name, String defaultValue)
Returns a Version from the specified attribute and default value.
protected boolean
isTrustedEnvironment()
Returns whether the JNLP file requests a trusted execution environment.
String[]
splitString(String source)
Returns an array of substrings seperated by spaces (spaces escaped with backslash do not separate strings).

Constructor Details

Parser

public Parser(JNLPFile file,
              URL base,
              Node root,
              boolean strict,
              boolean allowExtensions)
            throws ParseException
Create a parser for the JNLP file. If the location parameters is not null it is used as the default codebase (does not override value of jnlp element's href attribute).

The root node may be normalized as a side effect of this constructor.

Parameters:
file - the (uninitialized) file reference
base - if codebase is not specified, a default base for relative URLs
root - the root node
strict - whether to enforce strict compliance with the JNLP spec
allowExtensions - whether to allow extensions to the JNLP spec
Throws:
ParseException - if the JNLP file is invalid

Method Details

addInfo

protected void addInfo(InformationDesc info,
                       Node node,
                       String mod,
                       Object value)
Adds a key,value pair to the information object.
Parameters:
info - the information object
node - node name to be used as the key
mod - key name appended with "-"+mod if not null
value - the info object to add (icon or string)

getApplet

public AppletDesc getApplet(Node node)
            throws ParseException
Returns the applet descriptor.
Throws:
ParseException - if the JNLP file is invalid

getApplication

public ApplicationDesc getApplication(Node node)
            throws ParseException
Returns the application descriptor.
Throws:
ParseException - if the JNLP file is invalid

getAttribute

public String getAttribute(Node node,
                           String name,
                           String defaultValue)
Retuns an attribute or the specified defaultValue if there is no such attribute.
Parameters:
node - the node
name - the attribute
defaultValue - default if no such attribute

getChildNode

public static Node getChildNode(Node node,
                                String name)
Returns the first child node with the specified name.

getChildNodes

public static Node[] getChildNodes(Node node,
                                   String name)
Returns all child nodes with the specified name.

getCodeBase

public URL getCodeBase()
Returns the codebase.

getComponent

public ComponentDesc getComponent(Node node)
Returns the component descriptor.

getExtension

public ExtensionDesc getExtension(Node node)
            throws ParseException
Returns the Extension element at the specified node.
Parameters:
node - the extension node
Throws:
ParseException - if the JNLP file is invalid

getFileLocation

public URL getFileLocation()
Returns the file location.

getFileVersion

public Version getFileVersion()
Returns the file version.

getIcon

public IconDesc getIcon(Node node)
            throws ParseException
Returns the icon element at the specified node.
Parameters:
node - the icon node
Throws:
ParseException - if the JNLP file is invalid

getInfo

public List getInfo(Node parent)
            throws ParseException
Returns all of the information elements under the specified node.
Parameters:
parent - the parent node (jnlp)
Throws:
ParseException - if the JNLP file is invalid

getInformationDesc

public InformationDesc getInformationDesc(Node node)
            throws ParseException
Returns the information element at the specified node.
Parameters:
node - the information node
Throws:
ParseException - if the JNLP file is invalid

getInstaller

public InstallerDesc getInstaller(Node node)
Returns the installer descriptor.

getJAR

public JARDesc getJAR(Node node)
            throws ParseException
Returns the JAR element at the specified node.
Parameters:
node - the jar or nativelib node
Throws:
ParseException - if the JNLP file is invalid

getJRE

public JREDesc getJRE(Node node)
            throws ParseException
Returns the JRE element at the specified node.
Parameters:
node - the j2se node
Throws:
ParseException - if the JNLP file is invalid

getLauncher

public Object getLauncher(Node parent)
            throws ParseException
Returns the launch descriptor element, either AppletDesc, ApplicationDesc, ComponentDesc, or InstallerDesc.
Parameters:
parent - the parent node
Throws:
ParseException - if the JNLP file is invalid

getLocale

public Locale getLocale(String localeStr)
Returns a Locale from a single locale.
Parameters:

getLocales

public Locale[] getLocales(Node node)
Returns the Locale object(s) from a node's locale attribute.
Parameters:
node - the node with a locale attribute

getPackage

public PackageDesc getPackage(Node node)
            throws ParseException
Returns the Package element at the specified node.
Parameters:
node - the package node
Throws:
ParseException - if the JNLP file is invalid

getProperty

public PropertyDesc getProperty(Node node)
            throws ParseException
Returns the Property element at the specified node.
Parameters:
node - the property node
Throws:
ParseException - if the JNLP file is invalid

getRequiredAttribute

public String getRequiredAttribute(Node node,
                                   String name,
                                   String defaultValue)
            throws ParseException
Returns the same result as getAttribute except that if strict mode is enabled or the default value is null a parse exception is thrown instead of returning the default value.
Parameters:
node - the node
name - the attribute
defaultValue - default value
Throws:
ParseException - if the attribute does not exist or is empty

getRequiredURL

public URL getRequiredURL(Node node,
                          String name,
                          URL base)
            throws ParseException
Returns the same result as getURL except that a ParseException is thrown if the attribute is null or empty.
Parameters:
node - the node
name - the attribute containing an href
base - the base URL
Throws:
ParseException - if the JNLP file is invalid

getResources

public List getResources(Node parent,
                         boolean j2se)
            throws ParseException
Returns all of the ResourcesDesc elements under the specified node (jnlp or j2se).
Parameters:
parent - the parent node (either jnlp or j2se)
j2se - true if the resources are located under a j2se node
Throws:
ParseException - if the JNLP file is invalid

getResourcesDesc

public ResourcesDesc getResourcesDesc(Node node,
                                      boolean j2se)
            throws ParseException
Returns the ResourcesDesc element at the specified node.
Parameters:
node - the resources node
j2se - true if the resources are located under a j2se node
Throws:
ParseException - if the JNLP file is invalid

getRootNode

public static Node getRootNode(InputStream input)
            throws ParseException
Return the root node from the XML document in the specified input stream.
Throws:
ParseException - if the JNLP file is invalid

getSecurity

public SecurityDesc getSecurity(Node parent)
            throws ParseException
Returns the security descriptor element. If no security element was specified in the JNLP file then a SecurityDesc with applet permissions is returned.
Parameters:
parent - the parent node
Throws:
ParseException - if the JNLP file is invalid

getSpanText

public String getSpanText(Node node)
            throws ParseException
Returns the implied text under a node, for example "text" in "text".
Parameters:
node - the node with text under it
Throws:
ParseException - if the JNLP file is invalid

getSpecVersion

public Version getSpecVersion()
Returns the specification version.

getSupportedVersions

public static Version getSupportedVersions()
Return the JNLP specification versions supported.

getURL

public URL getURL(Node node,
                  String name,
                  URL base)
            throws ParseException
Returns a URL object from a href string relative to the code base. If the href denotes a relative URL, it must reference a location that is a subdirectory of the codebase.

Parameters:
node - the node
name - the attribute containing an href
base - the base URL
Throws:
ParseException - if the JNLP file is invalid

getVersion

public Version getVersion(Node node,
                          String name,
                          String defaultValue)
Returns a Version from the specified attribute and default value.
Parameters:
node - the node
name - the attribute
defaultValue - default if no such attribute
Returns:
a Version, or null if no such attribute and default is null

isTrustedEnvironment

protected boolean isTrustedEnvironment()
Returns whether the JNLP file requests a trusted execution environment.

splitString

public String[] splitString(String source)
Returns an array of substrings seperated by spaces (spaces escaped with backslash do not separate strings). This method splits strings as per the spec except that it does replace escaped other characters with their own value.