Class StaticDocumentLoader

java.lang.Object
de.wwu.scdh.annotation.selection.utils.StaticDocumentLoader
All Implemented Interfaces:
com.apicatalog.jsonld.loader.DocumentLoader

public class StaticDocumentLoader extends Object implements com.apicatalog.jsonld.loader.DocumentLoader
The StaticDocumentLoader is a DocumentLoader that returns local assets instead of remote one. It is configured with a resource mapping that maps URIs to local assets. Its purpose is to speed up JSON-LD processing with version pinned contexts, as for Web Annotations.

The loader delegated to a fallback loader when the requested URI is not in the resource mapping.

The structure of the resource mapping JSON file:

     {
       "https://www.w3.org/ns/anno.jsonld": {
         "path": "anno.jsonld"
       },
       "http://www.w3.org/ns/anno.jsonld": {
         "path": "anno.jsonld"
       }
     }
 
  • Field Details

    • CONTEXT_MAPPING

      public static final URL CONTEXT_MAPPING
      A default context mapping resource.
  • Constructor Details

    • StaticDocumentLoader

      public StaticDocumentLoader(File contextMap, com.apicatalog.jsonld.loader.DocumentLoader fallbackLoader, boolean delegateOnError)
      Creates a new StaticDocumentLoader from a resource mapping given by File.
      Parameters:
      contextMap - - a JSON
      invalid @link
      {@link File>
      } with the resource mapping
      fallbackLoader - - a DocumentLoader used to handle request for non-mapped resources
      delegateOnError - - whether to delegate the request to the fallback, when loading of a local asset failed.
    • StaticDocumentLoader

      public StaticDocumentLoader()
      Creates a new StaticDocumentLoader from the CONTEXT_MAPPING.
  • Method Details

    • loadDocument

      public com.apicatalog.jsonld.document.Document loadDocument(URI url, com.apicatalog.jsonld.loader.DocumentLoaderOptions options) throws com.apicatalog.jsonld.JsonLdError
      Specified by:
      loadDocument in interface com.apicatalog.jsonld.loader.DocumentLoader
      Throws:
      com.apicatalog.jsonld.JsonLdError
    • hasLocal

      public boolean hasLocal(URI uri)
      Tells whether this instance has a local version for a URI.
      Parameters:
      uri - - the remote URI
      Returns:
      - true if a local version is available.