summaryrefslogtreecommitdiff
path: root/src/com/memberwebs/ldapxml/LXSpecs.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/memberwebs/ldapxml/LXSpecs.java')
-rw-r--r--src/com/memberwebs/ldapxml/LXSpecs.java256
1 files changed, 256 insertions, 0 deletions
diff --git a/src/com/memberwebs/ldapxml/LXSpecs.java b/src/com/memberwebs/ldapxml/LXSpecs.java
new file mode 100644
index 0000000..98f1d55
--- /dev/null
+++ b/src/com/memberwebs/ldapxml/LXSpecs.java
@@ -0,0 +1,256 @@
+package com.memberwebs.ldapxml;
+
+import java.util.*;
+
+import com.memberwebs.ldapxml.helpers.*;
+import com.familymembers.util.ldap.*;
+
+/**
+ * Additional specifications for retrieving data from an
+ * LDAP directory.
+ *
+ * @author nielsen@memberwebs.com
+ * @version 0.5
+ */
+public class LXSpecs
+{
+ /**
+ * Don't retrieve any sub entries.
+ */
+ public static final int DEPTH_BASE = 0;
+
+ /**
+ * Retrive only direct children of the referenced entry.
+ */
+ public static final int DEPTH_SINGLE = 1;
+
+ /**
+ * Retrieve all sub entries.
+ */
+ public static final int DEPTH_INFINITE = 0xFFFFFFFF;
+
+
+ private static final String LANG = "lang-";
+
+ /**
+ * Construct a new LXSpecs object.
+ */
+ public LXSpecs()
+ {
+ m_filter = LDAPUtil.FILTER_ALL;
+ m_depth = DEPTH_BASE;
+ m_sort = null;
+ m_data = null;
+ m_language = null;
+ m_start = 0;
+ m_limit = Integer.MAX_VALUE;
+ }
+
+ public final int getStart()
+ {
+ return m_start;
+ }
+
+ public final int getLimit()
+ {
+ return m_limit;
+ }
+
+ public final void setStart(int start)
+ {
+ m_start = start;
+ }
+
+ public final void setLimit(int limit)
+ {
+ m_limit = limit;
+ }
+
+ /**
+ * Get preferred language.
+ *
+ * @return The language or null if none set.
+ */
+ public final String getLanguage()
+ {
+ return m_language;
+ }
+
+ /**
+ * Set preferred language for LDAP retrieval.
+ *
+ * @param language The language or null for no preference.
+ */
+ public final void setLanguage(String language)
+ {
+ m_language = language;
+
+ if(m_language != null && !m_language.startsWith(LANG))
+ m_language = LANG + m_language;
+ }
+
+ /**
+ * Returns the depth to which entries are recursively
+ * retrieved from the LDAP directory.
+ *
+ * @return The depth.
+ */
+ public final int getDepth()
+ {
+ return m_depth;
+ }
+
+ /**
+ * Sets the depth to which entries are recursively
+ * retrieved from the LDAP directory.
+ *
+ * @return The depth.
+ */
+ public final void setDepth(int depth)
+ {
+ m_depth = depth;
+ }
+
+ /**
+ * Gets the additional filter when searching for entries.
+ *
+ * @return The filter.
+ */
+ public final String getFilter()
+ {
+ return m_filter == null ? LDAPUtil.FILTER_ALL : m_filter;
+ }
+
+ /**
+ * Gets the filter when searching for entries, combining it
+ * with another filter.
+ *
+ * @param prevFilter The other filter.
+ * @return The combined filter.
+ */
+ public final String getFilter(String prevFilter)
+ {
+ String filter = LDAPUtil.combineFilters(m_filter, prevFilter);
+ return filter == null ? LDAPUtil.FILTER_ALL : filter;
+ }
+
+ /**
+ * Set an additional filter used when searching for entries.
+ *
+ * @param filter The filter.
+ */
+ public final void setFilter(String filter)
+ {
+ m_filter = LDAPUtil.combineFilters(filter, null);
+ }
+
+ /**
+ * Get the requested sort order.
+ *
+ * @return The sort order, or null if none present.
+ */
+ public final String[] getSort()
+ {
+ if(m_sort != null && m_sort.length > 0)
+ return m_sort;
+ else
+ return null;
+ }
+
+ /**
+ * Get the sort directions (ascending, descending) for the
+ * sort order.
+ *
+ * @return An array of sort directions.
+ */
+ public final boolean[] getSortDirection()
+ {
+ if(m_direc != null && m_direc.length > 0)
+ return m_direc;
+ else
+ return null;
+ }
+
+ /**
+ * Set the sort order. Attribute names prefixed with '-' are
+ * treated as descending.
+ *
+ * @param sort The sort order.
+ */
+ public final void setSort(String[] sort)
+ {
+ m_mappedSort = null;
+
+ m_sort = new String[sort.length];
+ m_direc = new boolean[sort.length];
+
+ for(int i = 0; i < sort.length; i++)
+ {
+ boolean desc = sort[i].startsWith("-");
+ if(desc)
+ m_sort[i] = sort[i].substring(1);
+ else
+ m_sort[i] = sort[i];
+
+ m_direc[i] = !desc;
+ }
+ }
+
+ public final Object getData()
+ {
+ return m_data;
+ }
+
+ public final void setData(Object data)
+ {
+ m_data = data;
+ }
+
+ /**
+ * Translate the sort order with mapped LDAP attribute
+ * names retrieved from the map.
+ *
+ * @param map The LX Map to get the attribute names from.
+ * @return The translated sort order.
+ */
+ protected final String[] getMappedSort(LXMap map)
+ {
+ if(m_mappedSort == null)
+ {
+ if(m_sort != null && m_sort.length > 0)
+ {
+ m_mappedSort = new String[m_sort.length];
+
+ Map nameMap = map.getNameMap();
+ for(int i = 0; i < m_sort.length; i++)
+ {
+ String name = (String)nameMap.get(m_sort[i]);
+ m_mappedSort[i] = name == null ? m_sort[i] : name;
+ }
+ }
+ }
+ return m_mappedSort;
+ }
+
+ // The additional filter
+ private String m_filter;
+
+ // The depth to which to recursively retrieve sub entries
+ private int m_depth;
+
+ // The starting point to retrieve entries
+ private int m_start;
+ // The number of entries to retrieve
+ private int m_limit;
+
+ // The sort order and direction
+ private String[] m_sort;
+ private String[] m_mappedSort;
+ private boolean[] m_direc;
+
+ // The preferred language
+ private String m_language;
+
+ // Data for hooks
+ private Object m_data;
+} \ No newline at end of file