Interface StringDocument

    • Field Detail

      • logger

        static final org.apache.logging.log4j.Logger logger
    • Method Detail

      • getContentAsString

        java.lang.String getContentAsString()
        Gets the document content as a string.
        Returns:
        the content of the document as a string.
      • cloneWithURI

        StringDocument cloneWithURI​(java.net.URI uri)
        Description copied from interface: FilterableDocument
        Gets a clone of the document with a different URI.
        Specified by:
        cloneWithURI in interface FilterableDocument
        Parameters:
        uri - the document returned document will have.
        Returns:
        A new document with the given URI.
      • cloneWithMetadata

        StringDocument cloneWithMetadata​(com.google.common.collect.ListMultimap<java.lang.String,​java.lang.String> metadata)
        Description copied from interface: FilterableDocument
        Gets a clone of the document with the given metadata.

        Note that the returned document will only have the metadata given as a paramater to this method. Typically the result of NoContentDocument.getCopyOfMetadata() should be manipulated then passed to this function to preserve existing metadata.

        Specified by:
        cloneWithMetadata in interface FilterableDocument
        Parameters:
        metadata - The only metadata that the returbed document will have.
        Returns:
        A new document with the given headers.
      • cloneWithStringContent

        StringDocument cloneWithStringContent​(DocumentType documentType,
                                              java.lang.String content)
        Creates a clone of the document with the given content and document type.
        Parameters:
        documentType - the type of content. Typically a predefined type from DocumentType should be used, otherwise a custom value can be built with DocumentType.fromContentType(String).
        content - The new content.
        Returns:
        a copy of the document with the new content and DocumentType.
      • getCharset

        java.util.Optional<java.nio.charset.Charset> getCharset()
        Charset of a StringDocument are always UTF-8, if the document contains any indication of charset it must be UTF-8
        Specified by:
        getCharset in interface NoContentDocument
        Returns:
        the charset of a document which is always UTF-8.
      • from

        static java.util.Optional<StringDocument> from​(FilterableDocument filterableDocument)
        Attempts to create a StingDocument from the given document.

        Makes a clone of the given document and converts the document content to a String. This will use the charset of the document if set otherwise it will guess the charset. If the charset could not be guessed or an error occurs while converting the content to a String then an optional empty is returned.

        Parameters:
        filterableDocument - the document to make a StringDocument from.
        Returns:
        A StringDocument copy of the given document or empty if a string document could not be created.
      • getOrGuessCharset

        static java.nio.charset.Charset getOrGuessCharset​(FilterableDocument filterableDocument)
        Gets the charset of the filterableDocument, if the charset is unknown this guesses the charset by looking at the raw bytes.
        Parameters:
        filterableDocument -
        Returns:
      • from

        static StringDocument from​(FilterableDocument filterableDocument,
                                   DocumentType documentType,
                                   java.lang.String content)
        Constructs a StringDocument from a FilterableDocument, with the given mimeType and content.

        This may be used when converting from binary to a string form, such as pdf to html.

        Parameters:
        filterableDocument - which the resulting document will be cloned from.
        documentType - of the given content.
        content - the new content of the document as a String.
        Returns:
        A StringDocument which is the same as the given filterableDocument except with the given documentType and content.