use of org.dom4j.io.XMLWriter in project Openfire by igniterealtime.
the class ArchiveIndexer method loadPropertiesFile.
/**
* Loads a property manager for search properties if it isn't already
* loaded. If an XML file for the search properties isn't already
* created, it will attempt to make a file with default values.
*/
private void loadPropertiesFile(File searchDir) throws IOException {
File indexPropertiesFile = new File(searchDir, "indexprops.xml");
// If it doesn't exists we have to create it.
if (!indexPropertiesFile.exists()) {
org.dom4j.Document doc = DocumentFactory.getInstance().createDocument(DocumentFactory.getInstance().createElement("search"));
// Now, write out to the file.
Writer out = null;
try {
// Use JDOM's XMLOutputter to do the writing and formatting.
out = new FileWriter(indexPropertiesFile);
XMLWriter outputter = new XMLWriter(out, OutputFormat.createPrettyPrint());
outputter.write(doc);
outputter.flush();
} catch (Exception e) {
Log.error(e.getMessage(), e);
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
// Ignore.
}
}
}
indexProperties = new XMLProperties(indexPropertiesFile);
}
use of org.dom4j.io.XMLWriter in project randomizedtesting by randomizedtesting.
the class JUnit4Mojo method createTemporaryAntFile.
/**
* Create a temporary ANT file for executing JUnit4 ANT task.
*/
private File createTemporaryAntFile(Document doc) throws IOException {
Closer closer = Closer.create();
try {
File antFile = File.createTempFile("junit4-ant-", ".xml", dir);
OutputStream os = closer.register(new FileOutputStream(antFile));
XMLWriter xmlWriter = new XMLWriter(os, OutputFormat.createPrettyPrint());
xmlWriter.write(doc);
return antFile;
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
}
}
use of org.dom4j.io.XMLWriter in project reflections by ronmamo.
the class XmlSerializer method save.
public File save(final Reflections reflections, final String filename) {
File file = Utils.prepareFile(filename);
try {
Document document = createDocument(reflections);
XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(file), OutputFormat.createPrettyPrint());
xmlWriter.write(document);
xmlWriter.close();
} catch (IOException e) {
throw new ReflectionsException("could not save to file " + filename, e);
} catch (Throwable e) {
throw new RuntimeException("Could not save to file " + filename + ". Make sure relevant dependencies exist on classpath.", e);
}
return file;
}
use of org.dom4j.io.XMLWriter in project atlas by alibaba.
the class ManifestFileUtils method saveFile.
private static void saveFile(Document document, OutputFormat format, File file) throws IOException {
// 声明写XML的对象
XMLWriter writer = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
use of org.dom4j.io.XMLWriter in project atlas by alibaba.
the class ManifestFileUtils method minifyManifest.
public static void minifyManifest(File mainManifest, File destManifest) throws IOException, DocumentException {
// 声明写XML的对象
XMLWriter writer = null;
SAXReader reader = new SAXReader();
OutputFormat format = OutputFormat.createPrettyPrint();
// 设置XML文件的编码格式
format.setEncoding("UTF-8");
FileOutputStream fos = new FileOutputStream(destManifest);
if (mainManifest.exists()) {
try {
// 读取XML文件
Document document = reader.read(mainManifest);
// removeComments(document);
Element element = document.getRootElement();
element.clearContent();
writer = new XMLWriter(fos, format);
writer.write(document);
} finally {
if (null != writer) {
writer.close();
}
IOUtils.closeQuietly(fos);
}
}
}
Aggregations