You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2004/12/12 21:58:01 UTC

svn commit: r111663 - in incubator/beehive/trunk/netui: src/pageflow/org/apache/beehive/netui/pageflow/internal src/pageflow/org/apache/beehive/netui/pageflow/util src/tags-html/org/apache/beehive/netui/tags/html src/tags-html/org/apache/beehive/netui/tags/internal src/util/org/apache/beehive/netui/core/urls test/ant

Author: rich
Date: Sun Dec 12 12:57:59 2004
New Revision: 111663

URL: http://svn.apache.org/viewcvs?view=rev&rev=111663
Log:
This is a contribution from Carlin Rogers:

    "- Changed Type enum to URLType in URLRewriter.

    - Modified URLRewriterService.registerURLRewriter() to log
      a message when an exclusive (allowOtherRewriters == false)
      rewriter has been registered and return false. When an
      exclusive rewriter does get registered it will remove the
      other rewriters and log a message about removing other
      rewriters, if necessary.

    - Implemented a simple diagnostic method to dump the chain
      of URLRewriters to a PrintStream.

    - Added some more Javadoc to URLRewriterService and
      MutableURI.

    - Added the character encoding, used to encode unencoded
      parameters of a query, as member data of the MutableURI.

    - Added a new JUnit test for the MutableURI class and
      included it in the NetUI"

Thanks Carlin!

DRT/BVT: netui (WinXP)
BB: self (linux)


Modified:
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java
   incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java
   incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
   incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java
   incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
   incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java
   incubator/beehive/trunk/netui/test/ant/junitCore.xml

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java&r1=111662&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java	Sun Dec 12 12:57:59 2004
@@ -27,6 +27,7 @@
 
 import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.core.urls.URLRewriter;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.pageflow.ServerAdapter;
 import org.apache.beehive.netui.pageflow.util.TemplateHelper;
 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
@@ -43,7 +44,7 @@
     }
 
     public void rewriteURL( ServletContext servletContext, ServletRequest request,
-                            ServletResponse response, MutableURI url, Type type, boolean needsToBeSecure )
+                            ServletResponse response, MutableURI url, URLType type, boolean needsToBeSecure )
     {
         // TODO... fix/modify TemplateHelper to use MutableURI or figure out a way for it subclass
         // MutableURI. This is just the old code from the depricate DefaultURLRewriter.
@@ -52,7 +53,7 @@
         // do the lookup to get the right template.
         // Apply the value to the template.
         String templateType = org.apache.beehive.netui.pageflow.util.URLRewriter.ACTION_UNSECURE;
-        if ( type.equals( URLRewriter.Type.ACTION ) )
+        if ( type.equals( URLType.ACTION ) )
         {
             if ( needsToBeSecure )
             {
@@ -63,7 +64,7 @@
                 templateType = org.apache.beehive.netui.pageflow.util.URLRewriter.ACTION_UNSECURE;
             }
         }
-        else if ( type.equals( URLRewriter.Type.RESOURCE ) )
+        else if ( type.equals( URLType.RESOURCE ) )
         {
             if ( needsToBeSecure )
             {
@@ -91,7 +92,7 @@
                 url.setPort( uri.getPort() );
                 url.setPath( uri.getPath() );
                 url.setQuery( null );
-                url.addParameters( uri.getParameters(), true, null );
+                url.addParameters( uri.getParameters(), true );
                 url.setFragment( uri.getFragment() );
             }
             catch ( URISyntaxException e )
@@ -161,7 +162,7 @@
             List< String > parameters = url.getParameters( ScopedServletUtils.SCOPE_ID_PARAM );
             if ( parameters != null && !parameters.contains( scopeID ) )
             {
-                url.addParameter( ScopedServletUtils.SCOPE_ID_PARAM, scopeID, true, null );
+                url.addParameter( ScopedServletUtils.SCOPE_ID_PARAM, scopeID, true );
             }
         }
     }

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java&r1=111662&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java	Sun Dec 12 12:57:59 2004
@@ -63,12 +63,12 @@
 
     public void rewriteURL( ServletContext servletContext, ServletRequest request,
                             ServletResponse response, MutableURI uri,
-                            org.apache.beehive.netui.core.urls.URLRewriter.Type type,
+                            org.apache.beehive.netui.core.urls.URLRewriter.URLType type,
                             boolean needsToBeSecure )
     {
         String tempType = URLRewriter.RESOURCE_UNSECURE;
 
-        if ( type.equals( org.apache.beehive.netui.core.urls.URLRewriter.Type.ACTION ) )
+        if ( type.equals( org.apache.beehive.netui.core.urls.URLRewriter.URLType.ACTION ) )
         {
             if ( needsToBeSecure )
             {
@@ -79,7 +79,7 @@
                 tempType = URLRewriter.ACTION_UNSECURE;
             }
         }
-        else if ( type.equals( org.apache.beehive.netui.core.urls.URLRewriter.Type.RESOURCE ) )
+        else if ( type.equals( org.apache.beehive.netui.core.urls.URLRewriter.URLType.RESOURCE ) )
         {
             if ( needsToBeSecure )
             {
@@ -102,7 +102,7 @@
             uri.setPort( newURI.getPort() );
             uri.setPath( newURI.getPath() );
             uri.setQuery( null );
-            uri.addParameters( newURI.getParameters(), true, null );
+            uri.addParameters( newURI.getParameters(), true );
             uri.setFragment( newURI.getFragment() );
         }
         catch ( java.net.URISyntaxException e )

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java&r1=111662&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java	Sun Dec 12 12:57:59 2004
@@ -113,17 +113,18 @@
         MutableURI mutableUri = null;
         try {
             mutableUri = new MutableURI( url );
-            org.apache.beehive.netui.core.urls.URLRewriter.Type tempType =
-                    org.apache.beehive.netui.core.urls.URLRewriter.Type.RESOURCE;
+            mutableUri.setEncoding( response.getCharacterEncoding() );
+            org.apache.beehive.netui.core.urls.URLRewriter.URLType tempType =
+                    org.apache.beehive.netui.core.urls.URLRewriter.URLType.RESOURCE;
             boolean needsToBeSecure = false;
 
             if ( type.equals( URLRewriter.ACTION_UNSECURE ) )
             {
-                tempType = org.apache.beehive.netui.core.urls.URLRewriter.Type.ACTION;
+                tempType = org.apache.beehive.netui.core.urls.URLRewriter.URLType.ACTION;
             }
             else if ( type.equals( URLRewriter.ACTION_SECURE ) )
             {
-                tempType = org.apache.beehive.netui.core.urls.URLRewriter.Type.ACTION;
+                tempType = org.apache.beehive.netui.core.urls.URLRewriter.URLType.ACTION;
                 needsToBeSecure = true;
             }
             else if ( type.equals( URLRewriter.RESOURCE_SECURE ) )

Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java&r1=111662&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java	(original)
+++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java	Sun Dec 12 12:57:59 2004
@@ -18,7 +18,7 @@
 package org.apache.beehive.netui.tags.html;
 
 import org.apache.beehive.netui.core.urls.MutableURI;
-import org.apache.beehive.netui.core.urls.URLRewriter;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.core.urls.URLRewriterService;
 import org.apache.beehive.netui.tags.AbstractClassicTag;
 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
@@ -92,13 +92,13 @@
         try {
             boolean needsToBeSecure = false;
             uri = new MutableURI(url);
+            uri.setEncoding( response.getCharacterEncoding() );
             if (!uri.isAbsolute() && PageFlowTagUtils.needsSecure(context, request, url, true)) {
                 needsToBeSecure = true;
             }
 
-            URLRewriterService.rewriteURL(context, request, response, uri, URLRewriter.Type.ACTION, needsToBeSecure);
-            //TODO... why no call to response.encodeURL(uri.toString()) for session ID?
-            write(uri.toString());
+            URLRewriterService.rewriteURL(context, request, response, uri, URLType.ACTION, needsToBeSecure);
+            write(response.encodeURL(uri.toString()));
         }
         catch (URISyntaxException e) {
             // report the error...

Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java&r1=111662&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java	(original)
+++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java	Sun Dec 12 12:57:59 2004
@@ -18,7 +18,7 @@
 package org.apache.beehive.netui.tags.internal;
 
 import org.apache.beehive.netui.core.urls.MutableURI;
-import org.apache.beehive.netui.core.urls.URLRewriter;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.core.urls.URLRewriterService;
 import org.apache.beehive.netui.pageflow.FlowController;
 import org.apache.beehive.netui.pageflow.FlowControllerFactory;
@@ -51,7 +51,7 @@
     /**
      * Create a mutable url object from an initial action url with query parameters 
      * and an anchor (location on page), checking if it needs to be secure then call
-     * the rewriter service using a type of {@link URLRewriter.Type.ACTION}.
+     * the rewriter service using a type of {@link URLType.ACTION}.
      *
      * @param pageContext   the current PageContext.
      * @param action        the action url to rewrite.
@@ -68,18 +68,18 @@
         String qualifiedAction = InternalUtils.qualifyAction( servletContext, action );
         String actionUrl = InternalUtils.createActionURL( ( HttpServletRequest ) request, qualifiedAction );
         MutableURI uri = new MutableURI( actionUrl );
+        uri.setEncoding( response.getCharacterEncoding() );
 
         if ( params != null )
         {
-            String encoding = response.getCharacterEncoding();
-            uri.addParameters( params, false, encoding );
+            uri.addParameters( params, false );
         }
 
         if ( location != null ) { uri.setFragment( location ); }
 
         boolean needsToBeSecure = needsSecure( servletContext, request, actionUrl, true );
         URLRewriterService.rewriteURL( servletContext, request, response, uri,
-                                       URLRewriter.Type.ACTION, needsToBeSecure );
+                                       URLType.ACTION, needsToBeSecure );
 
         return uri;
     }
@@ -87,7 +87,7 @@
     /**
      * Create a mutable url object from an initial href url with query parameters
      * and an anchor (location on page), checking if it needs to be secure then call
-     * the rewriter service using a type of {@link URLRewriter.Type.ACTION}.
+     * the rewriter service using a type of {@link URLType.ACTION}.
      *
      * @param pageContext   the current PageContext.
      * @param url           the href url to rewrite.
@@ -98,13 +98,13 @@
     public static MutableURI rewriteHrefURL( PageContext pageContext, String url, Map params, String location )
             throws URISyntaxException
     {
-        return rewriteResourceOrHrefURL( pageContext, url, params, location, URLRewriter.Type.ACTION );
+        return rewriteResourceOrHrefURL( pageContext, url, params, location, URLType.ACTION );
     }
 
     /**
      * Create a mutable url object from an initial resource url with query parameters
      * and an anchor (location on page), checking if it needs to be secure then call
-     * the rewriter service using a type of {@link URLRewriter.Type.RESOURCE}.
+     * the rewriter service using a type of {@link URLType.RESOURCE}.
      *
      * @param pageContext   the current PageContext.
      * @param url           the resource url to rewrite.
@@ -115,19 +115,20 @@
     public static MutableURI rewriteResourceURL( PageContext pageContext, String url, Map params, String location )
             throws URISyntaxException
     {
-        return rewriteResourceOrHrefURL( pageContext, url, params, location, URLRewriter.Type.RESOURCE );
+        return rewriteResourceOrHrefURL( pageContext, url, params, location, URLType.RESOURCE );
     }
 
     private static MutableURI rewriteResourceOrHrefURL( PageContext pageContext, String url, Map params,
-                                                       String location, URLRewriter.Type type )
+                                                       String location, URLType type )
             throws URISyntaxException
     {
         HttpServletResponse response = ( HttpServletResponse ) pageContext.getResponse();
         MutableURI uri = new MutableURI( url );
+        uri.setEncoding( response.getCharacterEncoding() );
+
         if ( params != null )
         {
-            String encoding = response.getCharacterEncoding();
-            uri.addParameters( params, false, encoding );
+            uri.addParameters( params, false );
         }
 
         if ( location != null ) { uri.setFragment( location ); }

Modified: incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java&r1=111662&p2=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java	(original)
+++ incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java	Sun Dec 12 12:57:59 2004
@@ -31,16 +31,41 @@
 import java.util.HashMap;
 
 /**
- * Class for creating URIs.
+ * Mutable class for creating URIs.
+ *
+ * <p> There is no checking that an instance of this class produces a legal
+ * URI reference as defined by <a href="http://www.ietf.org/rfc/rfc2396.txt">
+ * <i>RFC&nbsp;2396: Uniform Resource Identifiers (URI): Generic Syntax</i></a>.
+ * The only minimal checking for syntax is on constructors that take a String
+ * representation or the URI, a {@link URI}, or a {@link URL}.
+ * To avoid the cost of continually checking the syntax, it is up to the
+ * user to ensure that the components are set correctly. </p>
+ *
+ * <p> The setters of this class also assume that the data components are
+ * already encoded correctly for the given encoding of this URI, unless noted
+ * otherwise as in the methods to add unecoded parameters to the query.
+ * Then this class will handle the encoding.
+ * See {@link #addParameter( String name, String value, boolean encoded )}
+ * and {@link #addParameters( Map newParams, boolean encoded )}
+ * </p>
+ *
+ * <p> There is static convenience method in this class so callers can
+ * easily encode unencoded components before setting in this URI. </p>
  *
  * TODO... We need to implement some conditions for opaque URIs like mailto, etc.
- * TODO... determine what to do about constructor and initialization of path when (path == null) => opaque and URI.getPath() would return "" for non-opaue URIs.
+ * TODO... and determine what to do about constructor and init of path when (path == null) => opaque and URI.getPath() would return "" for non-opaue URIs.
  */
 public class MutableURI
 {
     /** Value used to set the port as undefined. */
     public static final int UNDEFINED_PORT = -1;
 
+    /** Value used to set the port as undefined. */
+    public static final String DEFAULT_ENCODING = "UTF-8";
+
+    /** Character encoding used for the URI. */
+    private String _encoding;
+
     /** Protocol scheme. */
     private String _scheme;
 
@@ -92,7 +117,7 @@
             throw new IllegalArgumentException( "The URI cannot be null." );
         }
 
-        // Parse this url into its component parts
+        // Parse this string into its components using URI
         URI uri = new URI( uriString );
         setScheme( uri.getScheme() );
         setUserInfo( uri.getRawUserInfo() );
@@ -151,7 +176,7 @@
      * Constructs a <code>MutableURI</code>.
      *
      * <p> This is just a convenience constructor that functions the same as
-     * {@link #MutableURI(java.net.URI)} constructor with
+     * {@link #MutableURI(URI)} constructor with
      * {@link java.net.URL#toURI()} as the argument. </p>
      *
      * <p>Note, any URL instance that complies with RFC 2396 can be converted
@@ -182,6 +207,26 @@
     }
 
     /**
+     * Set the encoding used when adding unencoded parameters.
+     *
+     * @param encoding
+     */
+    public void setEncoding( String encoding )
+    {
+        _encoding = encoding;
+    }
+
+    /**
+     * Returns the encoding that is used when adding unencoded parameters.
+     *
+     * @return encoding
+     */
+    public String getEncoding()
+    {
+        return _encoding;
+    }
+
+    /**
      * Sets the protocol/scheme.
      *
      * @param scheme protocol/scheme
@@ -368,11 +413,11 @@
             int eq = queryItem.indexOf( '=' );
             if ( eq != -1 )
             {
-                addParameter( queryItem.substring( 0, eq ).trim() , queryItem.substring( eq + 1 ).trim(), true, null );
+                addParameter( queryItem.substring( 0, eq ).trim() , queryItem.substring( eq + 1 ).trim(), true );
             }
             else
             {
-                addParameter( queryItem, null, true, null );
+                addParameter( queryItem, null, true );
             }
         }
     }
@@ -380,8 +425,12 @@
     /**
      * Returns the query string (encoded).
      *
+     * <p> It takes a String to be used to separate the parameters, usually
+     * either &quot;&amp;&quot; or &quot;&amp;amp;&quot;. The later option
+     * is typical when writing valid XML. See {@link #toXMLString()} </p>
+     *
      * @param paramSeparator The string used to separate the parameters in the
-     *                       query. (&quot;&amp;&quot; or &quot;&amp;amp;&quot;)
+     *                       query.
      * @return encoded query string.
      */
     public String getQuery( String paramSeparator )
@@ -423,8 +472,9 @@
      * <p> If the encoded flag is true then this method assumes that
      * the name and value do not need encoding or are already encoded
      * correctly. Otherwise, it translates the name and value with the
-     * character encoding and adds them to the set of parameters for
-     * the query. </p>
+     * character encoding of this URI and adds them to the set of
+     * parameters for the query. If the encoding for this URI has
+     * not been set, then the default encoding used is "UTF-8". </p>
      * <p> Multiple values for the same parameter can be set by
      * calling this method multiple times with the same name. </p>
      *
@@ -432,9 +482,8 @@
      * @param value value
      * @param encoded Flag indicating whether the names and values are
      *                already encoded.
-     * @param encoding The name of a supported character encoding.
      */
-    public void addParameter( String name, String value, boolean encoded, String encoding )
+    public void addParameter( String name, String value, boolean encoded )
     {
         if ( name == null )
         {
@@ -443,8 +492,8 @@
 
         if ( !encoded )
         {
-            name = encode( name, encoding );
-            value = encode( value, encoding );
+            name = encode( name, _encoding );
+            value = encode( value, _encoding );
         }
 
         if ( _params == null )
@@ -467,15 +516,15 @@
      * <p> If the encoded flag is true then this method assumes that
      * the name and value do not need encoding or are already encoded
      * correctly. Otherwise, it translates the name and value with the
-     * character encoding and adds them to the set of parameters for
-     * the query. </p>
+     * character encoding of this URI and adds them to the set of
+     * parameters for the query. If the encoding for this URI has
+     * not been set, then the default encoding used is "UTF-8". </p>
      *
      * @param newParams the map of new parameters to add to the URI
      * @param encoded Flag indicating whether the names and values are
      *                already encoded.
-     * @param encoding The name of a supported character encoding.
      */
-    public void addParameters( Map newParams, boolean encoded, String encoding )
+    public void addParameters( Map newParams, boolean encoded )
     {
         if ( newParams == null )
         {
@@ -498,7 +547,7 @@
             String name = ( String ) keys.next();
             String encodedName = name;
 
-            if ( !encoded ) { encodedName = encode( name, encoding ); }
+            if ( !encoded ) { encodedName = encode( name, _encoding ); }
 
             List< String > values = _params.get( encodedName );
             if ( values == null )
@@ -514,14 +563,14 @@
             }
             else if ( newValue instanceof String )
             {
-                addValue( values, ( String ) newValue, encoded, encoding );
+                addValue( values, ( String ) newValue, encoded );
             }
             else if ( newValue instanceof String[] )
             {
                 String newValues[] = ( String[] ) newValue;
                 for ( int i = 0; i < newValues.length; i++ )
                 {
-                    addValue( values, newValues[i], encoded, encoding );
+                    addValue( values, newValues[i], encoded );
                 }
             }
             else if ( newValue instanceof List )
@@ -529,21 +578,21 @@
                 Iterator newValues = ( ( List ) newValue ).iterator();
                 while ( newValues.hasNext() )
                 {
-                    addValue( values, newValues.next().toString(), encoded, encoding );
+                    addValue( values, newValues.next().toString(), encoded );
                 }
             }
             else /* Convert other objects to a string */
             {
-                addValue( values, newValue.toString(), encoded, encoding );
+                addValue( values, newValue.toString(), encoded );
             }
         }
     }
 
-    private static void addValue( List< String > list, String value, boolean encoded, String encoding )
+    private void addValue( List< String > list, String value, boolean encoded )
     {
         if ( !encoded )
         {
-            value = encode( value, encoding );
+            value = encode( value, _encoding );
         }
 
         list.add( value );
@@ -586,7 +635,16 @@
         }
         else
         {
-            return Collections.unmodifiableList( _params.get( name ) );
+            List< String > values = _params.get( name );
+
+            if ( values == null )
+            {
+                return EMPTY_LIST;
+            }
+            else
+            {
+                return Collections.unmodifiableList( values );
+            }
         }
     }
 
@@ -757,8 +815,14 @@
     }
 
     // @struts : from org.apache.struts.util.RequestUtils RC 1.1
-    // This has been modified from the strut to assume 1.4 because we ship
-    // with that.
+    // This has been modified to assume 1.4
+    /**
+     * Convenience method to encode unencoded components of a URI.
+     *
+     * @param url      the string to be encoded by {@link URLEncoder}
+     * @param encoding the character encoding to use
+     * @return         the encoded string
+     */
     public static String encode( String url, String encoding )
     {
         String encodedURL = null;
@@ -771,7 +835,7 @@
             // try utf-8 as a default encoding
             try
             {
-                encodedURL = URLEncoder.encode( url, "UTF-8" );
+                encodedURL = URLEncoder.encode( url, DEFAULT_ENCODING );
             }
             catch ( java.io.UnsupportedEncodingException ignore )
             {
@@ -804,12 +868,13 @@
                 ( _host == testURI.getHost() || ( _host != null && _host.equalsIgnoreCase( testURI.getHost() ) ) ) &&
                 _port == testURI.getPort() &&
                 ( _path == testURI.getPath() || ( _path != null && _path.equals( testURI.getPath() ) ) ) &&
-                ( _fragment == testURI.getFragment() || ( _fragment != null && _fragment.equals( testURI.getFragment() ) ) ) )
+                ( _fragment == testURI.getFragment() || ( _fragment != null && _fragment.equals( testURI.getFragment() ) ) ) &&
+                ( _encoding == testURI.getEncoding() || ( _encoding != null && _encoding.equals( testURI.getEncoding() ) ) ) )
         {
+            Map< String, List< String > > params = getParameters();
             Map< String, List< String > > testParams = testURI.getParameters();
 
-            if ( ( _params == null && testParams == null ) ||
-                    ( _params != null && _params.equals( testParams ) ) ) {
+            if ( params == testParams || ( params != null && params.equals( testParams ) ) ) {
                 return true;
             }
         }

Modified: incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java&r1=111662&p2=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java	(original)
+++ incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java	Sun Dec 12 12:57:59 2004
@@ -31,7 +31,7 @@
      * Passed to {@link URLRewriter#rewriteURL} for normal (non-resource) and resource, non-secure and
      * secure URLs.
      */
-    public enum Type { ACTION, RESOURCE }
+    public enum URLType { ACTION, RESOURCE }
 
     /**
      * Flag indicating that other rewriters are allowed to be used in the chain.
@@ -75,7 +75,7 @@
      * @param needsToBeSecure a flag indicating whether the URL should be secure (SSL required) or not
      */
     public abstract void rewriteURL( ServletContext servletContext, ServletRequest request,
-                                     ServletResponse response, MutableURI url, Type type,
+                                     ServletResponse response, MutableURI url, URLType type,
                                      boolean needsToBeSecure );
 
     /**

Modified: incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java&r1=111662&p2=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java	(original)
+++ incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java	Sun Dec 12 12:57:59 2004
@@ -17,11 +17,14 @@
  */
 package org.apache.beehive.netui.core.urls;
 
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
+import org.apache.beehive.netui.util.logging.Logger;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.io.PrintStream;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletResponse;
@@ -30,13 +33,22 @@
 /**
  * Methods for registering URL rewriters, adding URL rewriters
  * to the chain, and for rewriting URLs using registered rewriters.
+ *
+ * <p> Note that when a URLRewriter is registered with this service
+ * it is added to a chain (a List) of rewriters. When rewriting
+ * occurs, we loop through each rewriter in the list. The only exception
+ * to this is when a rewriter that does not allow other rewriters
+ * to be used is registered. This then becomes the exclusive rewriter
+ * to use and no other rewriters can be registered. </p>
  */
 public class URLRewriterService
 {
+    private static final Logger _log = Logger.getInstance( URLRewriterService.class );
+
     private static String URL_REWRITERS_KEY = "url_rewriters";
 
     /**
-     * Rewrite the given parameter name, using the registered URLRewriter.
+     * Rewrite the given parameter name, looping through the list of registered URLRewriters.
      *
      * @param servletContext the current ServletContext.
      * @param request        the current ServletRequest.
@@ -49,19 +61,9 @@
 
         if ( rewriters != null )
         {
-            URLRewriter exclusiveRewriter = getExclusiveRewriter( rewriters );
-            if ( exclusiveRewriter == null )
-            {
-                // No exclusive rewriters registered. Run through the chain.
-                for ( URLRewriter rewriter : rewriters )
-                {
-                    name = rewriter.rewriteName( servletContext, request, name );
-                }
-            }
-            else
+            for ( URLRewriter rewriter : rewriters )
             {
-                // Use just the exclusive rewriter that was registered
-                name = exclusiveRewriter.rewriteName( servletContext, request, name );
+                name = rewriter.rewriteName( servletContext, request, name );
             }
         }
 
@@ -69,7 +71,7 @@
     }
 
     /**
-     * Rewrite the given URL, using the list of registered URLRewriter objects.
+     * Rewrite the given URL, looping through the list of registered URLRewriters.
      *
      * @param servletContext the current ServletContext.
      * @param request        the current ServletRequest.
@@ -84,26 +86,16 @@
      * @see #registerURLRewriter
      */
     public static void rewriteURL( ServletContext servletContext, ServletRequest request,
-                                   ServletResponse response, MutableURI url, URLRewriter.Type type,
+                                   ServletResponse response, MutableURI url, URLType type,
                                    boolean needsToBeSecure )
     {
         ArrayList< URLRewriter > rewriters = getRewriters( request );
 
         if ( rewriters != null )
         {
-            URLRewriter exclusiveRewriter = getExclusiveRewriter( rewriters );
-            if ( exclusiveRewriter == null )
-            {
-                // No exclusive rewriters registered. Run through the chain.
-                for ( URLRewriter rewriter : rewriters )
-                {
-                    rewriter.rewriteURL( servletContext, request, response, url, type, needsToBeSecure );
-                }
-            }
-            else
+            for ( URLRewriter rewriter : rewriters )
             {
-                // Use just the exclusive rewriter that was registered
-                exclusiveRewriter.rewriteURL( servletContext, request, response, url, type, needsToBeSecure );
+                rewriter.rewriteURL( servletContext, request, response, url, type, needsToBeSecure );
             }
         }
     }
@@ -126,8 +118,12 @@
      *
      * @param request  the current ServletRequest.
      * @param rewriter the URLRewriter to register.
+     * @return <code>false</code> if a URLRewriter has been registered
+     *         that does not allow other rewriters. Otherwise, <code>true</code>
+     *         if the URLRewriter was added to the chain or already exists in
+     *         the chain.
      */
-    public static void registerURLRewriter( ServletRequest request, URLRewriter rewriter )
+    public static boolean registerURLRewriter( ServletRequest request, URLRewriter rewriter )
     {
         ArrayList< URLRewriter > rewriters = getRewriters( request );
 
@@ -139,11 +135,10 @@
         }
         else
         {
-            if ( otherRewritersAllowed( rewriters ) )
-            {
-                if ( !rewriters.contains( rewriter ) ) { rewriters.add( rewriter ); }
-            }
+            return addRewriter( rewriters, rewriter, rewriters.size() );
         }
+
+        return true;
     }
 
     /**
@@ -154,8 +149,12 @@
      * @param index    the place to insert the URLRewriter
      * @param request  the current ServletRequest.
      * @param rewriter the URLRewriter to register.
+     * @return <code>false</code> if a URLRewriter has been registered
+     *         that does not allow other rewriters. Otherwise, <code>true</code>
+     *         if the URLRewriter was added to the chain or already exists in
+     *         the chain.
      */
-    public static void registerURLRewriter( int index, ServletRequest request, URLRewriter rewriter )
+    public static boolean registerURLRewriter( int index, ServletRequest request, URLRewriter rewriter )
     {
         ArrayList< URLRewriter > rewriters = getRewriters( request );
 
@@ -167,11 +166,10 @@
         }
         else
         {
-            if ( otherRewritersAllowed( rewriters ) )
-            {
-                if ( !rewriters.contains( rewriter ) ) { rewriters.add( index, rewriter ); }
-            }
+            return addRewriter( rewriters, rewriter, index );
         }
+
+        return true;
     }
 
     private static ArrayList< URLRewriter > getRewriters( ServletRequest request )
@@ -179,30 +177,55 @@
         return ( ArrayList< URLRewriter > ) ScopedServletUtils.getScopedRequestAttribute( URL_REWRITERS_KEY, request );
     }
     
-    private static boolean otherRewritersAllowed( ArrayList< URLRewriter > rewriters )
+    private static boolean addRewriter( ArrayList< URLRewriter > rewriters, URLRewriter rewriter, int index )
     {
-        for ( URLRewriter rewriter : rewriters )
+        if ( otherRewritersAllowed( rewriters ) )
+        {
+            if ( !rewriters.contains( rewriter ) )
+            {
+                if ( !rewriter.allowOtherRewriters() )
+                {
+                    rewriters.clear();
+
+                    if ( rewriters.size() > 0 && _log.isInfoEnabled() )
+                    {
+                        StringBuilder message = new StringBuilder();
+                        message.append( "Register exclusive URLRewriter, \"");
+                        message.append( rewriter.getClass().getName() );
+                        message.append( "\". This removes any other URLRewriter objects already registered in the chain." );
+                        _log.info( message.toString() );
+                    }
+                }
+                rewriters.add( index, rewriter );
+            }
+        }
+        else
         {
-            if ( !rewriter.allowOtherRewriters() )
+            if ( _log.isInfoEnabled() )
             {
-                return false;
+                StringBuilder message = new StringBuilder();
+                message.append( "Cannot register URLRewriter, \"");
+                message.append( rewriter.getClass().getName() );
+                message.append( "\". The URLRewriter, \"" );
+                message.append( rewriters.get( 0 ).getClass().getName() );
+                message.append( "\", is already registered and does not allow other rewriters." );
+                _log.info( message.toString() );
             }
+
+            return false;
         }
 
         return true;
     }
 
-    private static URLRewriter getExclusiveRewriter( ArrayList< URLRewriter > rewriters )
+    private static boolean otherRewritersAllowed( ArrayList< URLRewriter > rewriters )
     {
-        for ( URLRewriter rewriter : rewriters )
+        if ( rewriters != null && rewriters.size() == 1 && !rewriters.get( 0 ).allowOtherRewriters() )
         {
-            if ( !rewriter.allowOtherRewriters() )
-            {
-                return rewriter;
-            }
+            return false;
         }
 
-        return null;
+        return true;
     }
 
     /**
@@ -247,8 +270,6 @@
      * Tell whether rewritten form actions should be allowed to have query parameters.  If this returns
      * <code>false</code>, then a form-tag implementation should render query parameters into hidden
      * fields on the form instead of allowing them to remain in the URL.
-     *
-     * @exclude
      */
     public static boolean allowParamsOnFormAction( ServletContext servletContext, ServletRequest request )
     {
@@ -263,5 +284,35 @@
         }
 
         return true;
+    }
+
+    /**
+     * Print out information about the chain of URLRewriters in this request.
+     *
+     * @param request the current HttpServletRequest.
+     * @param output a PrintStream to output chain of URLRewriters in this request.
+     *               If <code>null</null>, <code>System.err</code> is used.
+     */
+    public static void dumpURLRewriters( ServletRequest request, PrintStream output )
+    {
+        ArrayList< URLRewriter > rewriters = getRewriters( request );
+
+        if ( output == null ) output = System.err;
+        output.println( "*** List of URLRewriter objects: " + rewriters );
+
+        if ( rewriters != null )
+        {
+            int count = 0;
+            for ( URLRewriter rewriter : rewriters )
+            {
+                output.println( "        " + count++ + ".  " + rewriter.getClass().getName() );
+                output.println( "            allows other rewriters: " + rewriter.allowOtherRewriters() );
+                output.println( "            rewriter: " + rewriter );
+            }
+        }
+        else
+        {
+            output.println( "        No URLRewriter objects are registered with this request." );
+        }
     }
 }

Modified: incubator/beehive/trunk/netui/test/ant/junitCore.xml
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/ant/junitCore.xml?view=diff&rev=111663&p1=incubator/beehive/trunk/netui/test/ant/junitCore.xml&r1=111662&p2=incubator/beehive/trunk/netui/test/ant/junitCore.xml&r2=111663
==============================================================================
--- incubator/beehive/trunk/netui/test/ant/junitCore.xml	(original)
+++ incubator/beehive/trunk/netui/test/ant/junitCore.xml	Sun Dec 12 12:57:59 2004
@@ -42,6 +42,7 @@
             <sysproperty key="netuidrt.logdir" path="${testout.dir}"/>
             <test name="org.apache.beehive.netui.test.util.type.TypeUtilsTest" todir="${testout.dir}"/>
             <test name="org.apache.beehive.netui.test.util.config.ConfigTest" todir="${testout.dir}"/>
+            <test name="org.apache.beehive.netui.test.core.urls.MutableURITest" todir="${testout.dir}"/>
             <test name="org.apache.beehive.netui.test.databinding.expression.IndexedNameTest" todir="${testout.dir}"/>
             <test name="org.apache.beehive.netui.test.script.simpleaction.InternalExpressionUtilsTest" todir="${testout.dir}"/>
             <batchtest fork="yes" todir="${testout.dir}">
@@ -75,4 +76,4 @@
         <java classpathref="test.classpath" classname="${test.name}"/>
     </target>
 
-</project>
\ No newline at end of file
+</project>