Search in sources :

Example 6 with XMLWriter

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();
    }
}
Also used : Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter)

Example 7 with XMLWriter

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);
    }
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter)

Example 8 with XMLWriter

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;
}
Also used : SAXReader(org.dom4j.io.SAXReader) FileWriter(java.io.FileWriter) OutputFormat(org.dom4j.io.OutputFormat) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException)

Example 9 with XMLWriter

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();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) DataProperties(org.cpsolver.ifs.util.DataProperties) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 10 with XMLWriter

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();
    }
}
Also used : FileWriter(java.io.FileWriter) XMLWriter(org.dom4j.io.XMLWriter)

Aggregations

XMLWriter (org.dom4j.io.XMLWriter)42 Document (org.dom4j.Document)21 OutputFormat (org.dom4j.io.OutputFormat)17 IOException (java.io.IOException)15 Element (org.dom4j.Element)15 FileOutputStream (java.io.FileOutputStream)14 File (java.io.File)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 SAXReader (org.dom4j.io.SAXReader)9 FileWriter (java.io.FileWriter)6 StringWriter (java.io.StringWriter)5 BufferedWriter (java.io.BufferedWriter)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Writer (java.io.Writer)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TreeSet (java.util.TreeSet)3