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);
}
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);
}
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();
}
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);
}
}
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();
}
}
Aggregations