netscape.ldap.util

Class LDAPFilter

Implemented Interfaces:
Cloneable

public class LDAPFilter
extends java.lang.Object
implements Cloneable

Represents an LDAP search filter, which includes the string-based representation of the filter and other information retrieved from the LDAP filter configuration file (or from a buffer in memory or from a URL).

Although this class provides methods to create and modify LDAP filters, in most cases, you do not need to use these methods. In most situations, these classes are used to access individual filters from filter configuration files.

For example, you might do the following:

  1. Connect to the LDAP server and accept a set of search criteria.
  2. Create an LDAP filter configuration file.
  3. Call the LDAPFilterDescriptor constructor to read the filter configuration file into memory.
  4. Call the getFilters method to get a list of filters that match the search criteria. This list of filters is represented by an LDAPFilterList object.
  5. Iterate through the list of filters (each filter is represented by an LDAPFilter object), and apply the filter to a search.

For an example of using an object of this class and for more information on the filter configuration file syntax, see the documentation for LDAPFilterDescriptor.

See Also:
LDAPFilterDescriptor, LDAPFilterList

Constructor Summary

LDAPFilter(String strMatchPattern, String strDelimiter, String strFilterTemplate, String strDescription, String strScope)
Constructs an LDAPFilter object.
LDAPFilter(String strMatchPattern, String strDelimiter, String strFilterTemplate, String strDescription, int nScope)
Constructs an LDAPFilter object.

Method Summary

Object
clone()
Makes a copy of this LDAPFilter object.
String
getDelimiter()
Return this filter's delimiter.
String
getDescription()
Return this filter's description.
String
getFilter()
Returns the filter string.
String
getFilter(String strValue)
Create a filter string given a string value.
String
getFilter(String strValue, String strPrefix, String strSuffix)
Create a filter string given a string value.
String
getFilterTemplate()
Return this filter's filter template.
String
getLineNumber()
Return this filter's line number.
String
getMatchPattern()
Return this filter's match pattern.
String
getScope()
Return this filter's scope.
void
setFilterAffixes(String strPrefix, String strSuffix)
void
setupFilter(String strValue)
Sets up the filter string, given the string strValue.
void
setupFilter(String strValue, String strPrefix, String strSuffix)
Sets up the filter string, given the string strValue.
String
toString()
Print out a string representation of the LDAPFilter.

Constructor Details

LDAPFilter

public LDAPFilter(String strMatchPattern,
                  String strDelimiter,
                  String strFilterTemplate,
                  String strDescription,
                  String strScope)
            throws IllegalArgumentException
Constructs an LDAPFilter object. In most situations, you do not need to construct an LDAPFilter object. Instead, you work with LDAPFilter objects created from the LDAPFilter objects and LDAPFilterDescriptor objects.

This constructor uses the string value for a search scope in addition to other information to construct an LDAPFilter object. The string value of the search scope can be one of the following:

  • "base"
  • "onelevel"
  • "subtree"
If an invalid scope is specified, the constructor throws an illegalArgumentException.

LDAPFilter

public LDAPFilter(String strMatchPattern,
                  String strDelimiter,
                  String strFilterTemplate,
                  String strDescription,
                  int nScope)
            throws IllegalArgumentException
Constructs an LDAPFilter object. In most situations, you do not need to construct an LDAPFilter object. Instead, you work with LDAPFilter objects created from the LDAPFilter objects and LDAPFilterDescriptor objects.

This constructor uses the integer value for a search scope in addition to other information to construct an LDAPFilter object. The integer value of the search scope can be one of the following:

  • LDAPConnection.SCOPE_BASE
  • LDAPConnection.SCOPE_ONE
  • LDAPConnection.SCOPE_SUB
If an invalid scope is specified, the constructor throws an illegalArgumentException.

Method Details

clone

public Object clone()
Makes a copy of this LDAPFilter object.

getDelimiter

public String getDelimiter()
Return this filter's delimiter. The delmimeter is found as the second token in a filter configuration line in the ldapfilter.conf file.

getDescription

public String getDescription()
Return this filter's description. The description is found as the fourth token in a filter configuration line in the ldapfilter.conf file.

getFilter

public String getFilter()
Returns the filter string. This method will return null if the filter string has not been calculated by the setupFilter(), getFilter (strValue), or getFilter (strValue, strPrefix, strSuffix ) methods.
See Also:
setupFilter, getFilter

getFilter

public String getFilter(String strValue)
Create a filter string given a string value. This method uses any Prefixes or Suffixes that have been set by the setFilterAffixes() method.

This is the same as doing:

   setupFilter ( strValue );
   getFilter();
 

getFilter

public String getFilter(String strValue,
                        String strPrefix,
                        String strSuffix)
Create a filter string given a string value. If strPrefix and/or strSuffix is non-null, these values are prepended and appended to the returned string.

This is the same as doing:

   setupFilter ( strValue, strPrefix, strSuffix );
   getFilter();
 

getFilterTemplate

public String getFilterTemplate()
Return this filter's filter template. The filter template is found as the third token in a filter configuration line in the ldapfilter.conf file.

getLineNumber

public String getLineNumber()
Return this filter's line number. The line number is mostly a debugging variable to let the developer know which filter from the filter configuration file is being used.

getMatchPattern

public String getMatchPattern()
Return this filter's match pattern. The match pattern is found as the first token in a filter configuration line in the ldapfilter.conf file.

getScope

public String getScope()
Return this filter's scope. The scope is found as the fifth (optional) token in a filter configuration line in the ldapfilter.conf file.

setFilterAffixes

public void setFilterAffixes(String strPrefix,
                             String strSuffix)

setupFilter

public void setupFilter(String strValue)
Sets up the filter string, given the string strValue. This string, which is available through the getFilter() method, should be suitable for use as search criteria when calling the LDAPConnection.search() method.

Note: If you want to specify a filter prefix and suffix, you need to explicitly define them by calling the setFilterAffixes() method.


setupFilter

public void setupFilter(String strValue,
                        String strPrefix,
                        String strSuffix)
Sets up the filter string, given the string strValue. If the strPrefix and strSuffix arguments are non-null strings, they are prepended and appended to the filter string (respectively).

This string, which is available through the getFilter() method, should be suitable for use as search criteria when calling the LDAPConnection.search() method.

Notes:

  • This method does not maintain the affixes set with the LDAPFilterDescriptor.setFilterAffixes method, so you need to explicitly define any filter prefixes or suffixes here.

  • This method only uses the strPrefix and strSuffix for this invocation of setupFilter. It does not redefine strPrefix and strSuffix for later invocations.


toString

public String toString()
Print out a string representation of the LDAPFilter. Basically, it prints out the appropriate fields.

For example, suppose you called the method in this way:

System.out.println(filter.toString());
The resulting output might look like this:

      matchPtn: "@"
      delim:    " "
      filttmpl: "(mail=%v*)"
      descript: "start of email address"
      scope: "LDAPConnection.SCOPE_SUB"
      line:     "32"
      FILTER:   "(mail=babs@aceindustry.com*)"