Command Line Applications

1. Introduction

You can use PresentationServer to build standalone command-line applications running pipelines. Use cases include: creating a hardcopy of a web site, importing or exporting XML data to and from a relational database, testing pipelines, automating repetitive operations on XML files (selection, transformation, aggregation, etc.). PresentationServer becomes your "XML toolbox".

2. Command Line Interface

PresentationServer ships with a command line interface (CLI). The easiest way to run it is to use the executable cli-orbeon.jar file and pass it a pipeline file:

java -jar cli-orbeon.jar pipeline.xpl

In this case, a pipeline can use relative URLs, or, if using absolute URLs, can use either the file: protocol to access files or, equivalently, the oxf: protocol.

Sometimes, it is better to group files under a resources sandbox addressed by the oxf: protocol. This is the standard way of accessing resources (files) within web applications, but it is also useful with command-line applications. In such cases, specify a resource manager root directory with the -r option, for example:

java -jar cli-orbeon.jar -r . oxf:/pipeline.xpl

or:

java -jar cli-orbeon.jar -r C:/my-example oxf:/pipeline.xpl

When specifying a resource manager root directory, it is mandatory to use a protocol and an absolute path within the sandbox, as shown above.

Note
PresentationServer's jar file (cli-orbeon.jar) is executable via the java -jar mechanism. However, it depends on a number of libraries that must be in the 'lib' directory beneath the directory containing cli-orbeon.jar. It is recommended to expand the WAR file, and refer to the cli-orbeon.jar file under the WAR file's WEB-INF directory.

3. Examples

PresentationServer comes with simple examples of command-line applications under the src/examples/cli directory. To run those examples, from a command prompt, enter either one of the subdirectories and run the java command following the explanations above, for example, from the simple directory:

java -jar /path/to/orbeon-war/WEB-INF/cli-orbeon.jar stdout.xpl

or, from the transform directory:

java -jar /path/to/orbeon-war/WEB-INF/cli-orbeon.jar transform.xpl

Notice that those two example pipelines use serializers, for example:

  <p:config xmlns:p="http://www.orbeon.com/oxf/pipeline">
  <p:processor name="oxf:xslt">
  <p:input name="data" href="foo.xml"/>
  <p:input name="config" href="foo.xsl"/>
  <p:output name="data" id="result"/>
  </p:processor>
  <p:processor name="oxf:xml-serializer">
  <p:input name="config">
  <config/>
  </p:input>
  <p:input name="data" href="#result"/>
  </p:processor>
  </p:config>

It is important to note that, when running from within a servlet or portlet environment, serializers send their data to the web client, such as a web browser. When running from a command-line environment, serializers output data to the standard output.