Class DocumentLoader

java.lang.Object
com.github.jsonldjava.core.DocumentLoader

public class DocumentLoader extends Object
Resolves URLs to RemoteDocuments. Subclass this class to change the behaviour of loadDocument to suit your purposes.
  • Field Details

    • m_injectedDocs

      private final Map<String,Object> m_injectedDocs
    • DISALLOW_REMOTE_CONTEXT_LOADING

      public static final String DISALLOW_REMOTE_CONTEXT_LOADING
      Identifies a system property that can be set to "true" in order to disallow remote context loading.
      See Also:
    • httpClient

      private volatile org.apache.http.impl.client.CloseableHttpClient httpClient
  • Constructor Details

    • DocumentLoader

      public DocumentLoader()
  • Method Details

    • addInjectedDoc

      public DocumentLoader addInjectedDoc(String url, String doc) throws JsonLdError
      Avoid resolving a document by instead using the given serialised representation.
      Parameters:
      url - The URL this document represents.
      doc - The serialised document as a String
      Returns:
      This object for fluent addition of other injected documents.
      Throws:
      JsonLdError - If loading of the document failed for any reason.
    • loadDocument

      public RemoteDocument loadDocument(String url) throws JsonLdError
      Loads the URL if possible, returning it as a RemoteDocument.
      Parameters:
      url - The URL to load
      Returns:
      The resolved URL as a RemoteDocument
      Throws:
      JsonLdError - If there are errors loading or remote context loading has been disallowed.
    • getHttpClient

      public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
      Get the CloseableHttpClient which will be used by this DocumentLoader to resolve HTTP and HTTPS resources.
      Returns:
      The CloseableHttpClient which this DocumentLoader uses.
    • setHttpClient

      public void setHttpClient(org.apache.http.impl.client.CloseableHttpClient nextHttpClient)
      Call this method to override the default CloseableHttpClient provided by JsonUtils.getDefaultHttpClient.
      Parameters:
      nextHttpClient - The CloseableHttpClient to replace the default with.