org.apache.directory.api.ldap.model.url
Class LdapUrl

java.lang.Object
  extended by org.apache.directory.api.ldap.model.url.LdapUrl

public class LdapUrl
extends 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
 

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 String LDAP_SCHEME
          The constant for "ldap://" scheme.
static String LDAPS_SCHEME
          The constant for "ldaps://" scheme.
 
Constructor Summary
LdapUrl()
          Construct an empty LdapUrl
LdapUrl(String string)
          Create a new LdapUrl from a String after having parsed it.
 
Method Summary
 boolean equals(Object obj)
          
 List<String> getAttributes()
           
 byte[] getBytesCopy()
           
 byte[] getBytesReference()
           
 Dn getDn()
           
 LdapUrl.Extension getExtension(String type)
          Gets the extension.
 List<LdapUrl.Extension> getExtensions()
           
 String getExtensionValue(String type)
          Gets the extension value.
 String getFilter()
           
 String getHost()
           
 int getNbBytes()
           
 int getPort()
           
 String getScheme()
           
 SearchScope getScope()
          Returns the scope, one of SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE.
 String getString()
           
 int hashCode()
          
 void setAttributes(List<String> attributes)
          Sets the attributes, null removes all existing attributes.
 void setDn(Dn dn)
          Sets the dn.
 void setFilter(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(String host)
          Sets the host.
 void setPort(int port)
          Sets the port.
 void setScheme(String scheme)
          Sets the scheme.
 void setScope(int scope)
          Sets the scope.
 void setScope(SearchScope scope)
          Sets the scope.
 String toString()
          Get a string representation of a LdapUrl.
static String urlEncode(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 String LDAPS_SCHEME
The constant for "ldaps://" scheme.

See Also:
Constant Field Values

LDAP_SCHEME

public static final 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(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
Method Detail

urlEncode

public static String urlEncode(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 String toString()
Get a string representation of a LdapUrl.

Overrides:
toString in class Object
Returns:
A LdapUrl string
See Also:
forceScopeRendering

getAttributes

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

getDn

public Dn getDn()
Returns:
Returns the dn.

getExtensions

public List<LdapUrl.Extension> getExtensions()
Returns:
Returns the extensions.

getExtension

public LdapUrl.Extension getExtension(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 String getExtensionValue(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 String getFilter()
Returns:
Returns the filter.

getHost

public 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 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 String getString()
Returns:
the LdapUrl as a String

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

setScheme

public void setScheme(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(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(List<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(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


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.