org.bedework.caldav.server.CaldavBwNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bw-caldav-server Show documentation
Show all versions of bw-caldav-server Show documentation
A generic CalDAV server - used by bedework
/* ********************************************************************
Licensed to Jasig under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Jasig licenses this file to you under the Apache License,
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a
copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.bedework.caldav.server;
import org.bedework.caldav.server.sysinterface.SysIntf;
import org.bedework.util.calendar.XcalUtil;
import org.bedework.util.xml.tagdefs.CalWSSoapTags;
import org.bedework.util.xml.tagdefs.CalWSXrdDefs;
import org.bedework.util.xml.tagdefs.CaldavTags;
import org.bedework.util.xml.tagdefs.XrdTags;
import org.bedework.webdav.servlet.shared.WdCollection;
import org.bedework.webdav.servlet.shared.WdEntity;
import org.bedework.webdav.servlet.shared.WebdavException;
import org.bedework.webdav.servlet.shared.WebdavNsIntf;
import org.bedework.webdav.servlet.shared.WebdavNsNode;
import org.oasis_open.docs.ns.xri.xrd_1.LinkType;
import org.oasis_open.docs.ns.xri.xrd_1.PropertyType;
import org.oasis_open.docs.ws_calendar.ns.soap.CalendarAccessFeatureType;
import org.oasis_open.docs.ws_calendar.ns.soap.CreationDateTimeType;
import org.oasis_open.docs.ws_calendar.ns.soap.DisplayNameType;
import org.oasis_open.docs.ws_calendar.ns.soap.GetPropertiesBasePropertyType;
import org.oasis_open.docs.ws_calendar.ns.soap.ResourceOwnerType;
import org.oasis_open.docs.ws_calendar.ns.soap.SupportedFeaturesType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
/** Class to represent a caldav node.
*
* @author Mike Douglass douglm - rpi.edu
*/
public abstract class CaldavBwNode extends WebdavNsNode {
// protected CaldavURI cdURI;
protected boolean rootNode;
protected CalDAVCollection col;
private final static HashMap propertyNames =
new HashMap<>();
private final static Collection supportedReports =
new ArrayList<>();
private final static HashMap calWSSoapNames =
new HashMap<>();
static {
supportedReports.add(CaldavTags.calendarMultiget); // Calendar access
supportedReports.add(CaldavTags.calendarQuery); // Calendar access
addCalWSSoapName(CalWSSoapTags.creationDateTime, true);
addCalWSSoapName(CalWSSoapTags.displayName, true);
addCalWSSoapName(CalWSSoapTags.lastModifiedDateTime, true);
addCalWSSoapName(CalWSSoapTags.supportedFeatures, true);
}
/** Information about properties returned in an XRD object for the restful
* protocol
*/
public static final class PropertyTagXrdEntry extends PropertyTagEntry {
/** */
public String xrdName;
/** */
public boolean inLink;
/**
* @param tag
* @param xrdName
* @param inPropAll
* @param inLink
*/
public PropertyTagXrdEntry(final QName tag, final String xrdName,
final boolean inPropAll,
final boolean inLink) {
super(tag, inPropAll);
this.xrdName = xrdName;
this.inLink = inLink;
}
}
private final static HashMap xrdNames =
new HashMap();
static {
addXrdEntry(xrdNames, CalWSXrdDefs.created, true, false);
addXrdEntry(xrdNames, CalWSXrdDefs.displayname, true, true);
addXrdEntry(xrdNames, CalWSXrdDefs.lastModified, true, false);
addXrdEntry(xrdNames, CalWSXrdDefs.owner, true, false);
}
/* for accessing calendars */
private SysIntf sysi;
CaldavBwNode(final CaldavURI cdURI,
final SysIntf sysi) throws WebdavException {
this(sysi, cdURI.getPath(), cdURI.isCollection(),
cdURI.getUri());
}
CaldavBwNode(final SysIntf sysi,
final String path,
final boolean collection,
final String uri) {
super(sysi, sysi.getUrlHandler(), path, collection, uri);
this.sysi = sysi;
rootNode = (uri != null) && uri.equals("/");
}
CaldavBwNode(final boolean collection,
final SysIntf sysi,
final String uri) {
super(sysi, sysi.getUrlHandler(), null, collection, uri);
//this.cdURI = cdURI;
this.sysi = sysi;
rootNode = (uri != null) && uri.equals("/");
}
/** Returns a string value suitable for the web service token
*
* @return String token
* @throws WebdavException
*/
public abstract String getEtokenValue() throws WebdavException;
/* ====================================================================
* Public methods
* ==================================================================== */
/**
* @return the interface
*/
public SysIntf getIntf() {
return sysi;
}
@Override
public WdCollection getCollection(final boolean deref) throws WebdavException {
if (!deref) {
return col;
}
return (WdCollection)col.resolveAlias(true);
}
/**
* @return boolean if this is a calendar
* @throws WebdavException
*/
public boolean isCalendarCollection() throws WebdavException {
if (!isCollection()) {
return false;
}
CalDAVCollection c = (CalDAVCollection)getCollection(true);
if (c == null) {
return false;
}
return c.getCalType() == CalDAVCollection.calTypeCalendarCollection;
}
/**
* @return CalSvcI
*/
public SysIntf getSysi() {
return sysi;
}
/** Return a set of Qname defining reports this node supports.
*
* @return Collection of QName
* @throws WebdavException
*/
@Override
public Collection getSupportedReports() throws WebdavException {
Collection res = new ArrayList();
res.addAll(super.getSupportedReports());
res.addAll(supportedReports);
return res;
}
@Override
public String getSyncToken() throws WebdavException {
return null;
}
/* ====================================================================
* Required webdav properties
* ==================================================================== */
@Override
public boolean getContentBinary() throws WebdavException {
return false;
}
@Override
public Collection extends WdEntity> getChildren() throws WebdavException {
return null;
}
/* ====================================================================
* Property methods
* ==================================================================== */
@Override
public boolean knownProperty(final QName tag) {
if (propertyNames.get(tag) != null) {
return true;
}
// Not ours
return super.knownProperty(tag);
}
@Override
public boolean generatePropertyValue(final QName tag,
final WebdavNsIntf intf,
final boolean allProp) throws WebdavException {
try {
// Not known - try higher
return super.generatePropertyValue(tag, intf, allProp);
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
/**
* @param props
* @param tag
* @param intf
* @param allProp
* @return true if property emitted
* @throws WebdavException
*/
public boolean generateCalWsProperty(final List props,
final QName tag,
final WebdavNsIntf intf,
final boolean allProp) throws WebdavException {
try {
if (tag.equals(CalWSSoapTags.creationDateTime)) {
String val = getCreDate();
if (val == null) {
return true;
}
CreationDateTimeType cdt = new CreationDateTimeType();
cdt.setDateTime(XcalUtil.fromDtval(val));
props.add(cdt);
return true;
}
if (tag.equals(CalWSSoapTags.displayName)) {
String val = getDisplayname();
if (val == null) {
return true;
}
DisplayNameType dn = new DisplayNameType();
dn.setString(val);
props.add(dn);
return true;
}
if (tag.equals(CalWSSoapTags.supportedFeatures)) {
SupportedFeaturesType sf = new SupportedFeaturesType();
sf.getCalendarAccessFeature().add(new CalendarAccessFeatureType());
props.add(sf);
return true;
}
if (tag.equals(CalWSSoapTags.resourceOwner)) {
String href = intf.makeUserHref(getOwner().getPrincipalRef());
if (!href.endsWith("/")) {
href += "/";
}
ResourceOwnerType ro = new ResourceOwnerType();
ro.setString(href);
props.add(ro);
return true;
}
return false;
} catch (WebdavException wde) {
throw wde;
} catch (Throwable t) {
throw new WebdavException(t);
}
}
/**
* @param props
* @param name
* @param intf
* @param allProp
* @return true if proeprty emitted
* @throws WebdavException
*/
public boolean generateXrdProperties(final List