Example usage for org.dom4j Element getQName

List of usage examples for org.dom4j Element getQName

Introduction

In this page you can find the example usage for org.dom4j Element getQName.

Prototype

QName getQName();

Source Link

Document

Returns the QName of this element which represents the local name, the qualified name and the Namespace.

Usage

From source file:com.zimbra.cs.dav.resource.ScheduleInbox.java

License:Open Source License

@Override
public void patchProperties(DavContext ctxt, java.util.Collection<Element> set,
        java.util.Collection<QName> remove) throws DavException, IOException {
    ArrayList<Element> newSet = null;
    for (Element el : set) {
        if (el.getQName().equals(DavElements.E_CALENDAR_FREE_BUSY_SET)) {
            Iterator<?> hrefs = el.elementIterator(DavElements.E_HREF);
            ArrayList<String> urls = new ArrayList<String>();
            while (hrefs.hasNext())
                urls.add(((Element) hrefs.next()).getText());
            try {
                updateCalendarFreeBusySet(ctxt, urls);
            } catch (ServiceException e) {
                ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_FREE_BUSY_SET,
                        new DavException("error", DavProtocol.STATUS_FAILED_DEPENDENCY));
            } catch (DavException e) {
                ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_FREE_BUSY_SET, e);
            }/*from w  w  w .  j a va2 s.  co m*/
            if (newSet == null) {
                newSet = new ArrayList<Element>(set);
            }
            newSet.remove(el);
        }
    }
    if (newSet != null)
        set = newSet;
    super.patchProperties(ctxt, set, remove);
}

From source file:com.zimbra.cs.dav.service.DavServlet.java

License:Open Source License

private boolean isCtagRequest(DavContext ctxt) throws DavException {
    String httpMethod = ctxt.getRequest().getMethod();
    if (PropFind.PROPFIND.equalsIgnoreCase(httpMethod) && ctxt.hasRequestMessage()) {
        Document doc = ctxt.getRequestMessage();
        Element top = doc.getRootElement();
        if (top == null || !top.getQName().equals(DavElements.E_PROPFIND))
            return false;
        Element prop = top.element(DavElements.E_PROP);
        if (prop == null)
            return false;
        Iterator<?> iter = prop.elementIterator();
        while (iter.hasNext()) {
            prop = (Element) iter.next();
            if (prop.getQName().equals(DavElements.E_GETCTAG))
                return true;
        }/*from  www  . ja  va  2 s  .c  om*/
    }
    return false;
}

From source file:com.zimbra.cs.dav.service.method.Acl.java

License:Open Source License

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);// ww  w  . j a v  a2 s.com
}

From source file:com.zimbra.cs.dav.service.method.AclReports.java

License:Open Source License

@Override
public void handle(DavContext ctxt) throws DavException, ServiceException {
    ctxt.setStatus(DavProtocol.STATUS_MULTI_STATUS);
    Element query = ctxt.getRequestMessage().getRootElement();
    if (query.getQName().equals(DavElements.E_PRINCIPAL_PROPERTY_SEARCH))
        handlePrincipalPropertySearch(ctxt, query);
    else if (query.getQName().equals(DavElements.E_ACL_PRINCIPAL_PROP_SET))
        handleAclPrincipalPropSet(ctxt, query);
    else if (query.getQName().equals(DavElements.E_PRINCIPAL_MATCH))
        handlePrincipalMatch(ctxt, query);
    else if (query.getQName().equals(DavElements.E_PRINCIPAL_SEARCH_PROPERTY_SET))
        handlePrincipalSearchPropertySet(ctxt, query);
    else//w  ww  .  jav a 2  s.c  om
        throw new DavException("msg " + query.getName() + " is not an ACL report",
                HttpServletResponse.SC_BAD_REQUEST);
}

From source file:com.zimbra.cs.dav.service.method.AclReports.java

License:Open Source License

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();//from w w  w  .j  a v  a  2  s .c  o  m
    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;
}

From source file:com.zimbra.cs.dav.service.method.AclReports.java

License:Open Source License

/**
 * http://tools.ietf.org/html/rfc3744#section-9.2 DAV:acl-principal-prop-set REPORT
 * Postconditions:/*from  w ww  .j  av  a2 s  .  c om*/
 *     (DAV:number-of-matches-within-limits): The number of matching principals must fall within
 *     server-specific, predefined limits. For example, this condition might be triggered if a search
 *     specification would cause the return of an extremely large number of responses.
 */
private void handleAclPrincipalPropSet(DavContext ctxt, Element query) throws DavException, ServiceException {
    /* From rfc3744#section-9.2 DAV:acl-principal-prop-set REPORT
     *    This report is only defined when the Depth header has value "0"; other values result in a
     *    400 (Bad Request) error response.  Note that [RFC3253], Section 3.6, states that if the Depth header is
     *    not present, it defaults to a value of "0".
     */
    if (ctxt.getDepth() != Depth.zero) {
        throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
    }
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    // The response body for a successful request MUST be a DAV:multistatus XML element.  In the case where there
    // are no response elements, the returned multistatus XML element is empty.
    resp.getTop(DavElements.E_MULTISTATUS);
    for (DavResource rs : getAclPrincipals(ctxt))
        resp.addResource(ctxt, rs, reqProp, false);
}

From source file:com.zimbra.cs.dav.service.method.AclReports.java

License:Open Source License

/**
 * http://tools.ietf.org/html/rfc3744#section-9.3. DAV:principal-match REPORT
 *     This report is only defined when the Depth header has value "0";
 *     other values result in a 400 (Bad Request) error response.
 *//*from   w w w .jav  a2s . c o m*/
private void handlePrincipalMatch(DavContext ctxt, Element query) throws DavException, ServiceException {
    if (ctxt.getDepth() != Depth.zero) {
        throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
    }
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    // The response body for a successful request MUST be a DAV:multistatus XML element.  In the case where there
    // are no response elements, the returned multistatus XML element is empty.
    resp.getTop(DavElements.E_MULTISTATUS);
    Element principalProp = query.element(DavElements.E_PRINCIPAL_PROPERTY);
    if (principalProp == null) {
        // request must be to the principals path
        String path = ctxt.getUri();
        if (path.startsWith(UrlNamespace.PRINCIPALS_PATH))
            ret.add(UrlNamespace.getPrincipal(ctxt, ctxt.getAuthAccount()));
    } else {
        // we know of only <owner/> element
        Element owner = principalProp.element(DavElements.E_OWNER);
        if (owner != null) {
            // return the all the members of the collection.
            DavResource rs = ctxt.getRequestedResource();
            if (rs.isCollection())
                ret.addAll(rs.getChildren(ctxt));
        }
    }
    for (DavResource rs : ret)
        resp.addResource(ctxt, rs, reqProp, false);
}

From source file:com.zimbra.cs.dav.service.method.AclReports.java

License:Open Source License

/**
 * http://tools.ietf.org/html/rfc3744#section-9.5 DAV:principal-search-property-set REPORT
 *     This report is only defined when the Depth header has value "0";
 *     other values result in a 400 (Bad Request) error response.
 *//*from  w w w.  j  a  v a  2s . c o m*/
private void handlePrincipalSearchPropertySet(DavContext ctxt, Element query)
        throws DavException, ServiceException {
    if (ctxt.getDepth() != Depth.zero) {
        throw new DavException.REPORTwithDisallowedDepthException(query.getQName().getName(), ctxt.getDepth());
    }
    Element response = ctxt.getDavResponse().getTop(DavElements.E_PRINCIPAL_SEARCH_PROPERTY_SET);
    ctxt.setStatus(HttpServletResponse.SC_OK);
    for (Pair<QName, Element> prop : PRINCIPAL_SEARCH_PROPERTIES) {
        Element searchProp = response.addElement(DavElements.E_PRINCIPAL_SEARCH_PROPERTY);
        searchProp.addElement(DavElements.E_PROP).addElement(prop.getFirst());
        searchProp.add(prop.getSecond().createCopy());
    }
}

From source file:com.zimbra.cs.dav.service.method.AddressbookMultiget.java

License:Open Source License

@Override
public void handle(DavContext ctxt) throws ServiceException, DavException {
    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_MULTIGET))
        throw new DavException("msg " + query.getName() + " is not addressbook-multiget",
                HttpServletResponse.SC_BAD_REQUEST, null);

    DavResponse resp = ctxt.getDavResponse();
    DavResource reqResource = ctxt.getRequestedResource();
    if (!(reqResource instanceof AddressbookCollection))
        throw new DavException("requested resource is not an addressbook collection",
                HttpServletResponse.SC_BAD_REQUEST, null);
    RequestProp reqProp = ctxt.getRequestProp();
    for (Object obj : query.elements(DavElements.E_HREF)) {
        if (obj instanceof Element) {
            String href = ((Element) obj).getText();
            URI uri = URI.create(href);
            String[] fragments = HttpUtil.getPathFragments(uri);
            if (uri.getPath().toLowerCase().endsWith(AddressObject.VCARD_EXTENSION)) {
                // double encode the last fragment
                fragments[fragments.length - 1] = HttpUtil
                        .urlEscapeIncludingSlash(fragments[fragments.length - 1]);
            }// w  w w .  j  a va  2  s . co  m
            uri = HttpUtil.getUriFromFragments(fragments, uri.getQuery(), true, false);
            href = uri.getPath();
            DavResource rs = UrlNamespace.getResourceAtUrl(ctxt, href);
            if (rs != null)
                resp.addResource(ctxt, rs, reqProp, false);
        }
    }
}

From source file:com.zimbra.cs.dav.service.method.AddressbookQuery.java

License:Open Source License

public void handle(DavContext ctxt) throws DavException, ServiceException {
    DavResource rsc = ctxt.getRequestedResource();
    if (!(rsc instanceof AddressbookCollection))
        throw new DavException("not an addressbook resource", HttpServletResponse.SC_BAD_REQUEST, null);

    Element query = ctxt.getRequestMessage().getRootElement();
    if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_QUERY))
        throw new DavException("msg " + query.getName() + " is not addressbook-query",
                HttpServletResponse.SC_BAD_REQUEST, null);
    Element f = query.element(DavElements.CardDav.E_FILTER);
    if (f == null)
        throw new DavException("msg " + query.getName() + " is missing filter",
                HttpServletResponse.SC_BAD_REQUEST, null);
    Filter filter = new Filter.PropFilter((Element) f.elementIterator().next());
    Collection<AddressObject> contacts = filter.match(ctxt, ((AddressbookCollection) rsc));
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    resp.createResponse(ctxt);//from ww  w .j a va  2  s .  c om
    for (AddressObject c : contacts) {
        resp.addResource(ctxt, c, reqProp, false);
    }
}