You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2008/08/27 20:47:28 UTC

svn commit: r689558 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/util/LdapURL.java test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java

Author: seelmann
Date: Wed Aug 27 11:47:28 2008
New Revision: 689558

URL: http://svn.apache.org/viewvc?rev=689558&view=rev
Log:
Modified extension access mehtods

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java?rev=689558&r1=689557&r2=689558&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java Wed Aug 27 11:47:28 2008
@@ -22,15 +22,11 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
-
+import java.net.URI;
 import java.text.ParseException;
-
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.naming.InvalidNameException;
@@ -108,12 +104,6 @@
 
     /** The extensions. */
     private List<Extension> extensionList;
-    //
-    //    /** The extensions */
-    //    private Map<String, String> extensions;
-    //
-    //    /** The criticals extensions */
-    //    private Map<String, String> criticalExtensions;
 
     /** Stores the LdapURL as a String */
     private String string;
@@ -141,8 +131,6 @@
         scope = SearchControls.OBJECT_SCOPE;
         filter = null;
         extensionList = new ArrayList<Extension>( 2 );
-        //        extensions = new HashMap<String, String>();
-        //        criticalExtensions = new HashMap<String, String>();
     }
 
 
@@ -161,8 +149,6 @@
         scope = SearchControls.OBJECT_SCOPE;
         filter = null;
         extensionList = new ArrayList<Extension>( 2 );
-        //        extensions = new HashMap<String, String>();
-        //        criticalExtensions = new HashMap<String, String>();
 
         if ( ( chars == null ) || ( chars.length == 0 ) )
         {
@@ -1364,49 +1350,62 @@
 
 
     /**
-     * @return Returns the criticalExtensions.
+     * @return Returns the dn.
      */
-    public Map<String, String> getCriticalExtensions()
+    public LdapDN getDn()
     {
-        Map<String, String> criticalExtensions = new HashMap<String, String>();
+        return dn;
+    }
 
-        for ( Extension extension : extensionList )
-        {
-            if ( extension.isCritical )
-            {
-                criticalExtensions.put( extension.type, extension.value );
-            }
-        }
 
-        return criticalExtensions;
+    /**
+     * @return Returns the extensions.
+     */
+    public List<Extension> getExtensions()
+    {
+        return extensionList;
     }
 
 
     /**
-     * @return Returns the dn.
+     * Gets the extension.
+     * 
+     * @param type the extension type, case-insensitive
+     * 
+     * @return Returns the extension, null if this URL does not contain 
+     *         such an extension.
      */
-    public LdapDN getDn()
+    public Extension getExtension( String type )
     {
-        return dn;
+        for ( Extension extension : getExtensions() )
+        {
+            if ( extension.getType().equalsIgnoreCase( type ) )
+            {
+                return extension;
+            }
+        }
+        return null;
     }
 
 
     /**
-     * @return Returns the extensions.
+     * Gets the extension value.
+     * 
+     * @param type the extension type, case-insensitive
+     * 
+     * @return Returns the extension value, null if this URL does not  
+     *         contain such an extension or if the extension value is null.
      */
-    public Map<String, String> getExtensions()
+    public String getExtensionValue( String type )
     {
-        Map<String, String> extensions = new HashMap<String, String>();
-
-        for ( Extension extension : extensionList )
+        for ( Extension extension : getExtensions() )
         {
-            if ( extension.isCritical )
+            if ( extension.getType().equalsIgnoreCase( type ) )
             {
-                extensions.put( extension.type, extension.value );
+                return extension.getValue();
             }
         }
-
-        return extensions;
+        return null;
     }
 
 
@@ -1642,62 +1641,6 @@
 
 
     /**
-     * Sets the extensions, null removes all existing extensions.
-     * 
-     * @param extensions the extensions
-     */
-    public void setExtensions( Map<String, String> extensions )
-    {
-        // remove all old non-critical extensions
-        for ( Iterator<Extension> it = extensionList.iterator(); it.hasNext(); )
-        {
-            if ( !it.next().isCritical )
-            {
-                it.remove();
-            }
-        }
-
-        // add new non-critical extensions 
-        if ( extensions != null )
-        {
-            for ( String key : extensions.keySet() )
-            {
-                Extension extension = new Extension( false, key, extensions.get( key ) );
-                extensionList.add( extension );
-            }
-        }
-    }
-
-
-    /**
-     * Sets the critical extensions, null removes all existing critical extensions.
-     * 
-     * @param criticalExtensions the critical extensions
-     */
-    public void setCriticalExtensions( Map<String, String> criticalExtensions )
-    {
-        // remove all old critical extensions
-        for ( Iterator<Extension> it = extensionList.iterator(); it.hasNext(); )
-        {
-            if ( it.next().isCritical )
-            {
-                it.remove();
-            }
-        }
-
-        // add new critical extensions 
-        if ( criticalExtensions != null )
-        {
-            for ( String key : criticalExtensions.keySet() )
-            {
-                Extension extension = new Extension( true, key, criticalExtensions.get( key ) );
-                extensionList.add( extension );
-            }
-        }
-    }
-
-
-    /**
      * 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.
@@ -1722,19 +1665,98 @@
         return forceScopeRendering;
     }
 
-    private class Extension
+    /**
+     * An inner bean to hold extension information.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     * @version $Rev$, $Date$
+     */
+    public static class Extension
     {
         private boolean isCritical;
         private String type;
         private String value;
 
 
-        private Extension( boolean isCritical, String extype, String exvalue )
+        /**
+         * Creates a new instance of Extension.
+         *
+         * @param isCritical true for critical extension
+         * @param type the extension type
+         * @param value the extension value
+         */
+        public Extension( boolean isCritical, String type, String value )
         {
             super();
             this.isCritical = isCritical;
-            this.type = extype;
-            this.value = exvalue;
+            this.type = type;
+            this.value = value;
+        }
+
+
+        /**
+         * Checks if is critical.
+         * 
+         * @return true, if is critical
+         */
+        public boolean isCritical()
+        {
+            return isCritical;
+        }
+
+
+        /**
+         * Sets the critical.
+         * 
+         * @param isCritical the new critical
+         */
+        public void setCritical( boolean isCritical )
+        {
+            this.isCritical = isCritical;
+        }
+
+
+        /**
+         * Gets the type.
+         * 
+         * @return the type
+         */
+        public String getType()
+        {
+            return type;
+        }
+
+
+        /**
+         * Sets the type.
+         * 
+         * @param type the new type
+         */
+        public void setType( String type )
+        {
+            this.type = type;
+        }
+
+
+        /**
+         * Gets the value.
+         * 
+         * @return the value
+         */
+        public String getValue()
+        {
+            return value;
+        }
+
+
+        /**
+         * Sets the value.
+         * 
+         * @param value the new value
+         */
+        public void setValue( String value )
+        {
+            this.value = value;
         }
     }
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java?rev=689558&r1=689557&r2=689558&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/LdapUrlTest.java Wed Aug 27 11:47:28 2008
@@ -31,6 +31,7 @@
 
 import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.LdapURL.Extension;
 import org.junit.Test;
 
 
@@ -2018,6 +2019,32 @@
             LdapURL url = new LdapURL( "ldap://localhost:123/????!a=b,!c,!x,d=e,f=g,!h=i" );
 
             assertEquals( "ldap://localhost:123/????!a=b,!c,!x,d=e,f=g,!h=i", url.toString() );
+
+            List<Extension> extensions = url.getExtensions();
+
+            assertTrue( extensions.get( 0 ).isCritical() );
+            assertEquals( "a", extensions.get( 0 ).getType() );
+            assertEquals( "b", extensions.get( 0 ).getValue() );
+
+            assertTrue( extensions.get( 1 ).isCritical() );
+            assertEquals( "c", extensions.get( 1 ).getType() );
+            assertNull( extensions.get( 1 ).getValue() );
+
+            assertTrue( extensions.get( 2 ).isCritical() );
+            assertEquals( "x", extensions.get( 2 ).getType() );
+            assertNull( extensions.get( 2 ).getValue() );
+
+            assertFalse( extensions.get( 3 ).isCritical() );
+            assertEquals( "d", extensions.get( 3 ).getType() );
+            assertEquals( "e", extensions.get( 3 ).getValue() );
+
+            assertFalse( extensions.get( 4 ).isCritical() );
+            assertEquals( "f", extensions.get( 4 ).getType() );
+            assertEquals( "g", extensions.get( 4 ).getValue() );
+
+            assertTrue( extensions.get( 5 ).isCritical() );
+            assertEquals( "h", extensions.get( 5 ).getType() );
+            assertEquals( "i", extensions.get( 5 ).getValue() );
         }
         catch ( LdapURLEncodingException luee )
         {