RE: FOP and DOM Success
HI Solange , I do not know much about the userconfig file . I understood it as a way to specify additional command line options . I think changing the userconfig file and building the FOP should be enough . Please looks at Options class in org.apache.fop.apps.Options for more details ! Lakshmi -Original Message- From: Solange Desseignes [mailto:[EMAIL PROTECTED] Sent: Monday, January 21, 2002 12:26 AM To: [EMAIL PROTECTED] Subject: RE: FOP and DOM Success Thank you for this example !!! But how can I add an userconfig file in the transformation ??? -Message d'origine- De : Lakshmi Anantharaman [mailto:[EMAIL PROTECTED] Envoyé : vendredi 18 janvier 2002 21:26 À : Fop-User (E-mail) Objet : FOP and DOM Success I tried for long and with the help of fop-dev archive got my FOP servlet to work with a DOM . Here comes the code . I hope it is useful to someone down the line ! public void renderXML(HttpServletResponse response) throws ServletException { try { //Instantiate a DocumentBuilderFactory. DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); // And setNamespaceAware, which is required when parsing xsl files dFactory.setNamespaceAware(true); //Use the DocumentBuilderFactory to create a DocumentBuilder. DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); /**/ FileInputStream xmlfile = new FileInputStream("c:\\bea\\wlserver6.0\\contact.xml" ); Document xmlDoc = dBuilder.parse(xmlfile); javax.xml.transform.dom.DOMSource xmlDomSource = new javax.xml.transform.dom.DOMSource(xmlDoc); // // FileInputStream xsltFile = new FileInputStream("contactFO.xsl"); org.w3c.dom.Document xslDoc = dBuilder.parse(xsltFile); javax.xml.transform.dom.DOMSource xslDomSource = new javax.xml.transform.dom.DOMSource(xslDoc); javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); javax.xml.transform.Templates templates = tFactory.newTemplates(xslDomSource); javax.xml.transform.Transformer transformer = templates.newTransformer(); /*/ javax.xml.transform.dom.DOMResult foDomResult = new javax.xml.transform.dom.DOMResult(); transformer.transform(xmlDomSource, foDomResult); // Avoiding this step was what gave the null pointer exception ! org.w3c.dom.Document foDoc =(org.w3c.dom.Document)foDomResult.getNode(); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType("application/pdf"); org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver(); driver.setErrorDump(true); driver.setRenderer(driver.RENDER_PDF); driver.setupDefaultMappings() ; driver.setOutputStream(out); driver.render(foDoc); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); }catch(FileNotFoundException fnf) { fnf.printStackTrace(); } catch (Exception ex) { throw new ServletException(ex); } } Lakshmi
RE: FOP and DOM Success
Thank you for this example !!! But how can I add an userconfig file in the transformation ??? -Message d'origine- De : Lakshmi Anantharaman [mailto:[EMAIL PROTECTED] Envoyé : vendredi 18 janvier 2002 21:26 À : Fop-User (E-mail) Objet : FOP and DOM Success I tried for long and with the help of fop-dev archive got my FOP servlet to work with a DOM . Here comes the code . I hope it is useful to someone down the line ! public void renderXML(HttpServletResponse response) throws ServletException { try { //Instantiate a DocumentBuilderFactory. DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); // And setNamespaceAware, which is required when parsing xsl files dFactory.setNamespaceAware(true); //Use the DocumentBuilderFactory to create a DocumentBuilder. DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); /**/ FileInputStream xmlfile = new FileInputStream("c:\\bea\\wlserver6.0\\contact.xml" ); Document xmlDoc = dBuilder.parse(xmlfile); javax.xml.transform.dom.DOMSource xmlDomSource = new javax.xml.transform.dom.DOMSource(xmlDoc); // // FileInputStream xsltFile = new FileInputStream("contactFO.xsl"); org.w3c.dom.Document xslDoc = dBuilder.parse(xsltFile); javax.xml.transform.dom.DOMSource xslDomSource = new javax.xml.transform.dom.DOMSource(xslDoc); javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); javax.xml.transform.Templates templates = tFactory.newTemplates(xslDomSource); javax.xml.transform.Transformer transformer = templates.newTransformer(); /*/ javax.xml.transform.dom.DOMResult foDomResult = new javax.xml.transform.dom.DOMResult(); transformer.transform(xmlDomSource, foDomResult); // Avoiding this step was what gave the null pointer exception ! org.w3c.dom.Document foDoc =(org.w3c.dom.Document)foDomResult.getNode(); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType("application/pdf"); org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver(); driver.setErrorDump(true); driver.setRenderer(driver.RENDER_PDF); driver.setupDefaultMappings() ; driver.setOutputStream(out); driver.render(foDoc); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); }catch(FileNotFoundException fnf) { fnf.printStackTrace(); } catch (Exception ex) { throw new ServletException(ex); } } Lakshmi
VS: FOP and DOM Success
Thank you, I think this code really is useful! I really have reported a bu to bugzilla about the DOM input. the bug number is 5075. Should someone add this code there too as it really has to do with the reported problem? -Teemu > -Alkuperäinen viesti- > Lähettäjä:Lakshmi Anantharaman > [SMTP:[EMAIL PROTECTED] > Lähetetty:18. tammikuuta 2002 22:26 > Vastaanottaja:Fop-User (E-mail) > Aihe: FOP and DOM Success > > I tried for long and with the help of fop-dev archive got my FOP servlet > to > work with a DOM . > Here comes the code . I hope it is useful to someone down the line ! > > public void renderXML(HttpServletResponse response) throws > ServletException > { > try { > //Instantiate a DocumentBuilderFactory. > DocumentBuilderFactory dFactory = > DocumentBuilderFactory.newInstance(); > // And setNamespaceAware, which is required when parsing xsl files > dFactory.setNamespaceAware(true); > //Use the DocumentBuilderFactory to create a DocumentBuilder. > DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); > > /**/ > FileInputStream xmlfile = new > FileInputStream("c:\\bea\\wlserver6.0\\contact.xml" ); > Document xmlDoc = dBuilder.parse(xmlfile); > javax.xml.transform.dom.DOMSource xmlDomSource = new > javax.xml.transform.dom.DOMSource(xmlDoc); > // > > > // > FileInputStream xsltFile = new FileInputStream("contactFO.xsl"); > > org.w3c.dom.Document xslDoc = dBuilder.parse(xsltFile); > javax.xml.transform.dom.DOMSource xslDomSource = new > javax.xml.transform.dom.DOMSource(xslDoc); > javax.xml.transform.TransformerFactory tFactory = > javax.xml.transform.TransformerFactory.newInstance(); > javax.xml.transform.Templates templates = > tFactory.newTemplates(xslDomSource); > javax.xml.transform.Transformer transformer = > templates.newTransformer(); > /*/ > > javax.xml.transform.dom.DOMResult foDomResult = new > javax.xml.transform.dom.DOMResult(); > transformer.transform(xmlDomSource, foDomResult); > > // Avoiding this step was what gave the null pointer exception ! > org.w3c.dom.Document foDoc > =(org.w3c.dom.Document)foDomResult.getNode(); > > > ByteArrayOutputStream out = new ByteArrayOutputStream(); > response.setContentType("application/pdf"); > org.apache.fop.apps.Driver driver = new > org.apache.fop.apps.Driver(); > driver.setErrorDump(true); > driver.setRenderer(driver.RENDER_PDF); > driver.setupDefaultMappings() ; > driver.setOutputStream(out); > driver.render(foDoc); > > byte[] content = out.toByteArray(); > response.setContentLength(content.length); > response.getOutputStream().write(content); > response.getOutputStream().flush(); > }catch(FileNotFoundException fnf) > { > fnf.printStackTrace(); > } > catch (Exception ex) { > throw new ServletException(ex); > } > } > Lakshmi
FOP and DOM Success
I tried for long and with the help of fop-dev archive got my FOP servlet to work with a DOM . Here comes the code . I hope it is useful to someone down the line ! public void renderXML(HttpServletResponse response) throws ServletException { try { //Instantiate a DocumentBuilderFactory. DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); // And setNamespaceAware, which is required when parsing xsl files dFactory.setNamespaceAware(true); //Use the DocumentBuilderFactory to create a DocumentBuilder. DocumentBuilder dBuilder = dFactory.newDocumentBuilder(); /**/ FileInputStream xmlfile = new FileInputStream("c:\\bea\\wlserver6.0\\contact.xml" ); Document xmlDoc = dBuilder.parse(xmlfile); javax.xml.transform.dom.DOMSource xmlDomSource = new javax.xml.transform.dom.DOMSource(xmlDoc); // // FileInputStream xsltFile = new FileInputStream("contactFO.xsl"); org.w3c.dom.Document xslDoc = dBuilder.parse(xsltFile); javax.xml.transform.dom.DOMSource xslDomSource = new javax.xml.transform.dom.DOMSource(xslDoc); javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); javax.xml.transform.Templates templates = tFactory.newTemplates(xslDomSource); javax.xml.transform.Transformer transformer = templates.newTransformer(); /*/ javax.xml.transform.dom.DOMResult foDomResult = new javax.xml.transform.dom.DOMResult(); transformer.transform(xmlDomSource, foDomResult); // Avoiding this step was what gave the null pointer exception ! org.w3c.dom.Document foDoc =(org.w3c.dom.Document)foDomResult.getNode(); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType("application/pdf"); org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver(); driver.setErrorDump(true); driver.setRenderer(driver.RENDER_PDF); driver.setupDefaultMappings() ; driver.setOutputStream(out); driver.render(foDoc); byte[] content = out.toByteArray(); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); }catch(FileNotFoundException fnf) { fnf.printStackTrace(); } catch (Exception ex) { throw new ServletException(ex); } } Lakshmi