Skip Headers

Oracle® XML Developer's Kit Programmer's Guide 10g Release 2 (10.1.2) Part No. B14033-01 |
| Contents | Index

Previous | Next |

# 9 Pipeline Definition Language for Java

This chapter contains these topics:

- Using Pipeline Definition Language

- Example of a Pipeline Definition Language Application

- The Command-line Pipeline Tool orapipe

## Using Pipeline Definition Language

XML Pipeline definition Language from W3C, enables you to describe the processing relations between XML resources. A pipeline document specifies input and output of processes. A pipeline controller uses the pipeline document to execute the specified processes.

Oracle XML Pipeline Processor is built upon the XML Pipeline Definition Language Version 1.0, W3C Note 28 February 2002. The processor can take an input XML pipeline document and execute the pipeline processes according to the derived dependencies. The pipeline document is an XML document, and specifies the processes to be executed in a declarative manner. In addition to the XML Pipeline Processor, the XDK defines several Pipeline Processes which can be piped together in a pipeline document.

There are some differences between the W3C Note and the Oracle implementation. They are:

- The parser processes (`DOMParserProcess` and `SAXParserProcess`) are included in the XML pipeline (Section 1 of the note).

- Currently XML Base is not supported (Section 2.1)

- Only the final target output is checked to see if it is up-to-date with respect to the available pipeline inputs. The intermediate output of every process is not checked for being up-to-date. (Section 2.2).

- For the select attribute, anything between double-quotes "" is considered to be a string literal.

- The processor throws an error if more that one process produces the same infoset (Section 2.4.2.3).

- The document element is not supported, because it is redundant functionality (Section 2.4.2.8).

The Pipeline Definition Language is described at:

See Also: `http://www.w3.org/TR/xml-pipeline/`

## Example of a Pipeline Definition Language Application

The files for this example are in `/xdk/demo/java/pipeline/`. The application `PipelineSample.java` calls the pipeline document (an instance of the Pipeline Definition Language) named `pipedoc.xml`, which names `book.xsl` as the stylesheet to be used, `myresult.html` as the output HTML file, and `book.xml` as the XML document to be parsed. The processes are p2, p3, and p1 in the order given in `pipedoc.xml`. However, the processes are run in the order p1, p2, p3.

To run this example:

1. Add `xmlparserv2.jar` and the current directory to the `CLASSPATH`.

2. Use `make` to generate `.class` files.

3. Run the sample program:

       make demo

   Or run:

       java PipelineSample pipedoc.xml pipelog seq

   The first argument (`pipedoc.xml`) is the required pipeline document. `pipelog` is an optional log file that you name. If omitted, the default log file created is `pipeline.log`.

   `seq` can be either "para" or "seq", entered without the quotes. "seq" requests sequential processing. If omitted, the default mode is processing parallel threads, the same mode as if you entered "para".

4. View the pipeline target created, in this case `myresult.html`.

The error handler called by the Java program is `PipelineSampleErrHdlr.java`.

Here is `book.xml`, the input XML document with which you started the processing:

    <?xml version="1.0"?>
    <booklist>
      <book>
        <title>Twelve Red Herrings</title>
        <author>Jeffrey Archer</author>
        <publisher>Harper Collins</publisher>
        <price>7.99</price>
      </book>
      <book>
        <title language="English">The Eleventh Commandment</title>
        <author>Jeffrey Archer</author>
        <publisher>McGraw Hill</publisher>
        <price>3.99</price>
      </book>
      <book>
        <title language="English" country="USA">C++ Primer</title>
        <author>Lippmann</author>
        <publisher>Harper Collins</publisher>
        <price>4.99</price>
      </book>
      <book>
        <title>Emperor's New Mind</title>
        <author>Roger Penrose</author>
        <publisher>Oxford Publishing Company</publisher>
        <price>15.9</price>
      </book>
      <book>
        <title>Evening News</title>
        <author>Arthur Hailey</author>
        <publisher>MaMillan Publishers</publisher>
        <price>9.99</price>
      </book>
    </booklist>

Here is `pipedoc.xml`, the pipeline document:

    <pipeline xmlns="http://www.w3.org/2002/02/xml-pipeline"
                         xml:base="http://example.org/">

      <param name="target" select="myresult.html"/>

      <processdef name="domparser.p" definition="oracle.xml.pipeline.processes.DOMParserProcess"/>
      <processdef name="xslstylesheet.p" definition="oracle.xml.pipeline.processes.XSLStylesheetProcess"/>
      <processdef name="xslprocess.p" definition="oracle.xml.pipeline.processes.XSLProcess"/>

       <process id="p2" type="xslstylesheet.p" ignore-errors="false">
         <input name="xsl" label="book.xsl"/>
         <outparam name="stylesheet" label="xslstyle"/>
       </process>

       <process id="p3" type="xslprocess.p" ignore-errors="false">
         <param name="stylesheet" label="xslstyle"/>
         <input name="document" label="xmldoc"/>
         <output name="result" label="myresult.html"/>
       </process>

      <process id="p1" type="domparser.p" ignore-errors="true">
         <input name="xmlsource" label="book.xml "/>
         <output name="dom" label="xmldoc"/>
         <param name="preserveWhitespace" select="true"></param>
         <error name="dom">
           <html xmlns="http://www/w3/org/1999/xhtml">
             <head>
                <title>DOMParser Failure!</title>
             </head>
             <body>
               <h1>Error parsing document</h1>
             </body>
           </html>
         </error>
      </process>

    </pipeline>

The stylesheet `book.xsl` is listed next:

    <?xml version="1.0"?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

      <xsl:output method="xml"/>

      <xsl:template match="/">
        <HTML>
          <HEAD>
          </HEAD>
          <xsl:apply-templates/>
        </HTML>
      </xsl:template>

      <!-- document xsl:template -->

      <xsl:template match="booklist">
          <BODY BGCOLOR="#CCFFFF">
            <H1>List of books</H1>
            <P> This will illustrate the transformation of an XML file containing
                a list of books to an HTML table form </P>
            <xsl:apply-templates/>
          </BODY>
      </xsl:template>

      <xsl:template match="booklist/book">
    	<BR><B><xsl:apply-templates/></B></BR>
      </xsl:template>

      <xsl:template match="booklist/book/title">
          <xsl:apply-templates/>
      </xsl:template>

      <xsl:template match="booklist/book/author">
         <xsl:apply-templates/>
      </xsl:template>

      <xsl:template match="booklist/book/publisher">
      </xsl:template>

      <xsl:template match="booklist/book/price">
           Price: $<xsl:apply-templates/>
      </xsl:template>

    </xsl:stylesheet>

The output is `myresult.html` in the `/log` subdirectory

    <?xml version = '1.0'?>
    <HTML><HEAD/><BODY BGCOLOR="#CCFFFF"><H1>List of books</H1><P> This will
     illustrate the transformation of an XML file containing list of books to an
     HTML table form </P>
      <BR/>
        Twelve Red Herrings
        Jeffrey Archer

           Price: $7.99

      <BR/>
        The Eleventh Commandment
        Jeffrey Archer

           Price: $3.99

      <BR/>
        C++ Primer
        Lippmann

           Price: $4.99

      <BR/>
        Emperor's New Mind
        Roger Penrose

           Price: $15.9

      <BR/>
        Evening News
        Arthur Hailey

           Price: $9.99

    </BODY></HTML>

## The Command-line Pipeline Tool orapipe

The command-line pipeline tool is named `orapipe`. Before running it for the first time, add `xmlparserv2.jar` to your CLASSPATH. `orapipe` must have at least one argument, the pipeline document (`pipedoc.xml` in the code example presented in the preceding section).

To run orapipe, use the following syntax, where `pipedoc` is the required pipeline document you prepare in advance:

    orapipe options pipedoc

Table 9-1 describes the available options:

Table 9-1 orapipe: Command-line Options

Option | Purpose
--- | ---
`-help` | Prints the help message
`-log` `logfile` | Writes errors and messages to the log file you name. The default is `pipeline.log`.
`-noinfo` | Do not log informational items. The default is on.
`-nowarning` | Do not log any warnings. The default is on.
`-validate` | Validate the input `pipedoc` with the pipeline schema. The default is do not validate.
`-version` | Prints the release version.
`-sequential` | Executes the pipeline in sequential mode. The default is parallel.