use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.
the class DavContext method getDestinationCollection.
public Collection getDestinationCollection() throws DavException {
String destinationUrl = getDestinationUrl();
if (!destinationUrl.endsWith("/")) {
int slash = destinationUrl.lastIndexOf('/');
destinationUrl = destinationUrl.substring(0, slash + 1);
}
try {
destinationUrl = HttpUtil.urlUnescape(destinationUrl);
destinationUrl = getInternalDestinationUrl(destinationUrl);
DavResource r = UrlNamespace.getResourceAtUrl(this, destinationUrl);
if (r instanceof Collection)
return ((Collection) r);
return UrlNamespace.getCollectionAtUrl(this, destinationUrl);
} catch (Exception e) {
throw new DavException("can't get destination collection", DavProtocol.STATUS_FAILED_DEPENDENCY);
}
}
use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.
the class DavContext method getAllRequestedResources.
public java.util.Collection<DavResource> getAllRequestedResources() throws DavException, ServiceException {
ArrayList<DavResource> rss = new ArrayList<DavResource>();
if (mRequestType == RequestType.RESOURCE)
rss = (ArrayList<DavResource>) UrlNamespace.getResources(this, mUser, mPath, getDepth() == Depth.one);
else {
DavResource rs = UrlNamespace.getPrincipalAtUrl(this, mUri);
if (rs != null) {
ZimbraLog.addToContext(ZimbraLog.C_NAME, rs.getOwner());
rss.add(rs);
if (getDepth() == Depth.one)
rss.addAll(rs.getChildren(this));
}
}
if (rss.isEmpty())
throw new DavException("no DAV resource at " + mUri, HttpServletResponse.SC_NOT_FOUND, null);
return rss;
}
use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.
the class Acl method handle.
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
DavResource rs = ctxt.getRequestedResource();
if (!rs.isCollection() || !(rs instanceof MailItemResource))
throw new DavException("acl not implemented for non-collection resource", HttpServletResponse.SC_NOT_IMPLEMENTED);
if (!ctxt.hasRequestMessage())
throw new DavException("empty request", HttpServletResponse.SC_BAD_REQUEST);
Document reqMsg = ctxt.getRequestMessage();
Element acl = reqMsg.getRootElement();
if (!acl.getQName().equals(DavElements.E_ACL))
throw new DavException("request does not start with acl element", HttpServletResponse.SC_BAD_REQUEST);
List<Element> aceElements = acl.elements(DavElements.E_ACE);
ArrayList<Ace> aceList = new ArrayList<Ace>();
for (Element ace : aceElements) aceList.add(new Ace(ace));
MailItemResource mir = (MailItemResource) rs;
mir.setAce(ctxt, aceList);
}
use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.
the class AclReports method getMatchingResources.
private ArrayList<DavResource> getMatchingResources(DavContext ctxt, Element query) throws DavException, ServiceException {
// needs to be /principals/users, or apply-to-principal-collection-set is set.
ArrayList<DavResource> ret = new ArrayList<DavResource>();
boolean applyToPrincipalCollection = query.element(DavElements.E_APPLY_TO_PRINCIPAL_COLLECTION_SET) != null;
String path = ctxt.getUri();
if (!applyToPrincipalCollection && !path.startsWith(UrlNamespace.PRINCIPALS_PATH))
return ret;
// apple hack to do user / resource search
GalSearchType type = GalSearchType.all;
String queryType = query.attributeValue("type");
if (queryType != null) {
if (queryType.compareToIgnoreCase("INDIVIDUAL") == 0)
type = GalSearchType.account;
else if (queryType.compareToIgnoreCase("RESOURCE") == 0)
type = GalSearchType.resource;
}
@SuppressWarnings("unchecked") List propSearch = query.elements(DavElements.E_PROPERTY_SEARCH);
for (Object obj : propSearch) {
if (!(obj instanceof Element))
continue;
Element ps = (Element) obj;
Element prop = ps.element(DavElements.E_PROP);
Element match = ps.element(DavElements.E_MATCH);
if (prop != null && match != null) {
Element e = (Element) prop.elements().get(0);
ret.addAll(getMatchingPrincipals(ctxt, e.getQName(), match.getText(), type));
}
}
return ret;
}
use of com.zimbra.cs.dav.resource.DavResource in project zm-mailbox by Zimbra.
the class AclReports method getAclPrincipals.
private ArrayList<DavResource> getAclPrincipals(DavContext ctxt) throws DavException, ServiceException {
ArrayList<DavResource> ret = new ArrayList<DavResource>();
DavResource res = ctxt.getRequestedResource();
if (!(res instanceof MailItemResource))
return ret;
List<Ace> aces = ((MailItemResource) res).getAce(ctxt);
Provisioning prov = Provisioning.getInstance();
for (Ace ace : aces) {
if (ace.hasHref()) {
Account acct = prov.get(Key.AccountBy.id, ace.getZimbraId());
if (acct != null)
ret.add(UrlNamespace.getPrincipal(ctxt, acct));
}
}
return ret;
}
Aggregations