summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef <stef@ws.local>2004-06-13 03:15:25 +0000
committerStef <stef@ws.local>2004-06-13 03:15:25 +0000
commit337838e69ad5ac7efea9436508fe62a734290cc4 (patch)
treeaaf168c7f4601c07f07fec0f43ba86d6a4ae9dca
parent719790c0a8351ce519827419dbf7e1a2a774fae4 (diff)
- Use latest version of com.novell.ldap
- Fixed depth problems
-rw-r--r--ChangeLog7
-rw-r--r--build.xml2
-rw-r--r--build/.cvsignore3
-rw-r--r--lib/ldap.jarbin271564 -> 385619 bytes
-rw-r--r--src/com/memberwebs/ldapxml/LXReader.java154
-rw-r--r--src/com/memberwebs/ldapxml/LXResults.java10
6 files changed, 100 insertions, 76 deletions
diff --git a/ChangeLog b/ChangeLog
index 487cdb6..34666bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+0.9.3
+ - Fixed support for
+
+0.9.2
+ - Reversed dumb changes from 0.9.1
+ - Improved support for retrieving a single entry
+
0.9.1
- Fixed bug where LXReader would try to read an entire subtree
when only scope 'base' or 'onelevel' was required.
diff --git a/build.xml b/build.xml
index b495ece..a7ac3b4 100644
--- a/build.xml
+++ b/build.xml
@@ -2,7 +2,7 @@
<project name="ldapxml" default="build" basedir=".">
<target name="init">
- <property name="version" value="0.9.1"/>
+ <property name="version" value="0.9.2"/>
</target>
<target name="build">
diff --git a/build/.cvsignore b/build/.cvsignore
deleted file mode 100644
index 5481bd5..0000000
--- a/build/.cvsignore
+++ /dev/null
@@ -1,3 +0,0 @@
-ldapxml-*
-manifest
-com
diff --git a/lib/ldap.jar b/lib/ldap.jar
index 85eb8f9..b5af0af 100644
--- a/lib/ldap.jar
+++ b/lib/ldap.jar
Binary files differ
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;