use of com.zimbra.cs.account.AttributeManager.IDNType in project zm-mailbox by Zimbra.
the class Entry method toUnicode.
/*
* convert attr values to unicode and put back the converted value to the same attr map
* We are modifying a copy of the map created in getAttrs, not the
* mAttrs/mDefaults/mSecondaryDefaults data member
*/
private Map<String, Object> toUnicode(Map<String, Object> attrs) {
AttributeManager attrMgr = getAttributeManager();
Set<String> keySet = new HashSet<String>(attrs.keySet());
for (String key : keySet) {
IDNType idnType = AttributeManager.idnType(attrMgr, key);
if (idnType.isEmailOrIDN()) {
Object value = attrs.get(key);
if (value instanceof String[]) {
String[] sv = (String[]) value;
for (int i = 0; i < sv.length; i++) {
sv[i] = IDNUtil.toUnicode(sv[i], idnType);
}
} else if (value instanceof String) {
attrs.put(key, IDNUtil.toUnicode((String) value, idnType));
}
}
}
return attrs;
}
use of com.zimbra.cs.account.AttributeManager.IDNType in project zm-mailbox by Zimbra.
the class IDNCallback method preModify.
@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
MultiValueMod mod = multiValueMod(attrsToModify, attrName);
IDNType idnType = AttributeManager.idnType(AttributeManager.getInstance(), attrName);
if (mod.adding() || mod.replacing()) {
Set<String> asciiValues = new HashSet<String>();
List<String> addrs = mod.values();
for (String addr : addrs) {
if (addr == null || addr.equals(""))
continue;
String asciiName;
if (addr.charAt(0) == '@') {
// meant for catchall addresses
asciiName = "@" + IDNUtil.toAsciiDomainName(addr.substring(1));
} else {
asciiName = IDNUtil.toAscii(addr, idnType);
}
asciiValues.add(asciiName);
}
String aName = (mod.adding() ? "+" : "") + attrName;
attrsToModify.remove(aName);
attrsToModify.put(aName, asciiValues.toArray(new String[asciiValues.size()]));
}
}
use of com.zimbra.cs.account.AttributeManager.IDNType in project zm-mailbox by Zimbra.
the class ToXML method encodeAttrs.
public static void encodeAttrs(Element e, Map attrs, String key, Set<String> reqAttrs, Set<String> hideAttrs, AttrRightChecker attrRightChecker) {
AttributeManager attrMgr = null;
try {
attrMgr = AttributeManager.getInstance();
} catch (ServiceException se) {
ZimbraLog.account.warn("failed to get AttributeManager instance", se);
}
Set<String> reqAttrsLowerCase = null;
if (reqAttrs != null) {
reqAttrsLowerCase = new HashSet<String>();
for (String reqAttr : reqAttrs) {
reqAttrsLowerCase.add(reqAttr.toLowerCase());
}
}
for (Iterator iter = attrs.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Entry) iter.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
// Never return data source passwords
if (name.equalsIgnoreCase(Provisioning.A_zimbraDataSourcePassword)) {
continue;
}
value = Provisioning.sanitizedAttrValue(name, value);
// only returns requested attrs
if (reqAttrsLowerCase != null && !reqAttrsLowerCase.contains(name.toLowerCase())) {
continue;
}
// do not return attrs hidden by protocol
if (hideAttrs != null && hideAttrs.contains(name)) {
continue;
}
boolean allowed = attrRightChecker == null ? true : attrRightChecker.allowAttr(name);
IDNType idnType = AttributeManager.idnType(attrMgr, name);
if (value instanceof String[]) {
String[] sv = (String[]) value;
for (int i = 0; i < sv.length; i++) {
encodeAttr(e, name, sv[i], AdminConstants.E_A, key, idnType, allowed);
}
} else if (value instanceof String) {
value = com.zimbra.cs.service.account.ToXML.fixupZimbraPrefTimeZoneId(name, (String) value);
encodeAttr(e, name, (String) value, AdminConstants.E_A, key, idnType, allowed);
}
}
}
use of com.zimbra.cs.account.AttributeManager.IDNType in project zm-mailbox by Zimbra.
the class Entry method getUnicodeMultiAttr.
/**
* Returns the set of values for the given attribute, or an empty
* array if no values are defined.
*/
public String[] getUnicodeMultiAttr(String name) {
String[] values = getMultiAttr(name, true);
AttributeManager attrMgr = getAttributeManager();
IDNType idnType = AttributeManager.idnType(attrMgr, name);
if (idnType.isEmailOrIDN() && values != null) {
String[] unicodeValues = new String[values.length];
for (int i = 0; i < values.length; i++) unicodeValues[i] = IDNUtil.toUnicode(values[i], idnType);
return unicodeValues;
} else
return values;
}
use of com.zimbra.cs.account.AttributeManager.IDNType in project zm-mailbox by Zimbra.
the class LdapGalMapRule method apply.
void apply(IAttributes ldapAttrs, Map<String, Object> contactAttrs) {
AttributeManager attrMgr = AttributeManager.getInst();
// index into mContactAttrs
int index = 0;
for (String ldapAttr : mLdapAttrs) {
if (index >= mContactAttrs.length)
return;
String[] val;
try {
val = ldapAttrs.getMultiAttrString(ldapAttr, containsBinaryData(), isBinaryTransfer());
} catch (ServiceException e) {
return;
}
IDNType idnType = AttributeManager.idnType(attrMgr, ldapAttr);
if (val.length == 1) {
index = addToContactAttrs(contactAttrs, IDNUtil.toUnicode(val[0], idnType), index);
} else if (val.length > 1) {
if (mContactAttrs.length == 1) {
index = addToContactAttrs(contactAttrs, val, index);
return;
} else {
for (int i = 0; i < val.length; i++) {
if (index >= mContactAttrs.length)
return;
index = addToContactAttrs(contactAttrs, IDNUtil.toUnicode(val[i], idnType), index);
}
}
}
}
}
Aggregations