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);
}
}
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();
}
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());
}
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());
}
}
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();
}
Aggregations