com.marklogic.xcc

## Class ContentFactory

- java.lang.Object
- - com.marklogic.xcc.ContentFactory

-     public class ContentFactory
      extends java.lang.Object

  A helper class for creating instances of `Content`.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Content` | `newContent(java.lang.String uri, byte[] documentBytes, ContentCreateOptions createOptions)` Create a new `Content` object from a byte array.
    `static Content` | `newContent(java.lang.String uri, byte[] documentBytes, int offset, int length, ContentCreateOptions createOptions)` Create a new `Content` object from a subset of a byte array.
    `static Content` | `newContent(java.lang.String uri, org.w3c.dom.Document document, ContentCreateOptions createOptions)` Create a new `Content` object from a W3C DOM `Document` object.
    `static Content` | `newContent(java.lang.String uri, java.io.File documentFile, ContentCreateOptions createOptions)` Create a new `Content` object from a File object.
    `static Content` | `newContent(java.lang.String uri, java.io.InputStream documentStream, ContentCreateOptions createOptions)` Create a new `Content` object by consuming the given InputStream and buffereing it in memory.
    `static Content` | `newContent(java.lang.String uri, org.w3c.dom.Node documentNode, ContentCreateOptions createOptions)` Create a new `Content` object from a W3C DOM `Node` object.
    `static Content` | `newContent(java.lang.String uri, java.io.RandomAccessFile documentFile, ContentCreateOptions createOptions)` Create a new `Content` object from a RandomAccessFile object.
    `static Content` | `newContent(java.lang.String uri, java.lang.String documentString, ContentCreateOptions createOptions)` Create a new `Content` object from a String.
    `static Content` | `newContent(java.lang.String uri, java.net.URI documentUri, ContentCreateOptions createOptions)` Create a new `Content` object from a URI, buffering so that it's rewindable and only accesses the URL one time.
    `static Content` | `newContent(java.lang.String uri, java.net.URL documentUrl, ContentCreateOptions createOptions)` Create a new `Content` object from a URI, buffering so that it's rewindable and only accesses the URL one time.
    `static Content` | `newContent(java.lang.String uri, XdmNode documentNode, ContentCreateOptions createOptions)` Create a new `Content` object from an `XdmNode`.
    `static Content` | `newJsonContent(java.lang.String uri, com.fasterxml.jackson.databind.JsonNode documentNode, ContentCreateOptions createOptions)` Create a new `Content` object from a Jackson `Node` object.
    `static Content` | `newUnBufferedContent(java.lang.String uri, java.io.InputStream documentStream, ContentCreateOptions createOptions)` Create a new non-rewindable `Content` object for the given InputStream.
    `static Content` | `newUnBufferedContent(java.lang.String uri, java.net.URI documentUri, ContentCreateOptions createOptions)` Create a new, non-rewindable `Content` object from a `URI`.
    `static Content` | `newUnBufferedContent(java.lang.String uri, java.net.URL documentUrl, ContentCreateOptions createOptions)` Create a new, non-rewindable `Content` object from a `URL`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           org.w3c.dom.Document document,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from a W3C DOM `Document` object. If not explicitly overridden, the document format will be set to XML. This factory method makes use of the standard JAX `TransformerFactory` facility to serialize the DOM to a UTF-8-encoded byte stream. See `TransformerFactory.newInstance()` for information on how to customize the transformer implementation.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `document` - A W3C DOM `Document` object which is the content.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           org.w3c.dom.Node documentNode,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from a W3C DOM `Node` object.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content. If not explicitly overridden, the document format will be set to XML. This factory method makes use of the standard JAX `TransformerFactory` facility to serialize the DOM to a UTF-8-encoded byte stream. See `TransformerFactory.newInstance()` for information on how to customize the transformer implementation.
        `documentNode` - A W3C DOM `Node` object which is the content. Only Nodes of type Element or Text are valid.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`

    - #### newJsonContent

          public static Content newJsonContent(java.lang.String uri,
                                               com.fasterxml.jackson.databind.JsonNode documentNode,
                                               ContentCreateOptions createOptions)

      Create a new `Content` object from a Jackson `Node` object.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content. If not explicitly overridden, the document format will be set to JSON.
        `documentNode` - A Jackson `Node` object which is the content. Only Nodes of type Array or Object are valid.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           XdmNode documentNode,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from an `XdmNode`. This object may have been constructed locally or received as a member of a `ResultSequence`. If not explicitly overridden, the document format will be set to XML.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentNode` - An instance of `XdmNode` which is the document content. Only nodes of type `XdmElement`, `XdmText` or `XdmBinary` are valid.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           java.io.File documentFile,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from a File object.

      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentFile` - A File object from which the content will be read. If the createOptions argument selects `DocumentFormat.BINARY`, the content of the file will be transfered as an opaque blob. Otherwise, the file is assumed to be UTF-8 encoded text.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           java.io.RandomAccessFile documentFile,
                                           ContentCreateOptions createOptions)
                                    throws java.io.IOException

      Create a new `Content` object from a RandomAccessFile object.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentFile` - An open RandomAccessaFile object from which the content will be read. File data will be read from the current position to end-of-file. If the createOptions argument selects `DocumentFormat.BINARY`, the content of the file will be transfered as an opaque blob. Otherwise, the file is assumed to be UTF-8 encoded text.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Throws:
        `java.io.IOException` - If there is a problem reading data from the file.

    - #### newUnBufferedContent

          public static Content newUnBufferedContent(java.lang.String uri,
                                                     java.net.URL documentUrl,
                                                     ContentCreateOptions createOptions)
                                              throws java.io.IOException

      Create a new, non-rewindable `Content` object from a `URL`.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentUrl` - A `URL` object that represents the location from which the content can be fetched.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Throws:
        `java.io.IOException` - If there is a problem creating a `URL` or opening a data stream.

    - #### newUnBufferedContent

          public static Content newUnBufferedContent(java.lang.String uri,
                                                     java.net.URI documentUri,
                                                     ContentCreateOptions createOptions)
                                              throws java.io.IOException

      Create a new, non-rewindable `Content` object from a `URI`.
      Parameters:
        `uri` - The `URI` (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentUri` - A URI object that represents the location from which the content can be fetched.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Throws:
        `java.io.IOException` - If there is a problem creating a `URL` or opening a data stream.

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           java.net.URL documentUrl,
                                           ContentCreateOptions createOptions)
                                    throws java.io.IOException

      Create a new `Content` object from a URI, buffering so that it's rewindable and only accesses the URL one time.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentUrl` - A `URL` object that represents the location from which the content can be fetched.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Throws:
        `java.io.IOException` - If there is a problem creating a `URL` or reading the data from the stream.

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           java.net.URI documentUri,
                                           ContentCreateOptions createOptions)
                                    throws java.io.IOException

      Create a new `Content` object from a URI, buffering so that it's rewindable and only accesses the URL one time.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentUri` - A `URI` object that represents the location from which the content can be fetched. Unlike `URL`s, `URI` objects are not validated when they are created. This method converts the `URI` to a `URL`. If this parameter does not represent a valid URL, an exception will be thrown.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Throws:
        `java.io.IOException` - If there is a problem creating a `URL` or reading the data from the stream.
        `java.lang.IllegalArgumentException` - If the URI is not absolute.

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           java.lang.String documentString,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from a String.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentString` - A String which will be stored as the content of the document. If the createOptions argument selects `DocumentFormat.BINARY`, the bytes representing the UTF-8 encoding of the String will be stored.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      See Also:
        `DocumentFormat`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           byte[] documentBytes,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from a byte array.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentBytes` - A byte array which will be stored as the content of the document. If the createOptions argument is null, then `DocumentFormat.BINARY` will be assumed.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      See Also:
        `DocumentFormat`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           byte[] documentBytes,
                                           int offset,
                                           int length,
                                           ContentCreateOptions createOptions)

      Create a new `Content` object from a subset of a byte array.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new content.
        `documentBytes` - A byte array which will be stored as the content of the document. If the createOptions argument is null, then `DocumentFormat.BINARY` will be assumed.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
        `offset` - The starting point of the content in the array.
        `length` - The length of the content in the array.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Since:
        3.2
      See Also:
        `DocumentFormat`

    - #### newContent

          public static Content newContent(java.lang.String uri,
                                           java.io.InputStream documentStream,
                                           ContentCreateOptions createOptions)
                                    throws java.io.IOException

      Create a new `Content` object by consuming the given InputStream and buffereing it in memory. This factory method immediately reads the stream to the end and buffers it. This could result in an OutOfMemoryError if the stream contains a large amount of data. The provided documentStream will be closed.
      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new value.
        `documentStream` - The stream making up the document content.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A `Content` object suitable for passing to `Session.insertContent(Content)`
      Throws:
        `java.io.IOException` - If there is a problem reading the documentStream.

    - #### newUnBufferedContent

          public static Content newUnBufferedContent(java.lang.String uri,
                                                     java.io.InputStream documentStream,
                                                     ContentCreateOptions createOptions)

      Create a new non-rewindable `Content` object for the given InputStream. Note that the `Content` instance returned is not rewindable ( `Content.isRewindable()` == false) which means that auto-retry cannot be performed is there is a problem inserting the content.

      Parameters:
        `uri` - The URI (name) with which the document will be inserted into the content store. If the URI already exists in the store, it will be replaced with the new value.
        `documentStream` - The stream making up the document content.
        `createOptions` - Creation meta-information to be applied when the content is inserted into the contentbase. These options control the document format (json, xml, text, binary) and access permissions.
      Returns:
        A non-rewindable `Content` object suitable for passing to `Session.insertContent(Content)`

Copyright © 2025 MarkLogic Corporation. All Rights Reserved.

Complete online documentation for MarkLogic Server, XQuery and related components may be found at developer.marklogic.com