Search in sources :

Example 1 with XmlWriter

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

the class CDataValueWriterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    out = new ByteArrayOutputStream();
    writer = new CDataValueWriter();
    xmlWriter = new XmlWriter(out);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlWriter(io.milton.http.XmlWriter)

Example 2 with XmlWriter

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

the class MultiStatusEntity method write.

@Override
public void write(Response response, OutputStream outputStream) throws Exception {
    XmlWriter writer = new XmlWriter(response.getOutputStream());
    writer.writeXMLHeader();
    // only single namespace for this method
    writer.open("multistatus xmlns:D" + "=\"" + WebDavProtocol.NS_DAV + ":\"");
    writer.newLine();
    for (HrefStatus status : getStatii()) {
        XmlWriter.Element elResponse = writer.begin("response").open();
        writer.writeProperty("", "href", status.href);
        writer.writeProperty("", "status", status.status.code + "");
        elResponse.close();
    }
    writer.close("multistatus");
    writer.flush();
}
Also used : HrefStatus(io.milton.http.HrefStatus) XmlWriter(io.milton.http.XmlWriter)

Example 3 with XmlWriter

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

the class LockHandler method respondWithToken.

private void respondWithToken(LockToken tok, Request request, Response response) {
    response.setStatus(Status.SC_OK);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XmlWriter writer = new XmlWriter(out);
    writer.writeXMLHeader();
    String d = WebDavProtocol.DAV_PREFIX;
    writer.open(d + ":prop  xmlns:" + d + "=\"DAV:\"");
    writer.newLine();
    writer.open(d + ":lockdiscovery");
    writer.newLine();
    writer.open(d + ":activelock");
    writer.newLine();
    lockWriterHelper.appendType(writer, tok.info.type);
    lockWriterHelper.appendScope(writer, tok.info.scope);
    lockWriterHelper.appendDepth(writer, tok.info.depth);
    lockWriterHelper.appendOwner(writer, tok.info.lockedByUser);
    lockWriterHelper.appendTimeout(writer, tok.timeout.getSeconds());
    lockWriterHelper.appendTokenId(writer, tok.tokenId);
    String url = request.getAbsoluteUrl().replace("&", "%26");
    lockWriterHelper.appendRoot(writer, url);
    writer.close(d + ":activelock");
    writer.close(d + ":lockdiscovery");
    writer.close(d + ":prop");
    writer.flush();
    response.setEntity(new ByteArrayEntity(out.toByteArray()));
}
Also used : ByteArrayEntity(io.milton.http.entity.ByteArrayEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlWriter(io.milton.http.XmlWriter)

Example 4 with XmlWriter

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

the class PropFindXmlGeneratorHelper method appendResponse.

public void appendResponse(XmlWriter writer, PropFindResponse r, Map<String, String> mapOfNamespaces) {
    XmlWriter.Element el = writer.begin(WebDavProtocol.NS_DAV.getPrefix(), "response");
    el.open();
    writer.writeProperty(WebDavProtocol.NS_DAV.getPrefix(), "href", r.getHref());
    sendKnownProperties(writer, mapOfNamespaces, r.getKnownProperties(), r.getHref());
    if (r.getErrorProperties() != null) {
        for (Status status : r.getErrorProperties().keySet()) {
            List<NameAndError> props = r.getErrorProperties().get(status);
            sendErrorProperties(status, writer, mapOfNamespaces, props);
        }
    }
    el.close();
}
Also used : Status(io.milton.http.Response.Status) NameAndError(io.milton.http.webdav.PropFindResponse.NameAndError) XmlWriter(io.milton.http.XmlWriter)

Example 5 with XmlWriter

use of io.milton.http.XmlWriter in project polymap4-core by Polymap4.

the class DefaultContentFolder method sendDescription.

/**
 * This default implementation generates a file list in a HTML table. This
 * assumes, but does not check, that the given contentType is HTML.
 */
public void sendDescription(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException {
    XmlWriter w = new XmlWriter(out);
    w.open("html");
    w.open("body");
    w.begin("h1").open().writeText("webdav" + getPath().toString()).close();
    // description
    String description = getDescription(contentType);
    if (description != null) {
        w.begin("p").open().writeText(description).close();
    }
    // sort files and folders
    Map<String, IContentFile> files = new TreeMap();
    Map<String, IContentFolder> folders = new TreeMap();
    for (IContentNode node : getSite().getChildren(getPath())) {
        if (node instanceof IContentFile) {
            files.put(node.getName(), (IContentFile) node);
        } else if (node instanceof IContentFolder) {
            folders.put(node.getName(), (IContentFolder) node);
        } else {
            throw new IllegalStateException("Unknown node type: " + node.getClass());
        }
    }
    // folders list
    w.begin("h3").writeText("Folders: " + folders.size()).close();
    createFileTable(w, folders.values());
    // files list
    w.begin("h3").writeText("Files: " + files.size()).close();
    createFileTable(w, files.values());
    // upload via browser
    if (this instanceof IContentWriteable) {
        // FIXME hard coded servlet path
        String basePath = FilenameUtils.normalizeNoEndSeparator(getPath().toString());
        // + "/" + r.getName();
        String path = "/webdav" + basePath;
        w.writeText("<form action=\"" + path + "\"" + "  enctype=\"multipart/form-data\" method=\"post\">" + "  <p style=\"background:#e0e0e0;\">" + "    <b>File upload: </b>" + "    <input type=\"file\" name=\"datafile\" size=\"40\">" + // "  <div>" +
        "    <input type=\"submit\" value=\"Senden\">" + "  </p>" + "</form>");
    }
    w.begin("hr").writeAtt("size", "1").close();
    w.begin("em").open().writeText("Generated by <a href=\"http://github.com/Polymap4/\">Polymap4</a> WebDAV Service").close();
    w.close("body");
    w.close("html");
    w.flush();
    out.flush();
}
Also used : TreeMap(java.util.TreeMap) 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