diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/memberwebs/ldapxml/LXException.java | 68 | ||||
-rw-r--r-- | src/com/memberwebs/ldapxml/LXHook.java | 5 | ||||
-rw-r--r-- | src/com/memberwebs/ldapxml/LXReader.java | 58 | ||||
-rw-r--r-- | src/com/memberwebs/ldapxml/LXSpecs.java | 78 |
4 files changed, 188 insertions, 21 deletions
diff --git a/src/com/memberwebs/ldapxml/LXException.java b/src/com/memberwebs/ldapxml/LXException.java index 242e081..e7a14f6 100644 --- a/src/com/memberwebs/ldapxml/LXException.java +++ b/src/com/memberwebs/ldapxml/LXException.java @@ -1,7 +1,5 @@ package com.memberwebs.ldapxml; -import com.familymembers.util.*; - /** * Thrown when an error occurs during LX retrieval or * processing. @@ -10,7 +8,7 @@ import com.familymembers.util.*; * @version 1.0 */ public class LXException - extends WrappedException + extends Exception { /** * Creates a new LXException object. @@ -31,4 +29,68 @@ public class LXException { super(null, e); } + + /** + * Creates a new WrappedException with a message and an + * exception exception held internally. + * + * @param message The message to include. + * @param e The internal exception. + */ + public LXException(String message, Exception e) + { + super(message); + if(e != null) + m_exception = e; + } + + /** + * Returns the error message of this exception if present, or + * the internal exception. + * + * @return The message. + */ + public String getMessage() + { + String message = super.getMessage(); + + if(message == null && m_exception != null) + message = m_exception.getMessage(); + + return message; + } + + /** + * Returns the internal exception, or this if not present. + * + * @return The exception. + */ + public Exception getException() + { + if(m_exception == null) + return this; + else + return m_exception; + } + + /** + * Converts this object to a string. + * + * @return The string value. + */ + public String toString () + { + if(m_exception != null) + return m_exception.toString(); + else + return super.toString(); + } + + public StackTraceElement[] getStackTrace() + { + return getStackTrace(); + } + + // The internal exception + private Exception m_exception; }
\ No newline at end of file diff --git a/src/com/memberwebs/ldapxml/LXHook.java b/src/com/memberwebs/ldapxml/LXHook.java index eac7a6c..2c8cff7 100644 --- a/src/com/memberwebs/ldapxml/LXHook.java +++ b/src/com/memberwebs/ldapxml/LXHook.java @@ -1,7 +1,8 @@ package com.memberwebs.ldapxml; -import com.novell.ldap.*; -import org.w3c.dom.*; +import org.w3c.dom.Element; + +import com.novell.ldap.LDAPEntry; /** * Interface for hooking into LX processing. 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; diff --git a/src/com/memberwebs/ldapxml/LXSpecs.java b/src/com/memberwebs/ldapxml/LXSpecs.java index ed342ea..95768a4 100644 --- a/src/com/memberwebs/ldapxml/LXSpecs.java +++ b/src/com/memberwebs/ldapxml/LXSpecs.java @@ -2,8 +2,6 @@ package com.memberwebs.ldapxml; import java.util.Map; -import com.familymembers.util.ldap.LDAPUtil; - /** * Additional specifications for retrieving data from an * LDAP directory. @@ -30,13 +28,14 @@ public class LXSpecs private static final String LANG = "lang-"; + private static final String FILTER_ALL = "(objectClass=*)"; /** * Construct a new LXSpecs object. */ public LXSpecs() { - m_filter = LDAPUtil.FILTER_ALL; + m_filter = FILTER_ALL; m_depth = DEPTH_BASE; m_sort = null; m_data = null; @@ -117,7 +116,7 @@ public class LXSpecs */ public final String getFilter() { - return m_filter == null ? LDAPUtil.FILTER_ALL : m_filter; + return m_filter == null ? FILTER_ALL : m_filter; } /** @@ -129,8 +128,8 @@ public class LXSpecs */ public final String getFilter(String prevFilter) { - String filter = LDAPUtil.combineFilters(m_filter, prevFilter); - return filter == null ? LDAPUtil.FILTER_ALL : filter; + String filter = combineFilters(m_filter, prevFilter); + return filter == null ? FILTER_ALL : filter; } /** @@ -140,7 +139,7 @@ public class LXSpecs */ public final void setFilter(String filter) { - m_filter = LDAPUtil.combineFilters(filter, null); + m_filter = combineFilters(filter, null); } /** @@ -231,6 +230,71 @@ public class LXSpecs return m_mappedSort; } + /** + * Combine two LDAP filters in an AND operation. + * + * @param filter1 The first filter to combine. + * @param filter2 The second filter. + * @return The combined filter. + */ + protected static String combineFilters(String filter1, String filter2) + { + return combineFilters(filter1, filter2, '&'); + } + + /** + * Combine two LDAP filters in a boolean operation. + * + * @param filter1 The first filter to combine. + * @param filter2 The second filter. + * @param op The boolean operation (ie: '&' or '|' etc...) + * @return The combined filter. + */ + protected static String combineFilters(String filter1, String filter2, char op) + { + String filter = null; + + filter1 = cleanFilter(filter1); + filter2 = cleanFilter(filter2); + + if(filter1 != null) + filter = filter1; + + if(filter2 != null) + { + if(filter == null) + filter = filter2; + else + filter = "(" + op + filter + filter2 + ")"; + } + + return filter; + } + + /** + * Clean up an LDAP filter, substituting null for an empty, + * or all encompasing filter. Also wraps filters in parens + * as need. + * + * @param filter The filter to check. + * @return The new filter or null. + */ + protected static String cleanFilter(String filter) + { + if(filter != null) + { + if(!filter.startsWith("(")) + filter = "(" + filter + ")"; + + if(filter.equals("")) + filter = null; + else if(filter.equals(FILTER_ALL)) + filter = null; + } + + return filter; + } + // The additional filter private String m_filter; |