List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:com.zimbra.cs.account.AttributeManager.java
License:Open Source License
private void loadObjectClasses(File file, Document doc) { Element root = doc.getRootElement(); if (!root.getName().equals(E_OBJECTCLASSES)) { error(null, file, "root tag is not " + E_OBJECTCLASSES); return;//from w w w . j a v a 2 s . c om } String group = root.attributeValue(A_GROUP); String groupIdStr = root.attributeValue(A_GROUP_ID); if (group == null ^ groupIdStr == null) { error(null, file, A_GROUP + " and " + A_GROUP_ID + " both have to be both specified"); } int groupId = -1; if (group != null) { try { groupId = Integer.valueOf(groupIdStr); } catch (NumberFormatException nfe) { error(null, file, A_GROUP_ID + " is not a number: " + groupIdStr); } } if (groupId == 1) { error(null, file, A_GROUP_ID + " is not valid (used by ZimbraAttrType)"); } else if (groupId > 0) { if (mOCGroupMap.containsKey(groupId)) { error(null, file, "duplicate group id: " + groupId); } else if (mOCGroupMap.containsValue(group)) { error(null, file, "duplicate group: " + group); } else { mOCGroupMap.put(groupId, group); } } for (Iterator iter = root.elementIterator(); iter.hasNext();) { Element eattr = (Element) iter.next(); if (!eattr.getName().equals(E_OBJECTCLASS)) { error(null, file, "unknown element: " + eattr.getName()); continue; } int id = -1; ObjectClassType type = null; String canonicalName = null; String name = eattr.attributeValue(A_NAME); if (name == null) { error(null, file, "no name specified"); continue; } canonicalName = name.toLowerCase(); for (Iterator attrIter = eattr.attributeIterator(); attrIter.hasNext();) { Attribute attr = (Attribute) attrIter.next(); String aname = attr.getName(); if (aname.equals(A_NAME)) { // nothing to do - already processed } else if (aname.equals(A_TYPE)) { type = ObjectClassType.valueOf(attr.getValue()); } else if (aname.equals(A_ID)) { try { id = Integer.parseInt(attr.getValue()); if (id < 0) { error(name, file, "invalid id " + id + ": must be positive"); } } catch (NumberFormatException nfe) { error(name, file, aname + " is not a number: " + attr.getValue()); } } else { error(name, file, "unknown <attr> attr: " + aname); } } List<String> superOCs = new LinkedList<String>(); String description = null; List<String> comment = null; for (Iterator elemIter = eattr.elementIterator(); elemIter.hasNext();) { Element elem = (Element) elemIter.next(); if (elem.getName().equals(E_SUP)) { superOCs.add(elem.getText()); } else if (elem.getName().equals(E_DESCRIPTION)) { if (description != null) { error(name, file, "more than one " + E_DESCRIPTION); } description = elem.getText(); } else if (elem.getName().equals(E_COMMENT)) { if (comment != null) { error(name, file, "more than one " + E_COMMENT); } comment = new ArrayList<String>(); String[] lines = elem.getText().trim().split("\\n"); for (String line : lines) comment.add(line.trim()); } else { error(name, file, "unknown element: " + elem.getName()); } } // Check that if all bits are specified if (id <= 0) { error(name, file, "id not specified"); } if (type == null) { error(name, file, "type not specified"); } if (description == null) { error(name, file, "desc not specified"); } if (superOCs.isEmpty()) { error(name, file, "sup not specified"); } // there must be a one-to-one mapping between enums in AttributeClass and ocs defined in the xml AttributeClass attrClass = AttributeClass.getAttributeClass(name); if (attrClass == null) { error(name, file, "unknown class in AttributeClass: " + name); } ObjectClassInfo info = new ObjectClassInfo(attrClass, name, id, groupId, type, superOCs, mMinimize ? null : description, mMinimize ? null : comment); if (mOCs.get(canonicalName) != null) { error(name, file, "duplicate objectclass definiton"); } mOCs.put(canonicalName, info); } }
From source file:com.zimbra.cs.account.DataSourceConfig.java
License:Open Source License
private DataSourceConfig read(Element element) throws IOException { for (Object obj : element.attributes()) { Attribute attr = (Attribute) obj; String name = attr.getName(); if (name.equals(SYNC_ALL_FOLDERS)) { syncAllFolders = Boolean.valueOf(attr.getValue()); } else {/*from ww w. java2 s .com*/ throw invalidConfig("Unrecognized attribute name: " + name); } } for (Object obj : element.elements()) { Element el = (Element) obj; String name = el.getName(); if (name.equals(SERVICE)) { services.add(new Service().read(el)); } else { throw invalidConfig("Unrecognized element name: " + name); } } return this; }
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 ww w . j a va2s. c o 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(); } }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLAlgo.java
License:GNU General Public License
/** * Check if two elements are (recursively) equal * * TODO: remove and use equality tester from dom4j pkg * * @param e1 first element/* w ww . j av a 2 s . c o m*/ * @param e2 second element */ public static boolean equalElements(final Element e1, final Element e2) { if (!e1.getName().equals(e2.getName())) return false; if (!e1.getText().equals(e2.getText())) return false; for (final Object attrObj : e1.attributes()) { final Attribute attr = (Attribute) attrObj; if (!attr.getName().equals("bl") && !attr.getName().equals("bc") && !attr.getValue().equals(e2.attributeValue(attr.getName()))) return false; } final Iterator i = e1.elementIterator(); final Iterator j = e2.elementIterator(); while (i.hasNext() && j.hasNext()) if (!equalElements((Element) i.next(), (Element) j.next())) return false; if (i.hasNext() || j.hasNext()) return false; return true; }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLPattern.java
License:GNU General Public License
private static boolean matchingAttributes(final List<Attribute> pivotATTRs, final Element XMLelement) { for (final Attribute pivotAttr : pivotATTRs) { final String elem = XMLelement.attributeValue(pivotAttr.getName()); if (elem == null || !matchingAttribute(pivotAttr.getValue(), elem)) return false; }//from ww w . j a v a 2 s.c o m return true; }
From source file:cz.muni.stanse.utils.xmlpatterns.XMLPattern.java
License:GNU General Public License
private static boolean satisfyVarConstraints(final String elemName, final Attribute matchAttr, final Attribute exceptAttr) { return (matchAttr != null) ? retvalWhenItemInSet(true, elemName, splitAttrSymbols(matchAttr.getValue()).getSecond()) : (exceptAttr != null)/*from w w w .j a v a2s. c o m*/ ? retvalWhenItemInSet(false, elemName, splitAttrSymbols(exceptAttr.getValue()).getSecond()) : true; }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readAppCacheConfig(Element element) throws Exception { if (element == null) return;/* ww w . j a v a 2s . com*/ appCacheData = new CacheConfigData(); appCacheData.setCacheEnumType(CacheScopeType.Application); appCacheData.setId("application"); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value != null && !"".equals(value)) appCacheData.setId(value); } else if ("strategy".equalsIgnoreCase(name)) { if ("Fifo".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.Fifo); } else if ("Lru".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.Lru); } else if ("SoftRef".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.SoftRef); } else if ("WeakRef".equalsIgnoreCase(value)) { appCacheData.setCacheStrategy(CacheControlStrategy.WeakRef); } } else if ("maxObject".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; appCacheData.setMaxObject(Integer.parseInt(value)); } else if ("eternal".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { appCacheData.setEternal(false); } else { appCacheData.setEternal(true); } } else if ("entirety".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { appCacheData.setEntirety(false); } else { appCacheData.setEntirety(true); } } else if ("idleTime".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; appCacheData.setIdleTime(Integer.parseInt(value) * 1000); } else if ("liveTime".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; appCacheData.setLiveTime(Integer.parseInt(value) * 1000); } else if ("copyStrategy".equalsIgnoreCase(name)) { value = value.toLowerCase(); if ("field".equalsIgnoreCase(value)) appCacheData.setCopyStrategyType(CopyStrategyType.Field); else if ("serial".equalsIgnoreCase(value)) appCacheData.setCopyStrategyType(CopyStrategyType.Serial); else if ("ref".equalsIgnoreCase(value)) appCacheData.setCopyStrategyType(CopyStrategyType.Ref); } } cacheMap.put(appCacheData.getId(), appCacheData); }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readThreadCacheConfig(Element element) throws Exception { if (element == null) { return;//from w w w . ja v a 2 s . com } threadCacheData = new CacheConfigData(); threadCacheData.setCacheEnumType(CacheScopeType.Thread); threadCacheData.setId("thread"); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value != null && !"".equals(value)) threadCacheData.setId(value); } else if ("strategy".equalsIgnoreCase(name)) { if ("Fifo".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.Fifo); } else if ("Lru".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.Lru); } else if ("SoftRef".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.SoftRef); } else if ("WeakRef".equalsIgnoreCase(value)) { threadCacheData.setCacheStrategy(CacheControlStrategy.WeakRef); } } else if ("maxObject".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; threadCacheData.setMaxObject(Integer.parseInt(value)); } else if ("entirety".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { threadCacheData.setEntirety(false); } else { threadCacheData.setEntirety(true); } } else if ("copyStrategy".equalsIgnoreCase(name)) { value = value.toLowerCase(); if ("field".equalsIgnoreCase(value)) { threadCacheData.setCopyStrategyType(CopyStrategyType.Field); } else if ("serial".equalsIgnoreCase(value)) { threadCacheData.setCopyStrategyType(CopyStrategyType.Serial); } else if ("ref".equalsIgnoreCase(value)) { threadCacheData.setCopyStrategyType(CopyStrategyType.Ref); } } } cacheMap.put(threadCacheData.getId(), threadCacheData); }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readSessionCacheConfig(Element element) throws Exception { if (element == null) return;//from w ww .j ava 2 s . co m sessionCacheData = new CacheConfigData(); sessionCacheData.setCacheEnumType(CacheScopeType.Session); sessionCacheData.setId("session"); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value != null && !"".equals(value)) sessionCacheData.setId(value); } else if ("strategy".equalsIgnoreCase(name)) { if ("Fifo".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.Fifo); } else if ("Lru".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.Lru); } else if ("SoftRef".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.SoftRef); } else if ("WeakRef".equalsIgnoreCase(value)) { sessionCacheData.setCacheStrategy(CacheControlStrategy.WeakRef); } } else if ("maxObject".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; sessionCacheData.setMaxObject(Integer.parseInt(value)); } else if ("entirety".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { sessionCacheData.setEntirety(false); } else { sessionCacheData.setEntirety(true); } } else if ("copyStrategy".equalsIgnoreCase(name)) { value = value.toLowerCase(); if ("field".equalsIgnoreCase(value)) sessionCacheData.setCopyStrategyType(CopyStrategyType.Field); else if ("serial".equalsIgnoreCase(value)) sessionCacheData.setCopyStrategyType(CopyStrategyType.Serial); else if ("ref".equalsIgnoreCase(value)) sessionCacheData.setCopyStrategyType(CopyStrategyType.Ref); } } cacheMap.put(sessionCacheData.getId(), sessionCacheData); }
From source file:darks.orm.core.config.CacheConfiguration.java
License:Apache License
public void readEHCacheConfig(Element element) throws Exception { if (element == null) return;/*from ww w . j av a 2 s . c o m*/ CacheConfigData ehCacheData = new CacheConfigData(); ehCacheData.setCacheEnumType(CacheScopeType.EHCache); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) throw new Exception("EHCache Config id is null"); ehCacheData.setId(value); } if ("name".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) throw new Exception("EHCache Config name is null"); ehCacheData.setId(value); } if ("configPath".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setEhcacheConfigPath(value); } else if ("maxElementsInMemory".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setMaxObject(Integer.parseInt(value)); } else if ("maxElementsOnDisk".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setMaxElementsOnDisk(Integer.parseInt(value)); } else if ("eternal".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { ehCacheData.setEternal(false); } else { ehCacheData.setEternal(true); } } else if ("timeToIdleSeconds".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setIdleTime(Integer.parseInt(value)); } else if ("timeToLiveSeconds".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setLiveTime(Integer.parseInt(value)); } else if ("overflowToDisk".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { ehCacheData.setOverflowToDisk(false); } else { ehCacheData.setOverflowToDisk(true); } } else if ("diskPersistent".equalsIgnoreCase(name)) { if ("false".equalsIgnoreCase(value)) { ehCacheData.setDiskPersistent(false); } else { ehCacheData.setDiskPersistent(true); } } else if ("diskExpiryThreadIntervalSeconds".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setDiskExpiryThreadIntervalSeconds(Integer.parseInt(value)); } else if ("memoryStoreEvictionPolicy".equalsIgnoreCase(name)) { if (value == null || "".equals(value)) continue; ehCacheData.setMemoryStoreEvictionPolicy(value); } } cacheMap.put(ehCacheData.getId(), ehCacheData); }