Search in sources :

Example 31 with XMLWriter

use of org.dom4j.io.XMLWriter in project zm-mailbox by Zimbra.

the class WsdlGenerator method writeWsdl.

public static void writeWsdl(OutputStream xmlOut, String targetNamespace, String serviceName, List<WsdlInfoForNamespace> nsInfos) throws IOException {
    Document wsdlDoc = makeWsdlDoc(nsInfos, serviceName, targetNamespace);
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(xmlOut, format);
    writer.write(wsdlDoc);
    writer.close();
}
Also used : OutputFormat(org.dom4j.io.OutputFormat) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter)

Example 32 with XMLWriter

use of org.dom4j.io.XMLWriter in project zm-mailbox by Zimbra.

the class DomUtil method writeDocumentToStream.

public static void writeDocumentToStream(Document doc, OutputStream out) throws IOException {
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setTrimText(false);
    format.setOmitEncoding(false);
    XMLWriter writer = new XMLWriter(out, format);
    writer.write(doc);
}
Also used : OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter)

Example 33 with XMLWriter

use of org.dom4j.io.XMLWriter in project zm-mailbox by Zimbra.

the class DomUtil method toString.

/** Convert an Element to a String. */
public static String toString(Element env, boolean prettyPrint) {
    if (prettyPrint) {
        StringWriter buff = new StringWriter();
        try {
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter writer = new XMLWriter(buff, format);
            writer.write(env);
            writer.close();
        } catch (IOException e) {
        // ignore, since StringWriter doesn't throw IOExceptions
        }
        return buff.toString();
    } else {
        return env.asXML();
    }
}
Also used : StringWriter(java.io.StringWriter) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) XMLWriter(org.dom4j.io.XMLWriter)

Example 34 with XMLWriter

use of org.dom4j.io.XMLWriter in project tdi-studio-se by Talend.

the class ChangeMappingFileMigrationTask method changeSAPHanaMappingFile.

private void changeSAPHanaMappingFile(URL url) {
    File dir = new File(url.getFile());
    File target = null;
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            if (file.getName().equals("mapping_SAPHana.xml")) {
                //$NON-NLS-1$
                target = file;
                break;
            }
        }
    }
    if (target != null) {
        try {
            SAXReader reader = new SAXReader();
            Document document = reader.read(target);
            Element root = document.getRootElement();
            //$NON-NLS-1$
            Element node = root.element("dbms");
            //$NON-NLS-1$
            Attribute attr = node.attribute("label");
            if (attr != null && attr.getValue().equals("Mapping SAP Hana")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                attr.setValue("Mapping SAPHana");
                target.delete();
                XMLWriter writer = new XMLWriter(new FileWriter(target));
                writer.write(document);
                writer.close();
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) FileWriter(java.io.FileWriter) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 35 with XMLWriter

use of org.dom4j.io.XMLWriter in project cpsolver by UniTime.

the class TimetableXMLSaver method save.

public void save(File outFile) throws Exception {
    if (outFile == null)
        outFile = new File(iOutputFolder, "solution.xml");
    outFile.getParentFile().mkdirs();
    sLogger.debug("Writting XML data to:" + outFile);
    Document document = DocumentHelper.createDocument();
    document.addComment("University Course Timetabling");
    if (iSaveCurrent && getAssignment().nrAssignedVariables() != 0) {
        StringBuffer comments = new StringBuffer("Solution Info:\n");
        Map<String, String> solutionInfo = (getSolution() == null ? getModel().getExtendedInfo(getAssignment()) : getSolution().getExtendedInfo());
        for (String key : new TreeSet<String>(solutionInfo.keySet())) {
            String value = solutionInfo.get(key);
            comments.append("    " + key + ": " + value + "\n");
        }
        document.addComment(comments.toString());
    }
    Element root = document.addElement("timetable");
    doSave(root);
    if (iShowNames) {
        Progress.getInstance(getModel()).save(root);
        try {
            getSolver().getClass().getMethod("save", new Class[] { Element.class }).invoke(getSolver(), new Object[] { root });
        } catch (Exception e) {
        }
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(outFile);
        (new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(document);
        fos.flush();
        fos.close();
        fos = null;
    } finally {
        try {
            if (fos != null)
                fos.close();
        } catch (IOException e) {
        }
    }
    if (iConvertIds)
        iIdConvertor.save();
}
Also used : TreeSet(java.util.TreeSet) Element(org.dom4j.Element) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter) IOException(java.io.IOException)

Aggregations

XMLWriter (org.dom4j.io.XMLWriter)44 Document (org.dom4j.Document)22 OutputFormat (org.dom4j.io.OutputFormat)18 Element (org.dom4j.Element)16 IOException (java.io.IOException)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