Class JsonDocument

  • All Implemented Interfaces:
    Document

    public final class JsonDocument
    extends java.lang.Object
    implements Document
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private JsonDocument​(MediaType type, java.lang.String profile, jakarta.json.JsonStructure structure)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean accepts​(MediaType contentType)  
      private static void assertContentType​(MediaType contentType)  
      private static JsonDocument doParse​(MediaType contentType, jakarta.json.stream.JsonParser parser)  
      MediaType getContentType()
      The Content-Type of the loaded document, exclusive of any optional parameters.
      java.net.URI getContextUrl()
      The value of the HTTP Link header when profile attribute matches http://www.w3.org/ns/json-ld#context.
      java.net.URI getDocumentUrl()
      The final URI of the loaded document.
      java.util.Optional<jakarta.json.JsonStructure> getJsonContent()
      Get the document content as parsed JsonStructure.
      java.util.Optional<java.lang.String> getProfile()
      The value of any profile parameter retrieved as part of the original Document.getContentType().
      static JsonDocument of​(jakarta.json.JsonStructure structure)
      Create a new document from JsonStructure.
      static JsonDocument of​(java.io.InputStream is)
      Create a new document from content provided by InputStream.
      static JsonDocument of​(java.io.Reader reader)
      Create a new document from content provided by Reader.
      static JsonDocument of​(MediaType contentType, jakarta.json.JsonStructure structure)
      Create a new document from JsonStructure.
      static JsonDocument of​(MediaType contentType, java.io.InputStream is)
      Create a new document from content provided by InputStream.
      static JsonDocument of​(MediaType contentType, java.io.Reader reader)
      Create a new document from content provided by Reader.
      void setContextUrl​(java.net.URI contextUrl)  
      void setDocumentUrl​(java.net.URI documentUrl)  
      • Methods inherited from class java.lang.Object

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

      • contentType

        private final MediaType contentType
      • structure

        private final jakarta.json.JsonStructure structure
      • profile

        private final java.lang.String profile
      • documentUrl

        private java.net.URI documentUrl
      • contentUrl

        private java.net.URI contentUrl
    • Constructor Detail

      • JsonDocument

        private JsonDocument​(MediaType type,
                             java.lang.String profile,
                             jakarta.json.JsonStructure structure)
    • Method Detail

      • of

        public static JsonDocument of​(jakarta.json.JsonStructure structure)
        Create a new document from JsonStructure. Sets MediaType.JSON as the content type.
        Parameters:
        structure - representing parsed JSON content
        Returns:
        Document representing JSON content
      • of

        public static JsonDocument of​(MediaType contentType,
                                      jakarta.json.JsonStructure structure)
        Create a new document from JsonStructure.
        Parameters:
        contentType - reflecting the provided JsonStructure, e.g. MediaType.JSON_LD, any JSON based media type is allowed
        structure - representing parsed JSON content
        Returns:
        Document representing JSON content
      • of

        public static JsonDocument of​(java.io.InputStream is)
                               throws JsonLdError
        Create a new document from content provided by InputStream. Sets MediaType.JSON as the content type.
        Parameters:
        is - representing parsed JSON content
        Returns:
        Document representing JSON document
        Throws:
        JsonLdError
      • of

        public static JsonDocument of​(MediaType contentType,
                                      java.io.InputStream is)
                               throws JsonLdError
        Create a new document from content provided by InputStream.
        Parameters:
        contentType - reflecting the provided InputStream content, e.g. MediaType.JSON_LD, any JSON based media type is allowed
        is - providing JSON content
        Returns:
        Document representing JSON document
        Throws:
        JsonLdError
      • of

        public static JsonDocument of​(java.io.Reader reader)
                               throws JsonLdError
        Create a new document from content provided by Reader. Sets MediaType.JSON as the content type.
        Parameters:
        reader - providing JSON content
        Returns:
        Document representing JSON document
        Throws:
        JsonLdError
      • of

        public static JsonDocument of​(MediaType contentType,
                                      java.io.Reader reader)
                               throws JsonLdError
        Create a new document from content provided by Reader.
        Parameters:
        contentType - reflecting the provided content, e.g. MediaType.JSON_LD, any JSON based media type is allowed
        reader - providing JSON content
        Returns:
        Document representing JSON document
        Throws:
        JsonLdError
      • accepts

        public static boolean accepts​(MediaType contentType)
      • assertContentType

        private static void assertContentType​(MediaType contentType)
      • getJsonContent

        public java.util.Optional<jakarta.json.JsonStructure> getJsonContent()
        Description copied from interface: Document
        Get the document content as parsed JsonStructure.
        Specified by:
        getJsonContent in interface Document
        Returns:
        JsonStructure or Optional.empty() if document content is not JSON based
      • getContentType

        public MediaType getContentType()
        Description copied from interface: Document
        The Content-Type of the loaded document, exclusive of any optional parameters.
        Specified by:
        getContentType in interface Document
        Returns:
        Content-Type of the loaded document, never null
      • getContextUrl

        public java.net.URI getContextUrl()
        Description copied from interface: Document
        The value of the HTTP Link header when profile attribute matches http://www.w3.org/ns/json-ld#context.
        Specified by:
        getContextUrl in interface Document
        Returns:
        attached URI referencing document context or null if not available
      • setContextUrl

        public void setContextUrl​(java.net.URI contextUrl)
        Specified by:
        setContextUrl in interface Document
      • getDocumentUrl

        public java.net.URI getDocumentUrl()
        Description copied from interface: Document
        The final URI of the loaded document.
        Specified by:
        getDocumentUrl in interface Document
        Returns:
        URI of the loaded document or null if not available
      • setDocumentUrl

        public void setDocumentUrl​(java.net.URI documentUrl)
        Specified by:
        setDocumentUrl in interface Document
      • getProfile

        public java.util.Optional<java.lang.String> getProfile()
        Description copied from interface: Document
        The value of any profile parameter retrieved as part of the original Document.getContentType().
        Specified by:
        getProfile in interface Document
        Returns:
        document profile or Optional.empty()