directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r683660 - /directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
Date Thu, 07 Aug 2008 17:34:17 GMT
Author: akarasulu
Date: Thu Aug  7 10:34:17 2008
New Revision: 683660

URL: http://svn.apache.org/viewvc?rev=683660&view=rev
Log:
perfect changes now to toString() method

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java?rev=683660&r1=683659&r2=683660&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/util/LdapURL.java
Thu Aug  7 10:34:17 2008
@@ -114,6 +114,10 @@
     /** Stores the LdapURL as a byte array */
     private byte[] bytes;
     
+    /** modal parameter that forces explicit scope rendering in toString */
+    private boolean forceScopeRendering;
+    
+    
     // ~ Constructors
     // -------------------------------------------------------------------------------
 
@@ -1211,6 +1215,7 @@
      * Get a string representation of a LdapURL.
      * 
      * @return A LdapURL string
+     * @see LdapURL#forceScopeRendering
      */
     public String toString()
     {
@@ -1229,7 +1234,7 @@
         {
             sb.append( '/' ).append( urlEncode( dn.toString(), false ) );
 
-            if ( ( attributes.size() != 0 )
+            if ( attributes.size() != 0 || forceScopeRendering
                 || ( ( scope != SearchControls.OBJECT_SCOPE ) || ( filter != null ) || 
                     ( extensions.size() != 0 ) || ( criticalExtensions.size() != 0 ) ) )
             {
@@ -1251,9 +1256,8 @@
                     sb.append( urlEncode( attribute, false ) );
                 }
             }
-
-            if ( ( scope != SearchControls.OBJECT_SCOPE ) || ( filter != null ) || ( extensions.size()
!= 0 )
-                || ( criticalExtensions.size() != 0 ) )
+            
+            if ( forceScopeRendering )
             {
                 sb.append( '?' );
 
@@ -1261,8 +1265,7 @@
                 {
 
                     case SearchControls.OBJECT_SCOPE:
-
-                        // This is the default value.
+                        sb.append( "base" );
                         break;
 
                     case SearchControls.ONELEVEL_SCOPE:
@@ -1277,66 +1280,96 @@
                     default :
                         break;
                 }
+            }
 
-                if ( ( filter != null ) || ( ( extensions.size() != 0 ) || ( criticalExtensions.size()
!= 0 ) ) )
+            else
+            {
+                if ( ( scope != SearchControls.OBJECT_SCOPE ) || ( filter != null ) || (
extensions.size() != 0 )
+                    || ( criticalExtensions.size() != 0 ) )
                 {
-                    sb.append( "?" );
-
-                    if ( filter != null )
+                    sb.append( '?' );
+    
+                    switch ( scope )
                     {
-                        sb.append( urlEncode( filter, false ) );
+    
+                        case SearchControls.OBJECT_SCOPE:
+    
+                            // This is the default value.
+                            break;
+    
+                        case SearchControls.ONELEVEL_SCOPE:
+                            sb.append( "one" );
+                            break;
+    
+                        case SearchControls.SUBTREE_SCOPE:
+                            sb.append( "sub" );
+                            break;
+                            
+                            
+                        default :
+                            break;
                     }
-
-                    if ( ( extensions.size() != 0 ) || ( criticalExtensions.size() != 0 )
)
+    
+                    if ( ( filter != null ) || ( ( extensions.size() != 0 ) || ( criticalExtensions.size()
!= 0 ) ) )
                     {
-                        sb.append( '?' );
-
-                        boolean isFirst = true;
-
-                        if ( extensions.size() != 0 )
+                        sb.append( "?" );
+    
+                        if ( filter != null )
                         {
-                            for ( String key:extensions.keySet() )
-                            {
-
-                                if ( !isFirst )
-                                {
-                                    sb.append( ',' );
-                                }
-                                else
-                                {
-                                    isFirst = false;
-                                }
-
-                                sb.append( urlEncode( key, false ) ).append( '=' ).append(
-                                    urlEncode( extensions.get( key ), true ) );
-                            }
+                            sb.append( urlEncode( filter, false ) );
                         }
-
-                        isFirst = true;
-
-                        if ( criticalExtensions.size() != 0 )
+    
+                        if ( ( extensions.size() != 0 ) || ( criticalExtensions.size() !=
0 ) )
                         {
-                            for ( String key:criticalExtensions.keySet() )
+                            sb.append( '?' );
+    
+                            boolean isFirst = true;
+    
+                            if ( extensions.size() != 0 )
                             {
-
-                                if ( !isFirst )
-                                {
-                                    sb.append( ",!" );
-                                }
-                                else
+                                for ( String key:extensions.keySet() )
                                 {
-                                    sb.append( '!' );
-                                    isFirst = false;
+    
+                                    if ( !isFirst )
+                                    {
+                                        sb.append( ',' );
+                                    }
+                                    else
+                                    {
+                                        isFirst = false;
+                                    }
+    
+                                    sb.append( urlEncode( key, false ) ).append( '=' ).append(
+                                        urlEncode( extensions.get( key ), true ) );
                                 }
-
-                                sb.append( urlEncode( key, false ) );
-                                
-                                String value = criticalExtensions.get( key );
-                                
-                                if ( value != null )
+                            }
+    
+                            isFirst = true;
+    
+                            if ( criticalExtensions.size() != 0 )
+                            {
+                                for ( String key:criticalExtensions.keySet() )
                                 {
-                                    sb.append( '=' ).append(
-                                    urlEncode( value, true ) );
+    
+                                    if ( !isFirst )
+                                    {
+                                        sb.append( ",!" );
+                                    }
+                                    else
+                                    {
+                                        sb.append( '!' );
+                                        isFirst = false;
+                                    }
+    
+                                    sb.append( urlEncode( key, false ) );
+                                    
+                                    String value = criticalExtensions.get( key );
+                                    
+                                    if ( value != null )
+                                    {
+                                        sb.append( '=' ).append(
+                                        urlEncode( value, true ) );
+                                    }
                                 }
                             }
                         }
@@ -1352,7 +1385,6 @@
         return sb.toString();
     }
 
-
     /**
      * @return Returns the attributes.
      */
@@ -1649,4 +1681,30 @@
         }
     }
 
+    
+    /**
+     * 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.
+     * 
+     * @param forceScopeRendering the forceScopeRendering to set
+     */
+    public void setForceScopeRendering( boolean forceScopeRendering )
+    {
+        this.forceScopeRendering = 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.
+     * 
+     * @return the forceScopeRendering
+     */
+    public boolean isForceScopeRendering()
+    {
+        return forceScopeRendering;
+    }
+
 }



Mime
View raw message