Package net.sf.saxon.java
Class JavaPlatform
- java.lang.Object
-
- net.sf.saxon.java.JavaPlatform
-
- All Implemented Interfaces:
Platform
- Direct Known Subclasses:
JavaPlatformPE
public class JavaPlatform extends java.lang.Object implements Platform
Implementation of the Platform class containing methods specific to the Java platform (as distinct from .NET). This is a singleton class with no instance data.
-
-
Constructor Summary
Constructors Constructor Description JavaPlatform()
The constructor is called during the static initialization of the Configuration
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFunctionLibraries(FunctionLibraryList list, Configuration config, int hostLanguage)
Add the platform-specific function libraries to a function library list.boolean
canReturnCollationKeys(StringCollator collation)
Given a collation, determine whether it is capable of returning collation keys.RegularExpression
compileRegularExpression(Configuration config, UnicodeString regex, java.lang.String flags, java.lang.String hostLanguage, java.util.List<java.lang.String> warnings)
Compile a regular expressionAtomicMatchKey
getCollationKey(SimpleCollation namedCollation, java.lang.String value)
Given a collation, get a collation key.java.lang.String
getDefaultCountry()
Get the default country for localization.IDynamicLoader
getDefaultDynamicLoader()
Get the default DynamicLoader for the platformjava.lang.String
getDefaultLanguage()
Get the default language for localization.ExternalObjectType
getExternalObjectType(Configuration config, NamespaceUri uri, java.lang.String localName)
Get a SchemaType representing a wrapped external (Java or .NET) objectjava.lang.String
getInstallationDirectory(java.lang.String edition, Configuration config)
Return the name of the directory in which the software is installed (if available)java.lang.String
getPlatformSuffix()
Get a suffix letter to add to the Saxon version number to identify the platformjava.lang.String
getPlatformVersion()
Get the platform versionboolean
hasICUCollator()
No ICU featuresboolean
hasICUNumberer()
Indicate whether the ICU library is available and supports Numberersvoid
initialize(Configuration config)
Perform platform-specific initialization of the configurationboolean
isDotNet()
Return true if this is the .NET platformboolean
isJava()
Return true if this is the Java platformboolean
JAXPStaticContextCheck(RetainedStaticContext retainedStaticContext, StaticContext sc)
Checks if the supplied static context is an instance of the JAXP static context.org.xml.sax.XMLReader
loadParser()
Get a parser by instantiating the SAXParserFactoryorg.xml.sax.XMLReader
loadParserForXmlFragments()
Get a parser suitable for parsing XML fragmentsjava.io.InputStream
locateResource(java.lang.String filename, java.util.List<java.lang.String> messages)
Read a resource file issued with the Saxon productStringCollator
makeCollation(Configuration config, java.util.Properties props, java.lang.String uri)
Obtain a collation with a given set of properties.ModuleURIResolver
makeStandardModuleURIResolver(Configuration config)
Make an instance of the default module URI resolver for this platformStringCollator
makeUcaCollator(java.lang.String uri, Configuration config)
If available, make a collation using the ICU-J Libraryvoid
registerAllBuiltInObjectModels(Configuration config)
Register all the external object models that are provided as standard with the relevant edition of Saxon for this ConfigurationActiveSource
resolveSource(javax.xml.transform.Source source, Configuration config)
Convert a Source to an ActiveSource.void
setDefaultSAXParserFactory(Configuration config)
Set the default XML parser to be loaded by the SAXParserFactory on this platform.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.Platform
showEmbeddedResources
-
-
-
-
Method Detail
-
getDefaultLanguage
public java.lang.String getDefaultLanguage()
Get the default language for localization.- Specified by:
getDefaultLanguage
in interfacePlatform
- Returns:
- the default language
-
getDefaultCountry
public java.lang.String getDefaultCountry()
Get the default country for localization.- Specified by:
getDefaultCountry
in interfacePlatform
- Returns:
- the default country
-
locateResource
public java.io.InputStream locateResource(java.lang.String filename, java.util.List<java.lang.String> messages)
Read a resource file issued with the Saxon product- Specified by:
locateResource
in interfacePlatform
- Parameters:
filename
- the filename of the file to be readmessages
- List to be populated with messages in the event of failure- Returns:
- an InputStream for reading the file/resource
-
JAXPStaticContextCheck
public boolean JAXPStaticContextCheck(RetainedStaticContext retainedStaticContext, StaticContext sc)
Checks if the supplied static context is an instance of the JAXP static context. On Java we create namespace information from the JAXP XPath static context. On the .NET platform we do nothing.- Specified by:
JAXPStaticContextCheck
in interfacePlatform
- Parameters:
retainedStaticContext
- the retained static contextsc
- the supplied static context- Returns:
- boolean
- Since:
- 9.7.0.5
-
initialize
public void initialize(Configuration config)
Perform platform-specific initialization of the configuration- Specified by:
initialize
in interfacePlatform
- Parameters:
config
- the Saxon Configuration
-
isJava
public boolean isJava()
Return true if this is the Java platform
-
isDotNet
public boolean isDotNet()
Return true if this is the .NET platform
-
getPlatformVersion
public java.lang.String getPlatformVersion()
Get the platform version- Specified by:
getPlatformVersion
in interfacePlatform
- Returns:
- the version of the platform, for example "Java version 1.5.09"
-
getPlatformSuffix
public java.lang.String getPlatformSuffix()
Get a suffix letter to add to the Saxon version number to identify the platform- Specified by:
getPlatformSuffix
in interfacePlatform
- Returns:
- "J" for Java, "N" for .NET, "CS" for SaxonCS
-
getDefaultDynamicLoader
public IDynamicLoader getDefaultDynamicLoader()
Get the default DynamicLoader for the platform- Specified by:
getDefaultDynamicLoader
in interfacePlatform
- Returns:
- the default DynamicLoader
-
loadParser
public org.xml.sax.XMLReader loadParser()
Get a parser by instantiating the SAXParserFactory- Specified by:
loadParser
in interfacePlatform
- Returns:
- the parser (XMLReader)
-
loadParserForXmlFragments
public org.xml.sax.XMLReader loadParserForXmlFragments()
Get a parser suitable for parsing XML fragmentsFor background, see bugs 4127 and 4253. The problem is that to implement parse-xml-fragment(), we need to set an EntityResolver on the returned parser. But if an Apache catalog resolver is in use, the JAXP system properties may be set so that JAXP returns a custom XMLReader supplied by the catalog resolver, and that XMLReader ignores any attempt to set an EntityResolver. So we bypass JAXP and try to load the built-in parser within the JDK, which we know we can trust; only if this fails (presumably because this is not the Oracle JDK) do we fall back to using a JAXP-supplied parser. And if this turns out to ignore
setEntityResolver()
calls, we're hosed.- Specified by:
loadParserForXmlFragments
in interfacePlatform
- Returns:
- the parser (XMLReader)
-
resolveSource
public ActiveSource resolveSource(javax.xml.transform.Source source, Configuration config) throws XPathException
Convert a Source to an ActiveSource. This method is present in the Platform because different Platforms accept different kinds of Source object.- Specified by:
resolveSource
in interfacePlatform
- Parameters:
source
- A source object, typically the source supplied as the first argument toTransformer.transform(Source, Result)
or similar methods.config
- The Configuration. This provides the SourceResolver with access to configuration information; it also allows the SourceResolver to invoke the resolveSource() method on the Configuration object as a fallback implementation.- Returns:
- a source object that Saxon knows how to process. Return null if the Source object is not recognized
- Throws:
XPathException
- if the Source object is recognized but cannot be processed
-
makeCollation
public StringCollator makeCollation(Configuration config, java.util.Properties props, java.lang.String uri) throws XPathException
Obtain a collation with a given set of properties. The set of properties is extensible and variable across platforms. Common properties with example values include lang=ed-GB, strength=primary, case-order=upper-first, ignore-modifiers=yes, alphanumeric=yes. Properties that are not supported are generally ignored; however some errors, such as failing to load a requested class, are fatal.- Specified by:
makeCollation
in interfacePlatform
- Parameters:
config
- the configuration objectprops
- the desired properties of the collationuri
- the collation URI- Returns:
- a collation with these properties
- Throws:
XPathException
- if a fatal error occurs
-
canReturnCollationKeys
public boolean canReturnCollationKeys(StringCollator collation)
Given a collation, determine whether it is capable of returning collation keys. The essential property of collation keys is that if two values are equal under the collation, then the collation keys are equal under the equals() method.- Specified by:
canReturnCollationKeys
in interfacePlatform
- Parameters:
collation
- the collation, provided as a Comparator- Returns:
- true if this collation can supply collation keys
-
getCollationKey
public AtomicMatchKey getCollationKey(SimpleCollation namedCollation, java.lang.String value)
Given a collation, get a collation key. The essential property of collation keys is that if two values are equal under the collation, then the collation keys are compare correctly under the equals() method.- Specified by:
getCollationKey
in interfacePlatform
- Parameters:
namedCollation
- the collation in usevalue
- the string whose collation key is required- Returns:
- a representation of the collation key, such that two collation keys are equal() if and only if the string values they represent are equal under the specified collation.
- Throws:
java.lang.ClassCastException
- if the collation is not one that is capable of supplying collation keys (this should have been checked in advance)
-
hasICUCollator
public boolean hasICUCollator()
No ICU features- Specified by:
hasICUCollator
in interfacePlatform
- Returns:
- true if the ICU library class for collations appears to be loaded
-
hasICUNumberer
public boolean hasICUNumberer()
Description copied from interface:Platform
Indicate whether the ICU library is available and supports Numberers- Specified by:
hasICUNumberer
in interfacePlatform
- Returns:
- true if the ICU library class for rule-based numbering appears to be loaded
-
makeUcaCollator
public StringCollator makeUcaCollator(java.lang.String uri, Configuration config) throws XPathException
If available, make a collation using the ICU-J Library- Specified by:
makeUcaCollator
in interfacePlatform
- Parameters:
uri
- the collation URI (which will always be a UCA collation URI as defined in XSLT 3.0)config
- the Saxon configuration- Returns:
- the collation, or null if not available
- Throws:
XPathException
- if the URI is malformed in some way
-
compileRegularExpression
public RegularExpression compileRegularExpression(Configuration config, UnicodeString regex, java.lang.String flags, java.lang.String hostLanguage, java.util.List<java.lang.String> warnings) throws XPathException
Compile a regular expression- Specified by:
compileRegularExpression
in interfacePlatform
- Parameters:
config
- the Saxon configurationregex
- the regular expression as a stringflags
- the value of the flags attributehostLanguage
- one of "XSD10", "XSD11", "XP20" or "XP30". Also allow combinations, e.g. "XP20/XSD11".warnings
- if supplied, may capture warnings from the regular expression compiler- Returns:
- the compiled regular expression
- Throws:
XPathException
- if the regular expression or the flags are invalid
-
addFunctionLibraries
public void addFunctionLibraries(FunctionLibraryList list, Configuration config, int hostLanguage)
Add the platform-specific function libraries to a function library list. This version of the method does nothing- Parameters:
list
- the function library list that is to be extendedconfig
- the ConfigurationhostLanguage
- the host language, for example Configuration.XQUERY
-
getExternalObjectType
public ExternalObjectType getExternalObjectType(Configuration config, NamespaceUri uri, java.lang.String localName)
Description copied from interface:Platform
Get a SchemaType representing a wrapped external (Java or .NET) object- Specified by:
getExternalObjectType
in interfacePlatform
- Parameters:
config
- the Saxon Configurationuri
- the namespace URI of the schema typelocalName
- the local name of the schema type- Returns:
- the SchemaType object representing this type
-
getInstallationDirectory
public java.lang.String getInstallationDirectory(java.lang.String edition, Configuration config)
Return the name of the directory in which the software is installed (if available)- Specified by:
getInstallationDirectory
in interfacePlatform
- Parameters:
edition
- The edition of the software that is loaded ("HE", "PE", or "EE")config
- the Saxon configuration- Returns:
- the name of the directory in which Saxon is installed, if available, or null otherwise
-
registerAllBuiltInObjectModels
public void registerAllBuiltInObjectModels(Configuration config)
Register all the external object models that are provided as standard with the relevant edition of Saxon for this Configuration- Specified by:
registerAllBuiltInObjectModels
in interfacePlatform
- Parameters:
config
- the Saxon configuration- Since:
- 9.3
-
setDefaultSAXParserFactory
public void setDefaultSAXParserFactory(Configuration config)
Set the default XML parser to be loaded by the SAXParserFactory on this platform. Needed because the Apache catalog resolver uses the SAXParserFactory to instantiate a parser, and if not customized this causes a failure on the .NET platform.- Specified by:
setDefaultSAXParserFactory
in interfacePlatform
- Parameters:
config
- the Saxon configuration- Since:
- 9.4
-
makeStandardModuleURIResolver
public ModuleURIResolver makeStandardModuleURIResolver(Configuration config)
Description copied from interface:Platform
Make an instance of the default module URI resolver for this platform- Specified by:
makeStandardModuleURIResolver
in interfacePlatform
- Parameters:
config
- the Saxon configuration- Returns:
- an instance of ModuleURIResolver
-
-