<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en-us" xml:lang="en-us"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="security" content="public" /> <meta name="Robots" content="index,follow" /> <meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' /> <meta name="DC.Type" content="reference" /> <meta name="DC.Title" content="Example: Using XSLReportProcessor with PCLContext" /> <meta name="abstract" content="" /> <meta name="description" content="" /> <meta name="copyright" content="(C) Copyright IBM Corporation 2006" /> <meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" /> <meta name="DC.Format" content="XHTML" /> <meta name="DC.Identifier" content="pclrunreport" /> <meta name="DC.Language" content="en-us" /> <!-- All rights reserved. Licensed Materials Property of IBM --> <!-- US Government Users Restricted Rights --> <!-- Use, duplication or disclosure restricted by --> <!-- GSA ADP Schedule Contract with IBM Corp. --> <link rel="stylesheet" type="text/css" href="./ibmdita.css" /> <link rel="stylesheet" type="text/css" href="./ic.css" /> <title>Example: Using XSLReportProcessor with PCLContext</title> </head> <body id="pclrunreport"><a name="pclrunreport"><!-- --></a> <!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script> <h1 class="topictitle1">Example: Using XSLReportProcessor with PCLContext</h1> <div><p></p> <div class="section"><div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code example disclaimer</a> for important legal information.</div> <pre>////////////////////////////////////////////////////////////////////////////////// // // The following example (PCLRunReport) 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. // // To view the contents of example XML and XSL source files that you can use // with PCLRunReport, see <a href="realestatexml.htm#realestatexml">realestate.xml</a> and <a href="realestatexsl.htm#realestatexsl">realestate.xsl</a>. You can also // <a href="xmlxsljspsamples.zip">download a zip file</a> that contains the XML and XSL example files. The zip // file also contains a JSP example file that you can use with the // JSPReportProcessor example (JSPRunReport). // // Command syntax: // java PCLRunReport <xml_file> <xsl_file> // ////////////////////////////////////////////////////////////////////////////////// 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 server 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); } }</pre> </div> </div> </body> </html>