Skip to content

Commit

Permalink
Refactored property name sets
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Apr 1, 2024
1 parent e30858e commit bfbe152
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.ical4j.connector.ObjectStoreException;
import org.ical4j.connector.dav.property.BaseDavPropertyName;
import org.ical4j.connector.dav.property.CalDavPropertyName;
import org.ical4j.connector.dav.property.PropertyNameSets;
import org.ical4j.connector.event.ListenerList;
import org.ical4j.connector.event.ObjectCollectionListener;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -308,7 +309,7 @@ public final void delete() throws ObjectStoreException {
* @throws ObjectStoreException where an unexpected error occurs
*/
public final boolean exists() throws HttpResponseException, IOException, ObjectStoreException {
return !getStore().getClient().propFind(getPath(), CalDavCalendarCollection.propertiesForFetch()).isEmpty();
return !getStore().getClient().propFind(getPath(), PropertyNameSets.PROPFIND_CALENDAR).isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
import net.fortuna.ical4j.model.property.Uid;
import net.fortuna.ical4j.util.Calendars;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.security.SecurityConstants;
import org.apache.jackrabbit.webdav.version.report.ReportInfo;
import org.ical4j.connector.*;
import org.ical4j.connector.dav.property.*;
import org.ical4j.connector.dav.property.CalDavPropertyName;
import org.ical4j.connector.dav.property.DavPropertyBuilder;
import org.ical4j.connector.dav.property.ICalPropertyName;
import org.ical4j.connector.dav.property.PropertyNameSets;
import org.ical4j.connector.dav.request.CalendarQuery;
import org.ical4j.connector.dav.request.EventQuery;
import org.ical4j.connector.dav.response.GetCalendarData;
Expand Down Expand Up @@ -157,10 +157,8 @@ public Iterable<Calendar> getTasks() {
*/
public Iterable<Calendar> getComponentsByType(String componentType) {
try {
DavPropertyNameSet propertyNames = new DavPropertyNameSet();
propertyNames.add(DavPropertyName.GETETAG);
propertyNames.add(CalDavPropertyName.CALENDAR_DATA);
ReportInfo info = new ReportInfo(CalDavPropertyName.CALENDAR_QUERY, 1, propertyNames);
ReportInfo info = new ReportInfo(CalDavPropertyName.CALENDAR_QUERY, 1,
PropertyNameSets.REPORT_CALENDAR);
info.setContentElement(new CalendarQuery(componentType).build());

List<Calendar> calendars = getStore().getClient().report(getPath(), info, new GetCalendarData());
Expand Down Expand Up @@ -505,48 +503,7 @@ public Calendar[] getObjectsByMultiget(ArrayList<URI> hrefs, Element calData)
public Calendar[] doFreeBusyQuery() {
return new Calendar[0];
}

public static final DavPropertyNameSet propertiesForFetch() {
DavPropertyNameSet principalsProps = new DavPropertyNameSet();

principalsProps.add(BaseDavPropertyName.QUOTA_AVAILABLE_BYTES);
principalsProps.add(BaseDavPropertyName.QUOTA_USED_BYTES);
principalsProps.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
principalsProps.add(BaseDavPropertyName.PROP);
principalsProps.add(DavPropertyName.RESOURCETYPE);
principalsProps.add(DISPLAYNAME);
principalsProps.add(SecurityConstants.OWNER);

principalsProps.add(CalDavPropertyName.CALENDAR_DESCRIPTION);
principalsProps.add(CalDavPropertyName.SUPPORTED_CALENDAR_COMPONENT_SET);
principalsProps.add(CalDavPropertyName.FREE_BUSY_SET);
principalsProps.add(CalDavPropertyName.SCHEDULE_CALENDAR_TRANSP);
principalsProps.add(CalDavPropertyName.SCHEDULE_DEFAULT_CALENDAR_URL);
principalsProps.add(CalDavPropertyName.CALENDAR_TIMEZONE);
principalsProps.add(CalDavPropertyName.SUPPORTED_CALENDAR_DATA);
principalsProps.add(CalDavPropertyName.MAX_ATTENDEES_PER_INSTANCE);
principalsProps.add(CalDavPropertyName.MAX_DATE_TIME);
principalsProps.add(CalDavPropertyName.MIN_DATE_TIME);
principalsProps.add(CalDavPropertyName.MAX_INSTANCES);
principalsProps.add(CalDavPropertyName.MAX_RESOURCE_SIZE);

principalsProps.add(CSDavPropertyName.XMPP_SERVER);
principalsProps.add(CSDavPropertyName.XMPP_URI);
principalsProps.add(CSDavPropertyName.CTAG);
principalsProps.add(CSDavPropertyName.SOURCE);
principalsProps.add(CSDavPropertyName.SUBSCRIBED_STRIP_ALARMS);
principalsProps.add(CSDavPropertyName.SUBSCRIBED_STRIP_ATTACHMENTS);
principalsProps.add(CSDavPropertyName.SUBSCRIBED_STRIP_TODOS);
principalsProps.add(CSDavPropertyName.REFRESHRATE);
principalsProps.add(CSDavPropertyName.PUSH_TRANSPORTS);
principalsProps.add(CSDavPropertyName.PUSHKEY);

principalsProps.add(ICalPropertyName.CALENDAR_COLOR);
principalsProps.add(ICalPropertyName.CALENDAR_ORDER);

return principalsProps;
}


@Override
public String toString() {
return "Display Name: " + getDisplayName() + ", id: " + getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
import org.ical4j.connector.dav.method.PrincipalPropertySearchInfo;
import org.ical4j.connector.dav.property.BaseDavPropertyName;
import org.ical4j.connector.dav.property.CalDavPropertyName;
import org.ical4j.connector.dav.property.PropertyNameSets;
import org.ical4j.connector.dav.request.ExpandPropertyQuery;
import org.ical4j.connector.dav.response.GetCalDavCollections;
import org.ical4j.connector.dav.response.GetCollections;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -153,9 +155,9 @@ public CalDavCalendarCollection addCollection(String id, DavPropertySet properti
public CalDavCalendarCollection getCollection(String id) throws ObjectStoreException, ObjectNotFoundException {
try {
String resourcePath = pathResolver.getCalendarPath(id, "test");
DavPropertyNameSet principalsProps = CalDavCalendarCollection.propertiesForFetch();
Map<String, DavPropertySet> res = getClient().propFindResources(resourcePath, principalsProps,
CALENDAR, CALENDAR_PROXY_READ, CALENDAR_PROXY_WRITE);
Map<String, DavPropertySet> res = getClient().propFind(resourcePath,
PropertyNameSets.PROPFIND_CALENDAR,
new GetCollections(CALENDAR, CALENDAR_PROXY_READ, CALENDAR_PROXY_WRITE));
if (!res.isEmpty()) {
DavPropertySet props = res.entrySet().iterator().next().getValue();
return new CalDavCalendarCollection(this, id, props);
Expand Down Expand Up @@ -198,11 +200,7 @@ public String findCalendarHomeSet() throws ParserConfigurationException, IOExcep
* @throws DavException
*/
protected String findCalendarHomeSet(String propfindUri) throws IOException {
DavPropertyNameSet principalsProps = new DavPropertyNameSet();
principalsProps.add(CalDavPropertyName.CALENDAR_HOME_SET);
principalsProps.add(DavPropertyName.DISPLAYNAME);

DavPropertySet props = getClient().propFind(propfindUri, principalsProps);
DavPropertySet props = getClient().propFind(propfindUri, PropertyNameSets.PROPFIND_CALENDAR_HOME);
if (props.contains(CalDavPropertyName.CALENDAR_HOME_SET)) {
Element propElement = (Element) props.get(CalDavPropertyName.CALENDAR_HOME_SET).getValue();
return propElement.getFirstChild().getNodeValue();
Expand Down Expand Up @@ -241,9 +239,8 @@ public List<CalDavCalendarCollection> getCollections(String workspace) throws Ob
protected List<CalDavCalendarCollection> getCollectionsForHomeSet(CalDavCalendarStore store,
String urlForcalendarHomeSet) throws IOException, DavException {

DavPropertyNameSet principalsProps = CalDavCalendarCollection.propertiesForFetch();
return getClient().propFindResources(urlForcalendarHomeSet, principalsProps,
CALENDAR, CALENDAR_PROXY_READ, CALENDAR_PROXY_WRITE).entrySet().stream()
return getClient().propFind(urlForcalendarHomeSet, PropertyNameSets.PROPFIND_CALENDAR,
new GetCollections(COLLECTION)).entrySet().stream()
.map(e -> new CalDavCalendarCollection(this, e.getKey(), e.getValue()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@
import net.fortuna.ical4j.vcard.VCard;
import net.fortuna.ical4j.vcard.property.Uid;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.security.SecurityConstants;
import org.apache.jackrabbit.webdav.version.report.ReportInfo;
import org.ical4j.connector.CardCollection;
import org.ical4j.connector.FailedOperationException;
import org.ical4j.connector.ObjectNotFoundException;
import org.ical4j.connector.ObjectStoreException;
import org.ical4j.connector.dav.property.BaseDavPropertyName;
import org.ical4j.connector.dav.property.CalDavPropertyName;
import org.ical4j.connector.dav.property.CardDavPropertyName;
import org.ical4j.connector.dav.property.DavPropertyBuilder;
import org.ical4j.connector.dav.property.PropertyNameSets;
import org.ical4j.connector.dav.response.GetVCardData;

import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -151,46 +148,6 @@ public long getMaxResourceSize() {
public VCard[] export() {
throw new UnsupportedOperationException("not implemented");
}

public static final DavPropertyNameSet propertiesForFetch() {
DavPropertyNameSet principalsProps = new DavPropertyNameSet();

/*
* TODO : to add the following properties
<C:me-card xmlns:C="http://calendarserver.org/ns/" />
<C:push-transports xmlns:C="http://calendarserver.org/ns/" />
<C:pushkey xmlns:C="http://calendarserver.org/ns/" />
<D:bulk-requests xmlns:D="http://me.com/_namespace/" />
*/

principalsProps.add(DISPLAYNAME);


principalsProps.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
principalsProps.add(DavPropertyName.RESOURCETYPE);
principalsProps.add(SecurityConstants.OWNER);
principalsProps.add(CardDavPropertyName.MAX_RESOURCE_SIZE);
principalsProps.add(BaseDavPropertyName.RESOURCE_ID);
principalsProps.add(BaseDavPropertyName.SUPPORTED_REPORT_SET);
principalsProps.add(BaseDavPropertyName.SYNC_TOKEN);
principalsProps.add(BaseDavPropertyName.ADD_MEMBER);
principalsProps.add(CardDavPropertyName.MAX_IMAGE_SIZE);

/**
* FIXME jackrabbit generates an error when quota-used-bytes is sent.
* I suspect the problem is that the response have this attribute: e:dt="int"
*/
//principalsProps.add(BaseDavPropertyName.QUOTA_USED_BYTES);
//principalsProps.add(BaseDavPropertyName.QUOTA_AVAILABLE_BYTES);

/* In the absence of this property, the server MUST only accept data with the media type
* "text/vcard" and vCard version 3.0, and clients can assume that is
* all the server will accept.
*/
principalsProps.add(CardDavPropertyName.SUPPORTED_ADDRESS_DATA);

return principalsProps;
}

/* (non-Javadoc)
* @see org.ical4j.connector.ObjectCollection#getDescription()
Expand All @@ -211,11 +168,8 @@ public List<String> listObjectUIDs() {
*/
public Iterable<VCard> getAll() throws ObjectStoreException {
try {
DavPropertyNameSet properties = new DavPropertyNameSet();
properties.add(DavPropertyName.GETETAG);
properties.add(CardDavPropertyName.ADDRESS_DATA);

ReportInfo info = new ReportInfo(CardDavPropertyName.ADDRESSBOOK_QUERY, 1, properties);
ReportInfo info = new ReportInfo(CardDavPropertyName.ADDRESSBOOK_QUERY, 1,
PropertyNameSets.REPORT_CARD);

return getStore().getClient().report(getPath(), info, new GetVCardData());
} catch (IOException | ParserConfigurationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.fortuna.ical4j.vcard.VCard;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.security.SecurityConstants;
import org.apache.jackrabbit.webdav.version.report.ReportInfo;
Expand All @@ -46,8 +45,10 @@
import org.ical4j.connector.dav.property.BaseDavPropertyName;
import org.ical4j.connector.dav.property.CalDavPropertyName;
import org.ical4j.connector.dav.property.CardDavPropertyName;
import org.ical4j.connector.dav.property.PropertyNameSets;
import org.ical4j.connector.dav.request.ExpandPropertyQuery;
import org.ical4j.connector.dav.response.GetCardDavCollections;
import org.ical4j.connector.dav.response.GetCollections;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
Expand Down Expand Up @@ -126,8 +127,8 @@ public CardDavCollection addCollection(String id, DavPropertySet properties) thr
*/
public CardDavCollection getCollection(String id) throws ObjectStoreException, ObjectNotFoundException {
try {
DavPropertyNameSet principalsProps = CardDavCollection.propertiesForFetch();
return getClient().propFindResources(id, principalsProps, ResourceType.ADRESSBOOK).entrySet().stream()
return getClient().propFind(id, PropertyNameSets.PROPFIND_CARD,
new GetCollections(ResourceType.ADRESSBOOK)).entrySet().stream()
.map(e -> new CardDavCollection(this, e.getKey(), e.getValue()))
.collect(Collectors.toList()).get(0);
} catch (IOException e) {
Expand Down Expand Up @@ -163,11 +164,7 @@ protected String findAddressBookHomeSet() throws ParserConfigurationException, I
* @throws DavException
*/
protected String findAddressBookHomeSet(String propfindUri) throws IOException {
DavPropertyNameSet principalsProps = new DavPropertyNameSet();
principalsProps.add(CardDavPropertyName.ADDRESSBOOK_HOME_SET);
principalsProps.add(DavPropertyName.DISPLAYNAME);

DavPropertySet props = getClient().propFind(propfindUri, principalsProps);
DavPropertySet props = getClient().propFind(propfindUri, PropertyNameSets.PROPFIND_CARD_HOME);
return (String) props.get(CardDavPropertyName.ADDRESSBOOK_HOME_SET).getValue();
}

Expand Down Expand Up @@ -200,8 +197,8 @@ public List<CardDavCollection> getCollections(String workspace) throws ObjectSto
protected List<CardDavCollection> getCollectionsForHomeSet(CardDavStore store,
String urlForcalendarHomeSet) throws IOException, DavException {

DavPropertyNameSet principalsProps = CardDavCollection.propertiesForFetch();
return getClient().propFindResources(urlForcalendarHomeSet, principalsProps, ResourceType.ADRESSBOOK).entrySet().stream()
return getClient().propFind(urlForcalendarHomeSet, PropertyNameSets.PROPFIND_CARD,
new GetCollections(ResourceType.ADRESSBOOK)).entrySet().stream()
.map(e -> new CardDavCollection(this, e.getKey(), e.getValue()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.client.methods.*;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.property.PropEntry;
import org.apache.jackrabbit.webdav.version.report.ReportInfo;
import org.ical4j.connector.FailedOperationException;
import org.ical4j.connector.ObjectStoreException;
import org.ical4j.connector.dav.method.*;
import org.ical4j.connector.dav.property.CSDavPropertyName;
import org.ical4j.connector.dav.property.CalDavPropertyName;
import org.ical4j.connector.dav.property.PropertyNameSets;
import org.ical4j.connector.dav.request.CalendarQuery;
import org.ical4j.connector.dav.request.MkCalendarEntity;
import org.ical4j.connector.dav.request.MkColEntity;
Expand Down Expand Up @@ -180,13 +179,8 @@ public DavClientConfiguration getClientConfiguration() {
}

public List<SupportedFeature> getSupportedFeatures() throws IOException {
DavPropertyNameSet props = new DavPropertyNameSet();
props.add(DavPropertyName.RESOURCETYPE);
props.add(CSDavPropertyName.CTAG);
DavPropertyName owner = DavPropertyName.create(DavPropertyName.XML_OWNER, DavConstants.NAMESPACE);
props.add(owner);

HttpPropfind aGet = new HttpPropfind(repositoryPath, DavConstants.PROPFIND_BY_PROPERTY, props, 0);
HttpPropfind aGet = new HttpPropfind(repositoryPath, DavConstants.PROPFIND_BY_PROPERTY,
PropertyNameSets.PROPFIND_SUPPORTED_FEATURES, 0);

RequestConfig.Builder builder = aGet.getConfig() == null ? RequestConfig.custom() : RequestConfig.copy(aGet.getConfig());
builder.setAuthenticationEnabled(true);
Expand Down Expand Up @@ -226,20 +220,29 @@ public void mkCol(String path, DavPropertySet properties) throws ObjectStoreExce

@Override
public DavPropertySet propFind(String path, DavPropertyNameSet propertyNames) throws IOException {
HttpPropfind aGet = new HttpPropfind(resolvePath(path), propertyNames, 0);
return propFind(path, propertyNames, new GetResourceProperties());
}

// RequestConfig config = RequestConfig.custom().setAuthenticationEnabled(true).build();
// aGet.setConfig(config);
return execute(aGet, new GetResourceProperties());
@Override
public <T> T propFind(String path, DavPropertyNameSet propertyNames, ResponseHandler<T> handler)
throws IOException {
HttpPropfind aGet = new HttpPropfind(resolvePath(path), propertyNames, 0);
return execute(aGet, handler);
}

/**
*
* @param path
* @param propertyNames
* @param resourceTypes
* @return
* @throws IOException
* @deprecated use {@link WebDavSupport#propFind(String, DavPropertyNameSet, ResponseHandler)} instead
*/
@Deprecated
public Map<String, DavPropertySet> propFindResources(String path, DavPropertyNameSet propertyNames,
ResourceType...resourceTypes) throws IOException {
HttpPropfind aGet = new HttpPropfind(resolvePath(path), propertyNames, 0);

// RequestConfig config = RequestConfig.custom().setAuthenticationEnabled(true).build();
// aGet.setConfig(config);
return execute(aGet, new GetCollections(resourceTypes));
return propFind(path, propertyNames, new GetCollections(resourceTypes));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ default DavPropertySet propFind(String path, DavPropertyName... propertyNames) t
return propFind(path, nameSet);
}

<T> T propFind(String path, DavPropertyNameSet propertyNames, ResponseHandler<T> handler) throws IOException;

default DavPropertySet propFindAll(String path) throws IOException {
return propFindType(path, DavPropertyName.PROPFIND_ALL_PROP);
}
Expand Down
Loading

0 comments on commit bfbe152

Please sign in to comment.