Friday, January 15, 2010

FOP & JBoss & Oracle Apex

Add the missing Oracle XML Parser v2 (you may find them e.g. in JDeveloper/lib) libraries (lib/xmlparserv2.jar, lib/xml.jar) by opening the fop.war with your favorite zip program (e.g. rename fop.war to fop.zip) and saving the libraries WEB-INF/lib. Then copy the fop.war to the e.g. jboss\server\default\deploy directory. Maybe you have to restart your application server (dependent on your settings). Then try http://your-hostname:your-port/fop/apex_fop.jsp (e.g. http://127.0.0.1:8080/fop/apex_fop.jsp) to see if your work was successful.

Manage Service / Instance Settings / Report Printing
Print Server: Standard Support
Print Server Host Address: 127.0.0.1
Print Server Port:8080
Print Server Script: /fop/apex_fop.jsp

<%@ page import='java.io.*'%>
<%@ page import='org.xml.sax.InputSource'%>
<%@ page import='org.apache.fop.apps.Driver'%>
<%@ page import='org.apache.fop.apps.Options'%>
<%@ page import='oracle.xml.parser.v2.XMLDocument'%>
<%@ page import='oracle.xml.parser.v2.XSLProcessor'%>
<%@ page import='oracle.xml.parser.v2.XSLStylesheet'%>
<%@ page import='oracle.xml.parser.v2.DOMParser'%>
<%
// see http://xml.apache.org/fop/output.html for all output types
XMLDocument   v_doc;
XSLStylesheet v_xsl = null;
String        v_fop;
DOMParser     parser = new DOMParser();
XSLProcessor processor = new XSLProcessor();
String        v_encode = "UTF-8";
 
String p_xsl = request.getParameter("template");
String p_xml = request.getParameter("xml");
 
/* transform an XML source to XSLFO using an XSL transformation */
v_xsl = new XSLStylesheet(new java.io.StringReader(p_xsl),null);
parser.parse(new java.io.StringReader(p_xml));
v_doc = parser.getDocument();
ByteArrayOutputStream v_out = new ByteArrayOutputStream();
processor.processXSL(v_xsl, v_doc, v_out);
v_fop = new String(v_out.toByteArray(),v_encode);
 
/* The FOP process */
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
 
driver.setInputSource(new InputSource(new StringReader(v_fop)));
 
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
driver.setOutputStream(outBuffer);
 
driver.run();
 
OutputStream outStream = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(outBuffer.size());
outStream.write(outBuffer.toByteArray());
outStream.flush();
%>

No comments: