Chapter 9. downCast API Reference

1. Concepts
2. Using the API
3. General programming steps
3.1. Setup
3.2. The DowncastEngine object
3.3. Converting a document
3.4. Setting global parameters
4. Method reference

1. Concepts

Accessing downCast functionality is carried out via one instance of a broker object: DowncastEngine. You should create one instance of that object at startup and use it for many subsequent conversions, since creation of this object is rather expensive. There are no problems in reusing that object for subsequent conversions (in contrast e.g. to many XML parser implementations, for example) - to the contrary, it is highly recommended from a performance point of view.

You may create several instances of the DowncastEngine object in order to run multiple conversion threads at the same time in your single application. Please note that the number of parallel threads may be restricted by your license.

2. Using the API

We assume that you are familiar with Java programming and its concepts like objects, interfaces and implementations. You should also be fluent with the Java object notion and with Java Streams.

3. General programming steps

Converting a document with downCast is divided into the following, easy steps:

  1. Register the JAR with a license file.

  2. Instantiate an DowncastEngine object.

  3. Set any required global parameters.

  4. Convert the document.

If we look at these steps in actual Java code, the above would translate into (line numbers and steps corresponding):

DowncastEngine.setLicense( new FileInputStream( "/path/to/downcast.license") );
DowncastEngine dc = new DowncastEngine("instanceOne");  
dc.convertFile( "/Dev/src/doc.xml", "/Dev/dest/", "/Dev/xsl/preconvert.xsl" ); 

Let's have a look at the single steps in more detail.

3.1. Setup

The first thing you need to do (before any conversion can take place) is to register the application with an appropriate license. This is done via the static method

public static boolean setLicense( InputStream inStream )

It takes an InputStream of the XML based license file.

If you package your license file into your application JAR, you can use the following line to register your application:

boolean isRegistered =
    DowncastEngine.setLicense(
        DowncastEngine.class.getResourceAsStream( "downcast.license") );

3.2. The DowncastEngine object

You gain access to all functionality of downCast by means of objects of a single class: DowncastEngine. An instance of this object is what you will use in your application in order to access the full range of downCast API functionality.

Before you can do anything (after having registered the API with a license) with downCast, you need to instantiate a DowncastEngineobject:

DowncastEngine dc = new DowncastEngine( "instanceOne" );

The DowncastEngine class is located in the de.infinityloop.downcast package.

You should keep this object stored in a variable which you can access from all places inside your program where you need to access downCast functionality.

You should strive to have only one instance of the DowncastEngine object per physical CPU at any time for performance reasons. Also make sure you only instantiate this object once during the life of your application process, as instantiating and disposing of this object is a relatively costly operation.

3.3. Converting a document

Document conversion within downCast is a single-step process.

Converting a document is straightforward: a single method call converts an upCast DTD conforming XML file to RTF format, optionally pre-processing it with an XSLT processing sheet:

boolean success = dc.convertFile( "/path/to/src.xml", "/path/to/dest/", "/path/to/preprocess.xsl");

If you do not want any preprocessing to take place, pass null for the last argument in the call to convertFile().

Note

You must specify absolute paths for all parameters.

Any errors during the conversion phase will be reported by returning false from the method call.

3.4. Setting global parameters

For certain conversions, it might get necessary in the future to set some global conversion parameters. To set these types of parameters, you use the method

setGlobalParameter(String parameter, Object value)

4. Method reference

The API reference is provided in form of javadoc HTML documentation. This assures that the documentation is up-to-date since it is generated directly from the underlying source code. The most recent version of the downCast API documentation is available from our website at http://www.infinity-loop.de/support/techpub/api/downcast/1.0/.