115 lines
2.8 KiB
Java
115 lines
2.8 KiB
Java
package org.hwo.net.serverobjects;
|
|
|
|
import java.io.IOException;
|
|
|
|
import org.hwo.net.http.HttpException;
|
|
import org.hwo.net.serverobjects.dav.DAVCollection;
|
|
import org.hwo.net.serverobjects.dav.DAVPropertyName;
|
|
import org.hwo.net.serverobjects.dav.DAVPropertyNameList;
|
|
import org.hwo.net.serverobjects.dav.DAVResource;
|
|
import org.hwo.xml.NodeListIterator;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
|
|
public class DAVCollectionSO extends AbstractServerObject{
|
|
|
|
class RootCollection extends DAVCollection
|
|
{
|
|
|
|
public RootCollection(String name) {
|
|
super(name);
|
|
}
|
|
|
|
@Override
|
|
protected String constructURI() {
|
|
return "";
|
|
}
|
|
@Override
|
|
public DAVResource getParent() {
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private DAVCollection rootCollection;
|
|
|
|
public DAVCollectionSO()
|
|
{
|
|
rootCollection = new RootCollection("");
|
|
}
|
|
|
|
@Override
|
|
public void request(ServerObjectRequest request) throws IOException, HttpException
|
|
{
|
|
request.getHttpRequest().addResponseHeader("DAV", "1");
|
|
|
|
String method = request.getHttpRequest().getRequestMethod();
|
|
|
|
System.err.println("DAV Request: " + method);
|
|
|
|
if (method.equals("GET"))
|
|
{
|
|
request.getHttpRequest().setResponseHeader("Content-Type", "text/plain");
|
|
request.getHttpRequest().getResponseWriter().write("This is a DAV Container.");
|
|
} else if (method.equals("PROPFIND"))
|
|
{
|
|
doPROPFIND(request);
|
|
} else if (method.equals("PROPPATCH"))
|
|
{
|
|
doPROPPATCH(request);
|
|
} else if (method.equals("MKCOL"))
|
|
{
|
|
doMKCOL(request);
|
|
} else if (method.equals("DELETE"))
|
|
{
|
|
doDELETE(request);
|
|
} else if (method.equals("OPTIONS"))
|
|
{
|
|
doOPTIONS(request);
|
|
}
|
|
}
|
|
|
|
protected void doPROPFIND(ServerObjectRequest request) throws HttpException
|
|
{
|
|
System.err.println("PROPFIND:");
|
|
System.err.println(new String(request.getHttpRequest().getRequestContent()));
|
|
|
|
Document d = request.getHttpRequest().getXMLRequest();
|
|
if (d == null)
|
|
throw new HttpException(403);
|
|
|
|
Element propfind = d.getDocumentElement();
|
|
|
|
if (propfind.getLocalName().equals("propfind") && propfind.getNamespaceURI().equals("DAV:"))
|
|
{
|
|
for (Element child:NodeListIterator.create(propfind.getChildNodes()))
|
|
{
|
|
if (child.getLocalName().equals("prop"))
|
|
{
|
|
DAVPropertyNameList names = DAVPropertyNameList.fromXML(child);
|
|
for (DAVPropertyName name:names)
|
|
{
|
|
System.err.println("DAVProp: " + name.getNamespaceURI() + " : " + name.getPropertyName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
protected void doPROPPATCH(ServerObjectRequest request) throws HttpException
|
|
{
|
|
}
|
|
protected void doMKCOL(ServerObjectRequest request) throws HttpException
|
|
{
|
|
}
|
|
protected void doDELETE(ServerObjectRequest request) throws HttpException
|
|
{
|
|
}
|
|
protected void doOPTIONS(ServerObjectRequest request) throws HttpException
|
|
{
|
|
request.getHttpRequest().setResultCode(200);
|
|
}
|
|
|
|
}
|