[Bedework-commit] caldav r265 - in trunk:
boeingexchange/src/edu/rpi/cct/bedework/caldav
bwcaldav/src/org/bedework/caldav/bwserver
domino/src/edu/rpi/cct/bedework/caldav
google/src/edu/rpi/cct/bedework/caldav
server/src/org/bedework/caldav/server
svnadmin at bedework.org
svnadmin at bedework.org
Thu May 29 10:21:44 EDT 2008
Author: douglm
Date: 2008-05-29 10:21:40 -0400 (Thu, 29 May 2008)
New Revision: 265
Added:
trunk/server/src/org/bedework/caldav/server/CaldavResourceNode.java
Modified:
trunk/boeingexchange/src/edu/rpi/cct/bedework/caldav/BexchangeSysIntfImpl.java
trunk/bwcaldav/src/org/bedework/caldav/bwserver/BwSysIntfImpl.java
trunk/domino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java
trunk/google/src/edu/rpi/cct/bedework/caldav/GoogleSysIntfImpl.java
trunk/server/src/org/bedework/caldav/server/CaldavBWIntf.java
trunk/server/src/org/bedework/caldav/server/CaldavBwNode.java
trunk/server/src/org/bedework/caldav/server/CaldavCalNode.java
trunk/server/src/org/bedework/caldav/server/CaldavComponentNode.java
trunk/server/src/org/bedework/caldav/server/CaldavURI.java
trunk/server/src/org/bedework/caldav/server/SysIntf.java
Log:
Implement resources folders which can be created within a calendar collection. This follows the approach outlined in RFC 4791 and will provide a place to store shareable attachments while ensuring access restrictions are applied.
In addition, implement support for creating and retrieving 'file' resources which may be stored in any non-calendar collection. This will probably be useful when creating an image repository for example, but is also required for full implementation of shared attachments.
Currently, there is no ui support fo any of this, files may be uploaded with DAV explorer and viewed via a browser accessing the caldav server.
Modified: trunk/boeingexchange/src/edu/rpi/cct/bedework/caldav/BexchangeSysIntfImpl.java
===================================================================
--- trunk/boeingexchange/src/edu/rpi/cct/bedework/caldav/BexchangeSysIntfImpl.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/boeingexchange/src/edu/rpi/cct/bedework/caldav/BexchangeSysIntfImpl.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -32,6 +32,7 @@
import org.bedework.calfacade.BwDateTime;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwEventProxy;
+import org.bedework.calfacade.BwResource;
import org.bedework.calfacade.BwUser;
import org.bedework.calfacade.RecurringRetrievalMode;
import org.bedework.calfacade.ScheduleResult;
@@ -593,6 +594,48 @@
throw new WebdavException("unimplemented");
}
+ /* ====================================================================
+ * Files
+ * ==================================================================== */
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#putFile(org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwResource)
+ */
+ public void putFile(BwCalendar coll,
+ BwResource val) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFile(org.bedework.calfacade.BwCalendar, java.lang.String)
+ */
+ public BwResource getFile(BwCalendar coll,
+ String name) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getContent(org.bedework.calfacade.BwResource)
+ */
+ public void getFileContent(BwResource val) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.calfacade.BwCalendar)
+ */
+ public Collection<BwResource> getFiles(BwCalendar coll) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#updateFile(org.bedework.calfacade.BwResource, boolean)
+ */
+ public void updateFile(BwResource val,
+ boolean updateContent) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
public Calendar toCalendar(EventInfo ev) throws WebdavException {
throw new WebdavException("unimplemented");
}
Modified: trunk/bwcaldav/src/org/bedework/caldav/bwserver/BwSysIntfImpl.java
===================================================================
--- trunk/bwcaldav/src/org/bedework/caldav/bwserver/BwSysIntfImpl.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/bwcaldav/src/org/bedework/caldav/bwserver/BwSysIntfImpl.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -32,6 +32,7 @@
import org.bedework.calfacade.BwDateTime;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwEventProxy;
+import org.bedework.calfacade.BwResource;
import org.bedework.calfacade.BwSystem;
import org.bedework.calfacade.BwUser;
import org.bedework.calfacade.BwUserInfo;
@@ -825,6 +826,88 @@
}
}
+ /* ====================================================================
+ * Files
+ * ==================================================================== */
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#putFile(org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwResource)
+ */
+ public void putFile(BwCalendar coll,
+ BwResource val) throws WebdavException {
+ try {
+ getSvci().getResourcesHandler().save(coll.getPath(), val);
+ } catch (CalFacadeAccessException cfae) {
+ throw new WebdavForbidden();
+ } catch (CalFacadeException cfe) {
+ throw new WebdavException(cfe);
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFile(org.bedework.calfacade.BwCalendar, java.lang.String)
+ */
+ public BwResource getFile(BwCalendar coll,
+ String name) throws WebdavException {
+ try {
+ return getSvci().getResourcesHandler().get(coll.getPath() + "/" + name);
+ } catch (CalFacadeAccessException cfae) {
+ throw new WebdavForbidden();
+ } catch (CalFacadeException cfe) {
+ throw new WebdavException(cfe);
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getContent(org.bedework.calfacade.BwResource)
+ */
+ public void getFileContent(BwResource val) throws WebdavException {
+ try {
+ getSvci().getResourcesHandler().getContent(val);
+ } catch (CalFacadeAccessException cfae) {
+ throw new WebdavForbidden();
+ } catch (CalFacadeException cfe) {
+ throw new WebdavException(cfe);
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.calfacade.BwCalendar)
+ */
+ public Collection<BwResource> getFiles(BwCalendar coll) throws WebdavException {
+ try {
+ return getSvci().getResourcesHandler().getAll(coll.getPath());
+ } catch (CalFacadeAccessException cfae) {
+ throw new WebdavForbidden();
+ } catch (CalFacadeException cfe) {
+ throw new WebdavException(cfe);
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#updateFile(org.bedework.calfacade.BwResource, boolean)
+ */
+ public void updateFile(BwResource val,
+ boolean updateContent) throws WebdavException {
+ try {
+ getSvci().getResourcesHandler().update(val, updateContent);
+ } catch (CalFacadeAccessException cfae) {
+ throw new WebdavForbidden();
+ } catch (CalFacadeException cfe) {
+ throw new WebdavException(cfe);
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
public Calendar toCalendar(EventInfo ev) throws WebdavException {
try {
return trans.toIcal(ev, ev.getEvent().getScheduleMethod());
Modified: trunk/domino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java
===================================================================
--- trunk/domino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/domino/src/edu/rpi/cct/bedework/caldav/DominoSysIntfImpl.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -34,6 +34,7 @@
import org.bedework.calfacade.BwEventObj;
import org.bedework.calfacade.BwEventProxy;
import org.bedework.calfacade.BwFreeBusyComponent;
+import org.bedework.calfacade.BwResource;
import org.bedework.calfacade.BwUser;
import org.bedework.calfacade.RecurringRetrievalMode;
import org.bedework.calfacade.ScheduleResult;
@@ -621,6 +622,48 @@
throw new WebdavException("unimplemented");
}
+ /* ====================================================================
+ * Files
+ * ==================================================================== */
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#putFile(org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwResource)
+ */
+ public void putFile(BwCalendar coll,
+ BwResource val) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFile(org.bedework.calfacade.BwCalendar, java.lang.String)
+ */
+ public BwResource getFile(BwCalendar coll,
+ String name) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getContent(org.bedework.calfacade.BwResource)
+ */
+ public void getFileContent(BwResource val) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.calfacade.BwCalendar)
+ */
+ public Collection<BwResource> getFiles(BwCalendar coll) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#updateFile(org.bedework.calfacade.BwResource, boolean)
+ */
+ public void updateFile(BwResource val,
+ boolean updateContent) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
public Calendar toCalendar(EventInfo ev) throws WebdavException {
throw new WebdavException("unimplemented");
}
Modified: trunk/google/src/edu/rpi/cct/bedework/caldav/GoogleSysIntfImpl.java
===================================================================
--- trunk/google/src/edu/rpi/cct/bedework/caldav/GoogleSysIntfImpl.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/google/src/edu/rpi/cct/bedework/caldav/GoogleSysIntfImpl.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -34,6 +34,7 @@
import org.bedework.calfacade.BwEventObj;
import org.bedework.calfacade.BwEventProxy;
import org.bedework.calfacade.BwFreeBusyComponent;
+import org.bedework.calfacade.BwResource;
import org.bedework.calfacade.BwUser;
import org.bedework.calfacade.CalFacadeDefs;
import org.bedework.calfacade.RecurringRetrievalMode;
@@ -563,6 +564,48 @@
throw new WebdavException("unimplemented");
}
+ /* ====================================================================
+ * Files
+ * ==================================================================== */
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#putFile(org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwResource)
+ */
+ public void putFile(BwCalendar coll,
+ BwResource val) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFile(org.bedework.calfacade.BwCalendar, java.lang.String)
+ */
+ public BwResource getFile(BwCalendar coll,
+ String name) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getContent(org.bedework.calfacade.BwResource)
+ */
+ public void getFileContent(BwResource val) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#getFiles(org.bedework.calfacade.BwCalendar)
+ */
+ public Collection<BwResource> getFiles(BwCalendar coll) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
+ /* (non-Javadoc)
+ * @see org.bedework.caldav.server.SysIntf#updateFile(org.bedework.calfacade.BwResource, boolean)
+ */
+ public void updateFile(BwResource val,
+ boolean updateContent) throws WebdavException {
+ throw new WebdavException("unimplemented");
+ }
+
public Calendar toCalendar(EventInfo ev) throws WebdavException {
throw new WebdavException("unimplemented");
}
Modified: trunk/server/src/org/bedework/caldav/server/CaldavBWIntf.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/CaldavBWIntf.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/server/src/org/bedework/caldav/server/CaldavBWIntf.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -34,6 +34,8 @@
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwEventObj;
import org.bedework.calfacade.BwOrganizer;
+import org.bedework.calfacade.BwResource;
+import org.bedework.calfacade.BwResourceContent;
import org.bedework.calfacade.CalFacadeDefs;
import org.bedework.calfacade.RecurringRetrievalMode;
import org.bedework.calfacade.ScheduleResult;
@@ -83,6 +85,7 @@
import net.fortuna.ical4j.model.component.VFreeBusy;
import java.io.IOException;
+import java.io.InputStream;
import java.io.LineNumberReader;
import java.io.Reader;
import java.io.Serializable;
@@ -361,14 +364,15 @@
public WebdavNsNode getNode(String uri,
int existance,
int nodeType) throws WebdavException {
- return getNodeInt(uri, existance, nodeType, null, null);
+ return getNodeInt(uri, existance, nodeType, null, null, null);
}
private WebdavNsNode getNodeInt(String uri,
int existance,
int nodeType,
BwCalendar cal,
- EventInfo ei) throws WebdavException {
+ EventInfo ei,
+ BwResource r) throws WebdavException {
if (debug) {
debugMsg("About to get node for " + uri);
}
@@ -378,7 +382,7 @@
}
try {
- CaldavURI wi = findURI(uri, existance, nodeType, cal, ei);
+ CaldavURI wi = findURI(uri, existance, nodeType, cal, ei, r);
if (wi == null) {
throw new WebdavNotFound(uri);
@@ -392,6 +396,8 @@
nd = new CaldavGroupNode(wi, sysi, debug);
} else if (wi.isCollection()) {
nd = new CaldavCalNode(wi, sysi, debug);
+ } else if (wi.isResource()) {
+ nd = new CaldavResourceNode(wi, sysi, debug);
} else {
nd = new CaldavComponentNode(wi, sysi, debug);
}
@@ -445,6 +451,9 @@
}
}
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf#getChildren(edu.rpi.cct.webdav.servlet.shared.WebdavNsNode)
+ */
public Collection<WebdavNsNode> getChildren(WebdavNsNode node) throws WebdavException {
try {
CaldavBwNode wdnode = getBwnode(node);
@@ -469,6 +478,7 @@
while (it.hasNext()) {
Object o = it.next();
BwCalendar cal = null;
+ BwResource r = null;
EventInfo ei = null;
String name;
int nodeType;
@@ -480,6 +490,10 @@
if (debug) {
debugMsg("Found child " + cal);
}
+ } else if (o instanceof BwResource) {
+ r = (BwResource)o;
+ name = r.getName();
+ nodeType = WebdavNsIntf.nodeTypeEntity;
} else if (o instanceof EventInfo) {
cal = parent;
ei = (EventInfo)o;
@@ -491,7 +505,7 @@
al.add(getNodeInt(uri + "/" + name,
WebdavNsIntf.existanceDoesExist,
- nodeType, cal, ei));
+ nodeType, cal, ei, r));
}
return al;
@@ -507,23 +521,46 @@
return null;
}
- /*
- private void addProp(Vector v, QName tag, Object val) {
- if (val != null) {
- v.addElement(new WebdavProperty(tag, String.valueOf(val)));
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf#getContent(edu.rpi.cct.webdav.servlet.shared.WebdavNsNode)
+ */
+ public Reader getContent(WebdavNsNode node) throws WebdavException {
+ try {
+ if (!node.getAllowsGet()) {
+ return null;
+ }
+
+ CaldavBwNode bwnode = getBwnode(node);
+
+ return bwnode.getContent();
+ } catch (WebdavException we) {
+ throw we;
+ } catch (Throwable t) {
+ throw new WebdavException(t);
}
- }*/
+ }
- public Reader getContent(WebdavNsNode node)
- throws WebdavException {
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf#getBinaryContent(edu.rpi.cct.webdav.servlet.shared.WebdavNsNode)
+ */
+ public InputStream getBinaryContent(WebdavNsNode node) throws WebdavException {
try {
if (!node.getAllowsGet()) {
return null;
}
- CaldavBwNode uwnode = getBwnode(node);
+ if (!(node instanceof CaldavResourceNode)) {
+ throw new WebdavException("Unexpected node type");
+ }
- return uwnode.getContent();
+ CaldavResourceNode bwnode = (CaldavResourceNode)getBwnode(node);
+ BwResource r = bwnode.getResource();
+
+ if (r.getContent() == null) {
+ sysi.getFileContent(r);
+ }
+
+ return bwnode.getContentStream();
} catch (WebdavException we) {
throw we;
} catch (Throwable t) {
@@ -622,9 +659,10 @@
}
/* (non-Javadoc)
- * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf#putContent(edu.rpi.cct.webdav.servlet.shared.WebdavNsNode, java.io.Reader, boolean)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf#putContent(edu.rpi.cct.webdav.servlet.shared.WebdavNsNode, java.lang.String, java.io.Reader, boolean, java.lang.String)
*/
public PutContentResult putContent(WebdavNsNode node,
+ String contentType,
Reader contentRdr,
boolean create,
String ifEtag) throws WebdavException {
@@ -632,9 +670,18 @@
PutContentResult pcr = new PutContentResult();
pcr.node = node;
+ if (node instanceof CaldavResourceNode) {
+ throw new WebdavException(HttpServletResponse.SC_PRECONDITION_FAILED);
+ }
+
CaldavComponentNode bwnode = (CaldavComponentNode)getBwnode(node);
BwCalendar cal = bwnode.getCalendar();
+ if (!cal.getCalendarCollection() ||
+ ((contentType != null) && !contentType.equals("text/calendar"))) {
+ throw new WebdavForbidden(CaldavTags.supportedCalendarData);
+ }
+
Icalendar ic = sysi.fromIcal(cal, new MyReader(contentRdr));
/** We can only put a single resource - that resource will be an ics file
@@ -669,6 +716,93 @@
}
}
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsIntf#putBinaryContent(edu.rpi.cct.webdav.servlet.shared.WebdavNsNode, java.lang.String, java.io.InputStream, boolean, java.lang.String)
+ */
+ public PutContentResult putBinaryContent(WebdavNsNode node,
+ String contentType,
+ InputStream contentStream,
+ boolean create,
+ String ifEtag) throws WebdavException {
+ try {
+ PutContentResult pcr = new PutContentResult();
+ pcr.node = node;
+
+ if (!(node instanceof CaldavResourceNode)) {
+ throw new WebdavException(HttpServletResponse.SC_PRECONDITION_FAILED);
+ }
+
+ CaldavResourceNode bwnode = (CaldavResourceNode)getBwnode(node);
+ BwCalendar cal = bwnode.getCalendar();
+
+ if (cal.getCalendarCollection()) {
+ throw new WebdavException(HttpServletResponse.SC_PRECONDITION_FAILED);
+ }
+
+ BwResource r = bwnode.getResource();
+
+ if (r.unsaved()) {
+ create = true;
+ }
+
+ r.setContentType(contentType);
+
+ // XXX Fix this
+ int bufflen = 5000;
+ byte[] buff = new byte[bufflen];
+ byte[] res = null;
+
+ for (;;) {
+ int len = contentStream.read(buff, 0, bufflen);
+ if (len < 0) {
+ break;
+ }
+
+ if (res == null) {
+ res = buff;
+ buff = new byte[bufflen];
+ } else {
+ byte[] newres = new byte[res.length + len];
+ for (int i = 0; i < res.length; i++) {
+ newres[i] = res[i];
+ }
+
+ for (int i = 0; i < len; i++) {
+ newres[res.length + i] = buff[i];
+ }
+
+ res = newres;
+ }
+ }
+
+ BwResourceContent rc = r.getContent();
+
+ if (rc == null) {
+ sysi.getFileContent(r);
+ rc = r.getContent();
+
+ if (rc == null) {
+ rc = new BwResourceContent();
+ r.setContent(rc);
+ }
+ }
+
+ rc.setValue(res);
+ r.setContentLength(res.length);
+
+ if (create) {
+ sysi.putFile(cal, r);
+ } else {
+ sysi.updateFile(r, true);
+ }
+ return pcr;
+ } catch (WebdavException we) {
+ throw we;
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
private boolean putEvent(CaldavComponentNode bwnode,
EventInfo evinfo,
boolean create,
@@ -1369,8 +1503,8 @@
* @throws WebdavException
*/
public Collection<WebdavNsNode> query(WebdavNsNode wdnode,
- RecurringRetrievalMode retrieveRecur,
- Filter fltr) throws WebdavException {
+ RecurringRetrievalMode retrieveRecur,
+ Filter fltr) throws WebdavException {
CaldavBwNode node = getBwnode(wdnode);
Collection<EventInfo> events;
@@ -1421,8 +1555,7 @@
CaldavComponentNode evnode = (CaldavComponentNode)getNodeInt(evuri,
WebdavNsIntf.existanceDoesExist,
WebdavNsIntf.nodeTypeEntity,
- cal,
- ei);
+ cal, ei, null);
evnodes.add(evnode);
/*evnodeMap.put(evuri, evnode);
@@ -1521,6 +1654,7 @@
* @param nodeType Say's something about the type of node
* @param cal Supplied BwCalendar object if we already have it.
* @param ei
+ * @param r
* @return CaldavURI object representing the uri
* @throws WebdavException
*/
@@ -1528,7 +1662,8 @@
int existance,
int nodeType,
BwCalendar cal,
- EventInfo ei) throws WebdavException {
+ EventInfo ei,
+ BwResource r) throws WebdavException {
try {
if ((nodeType == WebdavNsIntf.nodeTypeUnknown) &&
(existance != WebdavNsIntf.existanceMust)) {
@@ -1570,8 +1705,12 @@
String name = null;
if (ei != null) {
name = ei.getEvent().getName();
+ curi = new CaldavURI(cal, ei, name);
+ } else if (r != null) {
+ curi = new CaldavURI(r);
+ } else {
+ curi = new CaldavURI(cal, ei, name);
}
- curi = new CaldavURI(cal, ei, name);
putUriPath(curi);
return curi;
@@ -1603,7 +1742,7 @@
debugMsg("create collection uri - cal=\"" + cal.getPath() + "\"");
}
- curi = new CaldavURI(cal, null, null);
+ curi = new CaldavURI(cal);
putUriPath(curi);
return curi;
@@ -1611,14 +1750,14 @@
}
// Entity or unknown
- String[] split = splitUri(uri);
+ SplitResult split = splitUri(uri);
- if (split[1] == null) {
+ if (split.name == null) {
// No name part
throw new WebdavNotFound(uri);
}
- cal = sysi.getCalendar(split[0]);
+ cal = sysi.getCalendar(split.path);
if (cal == null) {
if (nodeType == WebdavNsIntf.nodeTypeCollection) {
@@ -1634,28 +1773,52 @@
BwCalendar newCal = new BwCalendar();
newCal.setCalendar(cal);
- newCal.setName(split[1]);
+ newCal.setName(split.name);
newCal.setPath(cal.getPath() + "/" + newCal.getName());
- curi = new CaldavURI(newCal, null, null);
+ curi = new CaldavURI(newCal);
putUriPath(curi);
return curi;
}
- if (debug) {
- debugMsg("find event(s) - cal=\"" + cal.getPath() + "\" name=\"" +
- split[1] + "\"");
- }
- RecurringRetrievalMode rrm =
- new RecurringRetrievalMode(Rmode.overrides);
- ei = sysi.getEvent(cal, split[1], rrm);
+ if (cal.getCalendarCollection()) {
+ if (debug) {
+ debugMsg("find event(s) - cal=\"" + cal.getPath() + "\" name=\"" +
+ split.name + "\"");
+ }
- if ((existance == WebdavNsIntf.existanceMust) && (ei == null)) {
- throw new WebdavNotFound(uri);
+ RecurringRetrievalMode rrm =
+ new RecurringRetrievalMode(Rmode.overrides);
+ ei = sysi.getEvent(cal, split.name, rrm);
+
+ if ((existance == WebdavNsIntf.existanceMust) && (ei == null)) {
+ throw new WebdavNotFound(uri);
+ }
+
+ curi = new CaldavURI(cal, ei, split.name);
+ } else {
+ if (debug) {
+ debugMsg("find resource - cal=\"" + cal.getPath() + "\" name=\"" +
+ split.name + "\"");
+ }
+
+ /* Look for a resource */
+ r = sysi.getFile(cal, split.name);
+
+ if ((existance == WebdavNsIntf.existanceMust) && (r == null)) {
+ throw new WebdavNotFound(uri);
+ }
+
+ if (r == null) {
+ r = new BwResource();
+ r.setName(split.name);
+ r.setCalendar(cal);
+ }
+
+ curi = new CaldavURI(r);
}
- curi = new CaldavURI(cal, ei, split[1]);
putUriPath(curi);
return curi;
@@ -1666,11 +1829,21 @@
}
}
- /* Split the uri so that result[0] is the path up to the name part result[1]
+ private static class SplitResult {
+ String path;
+ String name;
+
+ SplitResult(String path, String name) {
+ this.path = path;
+ this.name = name;
+ }
+ }
+
+ /* Split the uri so that result.path is the path up to the name part result.name
*
* NormalizeUri was called previously so we have no trailing "/"
*/
- private String[] splitUri(String uri) throws WebdavException {
+ private SplitResult splitUri(String uri) throws WebdavException {
int pos = uri.lastIndexOf("/");
if (pos < 0) {
// bad uri
@@ -1678,16 +1851,10 @@
}
if (pos == 0) {
- return new String[]{
- uri,
- null
- };
+ return new SplitResult(uri, null);
}
- return new String[]{
- uri.substring(0, pos),
- uri.substring(pos + 1)
- };
+ return new SplitResult(uri.substring(0, pos), uri.substring(pos + 1));
}
private String normalizeUri(String uri) throws WebdavException {
Modified: trunk/server/src/org/bedework/caldav/server/CaldavBwNode.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/CaldavBwNode.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/server/src/org/bedework/caldav/server/CaldavBwNode.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -138,6 +138,13 @@
* Required webdav properties
* ==================================================================== */
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getContentBinary()
+ */
+ public boolean getContentBinary() throws WebdavException {
+ return false;
+ }
+
/* ====================================================================
* Property methods
* ==================================================================== */
Modified: trunk/server/src/org/bedework/caldav/server/CaldavCalNode.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/CaldavCalNode.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/server/src/org/bedework/caldav/server/CaldavCalNode.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -248,7 +248,12 @@
if (debug) {
debugMsg("POSSIBLE SEARCH: getChildren for cal " + c.getPath());
}
- return getSysi().getCalendars(c);
+
+ ArrayList ch = new ArrayList();
+ ch.addAll(getSysi().getCalendars(c));
+ ch.addAll(getSysi().getFiles(c));
+
+ return ch;
}
/* Otherwise, return the events in this calendar */
@@ -681,8 +686,7 @@
res.addAll(super.getSupportedReports());
/* Cannot do free-busy on in and outbox */
- if ((c.getCalType() == BwCalendar.calTypeCollection) ||
- (c.getCalType() == BwCalendar.calTypeFolder)) {
+ if (c.getCollectionInfo().allowFreeBusy) {
res.add(CaldavTags.freeBusyQuery); // Calendar access
}
Modified: trunk/server/src/org/bedework/caldav/server/CaldavComponentNode.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/CaldavComponentNode.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/server/src/org/bedework/caldav/server/CaldavComponentNode.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -97,7 +97,7 @@
private String entityName;
- // We also need a todo object and maybe a journal, freebusy and a timezone
+ // We also need a task object and maybe a journal, freebusy and a timezone
private boolean isTimezone;
Added: trunk/server/src/org/bedework/caldav/server/CaldavResourceNode.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/CaldavResourceNode.java (rev 0)
+++ trunk/server/src/org/bedework/caldav/server/CaldavResourceNode.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -0,0 +1,424 @@
+/*
+ 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.
+
+ 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 Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+
+package org.bedework.caldav.server;
+
+import org.bedework.calfacade.BwCalendar;
+import org.bedework.calfacade.BwResource;
+import org.bedework.calfacade.BwUser;
+import org.bedework.calfacade.util.DateTimeUtil;
+
+import org.w3c.dom.Element;
+
+import edu.rpi.cct.webdav.servlet.shared.WebdavException;
+import edu.rpi.cmt.access.PrivilegeDefs;
+import edu.rpi.cmt.access.Acl.CurrentAccess;
+
+import javax.xml.namespace.QName;
+
+/** Class to represent a resource such as a file.
+ *
+ * @author Mike Douglass douglm rpi.edu
+ */
+public class CaldavResourceNode extends CaldavBwNode {
+ private BwResource resource;
+
+ private BwCalendar cal;
+
+ private BwUser owner;
+
+ private String entityName;
+
+ private CurrentAccess currentAccess;
+
+ /** Place holder for status
+ *
+ * @param sysi
+ * @param status
+ * @param uri
+ * @param debug
+ */
+ public CaldavResourceNode(SysIntf sysi, int status, String uri, boolean debug) {
+ super(true, sysi, debug);
+ setStatus(status);
+ this.uri = uri;
+ }
+
+ /** Constructor
+ *
+ * @param cdURI
+ * @param sysi
+ * @param debug
+ * @throws WebdavException
+ */
+ public CaldavResourceNode(CaldavURI cdURI,
+ SysIntf sysi, boolean debug) throws WebdavException {
+ super(cdURI, sysi, debug);
+
+ resource = cdURI.getResource();
+ cal = cdURI.getCal();
+ collection = false;
+ allowsGet = true;
+ entityName = cdURI.getEntityName();
+
+ if (resource != null) {
+ resource.setPrevLastmod(resource.getLastmod());
+ resource.setPrevSeq(resource.getPrevSeq());
+ }
+ }
+
+ public void init(boolean content) throws WebdavException {
+ if (!content) {
+ return;
+ }
+
+ try {
+ if ((resource == null) && exists) {
+ if (entityName == null) {
+ exists = false;
+ return;
+ }
+ }
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+
+ /**
+ * @return BwCalendar containing this entity
+ */
+ public BwCalendar getCalendar() throws WebdavException {
+ BwCalendar curCal = cal;
+
+ if ((curCal != null) &&
+ (curCal.getCalType() == BwCalendar.calTypeAlias)) {
+ curCal = cal.getAliasTarget();
+ if (curCal == null) {
+ getSysi().resolveAlias(cal);
+ curCal = cal.getAliasTarget();
+ }
+ }
+
+ return curCal;
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getOwner()
+ */
+ public String getOwner() throws WebdavException {
+ if (owner == null) {
+ if (resource == null) {
+ return null;
+ }
+
+ owner = resource.getOwner();
+ }
+
+ if (owner != null) {
+ return owner.getAccount();
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#removeProperty(org.w3c.dom.Element)
+ */
+ public boolean removeProperty(Element val,
+ SetPropertyResult spr) throws WebdavException {
+ warn("Unimplemented - removeProperty");
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#setProperty(org.w3c.dom.Element)
+ */
+ public boolean setProperty(Element val,
+ SetPropertyResult spr) throws WebdavException {
+ if (super.setProperty(val, spr)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#update()
+ */
+ public void update() throws WebdavException {
+ if (resource != null) {
+ getSysi().updateFile(resource, true);
+ }
+ }
+
+ /**
+ * @return String
+ */
+ public String getEntityName() {
+ return entityName;
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#trailSlash()
+ */
+ public boolean trailSlash() {
+ return false;
+ }
+
+ /* ====================================================================
+ * Property methods
+ * ==================================================================== */
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#knownProperty(edu.rpi.sss.util.xml.QName)
+ */
+ public boolean knownProperty(QName tag) {
+ // Not ours
+ return super.knownProperty(tag);
+ }
+
+ /**
+ * @param val
+ */
+ public void setResource(BwResource val) {
+ resource = val;
+ }
+
+ /** Returns the resource object
+ *
+ * @return BwResource
+ * @throws WebdavException
+ */
+ public BwResource getResource() throws WebdavException {
+ init(true);
+
+ return resource;
+ }
+
+ /* ====================================================================
+ * Overridden property methods
+ * ==================================================================== */
+
+ public CurrentAccess getCurrentAccess() throws WebdavException {
+ if (currentAccess != null) {
+ return currentAccess;
+ }
+
+ if (resource == null) {
+ return null;
+ }
+
+ try {
+ currentAccess = getSysi().checkAccess(resource, PrivilegeDefs.privAny, true);
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+
+ return currentAccess;
+ }
+
+ public String getEtagValue(boolean strong) throws WebdavException {
+ init(true);
+
+ if (resource == null) {
+ return null;
+ }
+
+ return makeEtag(resource.getLastmod(), resource.getSeq(), strong);
+ }
+
+ /**
+ * @param strong
+ * @return etag before changes
+ * @throws WebdavException
+ */
+ public String getPrevEtagValue(boolean strong) throws WebdavException {
+ init(true);
+
+ if (resource == null) {
+ return null;
+ }
+
+ return makeEtag(resource.getPrevLastmod(), resource.getPrevSeq(), strong);
+ }
+
+ private String makeEtag(String lastmod, int seq, boolean strong) {
+ StringBuilder val = new StringBuilder();
+ if (!strong) {
+ val.append("W");
+ }
+
+ val.append("\"");
+ val.append(lastmod);
+ val.append("-");
+ val.append(seq);
+ val.append("\"");
+
+ return val.toString();
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("CaldavResourceNode{");
+ sb.append("path=");
+ sb.append(getPath());
+ sb.append(", entityName=");
+ sb.append(String.valueOf(entityName));
+ sb.append("}");
+
+ return sb.toString();
+ }
+
+ /* ====================================================================
+ * Required webdav properties
+ * ==================================================================== */
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getContentBinary()
+ */
+ public boolean getContentBinary() throws WebdavException {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getContentString()
+ */
+ public String getContentString() throws WebdavException {
+ init(true);
+ throw new WebdavException("binary content");
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getBinaryContent()
+ */
+ public byte[] getBinaryContent() throws WebdavException {
+ init(true);
+
+ if ((resource == null) || (resource.getContent() == null)) {
+ return null;
+ }
+
+ return resource.getContent().getValue();
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getContentLang()
+ */
+ public String getContentLang() throws WebdavException {
+ return "en";
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getContentLen()
+ */
+ public int getContentLen() throws WebdavException {
+ init(true);
+
+ if (resource == null) {
+ return 0;
+ }
+
+ return resource.getContentLength();
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getContentType()
+ */
+ public String getContentType() throws WebdavException {
+ if (resource == null) {
+ return null;
+ }
+
+ return resource.getContentType();
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getCreDate()
+ */
+ public String getCreDate() throws WebdavException {
+ init(false);
+
+ if (resource == null) {
+ return null;
+ }
+
+ return resource.getCreated();
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getDisplayname()
+ */
+ public String getDisplayname() throws WebdavException {
+ return getEntityName();
+ }
+
+ /* (non-Javadoc)
+ * @see edu.rpi.cct.webdav.servlet.shared.WebdavNsNode#getLastmodDate()
+ */
+ public String getLastmodDate() throws WebdavException {
+ init(false);
+
+ if (resource == null) {
+ return null;
+ }
+
+ try {
+ return DateTimeUtil.fromISODateTimeUTCtoRfc822(resource.getLastmod());
+ } catch (Throwable t) {
+ throw new WebdavException(t);
+ }
+ }
+}
Property changes on: trunk/server/src/org/bedework/caldav/server/CaldavResourceNode.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Modified: trunk/server/src/org/bedework/caldav/server/CaldavURI.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/CaldavURI.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/server/src/org/bedework/caldav/server/CaldavURI.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -56,6 +56,7 @@
import org.bedework.calfacade.BwCalendar;
import org.bedework.calfacade.BwEvent;
+import org.bedework.calfacade.BwResource;
import org.bedework.calfacade.svc.EventInfo;
/** We map uris onto an object which may be a calendar or an
@@ -71,8 +72,12 @@
* @author Mike Douglass douglm at rpi.edu
*/
public class CaldavURI {
+ /* For a resource or an entity, this is the containing collection
+ */
BwCalendar cal;
+ BwResource resource;
+
EventInfo entity;
String entityName;
@@ -80,12 +85,37 @@
boolean userUri; // entityname is user
+ boolean resourceUri; // entityname is resource
+
boolean groupUri;// entityname is group
+ /** Reference to a collection
+ *
+ * @param cal
+ */
+ CaldavURI(BwCalendar cal) {
+ init(cal, null, null, null);
+ }
+
+ /** Reference to a contained entity
+ *
+ * @param cal
+ * @param entity
+ * @param entityName
+ */
CaldavURI(BwCalendar cal, EventInfo entity, String entityName) {
- init(cal, entity, entityName);
+ init(cal, null, entity, entityName);
}
+ /** Reference to a contained resource
+ *
+ * @param res
+ */
+ CaldavURI(BwResource res) {
+ init(res.getCalendar(), res, null, res.getName());
+ resourceUri = true;
+ }
+
CaldavURI(String entityName, String path, boolean isUser) {
cal = null;
this.entityName = entityName;
@@ -97,8 +127,9 @@
this.path = path;
}
- private void init(BwCalendar cal, EventInfo entity, String entityName) {
+ private void init(BwCalendar cal, BwResource res, EventInfo entity, String entityName) {
this.cal = cal;
+ this.resource = res;
this.entity = entity;
this.entityName = entityName;
}
@@ -111,6 +142,13 @@
}
/**
+ * @return BwResource
+ */
+ public BwResource getResource() {
+ return resource;
+ }
+
+ /**
* @return Object
*/
public EventInfo getEntity() {
@@ -146,6 +184,8 @@
}
} else if (cal != null) {
return cal.getOwner().getAccount();
+ } else if (resource != null) {
+ return resource.getOwner().getAccount();
}
return null;
@@ -179,6 +219,13 @@
/**
* @return true if this represents a calendar
*/
+ public boolean isResource() {
+ return resourceUri;
+ }
+
+ /**
+ * @return true if this represents a calendar
+ */
public boolean isCollection() {
return entityName == null;
}
Modified: trunk/server/src/org/bedework/caldav/server/SysIntf.java
===================================================================
--- trunk/server/src/org/bedework/caldav/server/SysIntf.java 2008-05-15 15:03:49 UTC (rev 264)
+++ trunk/server/src/org/bedework/caldav/server/SysIntf.java 2008-05-29 14:21:40 UTC (rev 265)
@@ -30,6 +30,7 @@
import org.bedework.calfacade.BwDateTime;
import org.bedework.calfacade.BwEvent;
import org.bedework.calfacade.BwEventProxy;
+import org.bedework.calfacade.BwResource;
import org.bedework.calfacade.BwUserInfo;
import org.bedework.calfacade.RecurringRetrievalMode;
import org.bedework.calfacade.ScheduleResult;
@@ -518,6 +519,54 @@
*/
public void resolveAlias(BwCalendar cal) throws WebdavException;
+ /* ====================================================================
+ * Files
+ * ==================================================================== */
+
+ /** PUT a file.
+ *
+ * @param coll BwCalendar defining recipient collection
+ * @param val BwResource
+ * @throws WebdavException
+ */
+ public void putFile(BwCalendar coll,
+ BwResource val) throws WebdavException;
+
+ /** GET a file.
+ *
+ * @param coll BwCalendar containing file
+ * @param name
+ * @return BwResource
+ * @throws WebdavException
+ */
+ public BwResource getFile(BwCalendar coll,
+ String name) throws WebdavException;
+
+ /** Get resource content given the resource. It will be set in the resource
+ * object
+ *
+ * @param val BwResource
+ * @throws WebdavException
+ */
+ public void getFileContent(BwResource val) throws WebdavException;
+
+ /** Get the files in a collection.
+ *
+ * @param coll BwCalendar containing file
+ * @return Collection of BwResource
+ * @throws WebdavException
+ */
+ public Collection<BwResource> getFiles(BwCalendar coll) throws WebdavException;
+
+ /** Update a file.
+ *
+ * @param val BwResource
+ * @param updateContent if true we also update the content
+ * @throws WebdavException
+ */
+ public void updateFile(BwResource val,
+ boolean updateContent) throws WebdavException;
+
/** Make an ical Calendar from an event.
*
* @param ev
More information about the Bedework-commit
mailing list