com.marklogic.xcc.examples

## Class ContentLoader

- java.lang.Object
- - com.marklogic.xcc.examples.ContentLoader

-     public class ContentLoader
      extends java.lang.Object

  This program accepts a server URI (in the format expected by `ContentSourceFactory.newContentSource(java.net.URI)`) and one or more file pathnames of documents to load.

  Click here for the source code for this class

  The main() method in this example leaves the `ContentCreateOptions` value set to null which will apply defaults when documents are loaded. This means that document type (XML, text() or binary()) may be determined by URI extention. If you instantiate this class from another class, you can set explicit options via `setOptions(com.marklogic.xcc.ContentCreateOptions)` before calling `load(java.io.File[])`.

  The main() method uses the absolute pathname of each file as its URI for loading. There is also a method provided which takes parallel arrays of URI strings and File objects.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ContentLoader(java.net.URI serverUri)` Construct an instance that may be used to insert content.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `load(java.io.File[] files)` Load the provided `File`s into the contentbase, using the absolute pathname of each `File` as the document URI.
    `void` | `load(java.lang.String[] uris, java.io.File[] files)` Load the provided `File`s, using the provided URIs, into the content server.
    `static void` | `main(java.lang.String[] args)` Command-line main() module to run this content loader.
    `void` | `setOptions(ContentCreateOptions options)` Set (or clear) an instance of `ContentCreateOptions` which defines creation options to apply to each document loaded.

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

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

- - ### Constructor Detail

    - #### ContentLoader

          public ContentLoader(java.net.URI serverUri)
                        throws XccConfigException

      Construct an instance that may be used to insert content.
      Parameters:
        `serverUri` - A URI identifying a `ContentSource`, in the format expected by `ContentSourceFactory.newContentSource(java.net.URI)`.
      Throws:
        `XccConfigException` - Thrown if a `Session` cannot be created. This usually indicates that the host/port or user credentials are incorrect.

  - ### Method Detail

    - #### load

          public void load(java.lang.String[] uris,
                           java.io.File[] files)
                    throws RequestException

      Load the provided `File`s, using the provided URIs, into the content server.
      Parameters:
        `uris` - An array of URIs (identifiers) that correspond to the `File` instances given in the "files" parameter.
        `files` - An array of `File` objects representing disk files to be loaded. The `ContentCreateOptions` object set with `setOptions(com.marklogic.xcc.ContentCreateOptions)`, if any, will be applied to all documents when they are loaded.
      Throws:
        `RequestException` - If there is an unrecoverable problem with sending the data to the server. If this exception is thrown, none of the documents will have been committed to the contentbase.

    - #### load

          public void load(java.io.File[] files)
                    throws RequestException

      Load the provided `File`s into the contentbase, using the absolute pathname of each `File` as the document URI.
      Parameters:
        `files` - An array of `File` objects representing disk files to be loaded. The `ContentCreateOptions` object set with `setOptions(com.marklogic.xcc.ContentCreateOptions)`, if any, will be applied to all documents when they are loaded.
      Throws:
        `RequestException` - If there is an unrecoverable problem with sending the data to the server. If this exception is thrown, none of the documents will have been committed to the contentbase.

    - #### setOptions

          public void setOptions(ContentCreateOptions options)

      Set (or clear) an instance of `ContentCreateOptions` which defines creation options to apply to each document loaded. This is null (defaults) unless explictly set.
      Parameters:
        `options` -

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.net.URISyntaxException,
                                  XccConfigException,
                                  RequestException

      Command-line main() module to run this content loader.
      Parameters:
        `args` - A URI [arg 0] identifying the server/port/user/db where the content should be inserted and one or more [args 1-n] giving file pathnames of documents to load.
      Throws:
        `java.net.URISyntaxException` - If there is a problems interpreting the URI.
        `XccConfigException` - If a `Session` cannot be created.
        `RequestException` - If the content cannot be inserted in the contentbase.

Copyright © 2025 MarkLogic Corporation

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