Java 类org.dom4j.io.HTMLWriter 实例源码

项目:joai-project    文件:Dom4jUtils.java   
/**
 *  Formats an {@link org.dom4j.Node} as a printable string
 *
 * @param  node  the Node to display
 * @return       a nicley-formatted String representation of the Node.
 */
public static String prettyPrint(Node node) {
    StringWriter sw = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();

    format.setXHTML(true);
    //Default is false, this produces XHTML
    HTMLWriter ppWriter = new HTMLWriter(sw, format);
    try {
        ppWriter.write(node);
        ppWriter.flush();
    } catch (Exception e) {
        return ("Pretty Print Failed");
    }
    return sw.toString();
}
项目:dls-repository-stack    文件:Dom4jUtils.java   
/**
 *  Formats an {@link org.dom4j.Node} as a printable string
 *
 * @param  node  the Node to display
 * @return       a nicley-formatted String representation of the Node.
 */
public static String prettyPrint(Node node) {
    StringWriter sw = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();

    format.setXHTML(true);
    //Default is false, this produces XHTML
    HTMLWriter ppWriter = new HTMLWriter(sw, format);
    try {
        ppWriter.write(node);
        ppWriter.flush();
    } catch (Exception e) {
        return ("Pretty Print Failed");
    }
    return sw.toString();
}
项目:joai-project    文件:SchemaViewerForm.java   
/**
 *  Description of the Method
 *
 *@param  node           Description of the Parameter
 *@return                Description of the Return Value
 *@exception  Exception  Description of the Exception
 */
private String prettyPrint(Node node)
    throws Exception {
    StringWriter sw = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    //These are the default formats from createPrettyPrint, so you needn't set them:
    //  format.setNewlines(true);
    //  format.setTrimText(true);
    format.setXHTML(true);
    //Default is false, this produces XHTML
    HTMLWriter ppWriter = new HTMLWriter(sw, format);
    ppWriter.write(node);
    ppWriter.flush();
    return sw.toString();
}
项目:abina-common-util    文件:StringUtil.java   
/**
 * html 必须是格式良好的
 * 
 * @param str
 * @return
 * @throws Exception
 */
public static String formatHtml(String str) throws Exception {
    Document document = null;
    document = DocumentHelper.parseText(str);

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("utf-8");
    StringWriter writer = new StringWriter();

    HTMLWriter htmlWriter = new HTMLWriter(writer, format);

    htmlWriter.write(document);
    htmlWriter.close();
    return writer.toString();
}
项目:dls-repository-stack    文件:AdvancedQueryForm.java   
/**
 *  Description of the Method
 *
 *@param  node           Description of the Parameter
 *@return                Description of the Return Value
 *@exception  Exception  Description of the Exception
 */
private String prettyPrint(Node node)
    throws Exception {
    StringWriter sw = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    //These are the default formats from createPrettyPrint, so you needn't set them:
    //  format.setNewlines(true);
    //  format.setTrimText(true);
    format.setXHTML(true);
    //Default is false, this produces XHTML
    HTMLWriter ppWriter = new HTMLWriter(sw, format);
    ppWriter.write(node);
    ppWriter.flush();
    return sw.toString();
}
项目:dls-repository-stack    文件:SchemaViewerForm.java   
/**
 *  Description of the Method
 *
 *@param  node           Description of the Parameter
 *@return                Description of the Return Value
 *@exception  Exception  Description of the Exception
 */
private String prettyPrint(Node node)
    throws Exception {
    StringWriter sw = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    //These are the default formats from createPrettyPrint, so you needn't set them:
    //  format.setNewlines(true);
    //  format.setTrimText(true);
    format.setXHTML(true);
    //Default is false, this produces XHTML
    HTMLWriter ppWriter = new HTMLWriter(sw, format);
    ppWriter.write(node);
    ppWriter.flush();
    return sw.toString();
}
项目:jmsRestful    文件:StringUtil.java   
/**
 * html 必须是格式良好的
 * @param str
 * @return
 * @throws Exception
 */
public static String formatHtml(String str) throws Exception {
    Document document = null;
    document = DocumentHelper.parseText(str);

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("utf-8");
    StringWriter writer = new StringWriter();

    HTMLWriter htmlWriter = new HTMLWriter(writer, format);

    htmlWriter.write(document);
    htmlWriter.close();
    return writer.toString();
}
项目:rembrandt    文件:ReportGeneratorHelper.java   
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;
    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";
}