Homepage

netx.jnlp
Class Parser

    java.lang.Object
    |
    +--netx.jnlp.Parser

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.1 $
Author:
Jon A. Maxwell (JAM) - initial author

Constructor Summary
Parser(JNLPFile file, java.net.URL base, Node root, boolean strict, boolean allowExtensions)
          Create a parser for the JNLP file.
 
Method Summary
protected  void addInfo(InformationDesc info, Node node, java.lang.String mod, java.lang.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.
 java.lang.String getAttribute(Node node, java.lang.String name, java.lang.String defaultValue)
          Retuns an attribute or the specified defaultValue if there is no such attribute.
static Node getChildNode(Node node, java.lang.String name)
          Returns the first child node with the specified name.
static Node[] getChildNodes(Node node, java.lang.String name)
          Returns all child nodes with the specified name.
 java.net.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.
 java.net.URL getFileLocation()
          Returns the file location.
 Version getFileVersion()
          Returns the file version.
 IconDesc getIcon(Node node)
          Returns the icon element at the specified node.
 java.util.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.
 java.lang.Object getLauncher(Node parent)
          Returns the launch descriptor element, either AppletDesc, ApplicationDesc, ComponentDesc, or InstallerDesc.
 java.util.Locale getLocale(java.lang.String localeStr)
          Returns a Locale from a single locale.
 java.util.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.
 java.lang.String getRequiredAttribute(Node node, java.lang.String name, java.lang.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.
 java.net.URL getRequiredURL(Node node, java.lang.String name, java.net.URL base)
          Returns the same result as getURL except that a ParseException is thrown if the attribute is null or empty.
 java.util.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(java.io.InputStream input)
          Return the root node from the XML document in the specified input stream.
 SecurityDesc getSecurity(Node parent)
          Returns the security descriptor element.
 java.lang.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.
 java.net.URL getURL(Node node, java.lang.String name, java.net.URL base)
          Returns a URL object from a href string relative to the code base.
 Version getVersion(Node node, java.lang.String name, java.lang.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.
 java.lang.String[] splitString(java.lang.String source)
          Returns an array of substrings seperated by spaces (spaces escaped with backslash do not separate strings).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

    public Parser(JNLPFile file,
    java.net.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 Detail

getSupportedVersions

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


getFileVersion

    public Version getFileVersion()
Returns the file version.


getFileLocation

    public java.net.URL getFileLocation()
Returns the file location.


getCodeBase

    public java.net.URL getCodeBase()
Returns the codebase.


getSpecVersion

    public Version getSpecVersion()
Returns the specification version.


getResources

    public java.util.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

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

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

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

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

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

getInfo

    public java.util.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

addInfo

    protected void addInfo(InformationDesc info,
    Node node,
    java.lang.String mod,
    java.lang.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)

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

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

isTrustedEnvironment

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


getLauncher

    public java.lang.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

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

getComponent

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


getInstaller

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


splitString

    public java.lang.String[] splitString(java.lang.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.


getLocales

    public java.util.Locale[] getLocales(Node node)
Returns the Locale object(s) from a node's locale attribute.

Parameters:
node - the node with a locale attribute

getLocale

    public java.util.Locale getLocale(java.lang.String localeStr)
Returns a Locale from a single locale.


getSpanText

    public java.lang.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

getChildNode

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


getChildNodes

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


getRequiredURL

    public java.net.URL getRequiredURL(Node node,
    java.lang.String name,
    java.net.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

getURL

    public java.net.URL getURL(Node node,
    java.lang.String name,
    java.net.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,
    java.lang.String name,
    java.lang.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

getRequiredAttribute

    public java.lang.String getRequiredAttribute(Node node,
    java.lang.String name,
    java.lang.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

getAttribute

    public java.lang.String getAttribute(Node node,
    java.lang.String name,
    java.lang.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

getRootNode

    public static Node getRootNode(java.io.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

Homepage