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.client.soap.LmcSoapRequest.java
License:Open Source License
private LmcDocument parseDocumentCommon(Element doc, LmcDocument result) { result.setID(doc.attributeValue(MailConstants.A_ID)); result.setName(doc.attributeValue(MailConstants.A_NAME)); result.setContentType(doc.attributeValue(MailConstants.A_CONTENT_TYPE)); result.setFolder(doc.attributeValue(MailConstants.A_FOLDER)); result.setRev(doc.attributeValue(MailConstants.A_VERSION)); result.setLastModifiedDate(doc.attributeValue(MailConstants.A_DATE)); result.setLastEditor(doc.attributeValue(MailConstants.A_LAST_EDITED_BY)); result.setRestUrl(doc.attributeValue(MailConstants.A_REST_URL)); result.setCreator(doc.attributeValue(MailConstants.A_CREATOR)); result.setCreateDate(doc.attributeValue(MailConstants.A_CREATED_DATE)); for (Iterator it = doc.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); String elementType = e.getQName().getName(); if (elementType.equals(MailConstants.E_FRAG)) { // fragment result.setFragment(e.getText()); }//from www. j a v a 2 s. com } return result; }
From source file:com.zimbra.cs.dav.caldav.Filter.java
License:Open Source License
protected void parse(Element elem) { for (Object o : elem.elements()) { if (o instanceof Element) { Element e = (Element) o; QName name = e.getQName(); if (canHaveCompFilter() && name.equals(DavElements.E_COMP_FILTER)) mComps.add(new CompFilter(e)); else if (canHavePropFilter() && name.equals(DavElements.E_PROP_FILTER)) mProps.add(new PropFilter(e)); else if (canHaveParamFilter() && name.equals(DavElements.E_PARAM_FILTER)) mParams.add(new ParamFilter(e)); else if (name.equals(DavElements.E_TEXT_MATCH)) mTextMatches.add(new TextMatch(e)); else if (name.equals(DavElements.E_TIME_RANGE)) mTimeRange = new TimeRange(e); else if (name.equals(DavElements.E_IS_NOT_DEFINED)) mIsNotDefinedSet = true; else//from w w w . j a v a 2 s . c o m ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName()); } } }
From source file:com.zimbra.cs.dav.carddav.Filter.java
License:Open Source License
protected void parse(Element elem) { for (Object o : elem.elements()) { if (o instanceof Element) { Element e = (Element) o; QName name = e.getQName(); if (canHavePropFilter() && name.equals(DavElements.CardDav.E_PROP_FILTER)) mProps.add(new PropFilter(e)); else if (canHaveParamFilter() && name.equals(DavElements.CardDav.E_PARAM_FILTER)) mParams.add(new ParamFilter(e, this)); else if (name.equals(DavElements.CardDav.E_TEXT_MATCH)) mTextMatch = new TextMatch(e, this); else if (name.equals(DavElements.CardDav.E_IS_NOT_DEFINED)) mIsNotDefinedSet = true; else/*from w ww .j a va2s . c o m*/ ZimbraLog.dav.info("unrecognized filter " + name.getNamespaceURI() + ":" + name.getName()); } } }
From source file:com.zimbra.cs.dav.client.DavObject.java
License:Open Source License
public DavObject(Element objElem) { mProps = new HashMap<Integer, Element>(); if (!objElem.getQName().equals(DavElements.E_RESPONSE)) return;// ww w . j ava2 s.c o m Element href = objElem.element(DavElements.E_HREF); if (href != null) mHref = href.getText(); for (Object obj : objElem.elements(DavElements.E_PROPSTAT)) { Element propStat = (Element) obj; Integer status = null; Element statusElem = propStat.element(DavElements.E_STATUS); if (statusElem != null) status = parseStatusCode(statusElem.getText()); mProps.put(status, propStat.element(DavElements.E_PROP)); } }
From source file:com.zimbra.cs.dav.property.ResourceProperty.java
License:Open Source License
public ResourceProperty(Element elem) { this(elem.getQName()); mValue = elem.getText();/*w w w. j a v a2 s .c om*/ for (Object o : elem.elements()) { if (o instanceof Element) { mChildren.add((Element) o); } } }
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.// w ww .j a v a 2s .com * * 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.AddressObject.java
License:Open Source License
@Override public ResourceProperty getProperty(Element prop) { if (prop.getQName().equals(DavElements.CardDav.E_ADDRESS_DATA)) { return CardDavProperty.getAddressbookData(prop, this); }/*from w w w . java 2 s .c o m*/ return super.getProperty(prop); }
From source file:com.zimbra.cs.dav.resource.DavResource.java
License:Open Source License
public ResourceProperty getProperty(Element prop) { if (prop == null) return null; return getProperty(prop.getQName()); }
From source file:com.zimbra.cs.dav.resource.MailItemResource.java
License:Open Source License
private Map<QName, Element> getDeadProps(DavContext ctxt, MailItem item) throws IOException, ServiceException { HashMap<QName, Element> props = new HashMap<QName, Element>(); Mailbox mbox = item.getMailbox();/*from www . jav a 2s . c o m*/ Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY); if (data == null) return props; String configVal = data.get(Integer.toString(item.getId()), null); if (configVal == null) return props; if (configVal.length() == 0) return props; ByteArrayInputStream in = new ByteArrayInputStream(configVal.getBytes(StandardCharsets.UTF_8)); org.dom4j.Document doc = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(in); Element e = doc.getRootElement(); if (e == null) return props; for (Object obj : e.elements()) { if (obj instanceof Element) { Element elem = (Element) obj; elem.detach(); props.put(elem.getQName(), elem); } } return props; }
From source file:com.zimbra.cs.dav.resource.MailItemResource.java
License:Open Source License
@Override public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException { List<QName> reqProps = new ArrayList<QName>(); for (QName n : remove) { mDeadProps.remove(n);/*from w ww . jav a 2 s. co m*/ reqProps.add(n); } for (Element e : set) { QName name = e.getQName(); if (name.equals(DavElements.E_DISPLAYNAME) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) { // rename folder try { String val = e.getText(); String uri = getUri(); Mailbox mbox = getMailbox(ctxt); mbox.rename(ctxt.getOperationContext(), mId, type, val, mFolderId); setProperty(DavElements.P_DISPLAYNAME, val); UrlNamespace.addToRenamedResource(getOwner(), uri, this); UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this); } catch (ServiceException se) { ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } mDeadProps.remove(name); continue; } else if (name.equals(DavElements.E_CALENDAR_COLOR) && (type == MailItem.Type.FOLDER || type == MailItem.Type.MOUNTPOINT)) { // change color String colorStr = e.getText(); Color color = new Color(colorStr.substring(0, 7)); byte col = (byte) COLOR_LIST.indexOf(colorStr); if (col >= 0) color.setColor(col); try { Mailbox mbox = getMailbox(ctxt); mbox.setColor(ctxt.getOperationContext(), new int[] { mId }, type, color); } catch (ServiceException se) { ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } mDeadProps.remove(name); continue; } else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET)) { // change default view @SuppressWarnings("unchecked") List<Element> elements = e.elements(DavElements.E_COMP); boolean isTodo = false; boolean isEvent = false; for (Element element : elements) { Attribute attr = element.attribute(DavElements.P_NAME); if (attr != null && CalComponent.VTODO.name().equals(attr.getValue())) { isTodo = true; } else if (attr != null && CalComponent.VEVENT.name().equals(attr.getValue())) { isEvent = true; } } if (isEvent ^ isTodo) { // we support a calendar collection of type event or todo, not both or none. Type type = (isEvent) ? Type.APPOINTMENT : Type.TASK; try { Mailbox mbox = getMailbox(ctxt); mbox.setFolderDefaultView(ctxt.getOperationContext(), mId, type); // Update the view for this collection. This collection may get cached if display name is modified. // See UrlNamespace.addToRenamedResource() if (this instanceof Collection) { ((Collection) this).view = type; } } catch (ServiceException se) { ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), DavProtocol.STATUS_FAILED_DEPENDENCY)); } } else { ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name)); } continue; } mDeadProps.put(name, e); reqProps.add(name); } String configVal = ""; if (mDeadProps.size() > 0) { org.dom4j.Document doc = org.dom4j.DocumentHelper.createDocument(); Element top = doc.addElement(CONFIG_KEY); for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) top.add(entry.getValue().detach()); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat format = OutputFormat.createCompactFormat(); XMLWriter writer = new XMLWriter(out, format); writer.write(doc); configVal = new String(out.toByteArray(), "UTF-8"); if (configVal.length() > PROP_LENGTH_LIMIT) for (Map.Entry<QName, Element> entry : mDeadProps.entrySet()) ctxt.getResponseProp().addPropError(entry.getKey(), new DavException("prop length exceeded", DavProtocol.STATUS_INSUFFICIENT_STORAGE)); } Mailbox mbox = null; try { mbox = getMailbox(ctxt); mbox.lock.lock(); Metadata data = mbox.getConfig(ctxt.getOperationContext(), CONFIG_KEY); if (data == null) { data = new Metadata(); } data.put(Integer.toString(mId), configVal); mbox.setConfig(ctxt.getOperationContext(), CONFIG_KEY, data); } catch (ServiceException se) { for (QName qname : reqProps) ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), HttpServletResponse.SC_FORBIDDEN)); } finally { if (mbox != null) mbox.lock.release(); } }