Search in sources :

Example 36 with XMLWriter

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

the class Test method save.

/**
     * Save the problem and the resulting assignment
     * @param outputDir output directory
     * @param assignment final assignment
     */
protected void save(File outputDir, Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) {
    try {
        File outFile = new File(outputDir, "solution.xml");
        FileOutputStream fos = new FileOutputStream(outFile);
        try {
            (new XMLWriter(fos, OutputFormat.createPrettyPrint())).write(save(assignment));
            fos.flush();
        } finally {
            fos.close();
        }
    } catch (Exception e) {
        sLog.error("Failed to save solution: " + e.getMessage(), e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter) IOException(java.io.IOException)

Example 37 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 38 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 39 with XMLWriter

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

the class RightManager method writeXML.

private void writeXML(String fileName, Document document) throws IOException {
    // Pretty print the document to output file
    OutputFormat format = OutputFormat.createPrettyPrint();
    BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
    XMLWriter xmlWriter = new XMLWriter(writer, format);
    xmlWriter.write(document);
    writer.close();
}
Also used : FileWriter(java.io.FileWriter) OutputFormat(org.dom4j.io.OutputFormat) XMLWriter(org.dom4j.io.XMLWriter) BufferedWriter(java.io.BufferedWriter)

Example 40 with XMLWriter

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

the class DavMethod method toHttpMethod.

public HttpMethod toHttpMethod(DavContext ctxt, String targetUrl) throws IOException, DavException {
    if (ctxt.getUpload() != null && ctxt.getUpload().getSize() > 0) {
        PostMethod method = new PostMethod(targetUrl) {

            @Override
            public String getName() {
                return getMethodName();
            }
        };
        RequestEntity reqEntry;
        if (ctxt.hasRequestMessage()) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(baos);
            writer.write(ctxt.getRequestMessage());
            reqEntry = new ByteArrayRequestEntity(baos.toByteArray());
        } else {
            // this could be a huge upload
            reqEntry = new InputStreamRequestEntity(ctxt.getUpload().getInputStream(), ctxt.getUpload().getSize());
        }
        method.setRequestEntity(reqEntry);
        return method;
    }
    return new GetMethod(targetUrl) {

        @Override
        public String getName() {
            return getMethodName();
        }
    };
}
Also used : InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity) XMLWriter(org.dom4j.io.XMLWriter) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity)

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