summaryrefslogtreecommitdiff
path: root/src/com/memberwebs
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/memberwebs')
-rw-r--r--src/com/memberwebs/ldapxml/LXReader.java154
-rw-r--r--src/com/memberwebs/ldapxml/LXResults.java10
2 files changed, 92 insertions, 72 deletions
diff --git a/src/com/memberwebs/ldapxml/LXReader.java b/src/com/memberwebs/ldapxml/LXReader.java
index 50fa0a2..3e525f1 100644
--- a/src/com/memberwebs/ldapxml/LXReader.java
+++ b/src/com/memberwebs/ldapxml/LXReader.java
@@ -38,11 +38,14 @@
package com.memberwebs.ldapxml;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import java.util.Vector;
@@ -202,73 +205,62 @@ public class LXReader
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setMaxResults(0);
- // If no sort then we can have the server limit stuff
- // To get some added efficiency
- if(sort == null)
- cons.setMaxResults(last + 1);
-
- int scope = LDAPConnection.SCOPE_SUB;
- switch(specs.getDepth())
- {
- case 0:
- scope = LDAPConnection.SCOPE_BASE;
- break;
- case 1:
- scope = LDAPConnection.SCOPE_ONE;
- break;
- }
-
// Search tree for entries
- LDAPSearchResults results = m_connection.search(base, scope,
+ LDAPSearchResults results = m_connection.search(base, LDAPConnection.SCOPE_SUB,
specs.getFilter(filter), attrs, false, cons);
- if(sort != null)
- results.sort(new LDAPCompareAttrNames(sort, specs.getSortDirection()));
+ List res = new ArrayList();
+ if(results.hasMore())
+ {
+ while(results.hasMore())
+ res.add(results.next());
+
+ if(sort != null && sort.length > 0)
+ Collections.sort(res, new LDAPCompareAttrNames(sort, specs.getSortDirection()));
+ }
+ // Now retrieve each
Vector els = new Vector();
- if(results.getCount() > 0)
- {
- int number = 0;
- int skipped = 0;
- int retrieved = 0;
+ int number = 0;
+ int skipped = 0;
+ int retrieved = 0;
- // Idle through entries till we find the one we're supposed to
- // start at
- while(number < start && results.hasMoreElements())
- {
- results.next();
- number++;
- skipped++;
- }
+ Iterator it = res.iterator();
- // Now read each element in
- while(results.hasMoreElements() && number <= last)
- {
- LDAPEntry entry = results.next();
- Element el = retrieveEntry(doc, entry, specs);
+ // Idle through entries till we find the one we're supposed to start at
+ while(number < start && it.hasNext())
+ {
+ it.next();
+ number++;
+ skipped++;
+ }
- // And retrieve sub elements if neccessary
- if(el != null)
- {
- retrieveSubTree(doc, entry.getDN(), specs, el, specs.getDepth(), attrs);
- els.add(el);
- }
+ // Now read each element in
+ while(it.hasNext() && number <= last)
+ {
+ LDAPEntry entry = (LDAPEntry)it.next();
+ Element el = retrieveEntry(doc, entry, specs);
- number++;
- retrieved++;
+ // And retrieve sub elements if neccessary
+ if(el != null)
+ {
+ retrieveSubTree(doc, entry.getDN(), specs, el, specs.getDepth(), attrs);
+ els.add(el);
}
- if(batch)
- {
- start -= skipped;
- specs.setStart(start < 0 ? 0 : start);
+ number++;
+ retrieved++;
+ }
- int limit = specs.getLimit();
- limit -= retrieved;
- specs.setLimit(retrieved < 0 ? 0 : limit);
- }
+ if(batch)
+ {
+ start -= skipped;
+ specs.setStart(start < 0 ? 0 : start);
+ int limit = specs.getLimit();
+ limit -= retrieved;
+ specs.setLimit(retrieved < 0 ? 0 : limit);
}
// Create the root element etc...
@@ -309,16 +301,32 @@ public class LXReader
return retrieveEntry(doc, dn, new LXSpecs());
}
+ /**
+ * Retrieves a single entry from an LDAP tree with additional
+ * specifications.
+ *
+ * @param doc The document from which to create elements.
+ * @param dn The LDAP DN of the entry to retrieve.
+ * @param specs The additional retrieval specifications.
+ * @return The DOM element or null if not found.
+ */
+ public Element retrieveEntry(Document doc, String dn, LXSpecs specs)
+ throws LXException, LDAPException
+ {
+ return retrieveEntry(doc, dn, null, specs);
+ }
+
/**
* Retrieves a single entry from an LDAP tree with additional
* specifications.
*
* @param doc The document from which to create elements.
* @param dn The LDAP DN of the entry to retrieve.
+ * @param query An ldap query to filter the entry with.
* @param specs The additional retrieval specifications.
* @return The DOM element or null if not found.
*/
- public Element retrieveEntry(Document doc, String dn, LXSpecs specs)
+ public Element retrieveEntry(Document doc, String dn, String query, LXSpecs specs)
throws LXException, LDAPException
{
checkInternals();
@@ -327,19 +335,19 @@ public class LXReader
// Get the entry
LDAPSearchResults results = m_connection.search(dn,
- LDAPConnection.SCOPE_BASE, specs.getFilter(), attrs, false);
+ LDAPConnection.SCOPE_BASE, specs.getFilter(query), attrs, false);
Element el = null;
// If we got something then return it.
- if(results.hasMoreElements())
+ if(results.hasMore())
{
LDAPEntry entry = results.next();
el = retrieveEntry(doc, entry, specs);
- }
- // And get sub elements if neccessary
- retrieveSubTree(doc, dn, specs, el, specs.getDepth(), attrs);
+ // And get sub elements if neccessary
+ retrieveSubTree(doc, dn, specs, el, specs.getDepth(), attrs);
+ }
return el;
}
@@ -619,13 +627,7 @@ public class LXReader
checkInternals();
if(m_schema == null || force)
- {
- m_schema = new LDAPSchema();
- force = true;
- }
-
- if(force)
- m_schema.fetchSchema(m_connection);
+ m_schema = m_connection.fetchSchema(m_connection.getSchemaDN());
}
/**
@@ -645,18 +647,26 @@ public class LXReader
// If depth has gone down to zero, then no need
if(el != null && depth > 0)
{
+ LDAPSearchConstraints cons = new LDAPSearchConstraints();
+ cons.setMaxResults(0);
+
// Get everything at one level down
LDAPSearchResults results = m_connection.search(dn,
- LDAPConnection.SCOPE_ONE, specs.getFilter(), attrs, false);
+ LDAPConnection.SCOPE_ONE, specs.getFilter(), attrs, false, cons);
+
+ List res = new ArrayList();
+ while(results.hasMore())
+ res.add(results.next());
- String[] sort = specs.getMappedSort(m_map);
- if(sort != null)
- results.sort(new LDAPCompareAttrNames(sort, specs.getSortDirection()));
+ String[] sort = specs.getMappedSort(m_map);
+ if(sort != null && sort.length > 0)
+ Collections.sort(res, new LDAPCompareAttrNames(sort, specs.getSortDirection()));
// Now retrieve each
- while(results.hasMoreElements())
+ Iterator it = res.iterator();
+ while(it.hasNext())
{
- LDAPEntry entry = results.next();
+ LDAPEntry entry = (LDAPEntry)it.next();
Element sub = retrieveEntry(doc, entry, specs);
// And it's sub tree
diff --git a/src/com/memberwebs/ldapxml/LXResults.java b/src/com/memberwebs/ldapxml/LXResults.java
index 4369e4d..ddd0a12 100644
--- a/src/com/memberwebs/ldapxml/LXResults.java
+++ b/src/com/memberwebs/ldapxml/LXResults.java
@@ -152,6 +152,16 @@ public class LXResults
m_elements.addAll(results.m_elements);
}
+ /**
+ * Add a single element to these results
+ *
+ * @param el The element to add
+ */
+ public final void addElement(Element el)
+ {
+ m_elements.add(el);
+ }
+
// The elements that make up the results
private Vector m_elements;