Class StandardCollectionFinder

  • All Implemented Interfaces:
    CollectionFinder

    public class StandardCollectionFinder
    extends java.lang.Object
    implements CollectionFinder
    Default implementation of the CollectionFinder interface. The standard CollectionFinder recognizes four types of collection:

    1. Any URI may be explicitly registered and associated with an instance of ResourceCollection
    2. If the file: URI scheme is used, and the relevant file identifies a directory, the directory is treated as a collection: it is returned as an instance of DirectoryCollection
    3. If the URI ends with ".jar" or ".zip", or more generally, if the method isJarFileURI(String) returns true, the URI is treated as identifying a JAR or ZIP archive, whose contents form the resources in the collection: it is returned as an instance of JarCollection
    4. In all other cases, the URI is treated as the URI of an XML document listing the URIs of the resources in the collection, which are then retrieved using the URIResolver
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkFileExists​(java.io.File file, java.net.URI resolvedURI, XPathContext context)  
      static void checkNotNull​(java.lang.String collectionURI, XPathContext context)
      If the collectionURI is null, report that no default collection exists
      ResourceCollection findCollection​(XPathContext context, java.lang.String collectionURI)
      Locate the collection of resources corresponding to a collection URI.
      protected boolean isJarFileURI​(java.lang.String collectionURI)
      Ask whether the collection URI should be interpreted as identifying a JAR (or ZIP) file.
      void registerCollection​(java.lang.String collectionURI, ResourceCollection collection)
      Register a specific URI and bind it to a specific ResourceCollection
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StandardCollectionFinder

        public StandardCollectionFinder()
    • Method Detail

      • registerCollection

        public void registerCollection​(java.lang.String collectionURI,
                                       ResourceCollection collection)
        Register a specific URI and bind it to a specific ResourceCollection
        Parameters:
        collectionURI - the collection URI to be registered. Must not be null.
        collection - the ResourceCollection to be associated with this URI. Must not be null.
      • findCollection

        public ResourceCollection findCollection​(XPathContext context,
                                                 java.lang.String collectionURI)
                                          throws XPathException
        Locate the collection of resources corresponding to a collection URI.
        Specified by:
        findCollection in interface CollectionFinder
        Parameters:
        context - The XPath dynamic evaluation context
        collectionURI - The collection URI: an absolute URI, formed by resolving the argument supplied to the fn:collection or fn:uri-collection against the static base URI
        Returns:
        a ResourceCollection object representing the resources in the collection identified by this collection URI
        Throws:
        XPathException - if the collection URI cannot be resolved to a collection
      • 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 tested
        context - XPath evaluation context
        Throws:
        XPathException - if the collectionURI is null
      • isJarFileURI

        protected boolean isJarFileURI​(java.lang.String collectionURI)
        Ask whether the collection URI should be interpreted as identifying a JAR (or ZIP) file. This method is provided so that it can be overridden in subclasses. The default implementation returns true if the collection URI ends with the extension ".jar", ".zip", or ".docx", or if it is a URI using the "jar" scheme.

        The set of URIs recognized as ZIP collections can also be extended by setting the configuration property Feature.ZIP_URI_PATTERN.

        Parameters:
        collectionURI - the requested absolute collection URI
        Returns:
        true if the collection URI should be interpreted as a JAR or ZIP file