Embedding w2x in a Java™ application

Embedding w2x in a Java™ application is as simple as:

  1. Create an instance of class Processor.
  2. Configure it by passing an array of option strings identical to those of the w2x command line utility to method Processor.configure or (low-level) by directly adding conversion steps and parameters to Processor.stepList and Processor.parameterMap.
  3. Invoke the configured processor to convert specified input file to specified output file. This is done invoking high-level method Processor.process or low-level method Processor.executeSteps.

About thread-safety

An instance of Processor cannot be shared by different threads.

It’s strongly recommend not to reuse an instance of Processor. That is, please create one instance of Processor per conversion.

The reference manual (generated using javadoc) of the Java API of w2x is found in XMLmind Word To XML Java™ API.

High-level example w2x_install_dir/doc/manual/embed/Embed1.java:

Processor processor = new Processor();

int l = processor.configure(args);

File inFile = null;
File outFile = null;
if (l+2 == args.length) {
    inFile = new File(args[l]);
    outFile = new File(args[l+1]);
} else {
    System.exit(1);
}

processor.process(inFile, outFile, /*progress monitor*/ null);

Lower-level example w2x_install_dir/doc/manual/embed/Embed2.java:

Processor processor = new Processor();

ConvertStep convertStep = new ConvertStep("convert");
processor.stepList.add(convertStep);

EditStep editStep = new EditStep("edit");
processor.stepList.add(editStep);

processor.parameterMap.put("edit.xed-url-or-file", 
                           "w2x:xed/main-styled.xed");

SaveStep saveStep = new SaveStep("save");
processor.stepList.add(saveStep);

processor.parameterMap.put("save.indent", "yes");

processor.process(inFile, outFile, /*progress monitor*/ null);

[10]Apache Ant is a command-line utility for automating software build processes. By default, ant uses an XML file, called build.xml to describe the build process and its dependencies. In the case of the two above code samples, this file is w2x_install_dir/doc/manual/embed/build.xml.