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

java.lang.Object
  extended by org.apache.directory.shared.ldap.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 = DN 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: 923455 $, $Date: 2010-03-15 22:59:28 +0100 (Mon, 15 Mar 2010) $,
Author:
Apache Directory Project

Nested Class Summary
static class LdapURL.Extension
          An inner bean to hold extension information.
 
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()
           
 DN getDn()
           
 LdapURL.Extension getExtension(java.lang.String type)
          Gets the extension.
 java.util.List<LdapURL.Extension> getExtensions()
           
 java.lang.String getExtensionValue(java.lang.String type)
          Gets the extension value.
 java.lang.String getFilter()
           
 java.lang.String getHost()
           
 int getNbBytes()
           
 int getPort()
           
 java.lang.String getScheme()
           
 SearchScope getScope()
          Returns the scope, one of SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE.
 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
 boolean isForceScopeRendering()
          If set to true forces the toString method to render the scope regardless of optional nature.
 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 setDn(DN dn)
          Sets the dn.
 void setFilter(java.lang.String filter)
          Sets the filter.
 void setForceScopeRendering(boolean forceScopeRendering)
          If set to true forces the toString method to render the scope regardless of optional nature.
 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.
 void setScope(SearchScope 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.
 
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. RFC 4516, section 2.1. (Percent-Encoding) A generated LDAP URL MUST consist only of the restricted set of characters included in one of the following three productions defined in [RFC3986]: Implementations SHOULD accept other valid UTF-8 strings [RFC3629] as input. An octet MUST be encoded using the percent-encoding mechanism described in section 2.1 of [RFC3986] in any of these situations: The octet is not in the reserved set defined in section 2.2 of [RFC3986] or in the unreserved set defined in section 2.3 of [RFC3986]. It is the single Reserved character '?' and occurs inside a , , or other element of an LDAP URL. It is a comma character ',' that occurs inside an . RFC 3986, section 2.2 (Reserved Characters) reserved = gen-delims / sub-delims gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" RFC 3986, section 2.3 (Unreserved Characters) unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"

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
See Also:
forceScopeRendering

getAttributes

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

getDn

public DN getDn()
Returns:
Returns the dn.

getExtensions

public java.util.List<LdapURL.Extension> getExtensions()
Returns:
Returns the extensions.

getExtension

public LdapURL.Extension getExtension(java.lang.String type)
Gets the extension.

Parameters:
type - the extension type, case-insensitive
Returns:
Returns the extension, null if this URL does not contain such an extension.

getExtensionValue

public java.lang.String getExtensionValue(java.lang.String type)
Gets the extension value.

Parameters:
type - the extension type, case-insensitive
Returns:
Returns the extension value, null if this URL does not contain such an extension or if the extension value is null.

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 SearchScope getScope()
Returns the scope, one of SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE.

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(DN 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 SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE, otherwise SearchScope.OBJECT is assumed as default.

Parameters:
scope - the new scope

setScope

public void setScope(SearchScope scope)
Sets the scope. Must be one of SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE, otherwise SearchScope.OBJECT 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

setForceScopeRendering

public void setForceScopeRendering(boolean forceScopeRendering)
If set to true forces the toString method to render the scope regardless of optional nature. Use this when you want explicit search URL scope rendering.

Parameters:
forceScopeRendering - the forceScopeRendering to set

isForceScopeRendering

public boolean isForceScopeRendering()
If set to true forces the toString method to render the scope regardless of optional nature. Use this when you want explicit search URL scope rendering.

Returns:
the forceScopeRendering


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.