Author: rich
Date: Mon Jan 31 20:47:19 2005
New Revision: 149370

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

 Attaching a patch that contains the following changes
to extend the URLRewritingService API to use the
URL template config support committed in rev 123030...

- Implemented a mechanism to format a URL using templates
  as a final step in the URL rewriting process.
- Integrated the default templated URL formatting with
  the new URL template config support.
- Cleaned up rewriting routines in the tags PageFlowTagsUtil
  class to use new public PageFlowUtils methods with calls
  to the new templated URL formatting and removed duplicate
  code.
- Updated tags using the PageFlowTagsUtil changes.
- Created additional junit tests for URL templates and
  formatting.
- Removed an old, unused TemplateHelper class.
- Other minor clean up (javadoc, unused import statements, etc.)"

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


Added:
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/DefaultTemplatedURLFormatter.java
   (with props)
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/FreezableMutableURI.java
   (with props)
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/TemplatedURLFormatter.java
   (with props)
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplateDescriptor.java
   (with props)
    
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/FreezableMutableURITest.java
   (with props)
    
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/
    
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplateTest.java
   (with props)
    
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urltemplates/URLTemplatesTest.java
   (with props)
Removed:
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/TemplateHelper.java
Modified:
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowContextListener.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
    
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-databinding/org/apache/beehive/netui/databinding/datagrid/util/JspUtil.java
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.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/URLRewriterService.java
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplate.java
    
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urltemplates/URLTemplates.java
    incubator/beehive/trunk/netui/test/ant/junitCore.xml
    
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/MutableURITest.java
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/pageFlowUtils/index.jsp
    
incubator/beehive/trunk/netui/test/webapps/urlTemplates/testRecorder/tests/UrlTemplates.xml
    
incubator/beehive/trunk/netui/test/webapps/urlTemplates/urlTemplates/WEB-INF/url-template-config.xml
    
incubator/beehive/trunk/netui/test/webapps/urlTemplates/urlTemplates/testUrlTemplates/index.jsp

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowContextListener.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowContextListener.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowContextListener.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowContextListener.java
 Mon Jan 31 20:47:19 2005
@@ -20,10 +20,10 @@
 //java imports
 
 //internal imports
+import org.apache.beehive.netui.core.urltemplates.URLTemplateDescriptor;
 import org.apache.beehive.netui.pageflow.internal.InternalConstants;
 import org.apache.beehive.netui.pageflow.internal.AdapterManager;
 import org.apache.beehive.netui.pageflow.internal.LegacySettings;
-import org.apache.beehive.netui.pageflow.util.UrlTemplateDescriptor;
 import org.apache.beehive.netui.pageflow.handler.Handlers;
 import org.apache.beehive.netui.util.config.ConfigUtil;
 import org.apache.beehive.netui.util.config.ConfigInitializationException;
@@ -99,6 +99,6 @@
         LegacySettings.init( servletContext );
         Handlers.init( servletContext );
         AdapterManager.initServletContext( servletContext );
-        UrlTemplateDescriptor.getInstance().load( servletContext );
+        URLTemplateDescriptor.getInstance().load( servletContext );
     }
 }

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowManagedObject.java
 Mon Jan 31 20:47:19 2005
@@ -18,9 +18,6 @@
 package org.apache.beehive.netui.pageflow;
 
 import org.apache.beehive.netui.pageflow.internal.JavaControlUtils;
-import org.apache.beehive.netui.pageflow.internal.InternalUtils;
-import org.apache.beehive.netui.pageflow.scoping.ScopedRequest;
-import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
 import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.beehive.controls.api.context.ControlBeanContext;
 import org.apache.beehive.controls.api.properties.PropertyMap;

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
 Mon Jan 31 20:47:19 2005
@@ -17,9 +17,11 @@
  */
 package org.apache.beehive.netui.pageflow;
 
+import org.apache.beehive.netui.core.urls.FreezableMutableURI;
 import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.core.urls.URLRewriterService;
+import org.apache.beehive.netui.core.urltemplates.URLTemplateDescriptor;
 import org.apache.beehive.netui.pageflow.config.PageFlowActionFormBean;
 import org.apache.beehive.netui.pageflow.internal.ActionResultImpl;
 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
@@ -1171,7 +1173,7 @@
     {
         String qualifiedAction = InternalUtils.qualifyAction( servletContext, 
actionName );
         String actionUrl = InternalUtils.createActionURL( request, 
qualifiedAction );
-        MutableURI uri = new MutableURI( actionUrl );
+        FreezableMutableURI uri = new FreezableMutableURI( actionUrl );
         uri.setEncoding( response.getCharacterEncoding() );
 
         return uri;
@@ -1186,20 +1188,20 @@
      * @param actionName the action name to convert into a fully-rewritten URI.
      * @param params the additional parameters to include in the URI query.
      * @param fragment the fragment (anchor or location) for this url.
-     * @param asValidXml flag indicating that the query of the uri should be 
written
-     *                   using the "&" entity, rather than the character, 
'&'.
+     * @param forXML flag indicating that the query of the uri should be 
written
+     *               using the "&" entity, rather than the character, '&'.
      * @return a fully-rewritten URI for the given action.
      * @throws URISyntaxException if there is a problem converting the action 
URI (derived
      *                            from processing the given action name) into 
a MutableURI.
      */
     public static String getRewrittenActionURI( ServletContext servletContext, 
HttpServletRequest request,
                                                 HttpServletResponse response, 
String actionName, Map params,
-                                                String fragment, boolean 
asValidXml )
+                                                String fragment, boolean 
forXML )
             throws URISyntaxException
     {
         String qualifiedAction = InternalUtils.qualifyAction( servletContext, 
actionName );
         String actionUrl = InternalUtils.createActionURL( request, 
qualifiedAction );
-        MutableURI uri = new MutableURI( actionUrl );
+        FreezableMutableURI uri = new FreezableMutableURI( actionUrl );
         uri.setEncoding( response.getCharacterEncoding() );
 
         if ( params != null )
@@ -1214,36 +1216,67 @@
 
         boolean needsToBeSecure = needsToBeSecure( servletContext, request, 
actionUrl, true );
         URLRewriterService.rewriteURL( servletContext, request, response, uri, 
URLType.ACTION, needsToBeSecure );
+        String key = getURLTemplateKey( URLType.ACTION, needsToBeSecure );
 
-        if ( asValidXml )
-        {
-            return uri.toXMLString();
-        }
-
-        return uri.toString();
+        return URLRewriterService.getTemplatedURL( request, uri, key, forXML );
     }
 
     /**
      * Create a fully-rewritten URI given a path and parameters.
      *
+     * <p> Calls the rewriter service using a type of [EMAIL PROTECTED] 
URLType.RESOURCE}. </p>
+     *
      * @param servletContext the current ServletContext.
      * @param request the current HttpServletRequest.
      * @param response the current HttpServletResponse.
      * @param path the path to process into a fully-rewritten URI.
      * @param params the additional parameters to include in the URI query.
      * @param fragment the fragment (anchor or location) for this URI.
-     * @param asValidXml flag indicating that the query of the uri should be 
written
-     *                   using the "&amp;" entity, rather than the character, 
'&'.
+     * @param forXML flag indicating that the query of the uri should be 
written
+     *               using the "&amp;" entity, rather than the character, '&'.
      * @return a fully-rewritten URI for the given action.
      * @throws URISyntaxException if there's a problem converting the action 
URI (derived
      *                            from processing the given action name) into 
a MutableURI.
      */
     public static String getRewrittenResourceURI( ServletContext 
servletContext, HttpServletRequest request,
                                                   HttpServletResponse 
response, String path, Map params,
-                                                  String fragment, boolean 
asValidXml )
+                                                  String fragment, boolean 
forXML )
+            throws URISyntaxException
+    {
+        return rewriteResourceOrHrefURL( servletContext, request, response, 
path, params, fragment, forXML, URLType.RESOURCE );
+    }
+
+    /**
+     * Create a fully-rewritten URI given a path and parameters.
+     *
+     * <p> Calls the rewriter service using a type of [EMAIL PROTECTED] 
URLType.ACTION}. </p>
+     *
+     * @param servletContext the current ServletContext.
+     * @param request the current HttpServletRequest.
+     * @param response the current HttpServletResponse.
+     * @param path the path to process into a fully-rewritten URI.
+     * @param params the additional parameters to include in the URI query.
+     * @param fragment the fragment (anchor or location) for this URI.
+     * @param forXML flag indicating that the query of the uri should be 
written
+     *               using the "&amp;" entity, rather than the character, '&'.
+     * @return a fully-rewritten URI for the given action.
+     * @throws URISyntaxException if there's a problem converting the action 
URI (derived
+     *                            from processing the given action name) into 
a MutableURI.
+     */
+    public static String getRewrittenHrefURI( ServletContext servletContext, 
HttpServletRequest request,
+                                              HttpServletResponse response, 
String path, Map params,
+                                              String fragment, boolean forXML )
+            throws URISyntaxException
+    {
+        return rewriteResourceOrHrefURL( servletContext, request, response, 
path, params, fragment, forXML, URLType.ACTION );
+    }
+
+    private static String rewriteResourceOrHrefURL( ServletContext 
servletContext, HttpServletRequest request,
+                                                    HttpServletResponse 
response, String path, Map params,
+                                                    String fragment, boolean 
forXML, URLType urlType )
             throws URISyntaxException
     {
-        MutableURI uri = new MutableURI( path );
+        FreezableMutableURI uri = new FreezableMutableURI( path );
         uri.setEncoding( response.getCharacterEncoding() );
 
         if ( params != null )
@@ -1256,25 +1289,28 @@
             uri.setFragment( fragment );
         }
 
-        if ( !uri.isAbsolute() )
+        if ( uri.isAbsolute() )
         {
-            if ( !path.startsWith( "/" ) && !path.equals( "" ) )
+            if ( forXML )
             {
-                String reqUri = request.getRequestURI();
-                String reqPath = reqUri.substring( 0, reqUri.lastIndexOf( '/' 
) + 1 );
-                uri.setPath( reqPath + uri.getPath() );
+                return uri.getURIStringForXML();
             }
 
-            boolean needsToBeSecure = needsToBeSecure( servletContext, 
request, uri.getPath(), true );
-            URLRewriterService.rewriteURL( servletContext, request, response, 
uri, URLType.RESOURCE, needsToBeSecure );
+            return uri.getURIString();
         }
 
-        if ( asValidXml )
+        if ( ( path.length() != 0 ) && ( path.charAt( 0 ) !=  '/' ) )
         {
-            return uri.toXMLString();
+            String reqUri = request.getRequestURI();
+            String reqPath = reqUri.substring( 0, reqUri.lastIndexOf( '/' ) + 
1 );
+            uri.setPath( reqPath + uri.getPath() );
         }
 
-        return uri.toString();
+        boolean needsToBeSecure = needsToBeSecure( servletContext, request, 
uri.getPath(), true );
+        URLRewriterService.rewriteURL( servletContext, request, response, uri, 
urlType, needsToBeSecure );
+        String key = getURLTemplateKey( urlType, needsToBeSecure );
+
+        return URLRewriterService.getTemplatedURL( request, uri, key, forXML );
     }
 
     /**
@@ -1327,5 +1363,42 @@
         }
 
         return secure;
+    }
+
+    /**
+     * Returns a key for the URL template type given the URL type and a
+     * flag indicating a secure URL or not.
+     *
+     * @param urlType the type of URL (ACTION, RESOURCE).
+     * @param needsToBeSecure indicates that the template should be for a 
secure URL.
+     * @return the key/type of template to use.
+     */
+    public static String getURLTemplateKey( URLType urlType, boolean 
needsToBeSecure )
+    {
+        String key = URLTemplateDescriptor.ACTION_TEMPLATE;
+        if ( urlType.equals( URLType.ACTION ) )
+        {
+            if ( needsToBeSecure )
+            {
+                key = URLTemplateDescriptor.SECURE_ACTION_TEMPLATE;
+            }
+            else
+            {
+                key = URLTemplateDescriptor.ACTION_TEMPLATE;
+            }
+        }
+        else if ( urlType.equals( URLType.RESOURCE ) )
+        {
+            if ( needsToBeSecure )
+            {
+                key = URLTemplateDescriptor.SECURE_RESOURCE_TEMPLATE;
+            }
+            else
+            {
+                key = URLTemplateDescriptor.RESOURCE_TEMPLATE;
+            }
+        }
+
+        return key;
     }
 }

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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -17,18 +17,15 @@
  */
 package org.apache.beehive.netui.pageflow.internal;
 
-import java.net.URISyntaxException;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 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.ServletContainerAdapter;
-import org.apache.beehive.netui.pageflow.util.TemplateHelper;
 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
 import org.apache.beehive.netui.util.logging.Logger;
 
@@ -64,7 +61,7 @@
                     {
                         if (_log.isWarnEnabled())
                         {
-                            _log.warn("Could not rewrite URL " + 
url.toString() + " to be secure because a secure port was" +
+                            _log.warn("Could not rewrite URL " + 
url.getURIString() + " to be secure because a secure port was" +
                                       " not provided by the 
ServletContainerAdapter.");
                         }
                     }
@@ -84,7 +81,7 @@
                     {
                         if (_log.isWarnEnabled())
                         {
-                            _log.warn("Could not rewrite URL " + 
url.toString() + " to be non-secure because a secure port was" +
+                            _log.warn("Could not rewrite URL " + 
url.getURIString() + " to be non-secure because a secure port was" +
                                       " not provided by the 
ServletContainerAdapter.");
                         }
                     }
@@ -105,59 +102,6 @@
                 url.addParameter( ScopedServletUtils.SCOPE_ID_PARAM, scopeID, 
true );
             }
         }
-
-        // TODO... fix/modify TemplateHelper to use MutableURI and make a 
separate step.
-        // Look for the template config.  If it is found,
-        // 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( URLType.ACTION ) )
-        {
-            if ( needsToBeSecure )
-            {
-                templateType = 
org.apache.beehive.netui.pageflow.util.URLRewriter.ACTION_SECURE;
-            }
-            else
-            {
-                templateType = 
org.apache.beehive.netui.pageflow.util.URLRewriter.ACTION_UNSECURE;
-            }
-        }
-        else if ( type.equals( URLType.RESOURCE ) )
-        {
-            if ( needsToBeSecure )
-            {
-                templateType = 
org.apache.beehive.netui.pageflow.util.URLRewriter.RESOURCE_SECURE;
-            }
-            else
-            {
-                templateType = 
org.apache.beehive.netui.pageflow.util.URLRewriter.RESOURCE_UNSECURE;
-            }
-        }
-        TemplateHelper templateHelper = new TemplateHelper( ( 
HttpServletRequest ) request, ( HttpServletResponse ) response );
-        if ( templateHelper.hasTemplateRef( templateType ) )
-        {
-            // TODO.. this is a hack having to go back and forth between 
MutableURI and String.
-            String templateName = templateHelper.getTemplateName( templateType 
);
-            templateHelper.setTemplate( templateName );
-            templateHelper.setUrl( url.toString() );
-            String templateURI = templateHelper.toString();
-            try
-            {
-                MutableURI uri = new MutableURI( templateURI );
-                url.setScheme( uri.getScheme() );
-                url.setUserInfo( uri.getUserInfo() );
-                url.setHost( uri.getHost() );
-                url.setPort( uri.getPort() );
-                url.setPath( uri.getPath() );
-                url.setQuery( null );
-                url.addParameters( uri.getParameters(), true );
-                url.setFragment( uri.getFragment() );
-            }
-            catch ( URISyntaxException e )
-            {
-                _log.error( "Invalid URI from template " + templateName + ": " 
+ templateURI );
-            }
-        } // end temporary "if" statement for TemplateHelper
     }
 
     private static void internalRewriteUrl( MutableURI url, String protocol, 
int port, String serverName )

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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -92,7 +92,7 @@
         }
 
         String rewrittenURL = _oldURLRewriter.rewriteURL( servletContext, 
request, response,
-                                                          uri.toString(), 
tempType );
+                                                          uri.getURIString(), 
tempType );
         try
         {
             MutableURI newURI = new MutableURI( rewrittenURL );

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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -17,7 +17,7 @@
  */
 package org.apache.beehive.netui.pageflow.util;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
+import org.apache.beehive.netui.core.urls.FreezableMutableURI;
 import org.apache.beehive.netui.pageflow.PageFlowUtils;
 import org.apache.beehive.netui.pageflow.SecurityProtocol;
 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
@@ -37,7 +37,6 @@
  */
 public class URLRewriterService
 {
-    private static URLRewriter defaultRewriter = new DefaultURLRewriter();
     private static String URL_REWRITER_KEY = "url_rewriter";
     private static final Logger _log = Logger.getInstance( 
URLRewriterService.class );
 
@@ -110,9 +109,9 @@
     public static String rewriteURL(ServletContext servletContext, 
ServletRequest request, ServletResponse response, String url, String type, 
boolean doEncode)
     {
         String rewrittenURL = null;
-        MutableURI mutableUri = null;
+        FreezableMutableURI mutableUri = null;
         try {
-            mutableUri = new MutableURI( url );
+            mutableUri = new FreezableMutableURI( url );
             mutableUri.setEncoding( response.getCharacterEncoding() );
             org.apache.beehive.netui.core.urls.URLRewriter.URLType tempType =
                     
org.apache.beehive.netui.core.urls.URLRewriter.URLType.RESOURCE;
@@ -134,7 +133,14 @@
 
             org.apache.beehive.netui.core.urls.URLRewriterService.rewriteURL( 
servletContext, request, response,
                                                                               
mutableUri, tempType, needsToBeSecure );
-            rewrittenURL = mutableUri.toString();
+
+            //
+            // No need to call the new URLRewriterService.getTemplatedURL(). 
The old rewriters
+            // included the templating step within the rewriting process, 
returning a formatted
+            // String. And since the old rewriter will be exclusive, not 
chained, just return
+            // the rewritten URI.
+            //
+            rewrittenURL = mutableUri.getURIString();
         }
         catch ( java.net.URISyntaxException e )
         {
@@ -145,7 +151,7 @@
         if (doEncode)
         {
             HttpServletResponse httpResponse = (HttpServletResponse) response;
-            rewrittenURL = 
httpResponse.encodeRedirectURL(rewrittenURL.toString());
+            rewrittenURL = httpResponse.encodeRedirectURL(rewrittenURL);
         }
 
         return rewrittenURL;

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/util/JspUtil.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/util/JspUtil.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/util/JspUtil.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/util/JspUtil.java
 Mon Jan 31 20:47:19 2005
@@ -27,10 +27,17 @@
 
 import org.apache.struts.Globals;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
 
+import org.apache.beehive.netui.core.urls.FreezableMutableURI;
+import org.apache.beehive.netui.core.urls.URLRewriterService;
+import org.apache.beehive.netui.core.urls.URLRewriter;
+import org.apache.beehive.netui.pageflow.PageFlowUtils;
+import org.apache.beehive.netui.pageflow.internal.InternalUtils;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletContext;
+
 public class JspUtil {
 
     /* do not construct */
@@ -63,21 +70,72 @@
         }
 
         // Generate the opening anchor element
-        MutableURI uri = null;
+        String uri = null;
         if(action != null)
-            uri = PageFlowTagUtils.rewriteActionURL(pageContext, action, 
params, location);
+            // ToDo: remove tempRewriteURL() and call the PageFlowTagUtils 
routines, then update tests.
+            //uri = PageFlowTagUtils.rewriteActionURL(pageContext, action, 
params, location);
+            uri = tempRewriteURL(pageContext, true, action, params, location);
         else if(href != null)
-            uri = PageFlowTagUtils.rewriteHrefURL(pageContext, href, params, 
location);
+            //uri = PageFlowTagUtils.rewriteHrefURL(pageContext, href, params, 
location);
+            uri = tempRewriteURL(pageContext, false, href, params, location);
         else
             return 
((HttpServletRequest)pageContext.getRequest()).getPathTranslated();
 
         assert uri != null;
 
-        /* todo: shouldn't this also be a call to 
response.encodeURL(uri.toString()) for session ID? */
-        if(uri.isAbsolute())
-            return uri.toXMLString();
-        else
-            return uri.toString();
+        // todo: shouldn't this also be a call to response.encodeURL(uri) for 
session ID?
+        //HttpServletResponse response = 
(HttpServletResponse)pageContext.getResponse();
+        //return response.encodeURL(uri);
+        return uri;
+    }
+
+    // ToDo: remove this method
+    // temporary local method until we move to PageFlowTagUtils routines, then 
update tests
+    // with respect to the HTML vs. XHTML format of the query in the URLs.
+    private static String tempRewriteURL(PageContext pageContext, boolean 
isAction, String actionOrHref, Map params, String location)
+            throws URISyntaxException
+    {
+        ServletContext servletContext = pageContext.getServletContext();
+        HttpServletRequest request = (HttpServletRequest) 
pageContext.getRequest();
+        HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
+        String url = actionOrHref;
+        URLRewriter.URLType urlType = URLRewriter.URLType.RESOURCE;
+        if (isAction) {
+            String qualifiedAction = 
InternalUtils.qualifyAction(servletContext, actionOrHref);
+            url = InternalUtils.createActionURL(request, qualifiedAction);
+            urlType = URLRewriter.URLType.ACTION;
+        }
+
+        FreezableMutableURI uri = new FreezableMutableURI(url);
+        uri.setEncoding(response.getCharacterEncoding());
+        if (params != null)
+            uri.addParameters(params, false);
+        if (location != null)
+            uri.setFragment(location);
+
+        if (!isAction) {
+            if (uri.isAbsolute()) {
+                // this is the place that seems broken. we should be checking
+                // if this is an xhtml doc or not!!!
+                return uri.getURIStringForXML();
+            }
+
+            if ((actionOrHref.length() != 0) && (actionOrHref.charAt(0) !=  
'/')) {
+                String reqUri = request.getRequestURI();
+                String reqPath = reqUri.substring(0, reqUri.lastIndexOf('/') + 
1);
+                uri.setPath(reqPath + uri.getPath());
+            }
+        }
+
+        boolean needsToBeSecure = 
PageFlowUtils.needsToBeSecure(servletContext, request, uri.getPath(), true);
+        URLRewriterService.rewriteURL(servletContext, request, response, uri, 
urlType, needsToBeSecure);
+        String key = PageFlowUtils.getURLTemplateKey(urlType, needsToBeSecure);
+
+        boolean forXML = false;
+        if (uri.isAbsolute())
+            forXML = true;
+
+        return URLRewriterService.getTemplatedURL(request, uri, key, forXML);
     }
 
     /* todo: need to combine this with the getLocale(...) call in 
AbstractClassicTag */

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
 Mon Jan 31 20:47:19 2005
@@ -1,6 +1,5 @@
 package org.apache.beehive.netui.tags.html;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
 import org.apache.beehive.netui.tags.ByRef;
 import org.apache.beehive.netui.tags.HtmlUtils;
@@ -16,6 +15,7 @@
 
 import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.JspException;
 import java.net.URISyntaxException;
 import java.util.HashMap;
@@ -392,7 +392,7 @@
             }
             
             // Generate the opening anchor element
-            MutableURI uri = null;
+            String uri = null;
             try {
                 if (_action != null) {
                     uri = PageFlowTagUtils.rewriteActionURL(pageContext, 
_action, _params, _location);
@@ -414,13 +414,8 @@
                     return false;
             }
             else {
-                //TODO... shouldn't this also be a call to 
response.encodeURL(uri.toString()) for session ID?
-                if (uri.isAbsolute()) {
-                    _state.href = uri.toXMLString();
-                }
-                else {
-                    _state.href = qualifyUrlToContext(uri.toString());
-                }
+                HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
+                _state.href = response.encodeURL(uri);
             }
         }
 

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
 Mon Jan 31 20:47:19 2005
@@ -19,6 +19,7 @@
 
 import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.core.urls.URLRewriterService;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.pageflow.FlowController;
 import org.apache.beehive.netui.pageflow.PageFlowUtils;
 import org.apache.beehive.netui.pageflow.handler.Handlers;
@@ -51,10 +52,13 @@
 import javax.servlet.http.HttpSession;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 
 /**
  * This tag represents an input form, associated with a bean whose
@@ -724,12 +728,16 @@
         if (_state.method == null)
             _state.method = FORM_POST;
 
-        // encode the action
-        MutableURI actionUrl = null;
+        // Encode the action
+        // If the rewritten form action contains request parameters, turn them 
into hidden fields --
+        // it's not legal to include them in the action URI on a GET.
+        LinkedHashMap<String, List<String>> extraHiddenParams = new 
LinkedHashMap<String, List<String>>();
+        HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
+        String actionUrl = null;
         try {
-            actionUrl = PageFlowTagUtils.rewriteActionURL(pageContext, 
_state.action, null, _location);
+            actionUrl = rewriteActionURL(servletContext, request, response, 
extraHiddenParams);
         }
-        catch (java.net.URISyntaxException e) {
+        catch (URISyntaxException e) {
             // report the error...
             logger.error(Bundle.getString("Tags_URISyntaxException"));
             String s = Bundle.getString("Tags_Form_URLException",
@@ -737,31 +745,8 @@
             registerTagError(s, e);
         }
 
-        // If the rewritten form action contains request parameters, turn them 
into hidden fields --
-        // it's not legal to include them in the action URI on a GET.
-        Map extraHiddenParams = null;
-        if (actionUrl != null && _state.method != null && 
_state.method.equalsIgnoreCase(FORM_GET)
-                && 
!URLRewriterService.allowParamsOnFormAction(pageContext.getServletContext(), 
request)) {
-            extraHiddenParams = actionUrl.getParameters();
-            actionUrl.setQuery(null);
-        }
-
-        // Add a scope-ID hidden input, if there's one on this tag, or one in 
the request.
-        String targetScope = (_targetScope != null) ? _targetScope : 
request.getParameter(ScopedServletUtils.SCOPE_ID_PARAM);
-        if (targetScope != null) {
-            if (_params == null) {
-                _params = new HashMap();
-            }
-            _params.put(ScopedServletUtils.SCOPE_ID_PARAM, targetScope);
-            // If there's one on the URL, we're replacing it with a hidden 
param.
-            if (actionUrl != null) {
-                actionUrl.removeParameter(ScopedServletUtils.SCOPE_ID_PARAM);
-            }
-        }
-
-        HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
         if (actionUrl != null) {
-            _state.action = response.encodeURL(actionUrl.toString());
+            _state.action = response.encodeURL(actionUrl);
         }
 
         WriteRenderAppender writer = new WriteRenderAppender(pageContext);
@@ -804,14 +789,11 @@
         }
 
         // add the extra hidden parameters
-        if (extraHiddenParams != null) {
-            Iterator names = extraHiddenParams.keySet().iterator();
-            while (names.hasNext()) {
-                String name = (String) names.next();
-                List valueList = (List) extraHiddenParams.get(name);
-                Iterator values = valueList.iterator();
-                while (values.hasNext()) {
-                    writeHiddenParam(name, (String) values.next(), writer, 
request, true);
+        if (extraHiddenParams != null && extraHiddenParams.size() > 0) {
+            for (String name : extraHiddenParams.keySet()) {
+                for ( String value : extraHiddenParams.get( name ) )
+                {
+                    writeHiddenParam(name, value, writer, request, true);
                 }
             }
         }
@@ -906,6 +888,58 @@
         TagRenderingBase hiddenTag = 
TagRenderingBase.Factory.getRendering(TagRenderingBase.INPUT_HIDDEN_TAG, req);
         hiddenTag.doStartTag(results, _hiddenState);
         hiddenTag.doEndTag(results);
+    }
+
+    /*
+     * We have this local method because the Form may have the condition to 
manipulate the
+     * URL and write out action parameters as hidden fields.
+     *
+     * This method will rewrite the URL via the rewriter service, then if 
needed, pull off
+     * extra parameters from the rewritten URL to be turned into hidden 
fields, and finally
+     * runs the modified URL through the rewriter service's templated URL 
formatting.
+     */
+    private String rewriteActionURL(ServletContext servletContext, 
HttpServletRequest request,
+                                    HttpServletResponse response, 
LinkedHashMap<String, List<String>> extraHiddenParams)
+            throws URISyntaxException
+    {
+        String qualifiedAction = InternalUtils.qualifyAction(servletContext, 
_state.action);
+        String actionUrl = InternalUtils.createActionURL(request, 
qualifiedAction);
+        MutableURI uri = new MutableURI(actionUrl);
+        uri.setEncoding(response.getCharacterEncoding());
+
+        boolean needsToBeSecure = 
PageFlowUtils.needsToBeSecure(servletContext, request, actionUrl, true);
+        URLRewriterService.rewriteURL(servletContext, request, response, uri, 
URLType.ACTION, needsToBeSecure);
+
+        // Add a scope-ID hidden input, if there's one on this tag, or one in 
the request.
+        String targetScope = (_targetScope != null) ? _targetScope : 
request.getParameter(ScopedServletUtils.SCOPE_ID_PARAM);
+        if (targetScope != null) {
+            if (_params == null) {
+                _params = new HashMap();
+            }
+            _params.put(ScopedServletUtils.SCOPE_ID_PARAM, targetScope);
+            // If there's one on the URL, we're replacing it with a hidden 
param.
+            if (uri != null) {
+                uri.removeParameter(ScopedServletUtils.SCOPE_ID_PARAM);
+            }
+        }
+
+        // Check if the rewritten form action contains request parameters that 
need
+        // to be turned into hidden fields -- shouldn't include them in the 
action
+        // URI on a GET.
+        boolean forXML = false;
+        if (_state.method != null && _state.method.equalsIgnoreCase(FORM_GET)
+                && !URLRewriterService.allowParamsOnFormAction(servletContext, 
request)) {
+            extraHiddenParams.putAll( uri.getParameters() );
+        }
+        else {
+            // Params are allowed on the form action so see if this is for 
XHTML
+            forXML = TagRenderingBase.Factory.isXHTML(request);
+        }
+
+        String key = PageFlowUtils.getURLTemplateKey( URLType.ACTION, 
needsToBeSecure );
+        String rewrittenURI = URLRewriterService.getTemplatedURL(request, uri, 
key, forXML);
+
+        return rewrittenURI;
     }
 
     /**

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
 Mon Jan 31 20:47:19 2005
@@ -17,7 +17,6 @@
  */
 package org.apache.beehive.netui.tags.html;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
 import org.apache.beehive.netui.tags.rendering.ImageTag;
@@ -305,7 +304,7 @@
 
         // Generate the name definition or image element
 
-        MutableURI uri = null;
+        String uri = null;
         if (_state.src != null) {
             try {
                 uri = PageFlowTagUtils.rewriteResourceURL(pageContext, 
_state.src, _params, _location);
@@ -319,7 +318,7 @@
         }
 
         if (uri != null) {
-            _state.src = ((HttpServletResponse) 
pageContext.getResponse()).encodeURL(uri.toString());
+            _state.src = ((HttpServletResponse) 
pageContext.getResponse()).encodeURL(uri);
         }
 
         // we assume that tagId will over have override id if both

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
 Mon Jan 31 20:47:19 2005
@@ -17,7 +17,6 @@
  */
 package org.apache.beehive.netui.tags.html;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.tags.ByRef;
 import org.apache.beehive.netui.tags.IHtmlAccessable;
 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
@@ -411,8 +410,8 @@
         HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
         if (_imgState.src != null) {
             try {
-                MutableURI uri = 
PageFlowTagUtils.rewriteResourceURL(pageContext, _imgState.src, null, null);
-                _imgState.src = response.encodeURL(uri.toString());
+                String uri = PageFlowTagUtils.rewriteResourceURL(pageContext, 
_imgState.src, null, null);
+                _imgState.src = response.encodeURL(uri);
             }
             catch (URISyntaxException e) {
                 // report the error...
@@ -425,8 +424,8 @@
         // set the rollover image
         if (_rolloverImage != null) {
             try {
-                MutableURI uri = 
PageFlowTagUtils.rewriteResourceURL(pageContext, _rolloverImage, null, null);
-                _rolloverImage = 
response.encodeURL(qualifyUrlToContext(uri.toString()));
+                String uri = PageFlowTagUtils.rewriteResourceURL(pageContext, 
_rolloverImage, null, null);
+                _rolloverImage = response.encodeURL(qualifyUrlToContext(uri));
             }
             catch (URISyntaxException e) {
                 // report the error...

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java?view=diff&r1=149369&r2=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java
 Mon Jan 31 20:47:19 2005
@@ -17,7 +17,6 @@
  */
 package org.apache.beehive.netui.tags.html;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
 import org.apache.beehive.netui.tags.IHtmlAccessable;
 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
 import org.apache.beehive.netui.tags.javascript.CoreScriptFeature;
@@ -305,8 +304,8 @@
         tmp = src();
         if (tmp != null) {
             try {
-                MutableURI uri = 
PageFlowTagUtils.rewriteResourceURL(pageContext, tmp, null, null);
-                _state.src = response.encodeURL(uri.toString());
+                String uri = PageFlowTagUtils.rewriteResourceURL(pageContext, 
tmp, null, null);
+                _state.src = response.encodeURL(uri);
             }
             catch (URISyntaxException e) {
                 // report the error...
@@ -327,8 +326,8 @@
             }
 
             try {
-                MutableURI uri = 
PageFlowTagUtils.rewriteResourceURL(pageContext, _rolloverImage, null, null);
-                _rolloverImage = 
response.encodeURL(qualifyUrlToContext(uri.toString()));
+                String uri = PageFlowTagUtils.rewriteResourceURL(pageContext, 
_rolloverImage, null, null);
+                _rolloverImage = response.encodeURL(qualifyUrlToContext(uri));
             }
             catch (URISyntaxException e) {
                 // report the error...

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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -17,11 +17,12 @@
  */
 package org.apache.beehive.netui.tags.html;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
+import org.apache.beehive.netui.core.urls.FreezableMutableURI;
 import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
 import org.apache.beehive.netui.core.urls.URLRewriterService;
 import org.apache.beehive.netui.pageflow.PageFlowUtils;
 import org.apache.beehive.netui.tags.AbstractClassicTag;
+import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
 import org.apache.beehive.netui.util.Bundle;
 
 import javax.servlet.ServletContext;
@@ -88,17 +89,20 @@
         HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
         ServletContext context = pageContext.getServletContext();
 
-        MutableURI uri = null;
+        FreezableMutableURI uri = null;
         try {
             boolean needsToBeSecure = false;
-            uri = new MutableURI(url);
+            uri = new FreezableMutableURI(url);
             uri.setEncoding(response.getCharacterEncoding());
             if (!uri.isAbsolute() && PageFlowUtils.needsToBeSecure(context, 
request, url, true)) {
                 needsToBeSecure = true;
             }
 
             URLRewriterService.rewriteURL(context, request, response, uri, 
URLType.ACTION, needsToBeSecure);
-            write(response.encodeURL(uri.toString()));
+            String key = PageFlowUtils.getURLTemplateKey( URLType.ACTION, 
needsToBeSecure );
+            boolean forXML = TagRenderingBase.Factory.isXHTML( request );
+            String uriString = URLRewriterService.getTemplatedURL(request, 
uri, key, forXML);
+            write(response.encodeURL(uriString));
         }
         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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -17,15 +17,13 @@
  */
 package org.apache.beehive.netui.tags.internal;
 
-import org.apache.beehive.netui.core.urls.MutableURI;
 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.PageFlowConstants;
 import org.apache.beehive.netui.pageflow.PageFlowUtils;
 import org.apache.beehive.netui.pageflow.config.PageFlowActionMapping;
 import org.apache.beehive.netui.pageflow.internal.InternalConstants;
-import org.apache.beehive.netui.pageflow.internal.InternalUtils;
+import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
 import org.apache.struts.Globals;
 import org.apache.struts.action.ActionMapping;
 import org.apache.struts.config.ActionConfig;
@@ -42,113 +40,76 @@
 /**
  * This is a utility class for the beehive tags with routines for helping with 
URL rewriting.
  *
- * <p> Includes methods to create a mutable url objects based on an initial 
url with query
+ * <p> Includes methods to create a fully-rewritten url based on an initial 
url with query
  * parameters and an anchor (location on page), checking if it needs to be 
secure and
- * rewriting. There's also a method to check if if a url is an action.
+ * rewriting. There's also a method to check if a url is an action. </p>
  */
 public class PageFlowTagUtils
 {
     /**
-     * Create a mutable url object from an initial action url with query 
parameters
+     * Create a fully-rewritten url 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 [EMAIL PROTECTED] URLType.ACTION}.
      * @param pageContext the current PageContext.
      * @param action      the action url to rewrite.
      * @param params      the query parameters for this url.
      * @param location    the location (anchor or fragment) for this url.
-     * @return a mutable uri that has been run through the URL rewriter 
service.
+     * @return a uri that has been run through the URL rewriter service.
      */
-    public static MutableURI rewriteActionURL(PageContext pageContext, String 
action, Map params, String location)
+    public static String rewriteActionURL(PageContext pageContext, String 
action, Map params, String location)
             throws URISyntaxException
     {
         ServletContext servletContext = pageContext.getServletContext();
         HttpServletRequest request = (HttpServletRequest) 
pageContext.getRequest();
         HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
-        String qualifiedAction = InternalUtils.qualifyAction(servletContext, 
action);
-        String actionUrl = InternalUtils.createActionURL(request, 
qualifiedAction);
-        MutableURI uri = new MutableURI(actionUrl);
-        uri.setEncoding(response.getCharacterEncoding());
-
-        if (params != null) {
-            uri.addParameters(params, false);
-        }
-
-        if (location != null) {
-            uri.setFragment(location);
-        }
-
-        boolean needsToBeSecure = 
PageFlowUtils.needsToBeSecure(servletContext, request, actionUrl, true);
-        URLRewriterService.rewriteURL(servletContext, request, response, uri,
-                URLType.ACTION, needsToBeSecure);
-
-        return uri;
+        boolean forXML = TagRenderingBase.Factory.isXHTML( request );
+        return PageFlowUtils.getRewrittenActionURI(servletContext, request, 
response, action, params, location, forXML);
     }
 
     /**
-     * Create a mutable url object from an initial href url with query 
parameters
+     * Create a fully-rewritten url 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 [EMAIL PROTECTED] URLType.ACTION}.
      * @param pageContext the current PageContext.
      * @param url         the href url to rewrite.
      * @param params      the query parameters for this url.
      * @param location    the location (anchor or fragment) for this url.
-     * @return a mutable uri that has been run through the URL rewriter 
service.
+     * @return a url that has been run through the URL rewriter service.
+     *
+     * @see PageFlowUtils#getRewrittenHrefURI(javax.servlet.ServletContext, 
javax.servlet.http.HttpServletRequest,
+     *              javax.servlet.http.HttpServletResponse, String, 
java.util.Map, String, boolean)
      */
-    public static MutableURI rewriteHrefURL(PageContext pageContext, String 
url, Map params, String location)
+    public static String rewriteHrefURL(PageContext pageContext, String url, 
Map params, String location)
             throws URISyntaxException
     {
-        return rewriteResourceOrHrefURL(pageContext, url, params, location, 
URLType.ACTION);
+        ServletContext servletContext = pageContext.getServletContext();
+        HttpServletRequest request = (HttpServletRequest) 
pageContext.getRequest();
+        HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
+        boolean forXML = TagRenderingBase.Factory.isXHTML( request );
+        return PageFlowUtils.getRewrittenHrefURI(servletContext, request, 
response, url, params, location, forXML);
     }
 
     /**
-     * Create a mutable url object from an initial resource url with query 
parameters
+     * Create a fully-rewritten url 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 [EMAIL PROTECTED] 
URLType.RESOURCE}.
      * @param pageContext the current PageContext.
      * @param url         the resource url to rewrite.
      * @param params      the query parameters for this url.
      * @param location    the location (anchor or fragment) for this url.
-     * @return a mutable uri that has been run through the URL rewriter 
service.
+     * @return a url that has been run through the URL rewriter service.
+     *
+     * @see 
PageFlowUtils#getRewrittenResourceURI(javax.servlet.ServletContext, 
javax.servlet.http.HttpServletRequest,
+     *              javax.servlet.http.HttpServletResponse, String, 
java.util.Map, String, boolean)
      */
-    public static MutableURI rewriteResourceURL(PageContext pageContext, 
String url, Map params, String location)
-            throws URISyntaxException
-    {
-        return rewriteResourceOrHrefURL(pageContext, url, params, location, 
URLType.RESOURCE);
-    }
-
-    private static MutableURI rewriteResourceOrHrefURL(PageContext 
pageContext, String url, Map params,
-                                                       String location, 
URLType type)
+    public static String rewriteResourceURL(PageContext pageContext, String 
url, Map params, String location)
             throws URISyntaxException
     {
-        HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
-        MutableURI uri = new MutableURI(url);
-        uri.setEncoding(response.getCharacterEncoding());
-
-        if (params != null) {
-            uri.addParameters(params, false);
-        }
-
-        if (location != null) {
-            uri.setFragment(location);
-        }
-
-        if (uri.isAbsolute()) {
-            return uri;
-        }
-
-        HttpServletRequest request = (HttpServletRequest) 
pageContext.getRequest();
-        if (!url.startsWith("/") && !url.equals("")) {
-            String reqUri = request.getRequestURI();
-            String path = reqUri.substring(0, reqUri.lastIndexOf('/') + 1);
-            uri.setPath(path + uri.getPath());
-        }
-
         ServletContext servletContext = pageContext.getServletContext();
-        boolean needsToBeSecure = 
PageFlowUtils.needsToBeSecure(servletContext, request, uri.getPath(), true);
-        URLRewriterService.rewriteURL(servletContext, request, response, uri,
-                type, needsToBeSecure);
-
-        return uri;
+        HttpServletRequest request = (HttpServletRequest) 
pageContext.getRequest();
+        HttpServletResponse response = (HttpServletResponse) 
pageContext.getResponse();
+        boolean forXML = TagRenderingBase.Factory.isXHTML( request );
+        return PageFlowUtils.getRewrittenResourceURI(servletContext, request, 
response, url, params, location, forXML);
     }
 
     /**

Added: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/DefaultTemplatedURLFormatter.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/DefaultTemplatedURLFormatter.java?view=auto&rev=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/DefaultTemplatedURLFormatter.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/DefaultTemplatedURLFormatter.java
 Mon Jan 31 20:47:19 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.core.urls;
+
+import org.apache.beehive.netui.core.urltemplates.URLTemplate;
+import org.apache.beehive.netui.core.urltemplates.URLTemplateDescriptor;
+
+import javax.servlet.ServletRequest;
+
+
+/**
+ * Default implementation of TemplatedURLFormatter for formatting URLs
+ * based on templates from a URL template config file.
+ */
+public class DefaultTemplatedURLFormatter implements TemplatedURLFormatter
+{
+    private static final String DEFAULT_TEMPLATE_REF = "default-url-templates";
+
+    public String getTemplatedURL( ServletRequest request, MutableURI uri, 
String key, boolean forXML )
+    {
+        // Look for the template config and get the right template.
+        // If it is found, apply the value to the template.
+        String result = null;
+        String templateName = 
URLTemplateDescriptor.getInstance().getURLTemplateRef( DEFAULT_TEMPLATE_REF, 
key );
+
+        if ( templateName != null )
+        {
+            URLTemplate template = 
URLTemplateDescriptor.getInstance().getURLTemplate( templateName );
+            result = formatURIWithTemplate( request, uri, forXML, template );
+        }
+        else
+        {
+            // no template found, just return the uri as a String...
+            if ( forXML )
+            {
+                result = uri.getURIStringForXML();
+            }
+            else
+            {
+                result = uri.getURIString();
+            }
+        }
+
+        return result;
+    }
+
+    private String formatURIWithTemplate( ServletRequest request, MutableURI 
uri,
+                                          boolean forXML, URLTemplate template 
)
+    {
+        String scheme = uri.getScheme();
+        String host = uri.getHost();
+        int port = uri.getPort();
+
+        if ( scheme == null || scheme.length() == 0 ) { scheme = 
request.getScheme(); }
+
+        if ( host == null || host.length() == 0 ) { host = 
request.getServerName(); }
+
+        if ( port < 0 ) { port = request.getServerPort(); }
+
+        template.substitute( URLTemplateDescriptor.SCHEME_TOKEN, scheme );
+        template.substitute( URLTemplateDescriptor.DOMAIN_TOKEN, host );
+        template.substitute( URLTemplateDescriptor.PORT_TOKEN, port );
+        template.substitute( URLTemplateDescriptor.PATH_TOKEN, uri.getPath() );
+
+        String query = null;
+        if ( forXML )
+        {
+            query = uri.getQueryForXML();
+        }
+        else
+        {
+            query = uri.getQuery();
+        }
+
+        if ( query == null ) {
+            query = "";
+        }
+
+        template.substitute( URLTemplateDescriptor.QUERY_STRING_TOKEN, query );
+
+        return template.toString();
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/DefaultTemplatedURLFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/FreezableMutableURI.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/FreezableMutableURI.java?view=auto&rev=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/FreezableMutableURI.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/FreezableMutableURI.java
 Mon Jan 31 20:47:19 2005
@@ -0,0 +1,324 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.core.urls;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+
+/**
+ * A mutable class for creating URIs that can be set to "frozen" such
+ * that it becomes immutable. After this class is frozen, any calls to
+ * methods to set the data components of the URI will throw
+ */
+public class FreezableMutableURI extends MutableURI
+{
+
+    private boolean _frozen = false;
+
+    /**
+     * Constructs a <code>FreezableMutableURI</code>.
+     */
+    public FreezableMutableURI()
+    {
+    }
+
+    /**
+     * Constructs a <code>FreezableMutableURI</code>.
+     *
+     * @param  uriString the string to be parsed into a URI
+     * @see              java.net.URI#URI(String)
+     */
+    public FreezableMutableURI( String uriString ) throws URISyntaxException
+    {
+        super( uriString );
+    }
+
+    /**
+     * Constructs a <code>FreezableMutableURI</code>.
+     *
+     * @param scheme the name of the protocol to use
+     * @param userInfo the username and password
+     * @param host the name of the host
+     * @param port the port number on the host
+     * @param path the file on the host
+     * @param query the query part of this URI
+     * @param fragment the fragment part of this URI (internal reference in 
the URL)
+     */
+    public FreezableMutableURI( String scheme, String userInfo, String host, 
int port,
+                                String path, String query, String fragment )
+    {
+        super( scheme, userInfo, host, port, path, query, fragment );
+    }
+
+    /**
+     * Constructs a <code>FreezableMutableURI</code>.
+     *
+     * @param  uri the initial value for this mutable URI
+     */
+    public FreezableMutableURI( URI uri )
+    {
+        super( uri );
+    }
+
+    /**
+     * Constructs a <code>FreezableMutableURI</code>.
+     *
+     * <p> This is just a convenience constructor that functions the same as
+     * [EMAIL PROTECTED] #FreezableMutableURI(URI)} constructor with
+     * [EMAIL PROTECTED] java.net.URL#toURI()} as the argument. </p>
+     *
+     * <p>Note, any URL instance that complies with RFC 2396 can be converted
+     * to a URI. However, some URLs that are not strictly in compliance
+     * can not be converted to a URI. See [EMAIL PROTECTED] java.net.URL} </p>
+     *
+     * @param  url the initial value for this mutable URI
+     * @exception URISyntaxException if this URL is not formatted strictly
+     *            to RFC2396 and cannot be converted to a URI.
+     * @see        java.net.URL#toURI()
+     */
+    public FreezableMutableURI( URL url ) throws URISyntaxException
+    {
+        super( url );
+    }
+
+    public final boolean isFrozen()
+    {
+        return _frozen;
+    }
+
+    /**
+     * Sets a flag indicating that the URI is immutable (or not).
+     *
+     * @param frozen flag to indicate if the URI is now immutable or not.
+     */
+    public void setFrozen( boolean frozen )
+    {
+        this._frozen = frozen;
+    }
+
+    private void testFrozen()
+    {
+        if ( _frozen )
+        {
+            throw new IllegalStateException( "Cannot modify the URI data. This 
instance was set to be immutable." );
+        }
+    }
+
+    /**
+     * Reset the value of the <code>FreezableMutableURI</code>.
+     *
+     * <p> This method can also be used to clear the 
<code>FreezableMutableURI</code>.
+     *
+     * @param  uriString the string to be parsed into a URI
+     * @see              java.net.URI#URI(String)
+     */
+    @Override
+    public void setURI( String uriString ) throws URISyntaxException
+    {
+        testFrozen();
+        super.setURI( uriString );
+    }
+
+    /**
+     * Set the encoding used when adding unencoded parameters.
+     *
+     * @param encoding
+     */
+    @Override
+    public void setEncoding( String encoding )
+    {
+        testFrozen();
+        super.setEncoding( encoding );
+    }
+
+    /**
+     * Sets the protocol/scheme.
+     *
+     * @param scheme protocol/scheme
+     */
+    @Override
+    public void setScheme( String scheme )
+    {
+        testFrozen();
+        super.setScheme( scheme );
+    }
+
+    /**
+     * Sets the userInfo.
+     *
+     * @param userInfo userInfo
+     */
+    @Override
+    public void setUserInfo( String userInfo )
+    {
+        testFrozen();
+        super.setUserInfo( userInfo );
+    }
+
+    /**
+     * Sets the host.
+     *
+     * @param host host
+     */
+    @Override
+    public void setHost( String host )
+    {
+        testFrozen();
+        super.setHost( host );
+    }
+
+    /**
+     * Sets the port.
+     *
+     * @param port port
+     */
+    @Override
+    public void setPort( int port )
+    {
+        testFrozen();
+        super.setPort( port );
+    }
+
+    /**
+     * Sets the path.
+     *
+     * @param path path
+     */
+    @Override
+    public void setPath( String path )
+    {
+        testFrozen();
+        super.setPath( path );
+    }
+
+    /**
+     * Sets (and resets) the query string.
+     * This method assumes that the query is already encoded and
+     * the parameter delimiter is the '&amp;' character.
+     *
+     * @param query Query string
+     */
+    @Override
+    public void setQuery( String query )
+    {
+        testFrozen();
+        super.setQuery( query );
+    }
+
+    /**
+     * Add a parameter for the query string.
+     * <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 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>
+     *
+     * @param name  name
+     * @param value value
+     * @param encoded Flag indicating whether the names and values are
+     *                already encoded.
+     */
+    @Override
+    public void addParameter( String name, String value, boolean encoded )
+    {
+        testFrozen();
+        super.addParameter( name, value, encoded );
+    }
+
+    /**
+     * Add a parameter to the query string.
+     * <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 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.
+     */
+    @Override
+    public void addParameters( Map newParams, boolean encoded )
+    {
+        testFrozen();
+        super.addParameters( newParams, encoded );
+    }
+
+    /**
+     * Removes the given parameter.
+     *
+     * @param name name
+     */
+    @Override
+    public void removeParameter( String name )
+    {
+        testFrozen();
+        super.removeParameter( name );
+    }
+
+    /**
+     * Sets the fragment.
+     *
+     * @param fragment fragment
+     */
+    @Override
+    public void setFragment( String fragment )
+    {
+        testFrozen();
+        super.setFragment( fragment );
+    }
+
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( !( o instanceof FreezableMutableURI ) )
+        {
+            return false;
+        }
+        if ( !super.equals( o ) )
+        {
+            return false;
+        }
+
+        final FreezableMutableURI freezableMutableURI = ( FreezableMutableURI 
) o;
+
+        if ( _frozen != freezableMutableURI._frozen )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    public int hashCode()
+    {
+        int result = super.hashCode();
+        result = 29 * result + ( _frozen ? 1 : 0 );
+        return result;
+    }
+}
+

Propchange: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/FreezableMutableURI.java
------------------------------------------------------------------------------
    svn:eol-style = native

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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -54,7 +54,7 @@
  * easily encode unencoded components before setting in this URI. </p>
  *
  * TODO... We need to implement some conditions for opaque URIs like mailto, 
etc.
- * 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.
+ * to determine what to do about values of path when (path == null) => opaque 
and URI.getPath() would return "" for non-opaue URIs.
  */
 public class MutableURI
 {
@@ -92,6 +92,11 @@
     /** Fragment */
     private String _fragment;
 
+    /** Delimiter for query parameters */
+    private String _defaultParamDelimiter = PARAM_DELIMITER;
+    private static final String PARAM_DELIMITER = "&";
+    private static final String PARAM_DELIMITER_FOR_XML = "&amp;";
+
     private static final List< String > EMPTY_LIST = 
Collections.unmodifiableList( new ArrayList< String >( 0 ) );
     private static final Map< String, List< String > > EMPTY_MAP =
             Collections.unmodifiableMap( new HashMap< String, List< String > 
>() );
@@ -211,6 +216,40 @@
     }
 
     /**
+     * Reset the value of the <code>MutableURI</code>.
+     *
+     * <p> This method can also be used to clear the <code>MutableURI</code>. 
</p>
+     *
+     * @param  uriString the string to be parsed into a URI
+     * @see              java.net.URI#URI(String)
+     */
+    public void setURI( String uriString ) throws URISyntaxException
+    {
+        if ( uriString == null || uriString.trim().length() == 0 )
+        {
+            setScheme( null );
+            setUserInfo( null );
+            setHost( null );
+            setPort( UNDEFINED_PORT );
+            setPath( null );
+            setQuery( null );
+            setFragment( null );
+        }
+        else
+        {
+            // Parse this string into its components using URI
+            URI uri = new URI( uriString );
+            setScheme( uri.getScheme() );
+            setUserInfo( uri.getRawUserInfo() );
+            setHost( uri.getHost() );
+            setPort( uri.getPort() );
+            setPath( uri.getRawPath() );
+            setQuery( uri.getRawQuery() );
+            setFragment( uri.getRawFragment() );
+        }
+    }
+
+    /**
      * Set the encoding used when adding unencoded parameters.
      *
      * @param encoding
@@ -388,8 +427,48 @@
     }
 
     /**
+     * Sets the value of the delimiter used between each query parameter in
+     * the query to be the XML &quot;&amp;amp;&quot; entity, even for calls to
+     * the [EMAIL PROTECTED] #getQuery()} and [EMAIL PROTECTED] 
#getURIString()} methods.
+     *
+     * <p> The [EMAIL PROTECTED] #getQueryForXML()} and [EMAIL PROTECTED] 
#getURIStringForXML()} methods
+     * always use the XML &quot;&amp;amp;&quot; entity as the delimeter. 
However,
+     * the [EMAIL PROTECTED] #getQuery()} and [EMAIL PROTECTED] 
#getURIString()} methods
+     * use a default delimeter value which initially is set to be the
+     * '&amp;' character. This method lets a client override this value such
+     * that even the [EMAIL PROTECTED] #getQuery()} and [EMAIL PROTECTED] 
#getURIString()} methods
+     * will return strings with the XML &quot;&amp;amp;&quot; entity as the
+     * delimiter between the parameters in the query . </p>
+     *
+     * @param alwaysForXml flag for choosing the query parameter delimiter.
+     */
+    public void setAlwaysForXML( boolean alwaysForXml )
+    {
+        if ( alwaysForXml )
+        {
+            _defaultParamDelimiter = PARAM_DELIMITER_FOR_XML;
+        }
+        else
+        {
+            _defaultParamDelimiter = PARAM_DELIMITER;
+        }
+    }
+
+    /**
+     * Returns the value of the delimiter used between each query parameter
+     * in the .
+     *
+     * @return query parameter delimiter.
+     */
+    public String getDefaultParamDelimiter()
+    {
+        return _defaultParamDelimiter;
+    }
+
+    /**
      * Sets (and resets) the query string.
-     * This method assumes that the query is already encoded.
+     * This method assumes that the query is already encoded and
+     * the parameter delimiter is the '&amp;' character.
      *
      * @param query Query string
      */
@@ -417,15 +496,32 @@
     /**
      * 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 [EMAIL PROTECTED] 
#toXMLString()} </p>
+     * <p> This uses a default delimiter to separate the parameters, usually
+     * the &quot;&amp;&quot; character unless the instance has been set to
+     * always write the query for XML. In this case the delimiter value is
+     * the XML &quot;&amp;amp;&quot; entity. </p>
      *
-     * @param paramSeparator The string used to separate the parameters in the
-     *                       query.
      * @return encoded query string.
      */
-    public String getQuery( String paramSeparator )
+    public String getQuery()
+    {
+        return getQuery( getDefaultParamDelimiter() );
+    }
+
+    /**
+     * Returns the query string (encoded) to be used in an XML document.
+     *
+     * <p> This uses the XML &quot;&amp;amp;&quot; entity as the demilimeter
+     * to separate the parameters. </p>
+     *
+     * @return encoded query string.
+     */
+    public String getQueryForXML()
+    {
+        return getQuery( PARAM_DELIMITER_FOR_XML );
+    }
+
+    private String getQuery( String paramSeparator )
     {
         assert paramSeparator != null;
         if ( paramSeparator == null || paramSeparator.length() == 0 )
@@ -504,7 +600,7 @@
     }
 
     /**
-     * Add a separameter to the query string.
+     * Add a parameter to the query string.
      * <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
@@ -705,27 +801,28 @@
     }
 
     /**
-     * Returns a string form of this URL.
+     * Returns a string form of this URI.
      *
-     * @return string
+     * @return the URI as a <code>String</code>
      */
-    @Override
-    public String toString()
+    public String getURIString()
     {
-        return toString("&");
+        return getURIString( getDefaultParamDelimiter() );
     }
 
     /**
-     * Returns a valid XML string form of this URL.
+     * Returns a string form of this URI suitable for an XML document.
+     * I.E. uses the XML &quot;&amp;amp;&quot; entity as the demilimeter
+     * to separate the parameters in the query. </p>
      *
-     * @return string
+     * @return the URI as a <code>String</code>
      */
-    public String toXMLString()
+    public String getURIStringForXML()
     {
-        return toString("&amp;");
+        return getURIString( PARAM_DELIMITER_FOR_XML );
     }
 
-    private String toString(String paramSeparator)
+    private String getURIString(String paramSeparator)
     {
         StringBuilder buf = new StringBuilder( 128 );
 
@@ -807,7 +904,7 @@
     /**
      * Convenience method to encode unencoded components of a URI.
      *
-     * @param url      the string to be encoded by [EMAIL PROTECTED] 
URLEncoder}
+     * @param url      the string to be encoded by [EMAIL PROTECTED] URLCodec}
      * @param encoding the character encoding to use
      * @return         the encoded string
      */

Added: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/TemplatedURLFormatter.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/TemplatedURLFormatter.java?view=auto&rev=149370
==============================================================================
--- 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/TemplatedURLFormatter.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/TemplatedURLFormatter.java
 Mon Jan 31 20:47:19 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.core.urls;
+
+import javax.servlet.ServletRequest;
+
+/**
+ * Offers a method for formatting URLs based on templates from a URL
+ * template config file. A template is chosen from a reference group
+ * based on the template type (key).
+ */
+public interface TemplatedURLFormatter
+{
+    /**
+     * Format the given URL using a URL template, if defined in a URL
+     * template config file.
+     *
+     * @param request the current ServletRequest.
+     * @param uri the MutableURI to be formatted into a String.
+     * @param key key for the URL template type to use for formatting the URI
+     * @param forXML flag indicating that the query of the uri should be 
written
+     *               using the "&amp;" entity for XML, rather than the 
character, '&'.
+     */
+    public String getTemplatedURL( ServletRequest request, MutableURI uri, 
String key, boolean forXML );
+}

Propchange: 
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/core/urls/TemplatedURLFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

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&r1=149369&r2=149370
==============================================================================
--- 
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
 Mon Jan 31 20:47:19 2005
@@ -21,12 +21,12 @@
 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
 import org.apache.beehive.netui.util.logging.Logger;
 
+import java.io.PrintStream;
 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.ServletRequest;
 import javax.servlet.ServletResponse;
 
 
@@ -40,12 +40,21 @@
  * 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>
+ *
+ * <p> The final step of the full rewriting process should be to run the
+ * rewritten URI through the templated URL formatting process. See
+ * [EMAIL PROTECTED] #getTemplatedURL} </p>
+ *
+ * <p> Also note that this API allows a client to register their own templated
+ * URI formatter so they can manage their own templates and formatting. </p>
  */
 public class URLRewriterService
 {
     private static final Logger _log = Logger.getInstance( 
URLRewriterService.class );
 
-    private static String URL_REWRITERS_KEY = "url_rewriters";
+    private static final String URL_REWRITERS_KEY = "url_rewriters";
+    private static final String TEMPLATTED_URL_FORMATTER_KEY = 
"templated_url_formatter";
+    private static final DefaultTemplatedURLFormatter defaultFormatter = new 
DefaultTemplatedURLFormatter();
 
     /**
      * Rewrite the given parameter name, looping through the list of 
registered URLRewriters.
@@ -73,6 +82,15 @@
     /**
      * Rewrite the given URL, looping through the list of registered 
URLRewriters.
      *
+     * <p> Once the MutableURI has been rewritten, and if it is an instance of
+     * [EMAIL PROTECTED] FreezableMutableURI}, then this method will set the 
URI to a frozen
+     * state. I.e. immutable. If a user then tries to use a setter method on 
the
+     * rewritten URI, the FreezableMutableURI will throw an 
IllegalStateException. </p>
+     *
+     * <p> Note that after the rewritting the caller should run the rewritten 
URI
+     * through the templated URI formatting process as the last step in 
rewriting.
+     * See [EMAIL PROTECTED] #getTemplatedURL} </p>
+     *
      * @param servletContext the current ServletContext.
      * @param request        the current ServletRequest.
      * @param response       the current ServletResponse.
@@ -98,6 +116,11 @@
                 rewriter.rewriteURL( servletContext, request, response, url, 
type, needsToBeSecure );
             }
         }
+
+        if ( url instanceof FreezableMutableURI )
+        {
+            ( ( FreezableMutableURI ) url ).setFrozen( true );
+        }
     }
 
     /**
@@ -314,5 +337,58 @@
         {
             output.println( "        No URLRewriter objects are registered 
with this request." );
         }
+    }
+
+    /**
+     * Format the given URI using a URL template, if defined in the URL 
template
+     * config file, WEB-INF/url-template-config.xml.
+     *
+     * @param request the current ServletRequest.
+     * @param url the MutableURI to be formatted into a String.
+     * @param key the URL template type to use for formatting the URI
+     * @param forXML flag indicating that the query of the uri should be 
written
+     *               using the "&amp;" entity for XML, rather than the 
character, '&'.
+     */
+    public static String getTemplatedURL( ServletRequest request, MutableURI 
url, String key, boolean forXML )
+    {
+        TemplatedURLFormatter formatter = getTemplatedURLFormatter( request );
+
+        if ( formatter != null )
+        {
+            return formatter.getTemplatedURL( request, url, key, forXML );
+        }
+
+        return defaultFormatter.getTemplatedURL( request, url, key, forXML );
+    }
+
+    private static TemplatedURLFormatter getTemplatedURLFormatter( 
ServletRequest request )
+    {
+        return ( TemplatedURLFormatter ) 
ScopedServletUtils.getScopedRequestAttribute( TEMPLATTED_URL_FORMATTER_KEY, 
request );
+    }
+
+    /**
+     * Register a TemplatedURLFormatter in the request.
+     *
+     * <p> The TemplatedURLFormatter should be used as a final step in the 
rewriting
+     * process to format the rewritten URL as defined by a template in the
+     * WEB-INF/url-template-config.xml. There can only be one 
TemplatedURLFormatter,
+     * not a chain as with the URLRewriters. </p>
+     *
+     * @param request the current ServletRequest.
+     * @param formatter the TemplatedURLFormatter to register.
+     */
+    public static void registerTemplatedURLFormatter( ServletRequest request, 
TemplatedURLFormatter formatter )
+    {
+        request.setAttribute( TEMPLATTED_URL_FORMATTER_KEY, formatter );
+    }
+
+    /**
+     * Unregister the TemplatedURLFormatter from the request.
+     *
+     * @param request the current ServletRequest.
+     */
+    public static void unregisterTemplatedURLFormatter( ServletRequest request 
)
+    {
+        request.removeAttribute( TEMPLATTED_URL_FORMATTER_KEY );
     }
 }


Reply via email to