Package net.sourceforge.jnlp
Class Parser
- java.lang.Object
-
- net.sourceforge.jnlp.Parser
-
public final class Parser extends java.lang.ObjectContains methods to parse an XML document into a JNLPFile. Implements JNLP specification version 1.0.- Version:
- $Revision: 1.13 $
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowExtensionswhether to allow extensions to the JNLP specificationprivate static java.util.regex.PatternanyWhiteSpaceprivate java.net.URLbasethe base URL that all hrefs are relative toprivate java.net.URLcodebasethe codebase URLprivate JNLPFilefilethe file referenceprivate java.net.URLfileLocationthe file URLprivate static LoggerLOGprivate static java.lang.StringMAINCLASSprivate XmlNoderootthe root nodeprivate VersionStringspecThe versions of the specification that this JNLP file requires.private booleanstrictwhether to throw errors on non-fatal errors.
-
Constructor Summary
Constructors Constructor Description Parser(JNLPFile file, java.net.URL base, XmlNode root, ParserSettings settings)Create a parser for the JNLP file.Parser(JNLPFile file, java.net.URL base, XmlNode root, ParserSettings settings, java.net.URL codebase)Create a parser for the JNLP file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddInfo(InformationDesc info, XmlNode node, java.lang.String mod, java.lang.Object value)Adds a key,value pair to the information object.private java.net.URLaddSlash(java.net.URL source)Returns a URL with a trailing / appended to it if there is no trailing slash on the specified URL.(package private) voidcheckForInformation()Make sure a title and vendor are present and nonempty and localized as best matching as possible for the JVM's current locale.private static voidcheckJreVersionWithSystemProperty(VersionString version, boolean strict)private java.lang.StringcleanMainClassAttribute(java.lang.String main)(package private) AppletDescgetAppletDesc(XmlNode node)private intgetAppletDescSize(java.lang.String wh, XmlNode node)(package private) ApplicationDescgetApplicationDesc(ApplicationType applicationType, XmlNode node)private AssociationDescgetAssociation(XmlNode node)java.net.URLgetCodeBase()(package private) ComponentDescgetComponent(XmlNode parent)EntryPointgetEntryPointDesc(XmlNode parent)Load the entry point descriptor element.private ExtensionDescgetExtension(XmlNode node)java.net.URLgetFileLocation()Returns the file location.VersionIdgetFileVersion()Returns the version of the application being launched, as well as the version of the JNLP file itself.private IconDescgetIcon(XmlNode node)private static IconKindgetIconKind(XmlNode node)private InformationDescgetInformationDesc(XmlNode node)Returns the information element at the specified node.java.util.List<InformationDesc>getInformationDescs(XmlNode parent)Search through the information elements in the order specified in the JNLP file (resp.(package private) InstallerDescgetInstallerDesc(XmlNode node)private JARDescgetJAR(XmlNode node)Returns the JAR element at the specified node.private JREDescgetJRE(XmlNode node)private java.util.Locale[]getLocales(XmlNode node)Returns the locales for which the information element should be used.private java.lang.StringgetMainClass(XmlNode node, boolean required)private MenuDescgetMenu(XmlNode node)Returns the menu element at the specified node.private java.lang.StringgetOptionalMainClass(XmlNode node)private PackageDescgetPackage(XmlNode node)private PropertyDescgetProperty(XmlNode node)private RelatedContentDescgetRelatedContent(XmlNode node)java.util.List<ResourcesDesc>getResources(XmlNode parent, boolean j2se)private ResourcesDescgetResourcesDesc(XmlNode node, boolean j2se)SecurityDescgetSecurity(XmlNode parent)private ShortcutDescgetShortcut(XmlNode node)VersionStringgetSpecVersion()Returns the versions of the specification that this JNLP file requires.(package private) UpdateDescgetUpdate(XmlNode parent)private VersionStringgetVersionString(XmlNode node, java.lang.String attributeName, java.lang.String defaultValue)private booleanisTrustedEnvironment()Returns whether the JNLP file requests a trusted execution environment.private java.lang.String[]splitString(java.lang.String source)private static inttryRelativeAbsoluteSize(java.lang.String wh, java.lang.String readedSize)
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
MAINCLASS
private static java.lang.String MAINCLASS
-
anyWhiteSpace
private static final java.util.regex.Pattern anyWhiteSpace
-
file
private final JNLPFile file
the file reference
-
root
private final XmlNode root
the root node
-
spec
private final VersionString spec
The versions of the specification that this JNLP file requires. The value of the attribute is specified as a version string, see JSR-56, section 3.1
-
base
private final java.net.URL base
the base URL that all hrefs are relative to
-
codebase
private java.net.URL codebase
the codebase URL
-
fileLocation
private final java.net.URL fileLocation
the file URL
-
strict
private final boolean strict
whether to throw errors on non-fatal errors.
-
allowExtensions
private final boolean allowExtensions
whether to allow extensions to the JNLP specification
-
-
Constructor Detail
-
Parser
public Parser(JNLPFile file, java.net.URL base, XmlNode root, ParserSettings settings) 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 referencebase- if codebase is not specified, a default base for relative URLsroot- the root nodesettings- the parser settings to use when parsing the JNLP file- Throws:
ParseException- if the JNLP file is invalid
-
Parser
public Parser(JNLPFile file, java.net.URL base, XmlNode root, ParserSettings settings, java.net.URL codebase) 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 referencebase- if codebase is not specified, a default base for relative URLsroot- the root nodesettings- the parser settings to use when parsing the JNLP filecodebase- codebase to use if we did not parse one from JNLP file.- Throws:
ParseException- if the JNLP file is invalid
-
-
Method Detail
-
addSlash
private java.net.URL addSlash(java.net.URL source)
Returns a URL with a trailing / appended to it if there is no trailing slash on the specified URL.
-
getFileVersion
public VersionId getFileVersion()
Returns the version of the application being launched, as well as the version of the JNLP file itself.- Returns:
- version of file
-
getFileLocation
public java.net.URL getFileLocation()
Returns the file location.- Returns:
- url of source file
-
getCodeBase
public java.net.URL getCodeBase()
- Returns:
- the codebase.
-
getSpecVersion
public VersionString getSpecVersion()
Returns the versions of the specification that this JNLP file requires. The value of the attribute is specified as a version string, see JSR-56, section 3.1- Returns:
- the specification version.
-
getUpdate
UpdateDesc getUpdate(XmlNode parent) throws ParseException
- Throws:
ParseException
-
getResources
public java.util.List<ResourcesDesc> getResources(XmlNode parent, boolean j2se) throws ParseException
- Parameters:
parent- the parent node (either jnlp or j2se)j2se- true if the resources are located under a j2se or java node- Returns:
- all of the ResourcesDesc elements under the specified node (jnlp or j2se).
- Throws:
ParseException- if the JNLP file is invalid
-
getResourcesDesc
private ResourcesDesc getResourcesDesc(XmlNode node, boolean j2se) throws ParseException
- Parameters:
node- the resources nodej2se- true if the resources are located under a j2se or java node- Returns:
- the ResourcesDesc element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
getJRE
private JREDesc getJRE(XmlNode node) throws ParseException
- Parameters:
node- the j2se/java node- Returns:
- the JRE element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
checkJreVersionWithSystemProperty
private static void checkJreVersionWithSystemProperty(VersionString version, boolean strict)
-
getJAR
private JARDesc getJAR(XmlNode 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
private ExtensionDesc getExtension(XmlNode node) throws ParseException
- Parameters:
node- the extension node- Returns:
- the Extension element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
getProperty
private PropertyDesc getProperty(XmlNode node) throws ParseException
- Parameters:
node- the property node- Returns:
- the Property element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
getPackage
private PackageDesc getPackage(XmlNode node) throws ParseException
- Parameters:
node- the package node- Returns:
- the Package element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
checkForInformation
void checkForInformation() throws RequiredElementExceptionMake sure a title and vendor are present and nonempty and localized as best matching as possible for the JVM's current locale. Fallback to a generalized title and vendor otherwise. If none is found, throw an exception. Additionally prints homepage, description, title and vendor to stdout if in Debug mode.- Throws:
RequiredElementException
-
getInformationDescs
public java.util.List<InformationDesc> getInformationDescs(XmlNode parent) throws ParseException
Search through the information elements in the order specified in the JNLP file (resp. the specified node). For each information element, it checks if the value specified in the locale attribute matches the current locale. If a match is found, the values specified in that information element will be used, possibly overriding values found in previous information elements. Thus, the locale-independent information needs only to be specified once, in the information element without the locale attribute.- Parameters:
parent- the parent node containing the information elements in the order specified in the JNLP file- Returns:
- all of the information elements under the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
getInformationDesc
private InformationDesc getInformationDesc(XmlNode node) throws ParseException
Returns the information element at the specified node.- Parameters:
node- the node containing the information element as specified in the JNLP file- Returns:
- the information element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
addInfo
protected void addInfo(InformationDesc info, XmlNode node, java.lang.String mod, java.lang.Object value)
Adds a key,value pair to the information object.- Parameters:
info- the information objectnode- node name to be used as the keymod- key name appended with "-"+mod if not nullvalue- the info object to add (icon or string)
-
getIcon
private IconDesc getIcon(XmlNode node) throws ParseException
- Parameters:
node- the icon node- Returns:
- the icon element at the specified node.
- Throws:
ParseException- if the JNLP file is invalid
-
getSecurity
public SecurityDesc getSecurity(XmlNode parent) throws ParseException
- Parameters:
parent- the parent node- Returns:
- the security descriptor element. If no security element was specified in the JNLP file then a SecurityDesc with applet permissions is returned.
- Throws:
ParseException- if the JNLP file is invalid
-
isTrustedEnvironment
private boolean isTrustedEnvironment()
Returns whether the JNLP file requests a trusted execution environment.
-
getEntryPointDesc
public EntryPoint getEntryPointDesc(XmlNode parent) throws ParseException
Load the entry point descriptor element.- Parameters:
parent- the parent node- Returns:
- the entry point descriptor element, never
null - Throws:
ParseException- if the JNLP file is invalid- See Also:
EntryPoint
-
getAppletDesc
AppletDesc getAppletDesc(XmlNode node) throws ParseException
- Parameters:
node-- Returns:
- the applet descriptor.
- Throws:
ParseException- if the JNLP file is invalid
-
getAppletDescSize
private int getAppletDescSize(java.lang.String wh, XmlNode node) throws ParseException- Throws:
ParseException
-
tryRelativeAbsoluteSize
private static int tryRelativeAbsoluteSize(java.lang.String wh, java.lang.String readedSize)
-
getApplicationDesc
ApplicationDesc getApplicationDesc(ApplicationType applicationType, XmlNode node) throws ParseException
- Parameters:
node-- Returns:
- the application descriptor.
- Throws:
ParseException- if the JNLP file is invalid
-
getComponent
ComponentDesc getComponent(XmlNode parent) throws ParseException
- Parameters:
parent-- Returns:
- the component descriptor.
- Throws:
ParseException
-
getInstallerDesc
InstallerDesc getInstallerDesc(XmlNode node)
- Parameters:
node-- Returns:
- the installer descriptor.
-
getAssociation
private AssociationDesc getAssociation(XmlNode node) throws ParseException
- Parameters:
node-- Returns:
- the association descriptor.
- Throws:
ParseException
-
getShortcut
private ShortcutDesc getShortcut(XmlNode node) throws ParseException
- Returns:
- the shortcut descriptor.
- Throws:
ParseException
-
getMenu
private MenuDesc getMenu(XmlNode node)
Returns the menu element at the specified node.- Returns:
- the menu element at the specified node
-
getRelatedContent
private RelatedContentDesc getRelatedContent(XmlNode node) throws ParseException
- Returns:
- the related-content descriptor.
- Throws:
ParseException
-
splitString
private java.lang.String[] splitString(java.lang.String source)
- Returns:
- an array of substrings separated 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
private java.util.Locale[] getLocales(XmlNode node) throws ParseException
Returns the locales for which the information element should be used. Several locales can be specified, separated with spaces.- Parameters:
node- the node with a locale attribute- Returns:
- the Locale object(s) from a node's locale attribute.
- Throws:
ParseException
-
getVersionString
private VersionString getVersionString(XmlNode node, java.lang.String attributeName, java.lang.String defaultValue)
- Parameters:
node- the nodeattributeName- the attribute namedefaultValue- default if no such attribute- Returns:
- a version-string from the specified attribute and default value.
-
getOptionalMainClass
private java.lang.String getOptionalMainClass(XmlNode node)
-
getMainClass
private java.lang.String getMainClass(XmlNode node, boolean required) throws ParseException
- Throws:
ParseException
-
cleanMainClassAttribute
private java.lang.String cleanMainClassAttribute(java.lang.String main) throws ParseException- Throws:
ParseException
-
-