Example usage for org.dom4j.io OutputFormat setEncoding

List of usage examples for org.dom4j.io OutputFormat setEncoding

Introduction

In this page you can find the example usage for org.dom4j.io OutputFormat setEncoding.

Prototype

public void setEncoding(String encoding) 

Source Link

Document

DOCUMENT ME!

Usage

From source file:org.apache.openmeetings.servlet.outputhandler.LangExport.java

License:Apache License

public static void serializetoXML(OutputStream out, String aEncodingScheme, Document doc) throws Exception {
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding(aEncodingScheme);
    XMLWriter writer = new XMLWriter(out, outformat);
    writer.write(doc);/*from   w ww . ja  v a  2s . c  o  m*/
    writer.flush();
}

From source file:org.apache.openmeetings.util.LangExport.java

License:Apache License

public static void serializetoXML(Writer out, String aEncodingScheme, Document doc) throws Exception {
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding(aEncodingScheme);
    XMLWriter writer = new XMLWriter(out, outformat);
    writer.write(doc);/*from www  .  j  a v a2  s  .c  o  m*/
    writer.flush();
}

From source file:org.apache.openmeetings.util.XmlExport.java

License:Apache License

public static void toXml(Writer out, Document doc) throws Exception {
    OutputFormat outformat = OutputFormat.createPrettyPrint();
    outformat.setEncoding(StandardCharsets.UTF_8.name());
    XMLWriter writer = new XMLWriter(out, outformat);
    writer.write(doc);/* w w  w.j  a v  a 2  s .c o  m*/
    writer.flush();
    out.flush();
    out.close();
}

From source file:org.apache.poi.openxml4j.opc.StreamHelper.java

License:Apache License

/**
 * Turning the DOM4j object in the specified output stream.
 *
 * @param xmlContent/* ww w  .j a v  a2 s .  co m*/
 *            The XML document.
 * @param outStream
 *            The OutputStream in which the XML document will be written.
 * @return <b>true</b> if the xml is successfully written in the stream,
 *         else <b>false</b>.
 */
public static boolean saveXmlInStream(Document xmlContent, OutputStream outStream) {
    try {
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        outformat.setEncoding("UTF-8");
        XMLWriter writer = new XMLWriter(outStream, outformat);
        writer.write(xmlContent);
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:org.dentaku.gentaku.tools.cgen.plugin.GenGenPlugin.java

License:Apache License

private void prettyPrint(Document document, Writer writer) throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding(encoding);
    format.setSuppressDeclaration(false);
    format.setExpandEmptyElements(false);

    XMLWriter xmlWriter = new XMLWriter(writer, format);
    xmlWriter.write(document);/*from  ww w . j  a  va 2s.c  om*/
    xmlWriter.flush();
}

From source file:org.dentaku.gentaku.tools.cgen.visitor.JellyTemplateGeneratingVisitor.java

License:Apache License

public void handleElement(Element element) throws VisitorException {
    if (element.getParent().getName().equals("schema")) {
        QName rootName = DocumentFactory.getInstance().createQName("jelly", "j", "jelly:core");
        Branch parent = DocumentHelper.createDocument().addElement(rootName).addNamespace("x", "jelly:xml");

        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding(getEncoding());
        format.setSuppressDeclaration(false);
        format.setExpandEmptyElements(false);

        pushParent(parent.addElement(element.getName()));
        for (Iterator it = element.elementIterator(); it.hasNext();) {
            visit((Element) it.next());
        }/*from   w  w  w.j a v a2  s .c  o m*/
        popParent();

        try {
            String filename = element.getName() + ".jelly";

            Writer out = new FileWriter(new File(getRootDir(), filename));
            final XMLWriter xmlWriter = new XMLWriter(out, format);
            xmlWriter.setEscapeText(false);

            xmlWriter.write(parent);
            xmlWriter.flush();
            xmlWriter.close();
        } catch (Exception e) {
            throw new VisitorException("Exception occurred when running Jelly", e);
        }

        topLevelElements.put(element.getName(), element);

    } else {
        String refName = element.attributeValue("ref");
        if (refName != null) {
            Branch parent = getCurrentParent();
            // create an include
            QName qName = DocumentFactory.getInstance().createQName("import", "j", "jelly:core");
            parent.addElement(qName).addAttribute("uri", refName + ".jelly").addAttribute("inherit", "true");
        }
    }
}

From source file:org.dentaku.gentaku.tools.cgen.xmi.XMIGenTask.java

License:Apache License

private void writeFile(Branch document, File file) throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding(System.getProperty("file.encoding"));
    format.setSuppressDeclaration(false);
    format.setExpandEmptyElements(false);

    Writer out = new FileWriter(file);
    final XMLWriter xmlWriter = new XMLWriter(out, format);
    xmlWriter.setEscapeText(false);/*from  w ww. j  a  v a  2 s  . c  om*/

    xmlWriter.write(document);
    xmlWriter.flush();
    xmlWriter.close();
}

From source file:org.directwebremoting.convert.DOM4JConverter.java

License:Apache License

public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws ConversionException {
    try {//from w  w w.j  av  a  2  s .  com
        // Using XSLT to convert to a stream. Setup the source
        if (!(data instanceof Node)) {
            throw new ConversionException(data.getClass());
        }

        Node node = (Node) data;

        OutputFormat outformat = OutputFormat.createCompactFormat();
        outformat.setEncoding("UTF-8");

        // Setup the destination
        StringWriter xml = new StringWriter();

        XMLWriter writer = new XMLWriter(xml, outformat);
        writer.write(node);
        writer.flush();
        xml.flush();

        String script;
        if (data instanceof Element) {
            script = EnginePrivate.xmlStringToJavascriptDomElement(xml.toString());
        } else {
            script = EnginePrivate.xmlStringToJavascriptDomDocument(xml.toString());
        }

        OutboundVariable ov = new NonNestedOutboundVariable(script);
        outctx.put(data, ov);

        return ov;
    } catch (ConversionException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new ConversionException(data.getClass(), ex);
    }
}

From source file:org.eclipse.jubula.client.core.businessprocess.HtmlResultReportWriter.java

License:Open Source License

/**
 * //  w ww.j  av a2  s .c  om
 * {@inheritDoc}
 */
public void write(Document document) {
    // write html, transformed by XSLT
    OutputFormat htmlFormat = OutputFormat.createCompactFormat();
    htmlFormat.setEncoding(m_writer.getEncoding());
    TransformerFactory factory = TransformerFactory.newInstance();
    try {
        TestResultBP trbp = TestResultBP.getInstance();
        final Transformer transformer = factory
                .newTransformer(new StreamSource(trbp.getXslFileURL().openStream()));
        DocumentSource source = new DocumentSource(document);
        DocumentResult result = new DocumentResult();
        transformer.transform(source, result);
        Document transformedDoc = result.getDocument();
        XMLWriter htmlWriter = new XMLWriter(m_writer, htmlFormat);
        htmlWriter.write(transformedDoc);
    } catch (TransformerConfigurationException e1) {
        LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e1);
    } catch (TransformerException e) {
        LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e);
    } catch (IOException e) {
        LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e);
    }

}

From source file:org.eclipse.jubula.client.core.businessprocess.XmlResultReportWriter.java

License:Open Source License

/**
 * //  w  w w. j a  v  a 2 s.  c  o m
 * {@inheritDoc}
 */
public void write(Document document) {
    OutputFormat xmlFormat = OutputFormat.createPrettyPrint();
    xmlFormat.setEncoding(m_writer.getEncoding());

    XMLWriter xmlWriter = null;
    try {
        // write xml
        xmlWriter = new XMLWriter(m_writer, xmlFormat);
        xmlWriter.write(document);
    } catch (UnsupportedEncodingException e) {
        LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e);
    } catch (IOException e) {
        LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e);
    }

}