<?xml version="1.0" encoding="UTF-8"?>
<topic version="5.2" xml:id="embed" xmlns="http://docbook.org/ns/docbook">
  <info>
    <title>Embedding XMLmind Assembly Processor in a Java™ application</title>
  </info>

  <procedure>
    <step>
      <para>Add
      <filename><replaceable>assembly_install_dir</replaceable>/lib/assembly.jar</filename>
      to your <envar>CLASSPATH</envar>.</para>

      <para>Optionally, if your assembly loads XML documents having a DTD
      (e.g. transform DITA topics to DocBook topics), also
      add<filename><replaceable>assembly_install_dir</replaceable>/lib/xmlresolver.jar</filename>
      to your <envar>CLASSPATH</envar>. File
      <filename>xmlresolver.jar</filename> contains <link
      xlink:href="https://xmlresolver.org/"
      xmlns:xlink="http://www.w3.org/1999/xlink"/> an enhanced XML resolver
      with XML Catalog support.</para>
    </step>

    <step>
      <para>Create an instance of <link
      xlink:href="../api/com/xmlmind/assembly/Processor.html"
      xmlns:xlink="http://www.w3.org/1999/xlink">Processor</link>:</para>

      <programlisting>Processor processor = new Processor();</programlisting>

      <important>
        <para>Do not share this instance between different threads, as this
        class is <emphasis>not</emphasis> thread-safe.</para>
      </important>

      <para>If you don't want the error, warning and progress messages to be
      displayed on <literal>System.err</literal> and to
      <literal>System.out</literal>, implement interface <link
      xlink:href="../api/com/xmlmind/util/Console.html"
      xmlns:xlink="http://www.w3.org/1999/xlink">Console</link> and pass an
      instance of your implementation to the constructor.</para>
    </step>

    <step>
      <para>Parameterize the processor by invoking either <link
      xlink:href="../api/com/xmlmind/assembly/Processor.html#configure(java.lang.String[])"
      xmlns:xlink="http://www.w3.org/1999/xlink">configure(String[])</link> or
      individual configuration methods such as <link
      xlink:href="../api/com/xmlmind/assembly/Processor.html#setProcessedStructId(java.lang.String)"
      xmlns:xlink="http://www.w3.org/1999/xlink">setProcessedStructId(String)</link>,
      <link
      xlink:href="../api/com/xmlmind/assembly/Processor.html#setOutputFormat(java.lang.String)"
      xmlns:xlink="http://www.w3.org/1999/xlink">setOutputFormat(String)</link>,
      etc. Example:</para>

      <programlisting>int l = -1;
try {
    l = processor.configure(args);
} catch (IllegalArgumentException e) {
    <emphasis>// FATAL ERROR. DO SOMETHING HERE.</emphasis>
}

<emphasis>// PARSE THE REMAINING ARGUMENTS, IF ANY, 
// STARTING AT INDEX l.</emphasis></programlisting>
    </step>

    <step>
      <para>Finally invoke method <link
      xlink:href="../api/com/xmlmind/assembly/Processor.html#process(java.net.URL,java.io.File)"
      xmlns:xlink="http://www.w3.org/1999/xlink">process(URL, File)</link>.
      Pass this method the input assembly URL and the output realized document
      save file.</para>

      <programlisting>try {
    if (!processor.process(inURL, outFile)) {
        <emphasis>// FATAL ERROR. DO SOMETHING HERE.
        // ERRORS HAVE BEEN DISPLAYED ON THE <link
            xlink:href="../api/com/xmlmind/util/Console.html"
            xmlns:xlink="http://www.w3.org/1999/xlink">Console</link>.</emphasis>
    }
} catch (IOException e) 
    // FATAL ERROR. DO SOMETHING HERE.
}</programlisting>
    </step>
  </procedure>
</topic>
