Package net.sf.saxon.resource
Class AbstractResourceCollection
- java.lang.Object
-
- net.sf.saxon.resource.AbstractResourceCollection
-
- All Implemented Interfaces:
ResourceCollection
- Direct Known Subclasses:
CatalogCollection
,DirectoryCollection
,ExplicitCollection
,JarCollection
public abstract class AbstractResourceCollection extends java.lang.Object implements ResourceCollection
AbstractCollection is an abstract superclass for the various implementations of ResourceCollection within Saxon. It provides common services such as mapping of file extensions to MIME types, and mapping of MIME types to resource factories.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractResourceCollection.InputDetails
Information about a resource
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
collectionURI
protected Configuration
config
protected boolean
noExceptions
protected URIQueryParameters
params
-
Constructor Summary
Constructors Constructor Description AbstractResourceCollection(Configuration config)
Create a resource collection
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
checkNotNull(java.lang.String collectionURI, XPathContext context)
If the collectionURI is null, report that no default collection existsjava.lang.String
getCollectionURI()
Get the URI of the collectionprotected AbstractResourceCollection.InputDetails
getInputDetails(java.lang.String resourceURI)
Get details of a resource given the resource URIprotected java.lang.String
guessContentTypeFromContent(java.io.InputStream stream)
Attempt to establish the media type of a resource, given the actual content.protected java.lang.String
guessContentTypeFromName(java.lang.String resourceURI)
Attempt to establish the media type of a resource, given the resource URI.boolean
isStable(XPathContext context)
Ask whether the collection is stable.Resource
makeResource(XPathContext context, java.lang.String resourceURI)
Default method to make a resource, given a resource URIResource
makeResource(XPathContext context, AbstractResourceCollection.InputDetails details)
Internal method to make a resource for a single entry in the ZIP or JAR file.Resource
makeTypedResource(XPathContext context, Resource basicResource)
Given a resource whose type may be unknown, create a Resource of a specific type, for example an XML or JSON resourceprotected ParseOptions
optionsFromQueryParameters(URIQueryParameters params, XPathContext context)
Analyze URI query parameters and convert them to a set of parser optionsvoid
registerContentType(java.lang.String contentType, ResourceFactory factory)
Associate a media type with a resource factory.static ParseOptions
setupErrorHandlingForCollection(ParseOptions options, int onError, ErrorReporter oldErrorReporter)
boolean
stripWhitespace(SpaceStrippingRule rules)
Supply information about the whitespace stripping rules that apply to this collection.-
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.lib.ResourceCollection
getResources, getResourceURIs
-
-
-
-
Field Detail
-
config
protected Configuration config
-
collectionURI
protected java.lang.String collectionURI
-
params
protected URIQueryParameters params
-
noExceptions
protected boolean noExceptions
-
-
Constructor Detail
-
AbstractResourceCollection
public AbstractResourceCollection(Configuration config)
Create a resource collection- Parameters:
config
- the Saxon configuration
-
-
Method Detail
-
checkNotNull
public static void checkNotNull(java.lang.String collectionURI, XPathContext context) throws XPathException
If the collectionURI is null, report that no default collection exists- Parameters:
collectionURI
- the collection URI to be testedcontext
- XPath evaluation context- Throws:
XPathException
- if the collectionURI is null
-
getCollectionURI
public java.lang.String getCollectionURI()
Description copied from interface:ResourceCollection
Get the URI of the collection- Specified by:
getCollectionURI
in interfaceResourceCollection
- Returns:
- The URI as passed to the fn:collection() or fn:uri-collection() function, resolved if it is relative against the static base URI. If the collection() or uri-collection() function was called with no arguments (to get the "default collection") this will be the URI of the default collection registered with the Configuration.
-
isStable
public boolean isStable(XPathContext context)
Ask whether the collection is stable. This method should only be called after callingResourceCollection.getResources(XPathContext)
orResourceCollection.getResourceURIs(XPathContext)
- Specified by:
isStable
in interfaceResourceCollection
- Parameters:
context
- the XPath evaluation context.- Returns:
- true if the collection is defined to be stable, that is, if a subsequent call
on collection() with the same URI is guaranteed to return the same result. The method returns
true if the query parameter stable=yes is present in the URI, or if the configuration property
FeatureKeys.STABLE_COLLECTION_URI
is set.
-
registerContentType
public void registerContentType(java.lang.String contentType, ResourceFactory factory)
Associate a media type with a resource factory. Since 9.7.0.6 this registers the content type with the configuration, making the register of content types more accessible to applications.- Parameters:
contentType
- a media type or MIME type, for example application/xsd+xmlfactory
- a ResourceFactory used to parse (or otherwise process) resources of that type
-
optionsFromQueryParameters
protected ParseOptions optionsFromQueryParameters(URIQueryParameters params, XPathContext context)
Analyze URI query parameters and convert them to a set of parser options- Parameters:
params
- the query parameters extracted from the URIcontext
- the XPath evaluation context- Returns:
- a set of options to control document parsing
-
setupErrorHandlingForCollection
public static ParseOptions setupErrorHandlingForCollection(ParseOptions options, int onError, ErrorReporter oldErrorReporter)
-
getInputDetails
protected AbstractResourceCollection.InputDetails getInputDetails(java.lang.String resourceURI) throws XPathException
Get details of a resource given the resource URI- Parameters:
resourceURI
- the resource URI- Returns:
- details of the resource
- Throws:
XPathException
- if the information cannot be obtained
-
guessContentTypeFromName
protected java.lang.String guessContentTypeFromName(java.lang.String resourceURI)
Attempt to establish the media type of a resource, given the resource URI. This makes use ofURLConnection#guessContentTypeFromName
, and failing that the mapping from file extensions to media types held in the SaxonConfiguration
- Parameters:
resourceURI
- the resource URI- Returns:
- the media type if it can be gleaned, otherwise null.
-
guessContentTypeFromContent
protected java.lang.String guessContentTypeFromContent(java.io.InputStream stream)
Attempt to establish the media type of a resource, given the actual content. This makes use ofURLConnection#guessContentTypeFromStream
- Parameters:
stream
- the input stream. This should be positioned at the start; the reading position is not affected by the call.- Returns:
- the media type if it can be gleaned, otherwise null.
-
makeResource
public Resource makeResource(XPathContext context, AbstractResourceCollection.InputDetails details) throws XPathException
Internal method to make a resource for a single entry in the ZIP or JAR file. This involves making decisions about the type of resource. This method can be overridden in a user-defined subclass.- Parameters:
context
- The Saxon configurationdetails
- Details of the input.- Returns:
- a newly created Resource representing the content of this entry in the ZIP or JAR file
- Throws:
XPathException
-
makeTypedResource
public Resource makeTypedResource(XPathContext context, Resource basicResource) throws XPathException
Given a resource whose type may be unknown, create a Resource of a specific type, for example an XML or JSON resource- Parameters:
context
- the evaluation contextbasicResource
- the resource, whose type may be unknown- Returns:
- a Resource of a specific type
- Throws:
XPathException
- if a failure occurs (for example an XML or JSON parsing failure)
-
makeResource
public Resource makeResource(XPathContext context, java.lang.String resourceURI) throws XPathException
Default method to make a resource, given a resource URI- Parameters:
resourceURI
- the resource URI- Returns:
- the corresponding resource
- Throws:
XPathException
-
stripWhitespace
public boolean stripWhitespace(SpaceStrippingRule rules)
Supply information about the whitespace stripping rules that apply to this collection. This method will only be called when the collection() function is invoked from XSLT.- Parameters:
rules
- the space-stripping rules that apply to this collection, derived from the xsl:strip-space and xsl:preserve-space declarations in the stylesheet package containing the call to the collection() function.- Returns:
- true if the collection finder intends to take responsibility for whitespace stripping according to these rules; false if it wishes Saxon itself to post-process any returned XML documents to strip whitespace. Returning true may either indicate that the collection finder will strip whitespace before returning a document, or it may indicate that it does not wish the space stripping rules to be applied. The default (returned by this method if not overridden) is false.
-
-