List of usage examples for org.dom4j Element getText
String getText();
From source file:com.zimbra.common.soap.SoapTestHarness.java
License:Open Source License
private void doSelect(Element context, Element parent) throws SoapFaultException, IOException, HarnessException { String path = parent.getAttribute(A_PATH, null); String attr = parent.getAttribute(A_ATTR, null); String match = parent.getAttribute(A_MATCH, null); Element se; if (path != null) { // FIXME: hacky! org.dom4j.Element d4context = context.toXML(); org.dom4j.XPath xpath = d4context.createXPath(path); xpath.setNamespaceURIs(getURIs(mResponseProto)); org.dom4j.Node node = xpath.selectSingleNode(d4context); //System.out.println("path = " + path + " node = " + node); if (!(node instanceof org.dom4j.Element)) { mCurrent.check(false, "select failed: " + path); return; } else {/*from ww w .j a v a 2 s .c o m*/ se = Element.convertDOM((org.dom4j.Element) node); mCurrent.check(true, "select ok: " + path); } } else { se = context; } String value; if (attr != null) { value = se.getAttribute(attr, null); } else { value = se.getText(); } if (match != null) { boolean ok = Pattern.matches(match, value); mCurrent.check(ok, "match " + (ok ? "ok" : "failed") + " (" + match + ")" + " (" + value + ")"); } //System.out.println(se.getText()); String property = parent.getAttribute(A_SET, null); if (property != null) { //System.out.println(property+" "+value); setProperty(property, value); } for (Element e : parent.listElements()) { if (e.getQName().equals(E_SELECT)) { doSelect(se, e); } else { checkGlobals(e); } } }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
License:Open Source License
private void parseDesc(Element eDesc, Right right) throws ServiceException { if (right.getDesc() != null) throw ServiceException.PARSE_ERROR("multiple " + E_DESC, null); right.setDesc(eDesc.getText()); }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
License:Open Source License
private void parseDefault(Element eDefault, Right right) throws ServiceException { String defaultValue = eDefault.getText(); if ("allow".equalsIgnoreCase(defaultValue)) right.setDefault(Boolean.TRUE); else if ("deny".equalsIgnoreCase(defaultValue)) right.setDefault(Boolean.FALSE); else//from ww w .j a va2s.com throw ServiceException.PARSE_ERROR("invalid default value: " + defaultValue, null); }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
License:Open Source License
private void loadHelp(Element eHelp, File file) throws ServiceException { String name = eHelp.attributeValue(A_NAME); if (name == null) { throw ServiceException.PARSE_ERROR("no name specified", null); }/* w ww . j a va2 s .co m*/ checkName(name); Help help = new Help(name); for (Iterator elemIter = eHelp.elementIterator(); elemIter.hasNext();) { Element elem = (Element) elemIter.next(); if (elem.getName().equals(E_DESC)) { if (help.getDesc() != null) { throw ServiceException.PARSE_ERROR("desc for help " + name + " already set", null); } help.setDesc(elem.getText()); } else if (elem.getName().equals(E_ITEM)) { help.addItem(elem.getText()); } else { throw ServiceException.PARSE_ERROR("invalid element: " + elem.getName(), null); } } // make all required bits are set in the help help.validate(); sHelp.put(name, help); }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
License:Open Source License
private void loadUI(Element eUI, File file) throws ServiceException { String name = eUI.attributeValue(A_NAME); if (name == null) { throw ServiceException.PARSE_ERROR("no name specified", null); }/* www .ja v a 2 s. c o m*/ checkName(name); UI ui = new UI(name); String desc = eUI.getText(); ui.setDesc(desc); // make all required bits are set in the ui ui.validate(); sUI.put(name, ui); }
From source file:com.zimbra.cs.account.AttributeManager.java
License:Open Source License
private void loadAttrs(File file, Document doc) { Element root = doc.getRootElement(); if (!root.getName().equals(E_ATTRS)) { error(null, file, "root tag is not " + E_ATTRS); return;//from www . j a va 2s . c o m } Map<Integer, String> idsSeen = new HashMap<Integer, String>(); 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 == 2) { error(null, file, A_GROUP_ID + " is not valid (used by ZimbraObjectClass)"); } else if (groupId > 0) { if (mGroupMap.containsKey(groupId)) { error(null, file, "duplicate group id: " + groupId); } else if (mGroupMap.containsValue(group)) { error(null, file, "duplicate group: " + group); } else { mGroupMap.put(groupId, group); } } NEXT_ATTR: for (Iterator iter = root.elementIterator(); iter.hasNext();) { Element eattr = (Element) iter.next(); if (!eattr.getName().equals(E_ATTR)) { error(null, file, "unknown element: " + eattr.getName()); continue; } AttributeCallback callback = null; AttributeType type = null; AttributeOrder order = null; String value = null; String min = null; String max = null; boolean immutable = false; // boolean ignore = false; int id = -1; String parentOid = null; AttributeCardinality cardinality = null; Set<AttributeClass> requiredIn = null; Set<AttributeClass> optionalIn = null; Set<AttributeFlag> flags = null; String canonicalName = null; String name = eattr.attributeValue(A_NAME); if (name == null) { error(null, file, "no name specified"); continue; } canonicalName = name.toLowerCase(); List<AttributeServerType> requiresRestart = null; Version deprecatedSinceVer = null; List<Version> sinceVer = null; Boolean ephemeral = false; 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_CALLBACK)) { callback = loadCallback(attr.getValue()); } else if (aname.equals(A_IMMUTABLE)) { immutable = "1".equals(attr.getValue()); } else if (aname.equals(A_MAX)) { max = attr.getValue(); } else if (aname.equals(A_MIN)) { min = attr.getValue(); } else if (aname.equals(A_TYPE)) { type = AttributeType.getType(attr.getValue()); if (type == null) { error(name, file, "unknown <attr> type: " + attr.getValue()); continue NEXT_ATTR; } } else if (aname.equals(A_VALUE)) { value = attr.getValue(); } else if (aname.equals(A_PARENT_OID)) { parentOid = attr.getValue(); if (!parentOid.matches("^\\d+(\\.\\d+)+")) error(name, file, "invalid parent OID " + parentOid + ": must be an OID"); } 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 if (aname.equals(A_CARDINALITY)) { try { cardinality = AttributeCardinality.valueOf(attr.getValue()); } catch (IllegalArgumentException iae) { error(name, file, aname + " is not valid: " + attr.getValue()); } } else if (aname.equals(A_REQUIRED_IN)) { requiredIn = parseClasses(name, file, attr.getValue()); } else if (aname.equals(A_OPTIONAL_IN)) { optionalIn = parseClasses(name, file, attr.getValue()); } else if (aname.equals(A_FLAGS)) { flags = parseFlags(name, file, attr.getValue()); } else if (aname.equals(A_ORDER)) { try { order = AttributeOrder.valueOf(attr.getValue()); } catch (IllegalArgumentException iae) { error(name, file, aname + " is not valid: " + attr.getValue()); } } else if (aname.equals(A_REQUIRES_RESTART)) { requiresRestart = parseRequiresRestart(name, file, attr.getValue()); } else if (aname.equals(A_DEPRECATED_SINCE)) { String depreSince = attr.getValue(); if (depreSince != null) { try { deprecatedSinceVer = new Version(depreSince); } catch (ServiceException e) { error(name, file, aname + " is not valid: " + attr.getValue() + " (" + e.getMessage() + ")"); } } } else if (aname.equals(A_SINCE)) { String since = attr.getValue(); if (since != null) { try { String[] versions = since.split(","); sinceVer = new ArrayList<Version>(); for (String verStr : versions) { sinceVer.add(new Version(verStr.trim())); } } catch (ServiceException e) { error(name, file, aname + " is not valid: " + attr.getValue() + " (" + e.getMessage() + ")"); } } } else { error(name, file, "unknown <attr> attr: " + aname); } } List<String> globalConfigValues = new LinkedList<String>(); List<String> globalConfigValuesUpgrade = null; // note: init to null instead of empty List List<String> defaultCOSValues = new LinkedList<String>(); List<String> defaultExternalCOSValues = new LinkedList<String>(); List<String> defaultCOSValuesUpgrade = null; // note: init to null instead of empty List String description = null; String deprecateDesc = null; for (Iterator elemIter = eattr.elementIterator(); elemIter.hasNext();) { Element elem = (Element) elemIter.next(); if (elem.getName().equals(E_GLOBAL_CONFIG_VALUE)) { globalConfigValues.add(elem.getText()); } else if (elem.getName().equals(E_GLOBAL_CONFIG_VALUE_UPGRADE)) { if (globalConfigValuesUpgrade == null) globalConfigValuesUpgrade = new LinkedList<String>(); globalConfigValuesUpgrade.add(elem.getText()); } else if (elem.getName().equals(E_DEFAULT_COS_VALUE)) { defaultCOSValues.add(elem.getText()); } else if (elem.getName().equals(E_DEFAULT_EXTERNAL_COS_VALUE)) { defaultExternalCOSValues.add(elem.getText()); } else if (elem.getName().equals(E_DEFAULT_COS_VALUE_UPGRADE)) { if (defaultCOSValuesUpgrade == null) defaultCOSValuesUpgrade = new LinkedList<String>(); defaultCOSValuesUpgrade.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_DEPRECATE_DESC)) { if (deprecateDesc != null) { error(name, file, "more than one " + E_DEPRECATE_DESC); } deprecateDesc = elem.getText(); } else { error(name, file, "unknown element: " + elem.getName()); } } if (deprecatedSinceVer != null && deprecateDesc == null) error(name, file, "missing element " + E_DEPRECATE_DESC); else if (deprecatedSinceVer == null && deprecateDesc != null) error(name, file, "missing attr " + A_DEPRECATED_SINCE); if (deprecatedSinceVer != null) { String deprecateInfo = "Deprecated since: " + deprecatedSinceVer.toString() + ". " + deprecateDesc; if (description == null) description = deprecateInfo; else description = deprecateInfo + ". Orig desc: " + description; } // since is required after(inclusive) oid 525 - first attribute in 5.0 if (sinceVer == null && id >= 525) { error(name, file, "missing since (required after(inclusive) oid 710)"); } // Check that if id is specified, then cardinality is specified. if (id > 0 && cardinality == null) { error(name, file, "cardinality not specified"); } // Check that if id is specified, then at least one object class is defined if (id > 0 && (optionalIn != null && optionalIn.isEmpty()) && (requiredIn != null && requiredIn.isEmpty())) { error(name, file, "atleast one of " + A_REQUIRED_IN + " or " + A_OPTIONAL_IN + " must be specified"); } // Check that if id is specified, it must be unique if (id > 0) { String idForAttr = idsSeen.get(Integer.valueOf(id)); if (idForAttr != null) { error(name, file, "duplicate id: " + id + " is already used for " + idForAttr); } else { idsSeen.put(Integer.valueOf(id), name); } } // Check that if it is COS inheritable it is in account and COS classes checkFlag(name, file, flags, AttributeFlag.accountInherited, AttributeClass.account, AttributeClass.cos, null, requiredIn, optionalIn); // Check that if it is COS-domain inheritable it is in account and COS and domain classes checkFlag(name, file, flags, AttributeFlag.accountCosDomainInherited, AttributeClass.account, AttributeClass.cos, AttributeClass.domain, requiredIn, optionalIn); // Check that if it is domain inheritable it is in domain and global config checkFlag(name, file, flags, AttributeFlag.domainInherited, AttributeClass.domain, AttributeClass.globalConfig, null, requiredIn, optionalIn); // Check that if it is server inheritable it is in server and global config checkFlag(name, file, flags, AttributeFlag.serverInherited, AttributeClass.server, AttributeClass.globalConfig, null, requiredIn, optionalIn); // Check that if it is serverPreferAlwaysOn it is in server and alwaysOnCluster checkFlag(name, file, flags, AttributeFlag.serverPreferAlwaysOn, AttributeClass.server, AttributeClass.alwaysOnCluster, null, requiredIn, optionalIn); // Check that is cardinality is single, then not more than one // default value is specified if (cardinality == AttributeCardinality.single) { if (globalConfigValues.size() > 1) { error(name, file, "more than one global config value specified for cardinality " + AttributeCardinality.single); } if (defaultCOSValues.size() > 1 || defaultExternalCOSValues.size() > 1) { error(name, file, "more than one default COS value specified for cardinality " + AttributeCardinality.single); } } checkEphemeralFlags(name, file, flags, min, max, cardinality); AttributeInfo info = createAttributeInfo(name, id, parentOid, groupId, callback, type, order, value, immutable, min, max, cardinality, requiredIn, optionalIn, flags, globalConfigValues, defaultCOSValues, defaultExternalCOSValues, globalConfigValuesUpgrade, defaultCOSValuesUpgrade, mMinimize ? null : description, requiresRestart, sinceVer, deprecatedSinceVer); if (mAttrs.get(canonicalName) != null) { error(name, file, "duplicate definiton"); } mAttrs.put(canonicalName, info); if (flags != null) { for (AttributeFlag flag : flags) { mFlagToAttrsMap.get(flag).add(name); if (flag == AttributeFlag.accountCosDomainInherited) mFlagToAttrsMap.get(AttributeFlag.accountInherited).add(name); } } if (requiredIn != null || optionalIn != null) { if (requiredIn != null) { for (AttributeClass klass : requiredIn) { mClassToAttrsMap.get(klass).add(name); mClassToLowerCaseAttrsMap.get(klass).add(name.toLowerCase()); } } if (optionalIn != null) { for (AttributeClass klass : optionalIn) { mClassToAttrsMap.get(klass).add(name); mClassToLowerCaseAttrsMap.get(klass).add(name.toLowerCase()); } } } if (isBinaryType(type)) { mBinaryAttrs.add(canonicalName); } else if (isBinaryTransferType(type)) { mBinaryTransferAttrs.add(canonicalName); } if (flags != null && flags.contains(AttributeFlag.ephemeral)) { mEphemeralAttrs.put(canonicalName, info); mEphemeralAttrsSet.add(name); if (!info.isDynamic()) { addNonDynamicEphemeralAttr(info); } } } }
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 www. ja v a2 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.client.soap.LmcBrowseRequest.java
License:Open Source License
protected LmcBrowseData parseBrowseData(Element bdElem) { LmcBrowseData bd = new LmcBrowseData(); bd.setFlags(bdElem.attributeValue(MailConstants.A_BROWSE_DOMAIN_HEADER)); bd.setData(bdElem.getText()); return bd;/* w w w. j a v a 2s .c o m*/ }
From source file:com.zimbra.cs.client.soap.LmcGetInfoRequest.java
License:Open Source License
protected LmcSoapResponse parseResponseXML(Element responseXML) throws ServiceException { HashMap prefMap = new HashMap(); LmcGetInfoResponse response = new LmcGetInfoResponse(); // iterate over all the elements we received for (Iterator it = responseXML.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); if (elementType.equals(AccountConstants.E_NAME)) { response.setAcctName(e.getText()); } else if (elementType.equals(AccountConstants.E_LIFETIME)) { response.setLifetime(e.getText()); } else if (elementType.equals(AccountConstants.E_PREF)) { // add this preference to our map addPrefToMultiMap(prefMap, e); }//from ww w . j a va 2s .com } if (!prefMap.isEmpty()) response.setPrefMap(prefMap); return response; }
From source file:com.zimbra.cs.client.soap.LmcSoapRequest.java
License:Open Source License
protected LmcConversation parseConversation(Element conv) throws LmcSoapClientException, ServiceException { LmcConversation result = new LmcConversation(); // get the conversation attributes result.setID(conv.attributeValue(MailConstants.A_ID)); result.setTags(conv.attributeValue(MailConstants.A_TAGS)); String numMsgs = conv.attributeValue(MailConstants.A_NUM); if (numMsgs != null) result.setNumMessages(Integer.parseInt(numMsgs)); result.setDate(conv.attributeValue(MailConstants.A_DATE)); result.setFlags(conv.attributeValue(MailConstants.A_FLAGS)); result.setFolder(conv.attributeValue(MailConstants.A_FOLDER)); /*/*from ww w .ja va 2s . c o m*/ * iterate over subelements. allowed subelements are e-mail addresses, * subject, fragment, and messages. this assumes no particular order is * required for correctness. */ ArrayList emailAddrs = new ArrayList(); ArrayList msgs = new ArrayList(); for (Iterator it = conv.elementIterator(); it.hasNext();) { Element e = (Element) it.next(); // find out what element it is and go process that String elementType = e.getQName().getName(); if (elementType.equals(MailConstants.E_FRAG)) { // fragment result.setFragment(e.getText()); } else if (elementType.equals(MailConstants.E_EMAIL)) { // e-mail address LmcEmailAddress ea = parseEmailAddress(e); emailAddrs.add(ea); } else if (elementType.equals(MailConstants.E_SUBJECT)) { // subject result.setSubject(e.getText()); } else if (elementType.equals(MailConstants.E_MSG)) { // message LmcMessage m = parseMessage(e); msgs.add(m); } else { // don't know what it is throw new LmcSoapClientException("unknown element " + elementType + " within conversation"); } } // set the arrays in the result object if (!emailAddrs.isEmpty()) { LmcEmailAddress a[] = new LmcEmailAddress[emailAddrs.size()]; result.setParticipants((LmcEmailAddress[]) emailAddrs.toArray(a)); } if (!msgs.isEmpty()) { LmcMessage m[] = new LmcMessage[msgs.size()]; result.setMessages((LmcMessage[]) msgs.toArray(m)); } return result; }