diff options
Diffstat (limited to 'src/com/memberwebs/ldapxml/LXReader.java')
-rw-r--r-- | src/com/memberwebs/ldapxml/LXReader.java | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/src/com/memberwebs/ldapxml/LXReader.java b/src/com/memberwebs/ldapxml/LXReader.java index be32632..2b205b1 100644 --- a/src/com/memberwebs/ldapxml/LXReader.java +++ b/src/com/memberwebs/ldapxml/LXReader.java @@ -1,16 +1,16 @@ package com.memberwebs.ldapxml; import java.util.Arrays; +import java.util.Collection; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; import java.util.Set; import java.util.Vector; import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.familymembers.util.StringUtil; -import com.familymembers.util.ldap.LDAPUtil; import com.memberwebs.ldapxml.helpers.LXAttribute; import com.memberwebs.ldapxml.helpers.LXBase; import com.memberwebs.ldapxml.helpers.LXClass; @@ -38,6 +38,8 @@ import com.novell.ldap.LDAPSearchResults; */ public class LXReader { + private static final String CLASS = "objectClass"; + /** * Creates a new LXReader object. */ @@ -298,7 +300,7 @@ public class LXReader * Transform an already retrieved LDAP entry. * * @param doc The document from which to create elements. - * @entry The LDAP entry. + * @param The LDAP entry. * @return The DOM element or null if not found in map. */ public Element retrieveEntry(Document doc, LDAPEntry entry) @@ -327,7 +329,7 @@ public class LXReader // Get all the classes we use them to determine a number // of things - LDAPAttribute objectClasses = entry.getAttribute(LDAPUtil.CLASS); + LDAPAttribute objectClasses = entry.getAttribute(CLASS); if(objectClasses == null) return null; @@ -355,7 +357,7 @@ public class LXReader if(!hook.prefix(entry)) return null; - objectClasses = entry.getAttribute(LDAPUtil.CLASS); + objectClasses = entry.getAttribute(CLASS); classes = objectClasses.getStringValueArray(); // Create the entry element @@ -408,7 +410,7 @@ public class LXReader while(e.hasMoreElements()) attrs.add(e.nextElement()); - retrieveAttributes(StringUtil.toStringArray(attrs), + retrieveAttributes(toStringArray(attrs), clsEl, entry, lxclass, specs); } } @@ -447,7 +449,7 @@ public class LXReader // Retrieve the attribute based on language LDAPAttribute ldapattr = - LDAPUtil.getAttributeForLang(entry, attributes[i], language); + getAttributeForLang(entry, attributes[i], language); // Each one can have multiple values LXAttribute lxattr = lxcls.getAttribute(attributes[i]); @@ -693,7 +695,7 @@ public class LXReader names.addAll(Arrays.asList(sort)); if(names != null) - names.add(LDAPUtil.CLASS); + names.add(CLASS); if(names == null) { @@ -704,10 +706,48 @@ public class LXReader else { names.add("+"); - return StringUtil.toStringArray(names); + return toStringArray(names); } } + /** + * The language functionality in the Novell LDAP classes doesn't + * work as advertised. So this is a work around. + * + * @param entry The LDAP entry to retrieve the attribute from. + * @param attr The attribute name. + * @param language The language of the attribute. + */ + private static LDAPAttribute getAttributeForLang(LDAPEntry entry, + String attr, String language) + { + // Retrieve the attribute based on language + if(language == null) + return entry.getAttribute(attr); + else + { + LDAPAttribute ldapattr; + + if((ldapattr = entry.getAttribute(attr + ";" + language)) == null) + ldapattr = entry.getAttribute(attr); + + return ldapattr; + } + } + + protected static String[] toStringArray(Collection c) + { + String[] a = new String[c.size()]; + + int j = 0; + Iterator i = c.iterator(); + + while(i.hasNext()) + a[j++] = i.next().toString(); + + return a; + } + // The LDAP connection we're using private LDAPConnection m_connection; |