org.apache.directory.shared.ldap.codec.util
Class LdapURL

java.lang.Object
  extended by org.apache.directory.shared.ldap.codec.util.LdapURL

public class LdapURL
extends java.lang.Object

Decodes a LdapUrl, and checks that it complies with the RFC 2255. The grammar is the following : ldapurl = scheme "://" [hostport] ["/" [dn ["?" [attributes] ["?" [scope] ["?" [filter] ["?" extensions]]]]]] scheme = "ldap" attributes = attrdesc *("," attrdesc) scope = "base" / "one" / "sub" dn = LdapDN hostport = hostport from Section 5 of RFC 1738 attrdesc = AttributeDescription from Section 4.1.5 of RFC 2251 filter = filter from Section 4 of RFC 2254 extensions = extension *("," extension) extension = ["!"] extype ["=" exvalue] extype = token / xtoken exvalue = LDAPString token = oid from section 4.1 of RFC 2252 xtoken = ("X-" / "x-") token

Version:
$Rev: 657543 $, $Date: 2008-05-18 07:39:12 -0400 (Sun, 18 May 2008) $,
Author:
Apache Directory Project

Field Summary
static LdapURL EMPTY_URL
          A null LdapURL
static java.lang.String LDAP_SCHEME
          The constant for "ldap://" scheme.
static java.lang.String LDAPS_SCHEME
          The constant for "ldaps://" scheme.
 
Constructor Summary
LdapURL()
          Construct an empty LdapURL
LdapURL(byte[] bytes)
          Create a new LdapURL after having parsed it.
LdapURL(java.lang.String string)
          Create a new LdapURL from a String after having parsed it.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
static byte[] getAsciiBytes(java.lang.String data)
          Converts the specified string to byte array of ASCII characters.
 java.util.List<java.lang.String> getAttributes()
           
 byte[] getBytesCopy()
           
 byte[] getBytesReference()
           
 java.util.Map<java.lang.String,java.lang.String> getCriticalExtensions()
           
 LdapDN getDn()
           
 java.util.Map<java.lang.String,java.lang.String> getExtensions()
           
 java.lang.String getFilter()
           
 java.lang.String getHost()
           
 int getNbBytes()
           
 int getPort()
           
 java.lang.String getScheme()
           
 int getScope()
          Returns the scope, one of SearchControls.OBJECT_SCOPE, SearchControls.ONELEVEL_SCOPE or SearchControls.SUBTREE_SCOPE.
 java.lang.String getString()
           
static java.lang.String getString(byte[] data, int offset, int length, java.lang.String charset)
          From commons-httpclients.
static java.lang.String getString(byte[] data, java.lang.String charset)
          From commons-httpclients.
 int hashCode()
          Compute the instance's hash code
 void parse(char[] chars)
          Parse a LdapURL
 void setAttributes(java.util.List<java.lang.String> attributes)
          Sets the attributes, null removes all existing attributes.
 void setCriticalExtensions(java.util.Map<java.lang.String,java.lang.String> criticalExtensions)
          Sets the critical extensions, null removes all existing critical extensions.
 void setDn(LdapDN dn)
          Sets the dn.
 void setExtensions(java.util.Map<java.lang.String,java.lang.String> extensions)
          Sets the extensions, null removes all existing extensions.
 void setFilter(java.lang.String filter)
          Sets the filter.
 void setHost(java.lang.String host)
          Sets the host.
 void setPort(int port)
          Sets the port.
 void setScheme(java.lang.String scheme)
          Sets the scheme.
 void setScope(int scope)
          Sets the scope.
 java.lang.String toString()
          Get a string representation of a LdapURL.
static java.lang.String urlEncode(java.lang.String url, boolean doubleEncode)
          Encode a String to avoid special characters *NOTE* : this is an ugly function, just needed because the RFC 2255 is VERY unclear about the way LDAP searches are to be encoded.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LDAPS_SCHEME

public static final java.lang.String LDAPS_SCHEME
The constant for "ldaps://" scheme.

See Also:
Constant Field Values

LDAP_SCHEME

public static final java.lang.String LDAP_SCHEME
The constant for "ldap://" scheme.

See Also:
Constant Field Values

EMPTY_URL

public static final LdapURL EMPTY_URL
A null LdapURL

Constructor Detail

LdapURL

public LdapURL()
Construct an empty LdapURL


LdapURL

public LdapURL(java.lang.String string)
        throws LdapURLEncodingException
Create a new LdapURL from a String after having parsed it.

Parameters:
string - TheString that contains the LDAPURL
Throws:
LdapURLEncodingException - If the String does not comply with RFC 2255

LdapURL

public LdapURL(byte[] bytes)
        throws LdapURLEncodingException
Create a new LdapURL after having parsed it.

Parameters:
bytes - The byte buffer that contains the LDAPURL
Throws:
LdapURLEncodingException - If the byte array does not comply with RFC 2255
Method Detail

parse

public void parse(char[] chars)
           throws LdapURLEncodingException
Parse a LdapURL

Parameters:
chars - The chars containing the URL
Throws:
LdapURLEncodingException - If the URL is invalid

getString

public static java.lang.String getString(byte[] data,
                                         int offset,
                                         int length,
                                         java.lang.String charset)
From commons-httpclients. Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.

Parameters:
data - the byte array to be encoded
offset - the index of the first byte to encode
length - the number of bytes to encode
charset - the desired character encoding
Returns:
The result of the conversion.
Since:
3.0

getString

public static java.lang.String getString(byte[] data,
                                         java.lang.String charset)
From commons-httpclients. Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.

Parameters:
data - the byte array to be encoded
charset - the desired character encoding
Returns:
The result of the conversion.
Since:
3.0

getAsciiBytes

public static byte[] getAsciiBytes(java.lang.String data)
Converts the specified string to byte array of ASCII characters.

Parameters:
data - the string to be encoded
Returns:
The string as a byte array.
Since:
3.0

urlEncode

public static java.lang.String urlEncode(java.lang.String url,
                                         boolean doubleEncode)
Encode a String to avoid special characters *NOTE* : this is an ugly function, just needed because the RFC 2255 is VERY unclear about the way LDAP searches are to be encoded. Some references to RFC 1738 are made, but they are really useless and inadequat.

Parameters:
url - The String to encode
doubleEncode - Set if we need to encode the comma
Returns:
An encoded string

toString

public java.lang.String toString()
Get a string representation of a LdapURL.

Overrides:
toString in class java.lang.Object
Returns:
A LdapURL string

getAttributes

public java.util.List<java.lang.String> getAttributes()
Returns:
Returns the attributes.

getCriticalExtensions

public java.util.Map<java.lang.String,java.lang.String> getCriticalExtensions()
Returns:
Returns the criticalExtensions.

getDn

public LdapDN getDn()
Returns:
Returns the dn.

getExtensions

public java.util.Map<java.lang.String,java.lang.String> getExtensions()
Returns:
Returns the extensions.

getFilter

public java.lang.String getFilter()
Returns:
Returns the filter.

getHost

public java.lang.String getHost()
Returns:
Returns the host.

getPort

public int getPort()
Returns:
Returns the port.

getScope

public int getScope()
Returns the scope, one of SearchControls.OBJECT_SCOPE, SearchControls.ONELEVEL_SCOPE or SearchControls.SUBTREE_SCOPE.

Returns:
Returns the scope.

getScheme

public java.lang.String getScheme()
Returns:
Returns the scheme.

getNbBytes

public int getNbBytes()
Returns:
the number of bytes for this LdapURL

getBytesReference

public byte[] getBytesReference()
Returns:
a reference on the interned bytes representing this LdapURL

getBytesCopy

public byte[] getBytesCopy()
Returns:
a copy of the bytes representing this LdapURL

getString

public java.lang.String getString()
Returns:
the LdapURL as a String

hashCode

public int hashCode()
Compute the instance's hash code

Overrides:
hashCode in class java.lang.Object
Returns:
the instance's hash code

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

setScheme

public void setScheme(java.lang.String scheme)
Sets the scheme. Must be "ldap://" or "ldaps://", otherwise "ldap://" is assumed as default.

Parameters:
scheme - the new scheme

setHost

public void setHost(java.lang.String host)
Sets the host.

Parameters:
host - the new host

setPort

public void setPort(int port)
Sets the port. Must be between 1 and 65535, otherwise -1 is assumed as default.

Parameters:
port - the new port

setDn

public void setDn(LdapDN dn)
Sets the dn.

Parameters:
dn - the new dn

setAttributes

public void setAttributes(java.util.List<java.lang.String> attributes)
Sets the attributes, null removes all existing attributes.

Parameters:
attributes - the new attributes

setScope

public void setScope(int scope)
Sets the scope. Must be one of SearchControls.OBJECT_SCOPE, SearchControls.ONELEVEL_SCOPE or SearchControls.SUBTREE_SCOPE, otherwise SearchControls.OBJECT_SCOPE is assumed as default.

Parameters:
scope - the new scope

setFilter

public void setFilter(java.lang.String filter)
Sets the filter.

Parameters:
filter - the new filter

setExtensions

public void setExtensions(java.util.Map<java.lang.String,java.lang.String> extensions)
Sets the extensions, null removes all existing extensions.

Parameters:
extensions - the extensions

setCriticalExtensions

public void setCriticalExtensions(java.util.Map<java.lang.String,java.lang.String> criticalExtensions)
Sets the critical extensions, null removes all existing critical extensions.

Parameters:
criticalExtensions - the critical extensions


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.