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/resolver.jar to your CLASSPATH. File resolver.jar contains Apache XML Commons Resolver which implements catalog-based entity and URI resolution.

  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.
    }