List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator(QName qName);
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
protected LmcContact parseContact(Element cn) throws ServiceException { LmcContact result = new LmcContact(); // get the element's attributes result.setID(DomUtil.getAttr(cn, MailConstants.A_ID)); result.setTags(cn.attributeValue(MailConstants.A_TAGS)); result.setFlags(cn.attributeValue(MailConstants.A_FLAGS)); result.setFolder(cn.attributeValue(MailConstants.A_FOLDER)); // get the contact attributes (<a> elements) ArrayList cnAttrs = new ArrayList(); for (Iterator ait = cn.elementIterator(MailConstants.E_ATTRIBUTE); ait.hasNext();) { Element cnAttrElem = (Element) ait.next(); cnAttrs.add(parseContactAttr(cnAttrElem)); }//from w ww . j a va 2 s .c o m if (!cnAttrs.isEmpty()) { LmcContactAttr cnAttrArray[] = new LmcContactAttr[cnAttrs.size()]; result.setAttrs((LmcContactAttr[]) cnAttrs.toArray(cnAttrArray)); } // XXX: not clear from spec if the <mp> element is used -- assume not return result; }
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
/** * This parses the <folder> element pointed to by p. * @param p - the folder element// w ww. ja v a 2 s . com * @return an LmcFolder object that is populated with data from the XML * @throws ServiceException */ protected LmcFolder parseFolder(Element f) throws ServiceException { LmcFolder response = new LmcFolder(); /* * Get the attributes of this folder element. The root folder * object does not have the name, parent, and numUnread attributes. * Hence this parses them as optional. */ response.setFolderID(DomUtil.getAttr(f, MailConstants.A_ID)); response.setName(f.attributeValue(MailConstants.A_NAME)); response.setParentID(f.attributeValue(MailConstants.A_FOLDER)); response.setNumUnread(f.attributeValue(MailConstants.A_UNREAD)); response.setView(f.attributeValue(MailConstants.A_DEFAULT_VIEW)); // recurse if necessary ArrayList subFolders = new ArrayList(); for (Iterator ait = f.elementIterator(MailConstants.E_FOLDER); ait.hasNext();) { Element sub = (Element) ait.next(); subFolders.add(parseFolder(sub)); } if (!subFolders.isEmpty()) { LmcFolder fs[] = new LmcFolder[subFolders.size()]; response.setSubFolders((LmcFolder[]) subFolders.toArray(fs)); } return response; }
From source file:com.zimbra.cs.dav.resource.AbstractCalendarProxy.java
License:Open Source License
/** * Only support setting of which accounts are in the group-member-set - defined as those which * have the appropriate perms on the default Calendar folder * Need to grant access to new members of the set (with sending of invites) and revoke access to deleted * members as appropriate.//from ww w . j av a 2 s .co m * * Note that un-checking a box next to a name in the Yosemite Calendar UI would result in 2 PROPPATCHes, * one to add an entry to the read group and one to remove that entry from the write group (or vice versa) * * Note that there is a mismatch between the Apple model and ours in that in the Zimbra model we send out a * share notification email, and the recipient actively accepts the share - something the Apple model * doesn't require. */ @Override public void patchProperties(DavContext ctxt, Collection<Element> set, Collection<QName> remove) throws DavException, IOException { boolean readOnlyProxy = !(this instanceof CalendarProxyWrite); // Zimbra supports more fine grained permissions than this. ROLE_VIEW is a good match but // which role is appropriate for read-write proxy is probably either ROLE_MANAGER or ROLE_ADMIN // Flipped the coin and chosen ROLE_ADMIN here. short role = readOnlyProxy ? ACL.ROLE_VIEW : ACL.ROLE_ADMIN; Set<Account> origGroupMembers = ProxyGroupMemberSet.getUsersWithProxyAccessToCalendar(ctxt, getAccount(), readOnlyProxy); Set<Account> invitees = Sets.newHashSet(); Set<Account> newGroupMembers = Sets.newHashSet(); boolean settingNewGroupMembers = false; for (Element setElem : set) { if (setElem.getQName().equals(DavElements.E_GROUP_MEMBER_SET)) { settingNewGroupMembers = true; Iterator hrefs = setElem.elementIterator(DavElements.E_HREF); while (hrefs.hasNext()) { Account target = hrefToAccount(ctxt, (Element) hrefs.next()); if (target != null) { newGroupMembers.add(target); if ((!origGroupMembers.contains(target))) { invitees.add(target); } } } } } if (!settingNewGroupMembers) { return; } Set<Account> revokees = Sets.newHashSet(); for (Account origMember : origGroupMembers) { if (!newGroupMembers.contains(origMember)) { revokees.add(origMember); } } changeGroupMembership(ctxt, invitees, revokees, role); }
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 ww .j a va 2 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.method.ExpandProperty.java
License:Open Source License
/** * @param rs - the requested resource/* w w w . j ava2 s. c o m*/ * @param elem - specification of what should be expanded - either the top level {@code <DAV:expand-property>} * element or a descendant {@code <DAV:property>} element * @param resp - the target {@code <DAV:response>} element */ private void expandProperties(DavContext ctxt, DavResource rs, Element elem, Element resp) { rs.getProperty(DavElements.E_HREF).toElement(ctxt, resp, false); @SuppressWarnings("rawtypes") Iterator iter = elem.elementIterator(DavElements.E_PROPERTY); PropStat propstat = new PropStat(); while (iter.hasNext()) { Element property = (Element) iter.next(); Prop p = new Prop(property); ResourceProperty rp = rs.getProperty(p.getQName()); if (rp == null) { if (!ctxt.isBrief()) propstat.add(p.getQName(), null, HttpServletResponse.SC_NOT_FOUND); } else { @SuppressWarnings("rawtypes") Iterator subProps = property.elementIterator(); if (subProps.hasNext()) { PropStat sub = new PropStat(); sub.add(rp); Element subElem = DocumentHelper.createElement(DavElements.E_RESPONSE); sub.toResponse(ctxt, subElem, false); @SuppressWarnings("rawtypes") Iterator subPropstats = subElem.elementIterator(DavElements.E_PROPSTAT); while (subPropstats.hasNext()) { Element subPropstat = (Element) subPropstats.next(); Element status = subPropstat.element(DavElements.E_STATUS); if (!status.getText().equals(DavResponse.sStatusTextMap.get(HttpServletResponse.SC_OK))) continue; Element prop = subPropstat.element(DavElements.E_PROP); if (prop == null) continue; prop = prop.element(p.getQName()); if (prop == null) continue; @SuppressWarnings("rawtypes") Iterator hrefs = prop.elementIterator(DavElements.E_HREF); if (!hrefs.hasNext()) { propstat.add(rp); // need to say which property, even if the list is empty } else { while (hrefs.hasNext()) { Element href = (Element) hrefs.next(); String url = href.getText(); if (url == null) continue; try { url = URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { ZimbraLog.dav.warn("can't decode url %s", url, e); } try { DavResource target = UrlNamespace.getResourceAtUrl(ctxt, url); Element targetElem = DocumentHelper.createElement(DavElements.E_RESPONSE); expandProperties(ctxt, target, property, targetElem); propstat.add(rp.getName(), targetElem); } catch (DavException e) { ZimbraLog.dav.warn("can't find resource for " + url, e); } } } } } else { propstat.add(rp); } } } propstat.toResponse(ctxt, resp, false); }
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 ww w. j ava2 s .co m*/ 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.service.formatter.ContactCSV.java
License:Open Source License
private static void populateDelimiterInfo(Element delimiters) { delimiterInfo = new HashMap<String, Character>(); for (Iterator elements = delimiters.elementIterator(DELIMITER); elements.hasNext();) { Element field = (Element) elements.next(); String delim = field.attributeValue(ATTR_CHAR); if (delim == null || delim.isEmpty()) { continue; }/*from w ww .j ava2 s . c o m*/ String format = field.attributeValue(ATTR_FORMAT); if (format == null || format.isEmpty()) { continue; } String myLocale = field.attributeValue(ATTR_LOCALE); if (myLocale != null && !myLocale.isEmpty()) { format = format + "/" + myLocale; } delimiterInfo.put(format, delim.charAt(0)); } }
From source file:com.zimbra.cs.service.formatter.ContactCSV.java
License:Open Source License
private static void populateDateFormatInfo(Element dateFormats) { dateOrderInfo = new HashMap<String, String>(); for (Iterator elements = dateFormats.elementIterator(DATEFORMAT); elements.hasNext();) { Element dateFormat = (Element) elements.next(); String origOrder = dateFormat.attributeValue(ATTR_ORDER); if (origOrder == null || origOrder.isEmpty()) { continue; }//from w ww . j a v a 2 s . c o m String order = origOrder.toLowerCase(); if (!(order.equals("ymd") || order.equals("ydm") || order.equals("myd") || order.equals("mdy") || order.equals("dmy") || order.equals("dym"))) { LOG.debug("invalid \"order\" %s in zimbra-contact-fields.xml", origOrder); continue; } String format = dateFormat.attributeValue(ATTR_FORMAT); if (format == null || format.isEmpty()) { continue; } String myLocale = dateFormat.attributeValue(ATTR_LOCALE); if (myLocale != null && !myLocale.isEmpty()) { format = format + "/" + myLocale; } dateOrderInfo.put(format, order); } }
From source file:com.zimbra.cs.service.formatter.ContactCSV.java
License:Open Source License
private static void populateFields(Element fields) { knownFields = new HashSet<String>(); for (Iterator elements = fields.elementIterator(FIELD); elements.hasNext();) { Element field = (Element) elements.next(); knownFields.add(field.attributeValue(ATTR_NAME)); }// www . ja v a2s. c o m }
From source file:com.zimbra.cs.service.formatter.ContactCSV.java
License:Open Source License
private static void addFormat(Element format) { CsvFormat fmt = new CsvFormat(format); for (Iterator elements = format.elementIterator(COLUMN); elements.hasNext();) { Element col = (Element) elements.next(); fmt.add(col);/*from w ww.j ava 2 s . c o m*/ } if (knownFormats == null) { knownFormats = new HashSet<CsvFormat>(); } knownFormats.add(fmt); if (fmt.hasFlag("default")) { defaultFormat = fmt; } }