use of org.dom4j.io.XMLWriter in project reflections by ronmamo.
the class XmlSerializer method toString.
public String toString(final Reflections reflections) {
Document document = createDocument(reflections);
try {
StringWriter writer = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
xmlWriter.write(document);
xmlWriter.close();
return writer.toString();
} catch (IOException e) {
throw new RuntimeException();
}
}
use of org.dom4j.io.XMLWriter in project gradle by gradle.
the class DOM4JSerializer method exportToFile.
public static void exportToFile(ExportInteraction exportInteraction, ExtensionFileFilter fileFilter, DOM4JSettingsNode settingsNode) {
File file = promptForFile(exportInteraction, fileFilter);
if (file == null) {
//the user canceled.
return;
}
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
} catch (FileNotFoundException e) {
LOGGER.error("Could not write to file: " + file.getAbsolutePath(), e);
exportInteraction.reportError("Could not write to file: " + file.getAbsolutePath());
return;
}
try {
XMLWriter xmlWriter = new XMLWriter(fileOutputStream, OutputFormat.createPrettyPrint());
Element rootElement = settingsNode.getElement();
rootElement.detach();
Document document = DocumentHelper.createDocument(rootElement);
xmlWriter.write(document);
} catch (Throwable t) {
LOGGER.error("Internal error. Failed to save.", t);
exportInteraction.reportError("Internal error. Failed to save.");
} finally {
closeQuietly(fileOutputStream);
}
}
use of org.dom4j.io.XMLWriter in project tdi-studio-se by Talend.
the class XMLUtil method formatXMLFile.
/**
* format the exist xml file.
*
* @param filename
* @return
*/
public static int formatXMLFile(String filename, String enCode) {
int returnValue = 0;
try {
SAXReader saxReader = new SAXReader();
org.dom4j.Document document = saxReader.read(new File(filename));
XMLWriter writer = null;
/** format the output like the webBrowser */
OutputFormat format = OutputFormat.createPrettyPrint();
/** give the xml encoding */
format.setEncoding(enCode);
writer = new XMLWriter(new FileWriter(new File(filename)), format);
writer.write(document);
writer.close();
/** succes will retun 1 */
returnValue = 1;
} catch (Exception ex) {
// ex.printStackTrace();
org.talend.componentdesigner.exception.ExceptionHandler.process(ex);
}
return returnValue;
}
use of org.dom4j.io.XMLWriter in project cpsolver by UniTime.
the class StudentRequestXml method main.
public static void main(String[] args) {
try {
ToolBox.configureLogging();
StudentSectioningModel model = new StudentSectioningModel(new DataProperties());
Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
StudentSectioningXMLLoader xmlLoad = new StudentSectioningXMLLoader(model, assignment);
xmlLoad.setInputFile(new File(args[0]));
xmlLoad.load();
Document document = exportModel(assignment, model);
FileOutputStream fos = new FileOutputStream(new File(args[1]));
(new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(document);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.dom4j.io.XMLWriter in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method saveXmlDocoment.
protected void saveXmlDocoment(Document document, File outputFile) throws IOException {
XMLWriter output = null;
try {
output = new XMLWriter(new FileWriter(outputFile), OutputFormat.createPrettyPrint());
output.write(document);
} finally {
output.close();
}
}
Aggregations