////////////////////////////////////////////////////////////////////////////////// // // 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 realestate.xml and realestate.xsl. You can also // download a zip file 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); } }