List of usage examples for org.dom4j Element getQName
QName getQName();
QName
of this element which represents the local name, the qualified name and the Namespace
. From source file:com.zimbra.cs.dav.service.method.CalendarMultiget.java
License:Open Source License
public void handle(DavContext ctxt) throws ServiceException, DavException { Element query = ctxt.getRequestMessage().getRootElement(); if (!query.getQName().equals(DavElements.E_CALENDAR_MULTIGET)) throw new DavException("msg " + query.getName() + " is not calendar-multiget", HttpServletResponse.SC_BAD_REQUEST, null); DavResponse resp = ctxt.getDavResponse(); ArrayList<String> hrefs = new ArrayList<String>(); for (Object obj : query.elements(DavElements.E_HREF)) if (obj instanceof Element) hrefs.add(((Element) obj).getText()); long ts = System.currentTimeMillis(); DavResource reqResource = ctxt.getRequestedResource(); if (!(reqResource instanceof CalendarCollection)) throw new DavException("requested resource is not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null); CalendarCollection calResource = (CalendarCollection) reqResource; long now = System.currentTimeMillis(); ZimbraLog.dav.debug("GetRequestedResource: " + (now - ts) + "ms"); RequestProp reqProp = ctxt.getRequestProp(); for (DavResource rs : calResource.getAppointmentsByUids(ctxt, hrefs)) resp.addResource(ctxt, rs, reqProp, false); ts = now;/*from ww w . ja v a 2 s .c o m*/ now = System.currentTimeMillis(); ZimbraLog.dav.debug("multiget: " + (now - ts) + "ms"); }
From source file:com.zimbra.cs.dav.service.method.CalendarQuery.java
License:Open Source License
@Override public void handle(DavContext ctxt) throws DavException, ServiceException { Element query = ctxt.getRequestMessage().getRootElement(); if (!query.getQName().equals(DavElements.E_CALENDAR_QUERY)) { throw new DavException("msg " + query.getName() + " is not calendar-query", HttpServletResponse.SC_BAD_REQUEST, null); }//from ww w. ja v a 2 s. c o m RequestProp reqProp = ctxt.getRequestProp(); QueryContext qctxt = new QueryContext(ctxt, query, reqProp); if (qctxt.componentFilter == null) { throw new DavException("missing filter element in the request", HttpServletResponse.SC_BAD_REQUEST, null); } DavResource rsc = ctxt.getRequestedResource(); if (!(rsc instanceof CalendarCollection)) { throw new DavException("not a calendar resource", HttpServletResponse.SC_BAD_REQUEST, null); } CalendarCollection cal = (CalendarCollection) rsc; TimeRange tr = qctxt.componentFilter.getTimeRange(); if (tr == null) { tr = new TimeRange(rsc.getOwner()); } /** * Even if there are no matching items, we should return a DAV:multistatus report * http://tools.ietf.org/html/rfc4791#section-7.8 CALDAV:calendar-query REPORT * The response body for a successful request MUST be a DAV:multistatus XML element (i.e., the response uses * the same format as the response for PROPFIND). In the case where there are no response elements, the * returned DAV:multistatus XML element is empty. */ qctxt.davCtxt.setStatus(DavProtocol.STATUS_MULTI_STATUS); DavResponse resp = qctxt.davCtxt.getDavResponse(); resp.getTop(DavElements.E_MULTISTATUS); for (DavResource calItem : cal.getChildren(ctxt, tr)) { handleCalendarItem(qctxt, calItem); } }
From source file:com.zimbra.cs.dav.service.method.ExpandProperty.java
License:Open Source License
@Override public void handle(DavContext ctxt) throws ServiceException, DavException { Element query = ctxt.getRequestMessage().getRootElement(); if (!query.getQName().equals(DavElements.E_EXPAND_PROPERTY)) throw new DavException("msg " + query.getName() + " is not expand-property", HttpServletResponse.SC_BAD_REQUEST, null); DavResource rs = ctxt.getRequestedResource(); ctxt.setDavCompliance(DavProtocol.getComplianceString(rs.getComplianceList())); ctxt.setStatus(DavProtocol.STATUS_MULTI_STATUS); Element resp = ctxt.getDavResponse().getTop(DavElements.E_MULTISTATUS).addElement(DavElements.E_RESPONSE); expandProperties(ctxt, rs, query, resp); }
From source file:com.zimbra.cs.dav.service.method.FreeBusyQuery.java
License:Open Source License
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException { Element query = ctxt.getRequestMessage().getRootElement(); if (!query.getQName().equals(DavElements.E_FREE_BUSY_QUERY)) throw new DavException("msg " + query.getName() + " is not free-busy-query", HttpServletResponse.SC_BAD_REQUEST, null); Element trElem = query.element(DavElements.E_TIME_RANGE); if (trElem == null) throw new DavException("need time-range", HttpServletResponse.SC_BAD_REQUEST, null); TimeRange timeRange = new TimeRange(trElem); DavResource rs = ctxt.getRequestedResource(); if (!(rs instanceof CalendarCollection)) throw new DavException("not a calendar collection", HttpServletResponse.SC_BAD_REQUEST, null); try {//from w w w . j a v a 2s .c o m String freebusy = ((CalendarCollection) rs).getFreeBusyReport(ctxt, timeRange); HttpServletResponse resp = ctxt.getResponse(); resp.setContentType(MimeConstants.CT_TEXT_CALENDAR); resp.getOutputStream().write(freebusy.getBytes("UTF-8")); ctxt.responseSent(); } catch (ServiceException se) { throw new DavException("can't get freebusy report", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, se); } }
From source file:com.zimbra.cs.dav.service.method.Lock.java
License:Open Source License
@Override public void handle(DavContext ctxt) throws DavException, IOException, ServiceException { LockMgr lockmgr = LockMgr.getInstance(); LockMgr.Lock lock = null;//from w w w .j ava 2 s. c om if (ctxt.hasRequestMessage()) { DavContext.Depth depth = ctxt.getDepth(); if (depth == Depth.one) throw new DavException("invalid depth", HttpServletResponse.SC_BAD_REQUEST, null); String d = (depth == Depth.zero) ? "0" : depth.toString(); LockMgr.LockScope scope = LockScope.shared; LockMgr.LockType type = LockType.write; Document req = ctxt.getRequestMessage(); Element top = req.getRootElement(); if (!top.getName().equals(DavElements.P_LOCKINFO)) throw new DavException("msg " + top.getName() + " not allowed in LOCK", HttpServletResponse.SC_BAD_REQUEST, null); Element e = top.element(DavElements.E_LOCKSCOPE); @SuppressWarnings("unchecked") List<Element> ls = e.elements(); for (Element v : ls) { if (v.getQName().equals(DavElements.E_EXCLUSIVE)) scope = LockScope.exclusive; else if (v.getQName().equals(DavElements.E_SHARED)) scope = LockScope.shared; else throw new DavException("unrecognized scope element " + v.toString(), HttpServletResponse.SC_BAD_REQUEST, null); } e = top.element(DavElements.E_LOCKTYPE); @SuppressWarnings("unchecked") List<Element> lt = e.elements(); for (Element v : lt) { if (v.getQName().equals(DavElements.E_WRITE)) type = LockType.write; else throw new DavException("unrecognized type element " + v.toString(), HttpServletResponse.SC_BAD_REQUEST, null); } String owner; e = top.element(DavElements.E_OWNER); if (e != null && e.elementIterator(DavElements.E_HREF).hasNext()) { Element ownerElem = (Element) e.elementIterator(DavElements.E_HREF).next(); owner = ownerElem.getText(); } else { owner = ctxt.getAuthAccount().getName(); } lock = lockmgr.createLock(ctxt, owner, ctxt.getUri(), type, scope, d); ctxt.getResponse().addHeader(DavProtocol.HEADER_LOCK_TOKEN, lock.toLockTokenHeader()); } else { // refresh lock String token = ctxt.getRequest().getHeader(DavProtocol.HEADER_IF); if (token == null) { throw new DavException("no request body", HttpServletResponse.SC_BAD_REQUEST, null); } token = token.trim(); int len = token.length(); if (token.charAt(0) == '(' && token.charAt(len - 1) == ')') { token = token.substring(1, len - 1); } List<LockMgr.Lock> locks = lockmgr.getLocks(ctxt.getUri()); for (LockMgr.Lock l : locks) { if (l.token.equals(LockMgr.Lock.parseLockTokenHeader(token))) { l.extendExpiration(); lock = l; break; } } if (lock == null) { throw new DavException("Lock does not exist", HttpServletResponse.SC_PRECONDITION_FAILED, null); } } ctxt.getDavResponse().addProperty(ctxt, new LockDiscovery(lock)); ctxt.setStatus(HttpServletResponse.SC_OK); sendResponse(ctxt); }
From source file:com.zimbra.cs.dav.service.method.PropPatch.java
License:Open Source License
/** * @param setElems - list of elements under "set" in the request. Must NOT be null * @param removeElems - list of elements under "remove" in the request. Must NOT be null * @return Pair - first is list of elements representing properties to set. second is names of * properties to remove./*www.ja v a 2 s.c o m*/ */ public static Pair<List<Element>, List<QName>> processSetsAndRemoves(DavContext ctxt, DavResource resource, List<Element> setElems, List<Element> removeElems, boolean isCreate) throws DavException, IOException { List<Element> set = Lists.newArrayList(); List<QName> remove = Lists.newArrayList(); RequestProp rp = new RequestProp(true); ctxt.setResponseProp(rp); for (Element propElem : setElems) { QName propName = propElem.getQName(); ResourceProperty prop = resource.getProperty(propName); if (prop == null || !prop.isProtected()) { set.add(propElem); rp.addProp(propElem); } else if (isCreate && prop.isAllowSetOnCreate()) { set.add(propElem); } else { rp.addPropError(propName, new DavException.CannotModifyProtectedProperty(propName)); } } for (Element propElem : removeElems) { QName propName = propElem.getQName(); ResourceProperty prop = resource.getProperty(propName); if (prop == null || !prop.isProtected()) { remove.add(propName); rp.addProp(propElem); } else { rp.addPropError(propName, new DavException.CannotModifyProtectedProperty(propName)); } } return new Pair<List<Element>, List<QName>>(set, remove); }
From source file:com.zimbra.cs.dav.service.method.Report.java
License:Open Source License
@Override public void handle(DavContext ctxt) throws DavException, IOException, ServiceException { if (!ctxt.hasRequestMessage()) { throw new DavException("empty request body", HttpServletResponse.SC_BAD_REQUEST, null); }/*from ww w. ja v a2s. c o m*/ Document req = ctxt.getRequestMessage(); Element top = req.getRootElement(); if (top == null) { throw new DavException("empty request body", HttpServletResponse.SC_BAD_REQUEST, null); } QName topName = top.getQName(); DavMethod report = sReports.get(topName); if (report == null) { throw new DavException.UnsupportedReport(topName); } disableJettyTimeout(ctxt); if (ctxt.getDepth() != DavContext.Depth.zero) { ctxt.getDavResponse().createResponse(ctxt); } report.handle(ctxt); sendResponse(ctxt); }
From source file:com.zimbra.cs.service.formatter.ContactCSV.java
License:Open Source License
private static void readMapping(InputStream is) throws XmlParseException { delimiterInfo = new HashMap<String, Character>(); dateOrderInfo = new HashMap<String, String>(); Element root = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(is).getRootElement(); for (Iterator elements = root.elementIterator(); elements.hasNext();) { Element elem = (Element) elements.next(); if (elem.getQName().equals(FIELDS)) { populateFields(elem);//from w w w. ja va 2s . c om } else if (elem.getQName().equals(FORMAT)) { addFormat(elem); } else if (elem.getQName().equals(DELIMITERS)) { populateDelimiterInfo(elem); } else if (elem.getQName().equals(DATEFORMATS)) { populateDateFormatInfo(elem); } } }
From source file:de.fmaul.android.cmis.utils.FeedUtils.java
License:Apache License
public static Map<String, ArrayList<CmisProperty>> getCmisRepositoryProperties(Element feedEntry) { Map<String, ArrayList<CmisProperty>> infoServerList = new HashMap<String, ArrayList<CmisProperty>>(); ArrayList<CmisProperty> propsList = new ArrayList<CmisProperty>(); ArrayList<CmisProperty> propsCapabilities = new ArrayList<CmisProperty>(); ArrayList<CmisProperty> propsACLCapabilities = new ArrayList<CmisProperty>(); Element objectElement = feedEntry.element(CMISRA_REPO_INFO); if (objectElement != null) { List<Element> properties = objectElement.elements(); for (Element property : properties) { if (CMIS_REPO_CAPABILITES.equals(property.getQName())) { List<Element> props = property.elements(); for (Element prop : props) { propsCapabilities.add(new CmisProperty(null, null, null, prop.getName().replace("capability", ""), prop.getText())); }/* ww w .j a v a 2s. c o m*/ } else if (CMIS_REPO_ACL_CAPABILITES.equals(property.getQName())) { /*List<Element> props = property.elements(); for (Element prop : props) { propsACLCapabilities.add(new CmisProperty(null, null, null, prop.getName().replace("cmis:", ""), prop.getText())); }*/ } else { propsList.add(new CmisProperty(null, null, null, property.getName(), property.getText())); } } infoServerList.put(Server.INFO_GENERAL, propsList); infoServerList.put(Server.INFO_CAPABILITIES, propsCapabilities); infoServerList.put(Server.INFO_ACL_CAPABILITIES, propsACLCapabilities); } return infoServerList; }
From source file:edu.ucsd.library.dams.jhove.MyJhoveBase.java
License:Open Source License
public static void removeNS(Element elem) { elem.remove(elem.getNamespace());//from ww w . java2s . c o m elem.setQName(new QName(elem.getQName().getName(), Namespace.NO_NAMESPACE)); // fix children List children = elem.elements(); for (int i = 0; i < children.size(); i++) { Element child = (Element) children.get(i); removeNS(child); } }