Embedding w2x in a Java™ application
Embedding w2x in a Java™ application is as simple as:
Create an instance of class Processor.
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.
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);
Compile Embed1.java by executing “ant”10 in w2x_install_dir/doc/manual/embed/.
Run “ant tembed1” in w2x_install_dir/doc/manual/embed/. This creates w2x_install_dir/doc/manual/embed/tembed1.dita.
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);
Compile Embed2.java by executing “ant” in w2x_install_dir/doc/manual/embed/.
Run “ant tembed2” in w2x_install_dir/doc/manual/embed/. This creates w2x_install_dir/doc/manual/embed/tembed2.xhtml.
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.