Example: Using XSLReportProcessor with PCLContext

/*
 * IBM Confidential
 *
 * Copyright (C) 1999 by the IBM Corporation. All Rights Reserved.
 *
 * US Government Users Restricted Rights Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 * The program is provided  as is  without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * IBM will not be liable for any damages suffered by you as a result
 * of using the Program. In no event will IBM be liable for any
 * special, indirect or consequential damages or lost profits even if
 * IBM has been advised of the possibility of their occurrence. IBM
 * will not be liable for any third party claims against you.
 *
 *
 *
 * The following example uses the XSLPReportProcessor and the PCLContext
 * classes to obtain XML data and convert the data to the PCL format.
 * The data is then streamed to a printer OutputQueue.
 *
 */

import java.lang.*;
import java.awt.*;
import java.io.*;
import java.awt.print.*;
import java.awt.event.*;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.HashMap;

import com.ibm.xsl.composer.flo.*;
import com.ibm.xsl.composer.areas.*;
import com.ibm.xsl.composer.framework.*;
import com.ibm.xsl.composer.java2d.*;
import com.ibm.xsl.composer.prim.*;
import com.ibm.xsl.composer.properties.*;
import com.ibm.as400.util.reportwriter.processor.*;
import com.ibm.as400.util.reportwriter.pclwriter.*;
import java.io.IOException;
import java.io.Serializable;
import org.xml.sax.SAXException;
import com.ibm.as400.access.*;

public class PCLRunReport

{

    public static void main(String args[])
    {
        SpooledFileOutputStream fileout = null;
        String xmldocumentName = args[0];
        String xsldocumentName = args[1];

        String sys = "<system>";      /* Insert ISeries system name       */
        String user = "<user>";       /* Insert ISeries user profile name */
        String pass = "<password>";   /* Insert ISeries password          */

        AS400 system = new AS400(sys, user, pass);

        /* Insert ISeries output queue */
        String outqname = "/QSYS.LIB/qusrsys.LIB/<outq>.OUTQ";
        OutputQueue outq = new OutputQueue(system, outqname);
        PrintParameterList parms = new PrintParameterList();
        parms.setParameter(PrintObject.ATTR_OUTPUT_QUEUE, outq.getPath());

        try{
          fileout = new SpooledFileOutputStream(system, parms, null, null);
        }
        catch (Exception e)
        {}

        /** set up page format **/
        Paper paper = new Paper();
        paper.setSize(612,792);
        paper.setImageableArea(18, 36, 576, 720);
        PageFormat pf = new PageFormat();
        pf.setPaper(paper);

        /** create a PCLContext object and case FileOutputStream
            as an OutputStream **/
        PCLContext pclcontext = new PCLContext((OutputStream)fileout, pf);

        System.out.println("Ready to parse XSL document");

        /** create the XSLReportProcessor object **/
        XSLReportProcessor xslprocessor = new XSLReportProcessor(pclcontext);
        try {
        xslprocessor.setXMLDataSource(xmldocumentName);
        }
        catch (SAXException se) {
            String mes = se.getMessage();
            System.out.println(mes);
            System.exit(0);
            }
        catch (IOException ioe) {
            String mes = ioe.getMessage();
            System.out.println(mes);
            System.exit(0);
            }
        catch (NullPointerException np){
            String mes = np.getMessage();
            System.out.println(mes);
            System.exit(0);
            }
        /** set the template to the specified XML data source **/
        try {
        xslprocessor.setTemplate(xsldocumentName);
        }
        catch (NullPointerException np){
            String mes = np.getMessage();
            System.out.println(mes);
            System.exit(0);
            }
        catch (IOException e) {
            String mes = e.getMessage();
            System.out.println(mes);
            System.exit(0);
            }
        catch (SAXException se) {
            String mes = se.getMessage();
            System.out.println(mes);
            System.exit(0);
            }

        /** process the report **/
        try {
        xslprocessor.processReport();
        }
        catch (IOException e) {
            String mes = e.getMessage();
            System.out.println(mes);
            System.exit(0);
            }
        catch (SAXException se) {
            String mes = se.getMessage();
            System.out.println(mes);
            System.exit(0);
            }

        System.exit(0);
    }

}