Content Pipeline Guide > Using AOM with Pipelines and Filters > AOM Publishing using Java
  
AOM Publishing using Java
The following example shows how to create a pipeline using Java. HTMLFilecomposer has two public methods that take XML input (as an in-memory Arbortext Editor document or a file) and transforms it to an HTML file using the specified XSL stylesheet.
package com.arbortext.epic.compose.examples;
/*
* HTMLFileComposer is an example of calling the content
* pipeline using the AOM composer. In this example, an XML
* document is published to an HTML file. The source document
* can exist in one of two places, in Arbortext or a file.
* The composer uses the htmlfile pipeline defined in
* htmlfile.ccf in the composer directory of the Arbortext
* installation tree.
*/
import com.arbortext.epic.*;
import org.w3c.dom.*;
import java.io.File;
public class HTMLFileComposer {
/**
* Used internally to access the composer configuration file.
*/
private static final String HTMLFILE_CCF =
File.separator + "composer" + File.separator +
"htmlfile.ccf";
/**
* Used internally to access the entity substitution file.
*/
private static final String HTMLENTSUBFILE =
File.separator + "composer" + File.separator +
"htmlEntSub.xml";
/**
* Produces HTML from an in-memory XML file and an
* XSL stylesheet.
*@param docId is the ID of document to process.
*@param stylesheet is a fully-pathed XSL stylesheet.
*@param outputFile is a fully-pathed HTML output filename.
*/
public static void composeToHtmlFromDoc
(int docId, String stylesheet,String outputFile) {
ComposerLog log = new ComposerLog();
try {
String installPath = Acl.eval("main::aptpath");
//Create the Composer object for the HTML publishing process.
Composer composer = Application.createComposer(installPath
+ HTMLFILE_CCF);
PropertyMap params = Application.createPropertyMap();

//Set up the parameters.
params.putString("stylesheet", stylesheet);
params.putString("document", Integer.toString(docId));
//The entity substitution file for HTML
params.putString("html.entSubFname", installPath
+ HTMLENTSUBFILE);
params.putString("outputFile", outputFile);
//The following code creates the directory in which
//graphics would be placed and the associated href in
//the HTML document.
params.putString("graphicsHref",
(new File(outputFile)).getName() + ".graphics/");
params.putString("graphicsPath", outputFile + ".graphics/");
//Let the composer know we are using an XSL stylesheet.
params.putString("stylesheetType", "xsl");
//Start the composer log with level at info.
log.startJob("HTMLFileComposer", ComposerLog.SEVERITY_INFO);
//runPipeline returns a boolean indicating success or failure.
if (composer.runPipeline(params)) {
log.logMessage("Success", ComposerLog.SEVERITY_INFO);
}
else {
//Error information will have been placed into the
//Event Log.
log.logMessage("Failure", ComposerLog.SEVERITY_INFO);
}
}
catch (AclException ex) {
//Unexpected.
System.err.println("ACLException in
composeToHtmlFromDoc: " + ex);
ex.printStackTrace(System.err);
}
catch (AOMException aomex) {
//Unexpected.
System.err.println("AOMException in
composeToHtmlFromDoc: " + aomex);
aomex.printStackTrace(System.err);
}
finally {
log.endJob();
}
}
/**
* Produces HTML from an on-disk XML file and an XSL stylesheet.
* @param inputFile is a fully-pathed XML filename.
* @param stylesheet is a fully-pathed XSL stylesheet.
* @param outputFile is a fully-pathed HTML output filename.
*/
public static void composeToHtmlFromFile
(String inputFile, String stylesheet,
String outputFile) {
ADocument doc = null;
try {
doc = (ADocument) Application.openDocument
(inputFile, Application.OPEN_RDONLY |
Application.OPEN_NOSTYLE |
Application.OPEN_NOCC |
Application.OPEN_NOMSGS |
Application.OPEN_NODTPROMPT);
composeToHtmlFromDoc(doc.getAclId(), stylesheet,
outputFile);
}
catch (AOMException aomex) {
System.err.println
("AOMException in composeToHtmlFromFile: " +
aomex);
aomex.printStackTrace(System.err);
}
finally {
if (doc != null) {
doc.close();
}
}
}
}
The first step in this example is creating the composer object from the CCF file (Arbortext-path\composer\htmlfile.ccf):
Composer composer = Application.createComposer(installPath
+ HTMLFILE_CCF);
The composer expects to receive parameters as a PropertyMap AOM object. Refer to the createPropertyMap method in the Programmer's Referencefor more information.
PropertyMap params = Application.createPropertyMap();
params.putString("stylesheet", stylesheet);
...
The Event Log must be started before a publishing process is run. A ComposerLog object wraps the ACL calls. The source can be found in the examples.jar file distributed with the Content Pipeline Guide. (included in the examples.zip file).
log.startJob("HTMLFileComposer", ComposerLog.SEVERITY_INFO);
The pipeline is then run using the parameters provided by the PropertyMap AOM object. If the pipeline runs successfully, a true value is returned. If there are errors, a false value is returned.
if (composer.runPipeline(params)) ...
The Event Log must have an end signal to conclude logging. Place the end signal in the finally clause to ensure that this signal is called even if an exception occurs.
log.endJob();