Chapter 6. Embedding XMLmind Assembly Processor in a Java™ application

  1. Add assembly_install_dir/lib/assembly.jar to your CLASSPATH.

    Optionally, if your assembly loads XML documents having a DTD (e.g. transform DITA topics to DocBook topics), also addassembly_install_dir/lib/xmlresolver.jar to your CLASSPATH. File xmlresolver.jar contains https://xmlresolver.org/ an enhanced XML resolver with XML Catalog support.

  2. Create an instance of Processor:

    Processor processor = new Processor();

    Important

    Do not share this instance between different threads, as this class is not thread-safe.

    If you don't want the error, warning and progress messages to be displayed on System.err and to System.out, implement interface Console and pass an instance of your implementation to the constructor.

  3. Parameterize the processor by invoking either configure(String[]) or individual configuration methods such as setProcessedStructId(String), setOutputFormat(String), etc. Example:

    int l = -1;
    try {
        l = processor.configure(args);
    } catch (IllegalArgumentException e) {
        // FATAL ERROR. DO SOMETHING HERE.
    }
    
    // PARSE THE REMAINING ARGUMENTS, IF ANY, 
    // STARTING AT INDEX l.
  4. Finally invoke method process(URL, File). Pass this method the input assembly URL and the output realized document save file.

    try {
        if (!processor.process(inURL, outFile)) {
            // FATAL ERROR. DO SOMETHING HERE.
            // ERRORS HAVE BEEN DISPLAYED ON THE Console.
        }
    } catch (IOException e) 
        // FATAL ERROR. DO SOMETHING HERE.
    }