Example: Using JSPReportProcessor with PDFContext
/*
* 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 JSPReportProcessor and the PDFContext
* classes to obtain data from a specified URL and convert the data to the
* PDF format. The data is then streamed to a file as a PDF document.
*
*/
import java.lang.*;
import java.awt.*;
import java.io.*;
import java.net.*;
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.pdfwriter.*;
import java.io.IOException;
import java.io.Serializable;
import org.xml.sax.SAXException;
public class JSPRunReport
{
public static void main(String args[])
{
FileOutputStream fileout = null;
/** specify the URL that contains the data you want
to use in your report **/
String JSPurl = args[0];
URL jspurl = null;
try {
jspurl = new URL(JSPurl);
}
catch (MalformedURLException e)
{}
/** get output PDF file name **/
String filename = args[1];
try {
fileout = new FileOutputStream(filename);
}
catch (FileNotFoundException e)
{}
/** set up page format **/
Paper paper = new Paper();
paper.setSize(612,792);
paper.setImageableArea(18, 18, 576, 756);
PageFormat pf = new PageFormat();
pf.setPaper(paper);
/** create a PDFContext object and cast FileOutputStream
as an OutputStream **/
PDFContext pdfcontext = new PDFContext((OutputStream)fileout, pf);
System.out.println( Ready to parse XSL document );
/** create the JSPReportProcessor object and set the template
to the specified JSP **/
JSPReportProcessor jspprocessor = new JSPReportProcessor(pdfcontext);
try {
jspprocessor.setTemplate(jspurl);
}
catch (NullPointerException np){
String mes = np.getMessage();
System.out.println(mes);
System.exit(0);
}
/** process the report **/
try {
jspprocessor.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);
}
}