Search in sources :

Example 61 with OutputFormat

use of org.dom4j.io.OutputFormat in project tdq-studio-se by Talend.

the class DriverManager method saveDrivers.

/**
 * Saves the drivers back to disk
 * @throws ExplorerException
 */
public void saveDrivers() throws ExplorerException {
    Element root = new DefaultElement(DRIVERS);
    for (ManagedDriver driver : drivers.values()) root.add(driver.describeAsXml());
    try {
        FileWriter writer = new FileWriter(new File(ApplicationFiles.USER_DRIVER_FILE_NAME));
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter xmlWriter = new XMLWriter(writer, format);
        xmlWriter.write(root);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new ExplorerException(e);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) FileWriter(java.io.FileWriter) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 62 with OutputFormat

use of org.dom4j.io.OutputFormat in project JFramework by gugumall.

the class JUtilDom4j method save.

/**
 * 将Document对象保存为指定编码的xml文件
 * @param doc
 * @param xmlPath
 * @param encoding
 * @throws Exception
 */
public static void save(Document doc, String xmlPath, String encoding) throws Exception {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding(encoding);
    format.setLineSeparator(System.getProperty("line.separator"));
    XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(xmlPath), encoding), format);
    writer.write(doc);
    writer.flush();
    writer.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputFormat(org.dom4j.io.OutputFormat) OutputStreamWriter(java.io.OutputStreamWriter) XMLWriter(org.dom4j.io.XMLWriter)

Example 63 with OutputFormat

use of org.dom4j.io.OutputFormat in project JFramework by gugumall.

the class JUtilDom4j method toString.

/**
 * 将Document对象转换成xml字符串
 * @param doc
 * @return
 * @throws Exception
 */
public static String toString(Document doc) throws Exception {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding(doc.getXMLEncoding());
    ByteArrayOutputStream byteOS = new ByteArrayOutputStream();
    XMLWriter writer = new XMLWriter(new OutputStreamWriter(byteOS, doc.getXMLEncoding()), format);
    writer.write(doc);
    writer.flush();
    writer.close();
    return byteOS.toString(doc.getXMLEncoding());
}
Also used : OutputFormat(org.dom4j.io.OutputFormat) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLWriter(org.dom4j.io.XMLWriter)

Example 64 with OutputFormat

use of org.dom4j.io.OutputFormat in project jbosstools-hibernate by jbosstools.

the class XMLHelper method dump.

public static void dump(Element element) {
    try {
        // try to "pretty print" it
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(System.out, outformat);
        writer.write(element);
        writer.flush();
        // $NON-NLS-1$
        System.out.println("");
    } catch (Throwable t) {
        // otherwise, just dump it
        System.out.println(element.asXML());
    }
}
Also used : OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter)

Example 65 with OutputFormat

use of org.dom4j.io.OutputFormat in project iaf by ibissource.

the class XmlUtils method canonicalize.

public static String canonicalize(String input) throws DocumentException, IOException {
    if (StringUtils.isEmpty(input)) {
        return null;
    }
    org.dom4j.Document doc = DocumentHelper.parseText(input);
    StringWriter sw = new StringWriter();
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setExpandEmptyElements(true);
    XMLWriter xw = new XMLWriter(sw, format);
    xw.write(doc);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter)

Aggregations

OutputFormat (org.dom4j.io.OutputFormat)89 XMLWriter (org.dom4j.io.XMLWriter)75 IOException (java.io.IOException)39 Document (org.dom4j.Document)31 Element (org.dom4j.Element)27 ByteArrayOutputStream (java.io.ByteArrayOutputStream)18 StringWriter (java.io.StringWriter)18 SAXReader (org.dom4j.io.SAXReader)16 File (java.io.File)15 FileOutputStream (java.io.FileOutputStream)14 FileWriter (java.io.FileWriter)10 OutputStreamWriter (java.io.OutputStreamWriter)8 StringReader (java.io.StringReader)6 DocumentException (org.dom4j.DocumentException)6 OutputStream (java.io.OutputStream)5 Test (org.junit.Test)5 BufferedOutputStream (java.io.BufferedOutputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4