[Bedework-commit] webdav r231 - in
releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet:
common shared
svnadmin at bedework.org
svnadmin at bedework.org
Fri Sep 3 16:14:56 EDT 2010
Author: douglm
Date: 2010-09-03 16:14:56 -0400 (Fri, 03 Sep 2010)
New Revision: 231
Modified:
releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/GetMethod.java
releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/MethodBase.java
releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsIntf.java
releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsNode.java
Log:
Changes to support ACCEPT header on GET
* Will enable fetching of calendars and address books when targeting collections
* Will be used by new web service to get XRD objects
Changes to XmlEmit to support better abbreviating of namespaces and better handling of default namespace. Also changes to handle some new xrd needs.
CalDAV server has partial support for CalWS - supports GET of XRD object.
Modified: releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/GetMethod.java
===================================================================
--- releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/GetMethod.java 2010-08-30 14:20:26 UTC (rev 230)
+++ releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/GetMethod.java 2010-09-03 20:14:56 UTC (rev 231)
@@ -29,8 +29,8 @@
import edu.rpi.cct.webdav.servlet.shared.WebdavException;
import edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf;
import edu.rpi.cct.webdav.servlet.shared.WebdavNsNode;
+import edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf.Content;
-import java.io.CharArrayReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
@@ -91,33 +91,30 @@
return;
}
- Reader in = null;
+ Content c = null;
- /* For binary */
- InputStream streamIn = null;
-
/** Get the content now to set up length, type etc.
*/
- String contentType;
- long contentLength;
if (node.getContentBinary()) {
- streamIn = intf.getBinaryContent(node);
- contentType = node.getContentType();
- contentLength = node.getContentLen();
- } else if (node.isCollection()) {
- if (intf.getDirectoryBrowsingDisallowed()) {
- throw new WebdavException(HttpServletResponse.SC_FORBIDDEN);
+ c = intf.getBinaryContent(node);
+ // XXX check accept header
+ } else {
+ c = intf.getContent(req, resp, node);
+ }
+
+ if (c.written) {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return;
+ }
+
+ if (c == null) {
+ if (debug) {
+ debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT);
}
- String content = generateHtml(req, node);
- in = new CharArrayReader(content.toCharArray());
- contentType = "text/html";
- contentLength = content.getBytes().length;
- } else {
- in = intf.getContent(req, resp, node);
- contentType = node.getContentType();
- contentLength = node.getContentLen();
+ resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ return;
}
resp.setHeader("ETag", node.getEtagValue(true));
@@ -126,16 +123,16 @@
resp.addHeader("Last-Modified", node.getLastmodDate().toString());
}
- resp.setContentType(contentType);
+ resp.setContentType(c.contentType);
- if (contentLength > Integer.MAX_VALUE) {
+ if (c.contentLength > Integer.MAX_VALUE) {
resp.setContentLength(-1);
} else {
- resp.setContentLength((int)contentLength);
+ resp.setContentLength((int)c.contentLength);
}
if (doContent) {
- if ((in == null) && (streamIn == null)) {
+ if ((c.stream == null) && (c.rdr == null)) {
if (debug) {
debugMsg("status: " + HttpServletResponse.SC_NO_CONTENT);
}
@@ -143,16 +140,13 @@
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
if (debug) {
- debugMsg("send content - length=" + node.getContentLen());
+ debugMsg("send content - length=" + c.contentLength);
}
- if (node.getContentBinary()) {
- } else {
- }
- if (node.getContentBinary()) {
- streamContent(streamIn, resp.getOutputStream());
+ if (c.stream != null) {
+ streamContent(c.stream, resp.getOutputStream());
} else {
- writeContent(in, resp.getWriter());
+ writeContent(c.rdr, resp.getWriter());
}
}
}
@@ -216,124 +210,5 @@
} catch (Throwable t) {}
}
}
-
- /** Return a String giving an HTML representation of the directory.
- *
- * TODO
- *
- * <p>Use some form of template to generate an internationalized form of the
- * listing. We don't need a great deal to start with. It will also allow us to
- * provide stylesheets, images etc. Probably place it in the resources directory.
- *
- * @param req
- * @param node WebdavNsNode
- * @return Reader
- * @throws WebdavException
- */
- protected String generateHtml(final HttpServletRequest req,
- final WebdavNsNode node) throws WebdavException {
- try {
- Sbuff sb = new Sbuff();
-
- sb.lines(new String[] {"<html>",
- " <head>"});
- /* Need some styles I guess */
- sb.append(" <title>");
- sb.append(node.getDisplayname());
- sb.line("</title>");
-
- sb.lines(new String[] {"</head>",
- "<body>"});
-
- sb.append(" <h1>");
- sb.append(node.getDisplayname());
- sb.line("</h1>");
-
- sb.line(" <hr>");
-
- sb.line(" <table width=\"100%\" " +
- "cellspacing=\"0\"" +
- " cellpadding=\"4\">");
-
- for (WebdavNsNode child: getNsIntf().getChildren(node)) {
- /* icon would be nice */
-
- sb.line("<tr>");
-
- if (node.isCollection()) {
- /* folder */
- } else {
- /* calendar? */
- }
-
- sb.line(" <td align=\"left\">");
- sb.append("<a href=\"");
- sb.append(req.getContextPath());
- sb.append(child.getUri());
- sb.append("\">");
- sb.append(child.getDisplayname());
- sb.line("</a>");
- sb.line("</td>");
-
- sb.line(" <td align=\"left\">");
-
- String lastMod = child.getLastmodDate();
-
- if (lastMod != null) {
- sb.line(lastMod);
- } else {
- sb.line(" ");
- }
- sb.line("</td>");
- sb.append("</tr>\r\n");
- }
-
- sb.line("</table>");
-
- /* Could use a footer */
- sb.line("</body>");
- sb.line("</html>");
-
- return sb.toString();
- } catch (WebdavException we) {
- throw we;
- } catch (Throwable t) {
- throw new WebdavException(t);
- }
- }
-
- private static class Sbuff {
- StringBuilder sb = new StringBuilder();
-
- /**
- * @param ss
- */
- public void lines(final String[] ss) {
- for (int i = 0; i < ss.length; i++) {
- line(ss[i]);
- }
- }
-
- /**
- * @param s
- */
- public void line(final String s) {
- sb.append(s);
- sb.append("\r\n");
- }
-
- /**
- * @param s
- */
- public void append(final String s) {
- sb.append(s);
- }
-
- @Override
- public String toString() {
- return sb.toString();
- }
- }
-
}
Modified: releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/MethodBase.java
===================================================================
--- releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/MethodBase.java 2010-08-30 14:20:26 UTC (rev 230)
+++ releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/common/MethodBase.java 2010-09-03 20:14:56 UTC (rev 231)
@@ -1,31 +1,3 @@
-/*
- Copyright (c) 2000-2005 University of Washington. All rights reserved.
-
- Redistribution and use of this distribution in source and binary forms,
- with or without modification, are permitted provided that:
-
- The above copyright notice and this permission notice appear in
- all copies and supporting documentation;
-
- The name, identifiers, and trademarks of the University of Washington
- are not used in advertising or publicity without the express prior
- written permission of the University of Washington;
-
- Recipients acknowledge that this distribution is made available as a
- research courtesy, "as is", potentially with defects, without
- any obligation on the part of the University of Washington to
- provide support, services, or repair;
-
- THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR
- IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION
- ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
- WASHINGTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING
- NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
/* **********************************************************************
Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.
@@ -62,6 +34,7 @@
import edu.rpi.cct.webdav.servlet.shared.WebdavStatusCode;
import edu.rpi.sss.util.xml.XmlEmit;
import edu.rpi.sss.util.xml.XmlUtil;
+import edu.rpi.sss.util.xml.XmlEmit.NameSpace;
import edu.rpi.sss.util.xml.tagdefs.WebdavTags;
import org.apache.log4j.Logger;
@@ -548,9 +521,16 @@
/** Add a namespace
*
* @param val
+ * @throws WebdavException
*/
- public void addNs(final String val) {
- xml.addNs(val);
+ public void addNs(final String val) throws WebdavException {
+ if (xml.getNameSpace(val) == null) {
+ try {
+ xml.addNs(new NameSpace(val, null), false);
+ } catch (IOException e) {
+ throw new WebdavException(e);
+ }
+ }
}
/** Get a namespace abbreviation
Modified: releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsIntf.java
===================================================================
--- releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsIntf.java 2010-08-30 14:20:26 UTC (rev 230)
+++ releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsIntf.java 2010-09-03 20:14:56 UTC (rev 231)
@@ -35,12 +35,14 @@
import edu.rpi.cmt.access.Acl;
import edu.rpi.sss.util.xml.XmlEmit;
import edu.rpi.sss.util.xml.XmlUtil;
+import edu.rpi.sss.util.xml.XmlEmit.NameSpace;
import edu.rpi.sss.util.xml.tagdefs.WebdavTags;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Serializable;
@@ -360,7 +362,7 @@
*/
public void addNamespace(final XmlEmit xml) throws WebdavException {
try {
- xml.addNs(WebdavTags.namespace);
+ xml.addNs(new NameSpace(WebdavTags.namespace, "DAV"), true);
} catch (Throwable t) {
throw new WebdavException(t);
}
@@ -510,26 +512,44 @@
return true;
}
- /** Returns a Reader for the content.
+ /** */
+ public static class Content {
+ /** Content was written directly */
+ public boolean written;
+
+ /** A reader for the content */
+ public Reader rdr;
+
+ /** For binary */
+ public InputStream stream = null;
+
+ /** */
+ public String contentType;
+
+ /** */
+ public long contentLength;
+ }
+
+ /** Returns a Content object for the content.
*
* @param req
* @param resp
* @param node node in question
- * @return Reader A reader for the content.
+ * @return content.
* @throws WebdavException
*/
- public abstract Reader getContent(HttpServletRequest req,
- HttpServletResponse resp,
- WebdavNsNode node)
+ public abstract Content getContent(HttpServletRequest req,
+ HttpServletResponse resp,
+ WebdavNsNode node)
throws WebdavException;
- /** Returns an InputStream for the binary content.
+ /** Returns a Content object for the binary content.
*
* @param node node in question
- * @return inputStream A stream for the content.
+ * @return content.
* @throws WebdavException
*/
- public abstract InputStream getBinaryContent(WebdavNsNode node)
+ public abstract Content getBinaryContent(WebdavNsNode node)
throws WebdavException;
/** Result for putContent
@@ -819,7 +839,13 @@
Element propnode = children[i];
String ns = propnode.getNamespaceURI();
- xml.addNs(ns);
+ if (xml.getNameSpace(ns) == null) {
+ try {
+ xml.addNs(new NameSpace(ns, null), false);
+ } catch (IOException e) {
+ throw new WebdavException(e);
+ }
+ }
WebdavProperty prop = makeProp(propnode);
@@ -1142,6 +1168,124 @@
* Protected methods
* ==================================================================== */
+ /** Return a String giving an HTML representation of the directory.
+ *
+ * TODO
+ *
+ * <p>Use some form of template to generate an internationalized form of the
+ * listing. We don't need a great deal to start with. It will also allow us to
+ * provide stylesheets, images etc. Probably place it in the resources directory.
+ *
+ * @param req
+ * @param node WebdavNsNode
+ * @return Reader
+ * @throws WebdavException
+ */
+ protected String generateHtml(final HttpServletRequest req,
+ final WebdavNsNode node) throws WebdavException {
+ try {
+ Sbuff sb = new Sbuff();
+
+ sb.lines(new String[] {"<html>",
+ " <head>"});
+ /* Need some styles I guess */
+ sb.append(" <title>");
+ sb.append(node.getDisplayname());
+ sb.line("</title>");
+
+ sb.lines(new String[] {"</head>",
+ "<body>"});
+
+ sb.append(" <h1>");
+ sb.append(node.getDisplayname());
+ sb.line("</h1>");
+
+ sb.line(" <hr>");
+
+ sb.line(" <table width=\"100%\" " +
+ "cellspacing=\"0\"" +
+ " cellpadding=\"4\">");
+
+ for (WebdavNsNode child: getChildren(node)) {
+ /* icon would be nice */
+
+ sb.line("<tr>");
+
+ if (node.isCollection()) {
+ /* folder */
+ } else {
+ /* calendar? */
+ }
+
+ sb.line(" <td align=\"left\">");
+ sb.append("<a href=\"");
+ sb.append(req.getContextPath());
+ sb.append(child.getUri());
+ sb.append("\">");
+ sb.append(child.getDisplayname());
+ sb.line("</a>");
+ sb.line("</td>");
+
+ sb.line(" <td align=\"left\">");
+
+ String lastMod = child.getLastmodDate();
+
+ if (lastMod != null) {
+ sb.line(lastMod);
+ } else {
+ sb.line(" ");
+ }
+ sb.line("</td>");
+ sb.append("</tr>\r\n");
+ }
+
+ sb.line("</table>");
+
+ /* Could use a footer */
+ sb.line("</body>");
+ sb.line("</html>");
+
+ return sb.toString();
+ } catch (WebdavException we) {
+ throw we;
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
+ private static class Sbuff {
+ StringBuilder sb = new StringBuilder();
+
+ /**
+ * @param ss
+ */
+ public void lines(final String[] ss) {
+ for (int i = 0; i < ss.length; i++) {
+ line(ss[i]);
+ }
+ }
+
+ /**
+ * @param s
+ */
+ public void line(final String s) {
+ sb.append(s);
+ sb.append("\r\n");
+ }
+
+ /**
+ * @param s
+ */
+ public void append(final String s) {
+ sb.append(s);
+ }
+
+ @Override
+ public String toString() {
+ return sb.toString();
+ }
+ }
+
protected Logger getLogger() {
if (log == null) {
log = Logger.getLogger(this.getClass());
Modified: releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsNode.java
===================================================================
--- releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsNode.java 2010-08-30 14:20:26 UTC (rev 230)
+++ releases/bedework-3.6/server/src/edu/rpi/cct/webdav/servlet/shared/WebdavNsNode.java 2010-09-03 20:14:56 UTC (rev 231)
@@ -104,7 +104,7 @@
private final static Collection<QName> supportedReports = new ArrayList<QName>();
/** */
- public static final class PropertyTagEntry {
+ public static class PropertyTagEntry {
/** */
public QName tag;
/** */
More information about the Bedework-commit
mailing list