List of usage examples for org.dom4j.io HTMLWriter HTMLWriter
public HTMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException
From source file:gov.nih.nci.ispy.web.helper.ReportGeneratorHelper.java
License:BSD License
/** * This static method will render a query report of the passed reportXML, in * HTML using the XSLT whose name has been passed, to the jsp whose * jspWriter has been passed. The request is used to acquire any filter * params that may have been added to the request and that may be applicable * to the XSLT./* w w w. ja v a 2 s . c o m*/ * * @param request --the request that will contain any parameters you want applied * to the XSLT that you specify * @param reportXML -- this is the XML that you want transformed to HTML * @param xsltFilename --this the XSLT that you want to use * @param out --the JSPWriter you want the transformed document to go to... */ /* public static void renderReport(HttpServletRequest request, Document reportXML, String xsltFilename, JspWriter out) { File styleSheet = new File(RembrandtContextListener.getContextPath()+"/XSL/"+xsltFilename); // load the transformer using JAX logger.debug("Applying XSLT "+xsltFilename); Transformer transformer; try { transformer = new Transformer(styleSheet, (HashMap)request.getAttribute(RembrandtConstants.FILTER_PARAM_MAP)); Document transformedDoc = transformer.transform(reportXML); //* // * right now this assumes that we will only have one XSL for CSV // * and it checks for that as we do not want to "pretty print" the CSV, we // * only want to spit it out as a string, or formatting gets messed up // * we will of course want to pretty print the XHTML for the graphical reports // * later we can change this to handle mult XSL CSVs // * RCL // if(!xsltFilename.equals(RembrandtConstants.DEFAULT_XSLT_CSV_FILENAME)){ OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer; writer = new XMLWriter(out, format ); writer.write( transformedDoc ); writer.close(); } else { String csv = transformedDoc.getStringValue(); csv.trim(); out.println(csv); } }catch (UnsupportedEncodingException uee) { logger.error("UnsupportedEncodingException"); logger.error(uee); }catch (IOException ioe) { logger.error("IOException"); logger.error(ioe); } } */ public static String renderReport(Map params, Document reportXML, String xsltFilename) { //used only for finding based AJAX //Changed XSL to xsl RCL 3/6...this is bombing File styleSheet = new File(ISPYContextListener.getContextPath() + "/xsl/" + xsltFilename); // load the transformer using JAXP logger.debug("Applying XSLT " + xsltFilename); Transformer transformer; try { transformer = new Transformer(styleSheet, params); Document transformedDoc = transformer.transform(reportXML); /* * right now this assumes that we will only have one XSL for CSV * and it checks for that as we do not want to "pretty print" the CSV, we * only want to spit it out as a string, or formatting gets messed up * we will of course want to pretty print the XHTML for the graphical reports * later we can change this to handle mult XSL CSVs * RCL */ if (!xsltFilename.equals(ispyConstants.DEFAULT_XSLT_CSV_FILENAME)) { StringBuffer sb = new StringBuffer(); OutputFormat format = OutputFormat.createCompactFormat(); StringWriter sw = new StringWriter(1024); HTMLWriter writer = new HTMLWriter(sw, format); writer.write(transformedDoc); sb = sw.getBuffer(); return sb.toString(); } else { String csv = transformedDoc.getStringValue(); csv.trim(); return csv; } } catch (UnsupportedEncodingException uee) { logger.error("UnsupportedEncodingException"); logger.error(uee); } catch (IOException ioe) { logger.error("IOException"); logger.error(ioe); } return "Reporting Error"; }
From source file:gov.nih.nci.rembrandt.web.helper.ReportGeneratorHelper.java
License:BSD License
public static String renderReport(Map params, Document reportXML, String xsltFilename) { //used only for finding based AJAX File styleSheet = new File(RembrandtContextListener.getContextPath() + "/XSL/" + xsltFilename); // load the transformer using JAXP logger.debug("Applying XSLT " + xsltFilename); Transformer transformer;//w w w . j a va 2s .c o m try { transformer = new Transformer(styleSheet, params); Document transformedDoc = transformer.transform(reportXML); /* * right now this assumes that we will only have one XSL for CSV * and it checks for that as we do not want to "pretty print" the CSV, we * only want to spit it out as a string, or formatting gets messed up * we will of course want to pretty print the XHTML for the graphical reports * later we can change this to handle mult XSL CSVs * RCL */ if (!xsltFilename.equals(RembrandtConstants.DEFAULT_XSLT_CSV_FILENAME)) { StringBuffer sb = new StringBuffer(); OutputFormat format = OutputFormat.createCompactFormat(); StringWriter sw = new StringWriter(1024); HTMLWriter writer = new HTMLWriter(sw, format); writer.write(transformedDoc); sb = sw.getBuffer(); return sb.toString(); } else { String csv = transformedDoc.getStringValue(); csv.trim(); return csv; } } catch (UnsupportedEncodingException uee) { logger.error("UnsupportedEncodingException"); logger.error(uee); } catch (IOException ioe) { logger.error("IOException"); logger.error(ioe); } return "Reporting Error"; }
From source file:net.contextfw.web.application.internal.WebResponder.java
License:Apache License
public void sendHTMLResponse(Document document, HttpServletResponse resp, Mode mode) throws ServletException, IOException { resp.setContentType(mode.getContentType()); resp.setHeader("Expires", "-1"); resp.setHeader("Pragma", "no-cache"); resp.setHeader("Cache-Control", "no-cache, no-store"); if (!transformers.isInitialized()) { synchronized (transformers) { if (!transformers.isInitialized()) { transformers.initialize(getXSLDocument()); }/* www .ja v a 2 s.c o m*/ } } Document rDocument = transformers.transform(document); if (mode == Mode.INIT) { rDocument.addDocType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"); } new HTMLWriter(resp.getWriter(), htmlFormat).write(rDocument); }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
public void writeAsHTML(OutputStream outputStream) throws IOException { HTMLWriter writer = new HTMLWriter(outputStream, OutputFormat.createPrettyPrint()); writer.write(this.document); writer.flush();/* ww w. ja va2 s . c o m*/ }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
public void writeAsHTML(OutputStream outputStream) throws IOException { HTMLWriter writer = new HTMLWriter(outputStream, OutputFormat.createPrettyPrint()); writer.write(this.document); writer.flush();/*from ww w .j a va 2 s. c om*/ }
From source file:org.apache.commons.jelly.tags.core.FileTag.java
License:Apache License
/** * A Factory method to create a new XMLOutput from the given Writer. *///from ww w . j av a2 s . c o m protected XMLOutput createXMLOutput(Writer writer) { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if (encoding != null) { format.setEncoding(encoding); } if (omitXmlDeclaration) { format.setSuppressDeclaration(true); } boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase("html"); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(writer, format) : new XMLWriter(writer, format); xmlWriter.setEscapeText(isEscapeText()); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
From source file:org.apache.taglibs.xtags.xpath.OutputTag.java
License:Apache License
public int doStartTag() throws JspException { OutputFormat format = null;/*from w ww. java 2 s. c o m*/ if (indent != null) { format = OutputFormat.createPrettyPrint(); format.setIndent(indent); } else { format = new OutputFormat(); } format.setOmitEncoding(asBoolean(omitXmlDeclaration)); Writer out = pageContext.getOut(); if (method != null && method.equalsIgnoreCase("html")) { xmlWriter = new HTMLWriter(out, format); } else { xmlWriter = new XMLWriter(out, format); } return EVAL_BODY_INCLUDE; }
From source file:org.thingml.testing.reportbuilder.ReportBuilder.java
License:Apache License
public void saveToHTML(String path) throws IOException { Document document = DocumentHelper.createDocument(); document.addDocType("html", null, null); Element html = document.addElement("html"); Element head = html.addElement("head"); Element body = html.addElement("body"); buildHead(html, head);//from ww w. ja v a 2 s . c o m buildDocument(head, body); addModal(body); OutputFormat format = OutputFormat.createPrettyPrint(); format.setExpandEmptyElements(true); FileWriter file = new FileWriter(path); HTMLWriter writer = new HTMLWriter(file, format); writer.write(document); writer.close(); }