Search in sources :

Example 6 with XmlWriter

use of io.milton.http.XmlWriter in project lobcder by skoulouzis.

the class TestXmlWriter method testNested.

public void testNested() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XmlWriter w = new XmlWriter(out);
    w.begin("a").begin("b").prop("b1", "b1_val").close().close();
    // .prop("a1","a1_val");
    w.flush();
    String s = out.toString();
    System.out.println("actual: \n" + s);
}
Also used : ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) XmlWriter(io.milton.http.XmlWriter)

Example 7 with XmlWriter

use of io.milton.http.XmlWriter in project lobcder by skoulouzis.

the class TestXmlWriter method test.

public void test() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XmlWriter w = new XmlWriter(out);
    XmlWriter.Element el = w.begin("a").writeAtt("att", "val");
    el.open();
    el.writeText("abc");
    el.close();
    w.flush();
    String s = out.toString();
    System.out.println("actual..");
    System.out.println(s);
    String expected = "<a att=\"val\">\nabc</a>\n";
    System.out.println("expected..");
    System.out.println(expected);
// assertEquals(expected,s);
}
Also used : ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) XmlWriter(io.milton.http.XmlWriter)

Example 8 with XmlWriter

use of io.milton.http.XmlWriter in project lobcder by skoulouzis.

the class PropFindXmlGenerator method generate.

public void generate(List<PropFindResponse> propFindResponses, OutputStream responseOutput) {
    Map<String, String> mapOfNamespaces = helper.findNameSpaces(propFindResponses);
    XmlWriter writer = new XmlWriter(responseOutput);
    writer.writeXMLHeader();
    writer.open(WebDavProtocol.NS_DAV.getPrefix(), "multistatus" + helper.generateNamespaceDeclarations(mapOfNamespaces));
    writer.newLine();
    helper.appendResponses(writer, propFindResponses, mapOfNamespaces);
    writer.close(WebDavProtocol.NS_DAV.getPrefix(), "multistatus");
    writer.flush();
}
Also used : XmlWriter(io.milton.http.XmlWriter)

Example 9 with XmlWriter

use of io.milton.http.XmlWriter in project lobcder by skoulouzis.

the class PropFindXmlGenerator method generate.

public String generate(List<PropFindResponse> propFindResponses) {
    ByteArrayOutputStream responseOutput = new ByteArrayOutputStream();
    generate(propFindResponses, responseOutput);
    Map<String, String> mapOfNamespaces = helper.findNameSpaces(propFindResponses);
    ByteArrayOutputStream generatedXml = new ByteArrayOutputStream();
    XmlWriter writer = new XmlWriter(generatedXml);
    writer.writeXMLHeader();
    writer.open(WebDavProtocol.NS_DAV.getPrefix(), "multistatus" + helper.generateNamespaceDeclarations(mapOfNamespaces));
    writer.newLine();
    helper.appendResponses(writer, propFindResponses, mapOfNamespaces);
    writer.close(WebDavProtocol.NS_DAV.getPrefix(), "multistatus");
    writer.flush();
    if (log.isTraceEnabled()) {
        log.trace("---- PROPFIND response START: " + HttpManager.request().getAbsolutePath() + " -----");
        log.trace(generatedXml.toString());
        log.trace("---- PROPFIND response END -----");
    }
    try {
        return responseOutput.toString("UTF-8");
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) XmlWriter(io.milton.http.XmlWriter)

Example 10 with XmlWriter

use of io.milton.http.XmlWriter in project lobcder by skoulouzis.

the class PropFindXmlGeneratorHelper method sendErrorProperties.

private void sendErrorProperties(Response.Status status, XmlWriter writer, Map<String, String> mapOfNamespaces, List<NameAndError> properties) {
    // log.debug( "sendUnknownProperties: " + properties.size() );
    if (!properties.isEmpty()) {
        XmlWriter.Element elPropStat = writer.begin(WebDavProtocol.NS_DAV.getPrefix(), "propstat").open();
        XmlWriter.Element elProp = writer.begin(WebDavProtocol.NS_DAV.getPrefix(), "prop").open();
        for (NameAndError ne : properties) {
            QName qname = ne.getName();
            String prefix = mapOfNamespaces.get(qname.getNamespaceURI());
            writer.writeProperty(prefix, qname.getLocalPart());
        }
        elProp.close();
        writer.writeProperty(WebDavProtocol.NS_DAV.getPrefix(), "status", status.toString());
        elPropStat.close();
    }
}
Also used : NameAndError(io.milton.http.webdav.PropFindResponse.NameAndError) QName(javax.xml.namespace.QName) XmlWriter(io.milton.http.XmlWriter)

Aggregations

XmlWriter (io.milton.http.XmlWriter)11 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)3 NameAndError (io.milton.http.webdav.PropFindResponse.NameAndError)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 QName (javax.xml.namespace.QName)2 HrefStatus (io.milton.http.HrefStatus)1 Status (io.milton.http.Response.Status)1 ByteArrayEntity (io.milton.http.entity.ByteArrayEntity)1 ValueAndType (io.milton.http.values.ValueAndType)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 TreeMap (java.util.TreeMap)1