use of com.zimbra.common.soap.Element.KeyValuePair in project zm-mailbox by Zimbra.
the class ZGetInfoResult method getMap.
static Map<String, List<String>> getMap(Element e, String root, String elName) {
Map<String, List<String>> result = new HashMap<String, List<String>>();
Element attrsEl = e.getOptionalElement(root);
if (attrsEl != null) {
for (KeyValuePair pair : attrsEl.listKeyValuePairs(elName, AccountConstants.A_NAME)) {
//StringUtil.addToMultiMap(mAttrs, pair.getKey(), pair.getValue());
String name = pair.getKey();
List<String> list = result.get(name);
if (list == null) {
list = new ArrayList<String>();
result.put(name, list);
}
list.add(pair.getValue());
}
}
return result;
}
use of com.zimbra.common.soap.Element.KeyValuePair in project zm-mailbox by Zimbra.
the class GetAllConfigTest method unmarshallGetAllConfigResponseTest.
@Test
public void unmarshallGetAllConfigResponseTest() throws Exception {
InputStream is = getClass().getResourceAsStream("GetAllConfigResponse.xml");
Element elem = Element.parseXML(is);
List<KeyValuePair> kvps = elem.listKeyValuePairs();
is.close();
is = getClass().getResourceAsStream("GetAllConfigResponse.xml");
GetAllConfigResponse resp = (GetAllConfigResponse) unmarshaller.unmarshal(is);
Assert.assertNotNull("Response", resp);
List<Attr> attrs = resp.getAttrs();
LOG.info("unmarshallGetAllConfigResponseTest:KVPS from elem=" + kvps.size() + " from jaxb=" + attrs.size());
Assert.assertTrue("Have some attrs", attrs.size() > 20);
Assert.assertEquals("Number of attrs from elem and from jaxb agree", kvps.size(), attrs.size());
}
use of com.zimbra.common.soap.Element.KeyValuePair in project zm-mailbox by Zimbra.
the class AccountService method getAttrs.
/**
* @param request
* @return
* @throws ServiceException
*/
public static Map<String, Object> getAttrs(Element request, boolean ignoreEmptyValues, String nameAttr) throws ServiceException {
Map<String, Object> result = new HashMap<String, Object>();
for (KeyValuePair pair : request.listKeyValuePairs(AdminConstants.E_A, nameAttr)) {
String name = pair.getKey();
String value = pair.getValue();
if (!ignoreEmptyValues || (value != null && value.length() > 0))
StringUtil.addToMultiMap(result, name, value);
}
return result;
}
use of com.zimbra.common.soap.Element.KeyValuePair in project zm-mailbox by Zimbra.
the class ModifyPrefs method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
HashMap<String, Object> prefs = new HashMap<String, Object>();
Map<String, Set<String>> name2uniqueAttrValues = new HashMap<String, Set<String>>();
for (KeyValuePair kvp : request.listKeyValuePairs(AccountConstants.E_PREF, AccountConstants.A_NAME)) {
String name = kvp.getKey(), value = kvp.getValue();
char ch = name.length() > 0 ? name.charAt(0) : 0;
int offset = ch == '+' || ch == '-' ? 1 : 0;
if (!name.startsWith(PREF_PREFIX, offset))
throw ServiceException.INVALID_REQUEST("pref name must start with " + PREF_PREFIX, null);
AttributeInfo attrInfo = AttributeManager.getInstance().getAttributeInfo(name.substring(offset));
if (attrInfo == null) {
throw ServiceException.INVALID_REQUEST("no such attribute: " + name, null);
}
if (attrInfo.isCaseInsensitive()) {
String valueLowerCase = Strings.nullToEmpty(value).toLowerCase();
if (name2uniqueAttrValues.get(name) == null) {
Set<String> set = new HashSet<String>();
set.add(valueLowerCase);
name2uniqueAttrValues.put(name, set);
StringUtil.addToMultiMap(prefs, name, value);
} else {
Set<String> set = name2uniqueAttrValues.get(name);
if (set.add(valueLowerCase)) {
StringUtil.addToMultiMap(prefs, name, value);
}
}
} else {
StringUtil.addToMultiMap(prefs, name, value);
}
}
if (prefs.containsKey(Provisioning.A_zimbraPrefMailForwardingAddress)) {
if (!account.getBooleanAttr(Provisioning.A_zimbraFeatureMailForwardingEnabled, false))
throw ServiceException.PERM_DENIED("forwarding not enabled");
}
// call modifyAttrs and pass true to checkImmutable
Provisioning.getInstance().modifyAttrs(account, prefs, true, zsc.getAuthToken());
Element response = zsc.createElement(AccountConstants.MODIFY_PREFS_RESPONSE);
return response;
}
use of com.zimbra.common.soap.Element.KeyValuePair in project zm-mailbox by Zimbra.
the class ToXML method encodeAttr.
public static void encodeAttr(Element parent, String key, String value, String eltname, String attrname, IDNType idnType, boolean allowed) {
KeyValuePair kvPair;
if (allowed) {
kvPair = parent.addKeyValuePair(key, IDNUtil.toUnicode(value, idnType), eltname, attrname);
} else {
kvPair = parent.addKeyValuePair(key, "", eltname, attrname);
kvPair.addAttribute(AccountConstants.A_PERM_DENIED, true);
}
}
Aggregations