One comment inline - john
-----Original Message-----
From: Richard Feit
Sent: Monday, December 06, 2004 5:44 PM
To: Beehive Developers
Subject: Re: checkin request netui page flow
Hey Carlin,
This looks good to me. I have a few minor suggestions:
- In URLRewriterService, I think it would be clearer to rename the
Type enum to URLType. By its location, Type suggests that it's the
URLRewriter type.
- Currently, it looks like if there's an exclusive
(allowOtherRewriters == false) rewriter in the list, no others can be
added. If this is the case, it seems like adding an exclusive rewriter
should also delete all existing ones from the list (with log messages).
What do you think?
[jr] You might also consider an approach that is more "in your face".
Force the dev to remove existing rewriters by have the "add exclusive"
fail if others are in the list. Keep in mind that I making this
suggestion without looking at the api :)
- There should be info-level logging when adding a URLRewriter fails
because there's already one registered which doesn't allow others.
None of these changes are urgent -- I'll check this in, and if you agree
with the changes you could submit another patch (or I could just do it
myself).
Thanks,
Rich
Carlin Rogers wrote:
> Another minor checkin request with respect to URL rewriting in
> NetUI Page Flow. The following patch file (output from "svn diff")
> contains the changes described below. Several of the changes are
> post review of the previous URL rewriting work. Thanks!
>
> Thanks,
> Carlin
>
> Changes...
> - Remove obsolete class,
> org.apache.beehive.netui.pageflow.util.PageflowTagUtils
>
> - Moved the new PageFlowTagUtils class from the package,
> org.apache.beehive.netui.tags, to the package,
> org.apache.beehive.netui.tags.internal, to indicate that
> this is used internally by tags and not really intended
> as part of an external API.
>
> - Added a new method to PageFlowTagUtils, rewriteHrefURL(),
> to ensure that the url type is action rather than resource
> for the rewriting.
>
> - Modified abstract base URLRewriter class to allow a
> rewriter to be defined as exclusive within the chain of
> rewriters. (I.E. Not allow other rewriters when registered).
>
>
>-----------------------------------------------------------------------
-
>
>Index: netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
>===================================================================
>--- netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
(revision 109952)
>+++ netui/src/tags-html/org/apache/beehive/netui/tags/tree/Tree.java
(working copy)
>@@ -26,6 +26,7 @@
> import org.apache.beehive.netui.tags.*;
> import org.apache.beehive.netui.tags.html.HtmlConstants;
> import org.apache.beehive.netui.tags.html.JavaScriptUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.tags.rendering.*;
> import org.apache.beehive.netui.util.Bundle;
>
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeItem.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeItem.java
(revision 109952)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeItem.java
(working copy)
>@@ -18,7 +18,7 @@
> package org.apache.beehive.netui.tags.tree;
>
> import org.apache.beehive.netui.tags.AbstractSimpleTag;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.util.Bundle;
>
> import javax.servlet.http.HttpServletRequest;
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/PageFlowTagUtils.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/PageFlowTagUtils.java
(revision 109952)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/PageFlowTagUtils.java
(working copy)
>@@ -1,188 +0,0 @@
>-/*
>- * 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.tags;
>-
>-import org.apache.beehive.netui.core.urls.MutableURI;
>-import org.apache.beehive.netui.core.urls.URLRewriter;
>-import org.apache.beehive.netui.core.urls.URLRewriterService;
>-import org.apache.beehive.netui.pageflow.FlowController;
>-import org.apache.beehive.netui.pageflow.FlowControllerFactory;
>-import org.apache.beehive.netui.pageflow.PageFlowConstants;
>-import org.apache.beehive.netui.pageflow.PageFlowUtils;
>-import org.apache.beehive.netui.pageflow.SecurityProtocol;
>-import org.apache.beehive.netui.pageflow.internal.InternalUtils;
>-
>-import java.util.Map;
>-import javax.servlet.jsp.PageContext;
>-import javax.servlet.ServletContext;
>-import javax.servlet.ServletRequest;
>-import javax.servlet.http.HttpServletResponse;
>-import javax.servlet.http.HttpServletRequest;
>-
>-
>-/**
>- * @exclude
>- */
>-public class PageFlowTagUtils
>-{
>- public static MutableURI rewriteActionURL( PageContext
pageContext, String action, Map params, String location )
>- throws java.net.URISyntaxException
>- {
>- ServletContext servletContext =
pageContext.getServletContext();
>- ServletRequest request = pageContext.getRequest();
>- HttpServletResponse response = ( HttpServletResponse )
pageContext.getResponse();
>- String qualifiedAction = InternalUtils.qualifiedAction(
servletContext, action );
>- String actionUrl = InternalUtils.createActionURL( (
HttpServletRequest ) request, qualifiedAction );
>- MutableURI uri = new MutableURI( actionUrl );
>-
>- if ( params != null )
>- {
>- String encoding = response.getCharacterEncoding();
>- uri.addParameters( params, false, encoding );
>- }
>-
>- if ( location != null ) { uri.setFragment( location ); }
>-
>- boolean needsToBeSecure = needsSecure( servletContext,
request, actionUrl, true );
>- URLRewriterService.rewriteURL( servletContext, request,
response, uri,
>- URLRewriter.Type.ACTION,
needsToBeSecure );
>-
>- return uri;
>- }
>-
>- public static MutableURI rewriteResourceURL( PageContext
pageContext, String url, Map params, String location )
>- throws java.net.URISyntaxException
>- {
>- HttpServletResponse response = ( HttpServletResponse )
pageContext.getResponse();
>- MutableURI uri = new MutableURI( url );
>- if ( params != null )
>- {
>- String encoding = response.getCharacterEncoding();
>- uri.addParameters( params, false, encoding );
>- }
>-
>- 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 = needsSecure( servletContext,
request, url, true );
>- URLRewriterService.rewriteURL( servletContext, request,
response, uri,
>- URLRewriter.Type.RESOURCE,
needsToBeSecure );
>-
>- return uri;
>- }
>-
>- public static boolean isAction( HttpServletRequest request,
HttpServletResponse response,
>- ServletContext servletContext,
String action )
>- {
>- boolean isAnAction = true;
>- FlowController flowController =
InternalUtils.getCurrentPageFlow( request, false );
>- if ( flowController != null )
>- {
>- String checkAction = action;
>- if ( checkAction.startsWith( "/" ) )
>- {
>- checkAction = checkAction.substring( 1 );
>- }
>- if ( checkAction.endsWith(
PageFlowConstants.ACTION_EXTENSION ) )
>- {
>- checkAction = checkAction.substring( 0,
checkAction.length() - PageFlowConstants.ACTION_EXTENSION.length() );
>- }
>- isAnAction = flowController.isAction( checkAction );
>-
>- if ( !isAnAction )
>- {
>- FlowController globalController =
>- FlowControllerFactory.getSharedFlowForRequest(
request, response, servletContext );
>- if ( globalController != null )
>- {
>- isAnAction = globalController.isAction(
checkAction );
>- }
>- }
>- }
>-
>- return isAnAction;
>- }
>-
>- /**
>- * Tell whether a given URI should be written to be secure.
>- *
>- * @param request the current HttpServletRequest.
>- * @param context the current ServletContext.
>- * @param uri the URI to check.
>- * @param stripContextPath if <code>true</code>, strip the webapp
context path from the URI before
>- * processing it.
>- * @return <code>true</code> when:
>- * <ul>
>- * <li>the given URI is configured in the deployment
descriptor to be secure (according to
>- * [EMAIL PROTECTED]
org.apache.beehive.netui.core.SecurityProtocol}), or
>- * <li>the given URI is not configured in the deployment
descriptor, and the current request
>- * is secure ([EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest#isSecure} returns
>- * <code>true</code>).
>- * </ul>
>- * <code>false</code> when:
>- * <ul>
>- * <li>the given URI is configured explicitly in the
deployment descriptor to be unsecure
>- * (according to [EMAIL PROTECTED]
org.apache.beehive.netui.core.SecurityProtocol}), or
>- * <li>the given URI is not configured in the deployment
descriptor, and the current request
>- * is unsecure ([EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest#isSecure} returns
>- * <code>false</code>).
>- * </ul>
>- */
>- public static boolean needsSecure( ServletContext context,
ServletRequest request,
>- String uri, boolean
stripContextPath )
>- {
>- // Get the web-app relative path for security check
>- String secureCheck = uri;
>- if ( stripContextPath )
>- {
>- String contextPath = ( ( HttpServletRequest ) request
).getContextPath();
>- if ( secureCheck.startsWith( contextPath ) )
>- {
>- secureCheck = secureCheck.substring(
contextPath.length() );
>- }
>- }
>-
>- boolean secure = false;
>- if ( secureCheck.indexOf( '?' ) > -1 )
>- {
>- secureCheck = secureCheck.substring( 0,
secureCheck.indexOf( '?' ) );
>- }
>-
>- SecurityProtocol sp = PageFlowUtils.getSecurityProtocol(
secureCheck, context, ( HttpServletRequest ) request );
>- if ( sp.equals( SecurityProtocol.UNSPECIFIED ) )
>- {
>- secure = request.isSecure();
>- }
>- else
>- {
>- secure = sp.equals( SecurityProtocol.SECURE );
>- }
>-
>- return secure;
>- }
>-}
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
>===================================================================
>--- netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
(revision 109952)
>+++ netui/src/tags-html/org/apache/beehive/netui/tags/html/Image.java
(working copy)
>@@ -18,7 +18,7 @@
> package org.apache.beehive.netui.tags.html;
>
> import org.apache.beehive.netui.core.urls.MutableURI;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
> import org.apache.beehive.netui.tags.rendering.ImageTag;
> import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
>Index: netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
>===================================================================
>--- netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
(revision 109952)
>+++ netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
(working copy)
>@@ -24,7 +24,7 @@
> import org.apache.beehive.netui.pageflow.internal.InternalUtils;
> import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
> import org.apache.beehive.netui.tags.IHtmlIdWriter;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.tags.rendering.*;
> import org.apache.beehive.netui.util.Bundle;
> import org.apache.beehive.netui.util.logging.Logger;
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java
(revision 109952)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.java
(working copy)
>@@ -21,7 +21,7 @@
> import org.apache.beehive.netui.core.urls.URLRewriter;
> import org.apache.beehive.netui.core.urls.URLRewriterService;
> import org.apache.beehive.netui.tags.AbstractClassicTag;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.util.Bundle;
>
> import java.net.URISyntaxException;
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
(revision 109952)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/html/AnchorBase.java
(working copy)
>@@ -5,7 +5,7 @@
> import org.apache.beehive.netui.tags.ByRef;
> import org.apache.beehive.netui.tags.IScriptReporter;
> import org.apache.beehive.netui.tags.HtmlUtils;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.util.Bundle;
> import org.apache.beehive.netui.util.ParamHelper;
> import org.apache.beehive.netui.util.logging.Logger;
>@@ -368,8 +368,7 @@
> uri =
PageFlowTagUtils.rewriteActionURL(pageContext, _action, _params,
_location);
> }
> else if (_href != null) {
>- //TODO... OK to use rewrittenResourceURL implying
type=RESOURCE for rewriting?
>- uri =
PageFlowTagUtils.rewriteResourceURL(pageContext, _href, _params,
_location);
>+ uri = PageFlowTagUtils.rewriteHrefURL(pageContext,
_href, _params, _location);
> }
> }
> catch (URISyntaxException e) {
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/html/Button.java
>===================================================================
>--- netui/src/tags-html/org/apache/beehive/netui/tags/html/Button.java
(revision 109952)
>+++ netui/src/tags-html/org/apache/beehive/netui/tags/html/Button.java
(working copy)
>@@ -20,7 +20,7 @@
> import org.apache.beehive.netui.core.urls.URLRewriterService;
> import org.apache.beehive.netui.tags.HtmlUtils;
> import org.apache.beehive.netui.tags.IHtmlAccessable;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
> import org.apache.beehive.netui.tags.rendering.InputSubmitTag;
> import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
(revision 109952)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageAnchor.java
(working copy)
>@@ -20,7 +20,7 @@
> import org.apache.beehive.netui.core.urls.MutableURI;
> import org.apache.beehive.netui.tags.IHtmlAccessable;
> import org.apache.beehive.netui.tags.ByRef;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.tags.rendering.*;
> import org.apache.beehive.netui.util.Bundle;
>
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java
(revision 109952)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/html/ImageButton.java
(working copy)
>@@ -19,7 +19,7 @@
>
> import org.apache.beehive.netui.core.urls.MutableURI;
> import org.apache.beehive.netui.tags.IHtmlAccessable;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
> import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
> import org.apache.beehive.netui.tags.rendering.InputImageTag;
> import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
>Index:
netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUt
ils.java
>===================================================================
>---
netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUt
ils.java (revision 0)
>+++
netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUt
ils.java (working copy)
>@@ -15,7 +15,7 @@
> *
> * $Header:$
> */
>-package org.apache.beehive.netui.tags;
>+package org.apache.beehive.netui.tags.internal;
>
> import org.apache.beehive.netui.core.urls.MutableURI;
> import org.apache.beehive.netui.core.urls.URLRewriter;
>@@ -27,6 +27,7 @@
> import org.apache.beehive.netui.pageflow.SecurityProtocol;
> import org.apache.beehive.netui.pageflow.internal.InternalUtils;
>
>+import java.net.URISyntaxException;
> import java.util.Map;
> import javax.servlet.jsp.PageContext;
> import javax.servlet.ServletContext;
>@@ -34,14 +35,28 @@
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.http.HttpServletRequest;
>
>-
> /**
>- * @exclude
>+ * 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
>+ * 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.
> */
> public class PageFlowTagUtils
> {
>+ /**
>+ * 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 [EMAIL PROTECTED]
URLRewriter.Type.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.
>+ */
> public static MutableURI rewriteActionURL( PageContext
pageContext, String action, Map params, String location )
>- throws java.net.URISyntaxException
>+ throws URISyntaxException
> {
> ServletContext servletContext =
pageContext.getServletContext();
> ServletRequest request = pageContext.getRequest();
>@@ -65,9 +80,44 @@
> return uri;
> }
>
>+ /**
>+ * 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 [EMAIL PROTECTED]
URLRewriter.Type.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.
>+ */
>+ public static MutableURI rewriteHrefURL( PageContext pageContext,
String url, Map params, String location )
>+ throws URISyntaxException
>+ {
>+ return rewriteResourceOrHrefURL( pageContext, url, params,
location, URLRewriter.Type.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 [EMAIL PROTECTED]
URLRewriter.Type.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.
>+ */
> public static MutableURI rewriteResourceURL( PageContext
pageContext, String url, Map params, String location )
>- throws java.net.URISyntaxException
>+ throws URISyntaxException
> {
>+ return rewriteResourceOrHrefURL( pageContext, url, params,
location, URLRewriter.Type.RESOURCE );
>+ }
>+
>+ private static MutableURI rewriteResourceOrHrefURL( PageContext
pageContext, String url, Map params,
>+ String
location, URLRewriter.Type type )
>+ throws URISyntaxException
>+ {
> HttpServletResponse response = ( HttpServletResponse )
pageContext.getResponse();
> MutableURI uri = new MutableURI( url );
> if ( params != null )
>@@ -91,11 +141,21 @@
> ServletContext servletContext =
pageContext.getServletContext();
> boolean needsToBeSecure = needsSecure( servletContext,
request, url, true );
> URLRewriterService.rewriteURL( servletContext, request,
response, uri,
>- URLRewriter.Type.RESOURCE,
needsToBeSecure );
>+ type, needsToBeSecure );
>
> return uri;
> }
>
>+ /**
>+ * Determine whether a given URI is an Action.
>+ *
>+ * @param request the current HttpServletRequest.
>+ * @param response the current HttpServletResponse.
>+ * @param servletContext the current ServletContext.
>+ * @param action the URI to check.
>+ * @return <code>true</code> if the action is defined in the
current page flow
>+ * or in a shared flow. Otherwise, return
<code>false</code>.
>+ */
> public static boolean isAction( HttpServletRequest request,
HttpServletResponse response,
> ServletContext servletContext,
String action )
> {
>@@ -139,7 +199,7 @@
> * @return <code>true</code> when:
> * <ul>
> * <li>the given URI is configured in the deployment
descriptor to be secure (according to
>- * [EMAIL PROTECTED]
org.apache.beehive.netui.core.SecurityProtocol}), or
>+ * [EMAIL PROTECTED]
org.apache.beehive.netui.pageflow.SecurityProtocol}), or
> * <li>the given URI is not configured in the deployment
descriptor, and the current request
> * is secure ([EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest#isSecure} returns
> * <code>true</code>).
>@@ -147,7 +207,7 @@
> * <code>false</code> when:
> * <ul>
> * <li>the given URI is configured explicitly in the
deployment descriptor to be unsecure
>- * (according to [EMAIL PROTECTED]
org.apache.beehive.netui.core.SecurityProtocol}), or
>+ * (according to [EMAIL PROTECTED]
org.apache.beehive.netui.pageflow.SecurityProtocol}), or
> * <li>the given URI is not configured in the deployment
descriptor, and the current request
> * is unsecure ([EMAIL PROTECTED]
javax.servlet.http.HttpServletRequest#isSecure} returns
> * <code>false</code>).
>Index:
netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid
/util/JspUtil.java
>===================================================================
>---
netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid
/util/JspUtil.java (revision 109952)
>+++
netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid
/util/JspUtil.java (working copy)
>@@ -27,7 +27,7 @@
> import org.apache.beehive.netui.core.urls.MutableURI;
> import org.apache.beehive.netui.util.logging.Logger;
> import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
>-import org.apache.beehive.netui.tags.PageFlowTagUtils;
>+import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
>
> public class JspUtil
> {
>@@ -72,8 +72,7 @@
> }
> else if(href != null)
> {
>- //TODO... OK to use rewrittenResourceURL implying
type=RESOURCE for rewriting?
>- uri = PageFlowTagUtils.rewriteResourceURL(pageContext,
href, params, location);
>+ uri = PageFlowTagUtils.rewriteHrefURL(pageContext, href,
params, location);
> }
>
> assert uri != null;
>Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProc
essor.java
>===================================================================
>---
netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProc
essor.java (revision 109952)
>+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowRequestProc
essor.java (working copy)
>@@ -783,7 +783,7 @@
> //
> // Register the default URLRewriter
> //
>- URLRewriterService.registerURLRewriter( request, new
DefaultURLRewriter() );
>+ URLRewriterService.registerURLRewriter( 0, request, new
DefaultURLRewriter() );
>
> try
> {
>Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/PageflowTagUti
ls.java
>===================================================================
>---
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/PageflowTagUti
ls.java (revision 109952)
>+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/PageflowTagUti
ls.java (working copy)
>@@ -1,442 +0,0 @@
>-/*
>- * 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.pageflow.util;
>-
>-//java imports
>-import java.net.URLEncoder;
>-import java.net.MalformedURLException;
>-import java.util.Map;
>-import java.util.Iterator;
>-
>-//internal imports
>-import org.apache.beehive.netui.pageflow.FlowController;
>-import org.apache.beehive.netui.pageflow.FlowControllerFactory;
>-import org.apache.beehive.netui.pageflow.internal.InternalUtils;
>-
>-import org.apache.beehive.netui.util.logging.Logger;
>-import org.apache.beehive.netui.util.FileUtils;
>-
>-//external imports
>-import javax.servlet.jsp.PageContext;
>-import javax.servlet.ServletContext;
>-import javax.servlet.ServletRequest;
>-import javax.servlet.http.HttpServletResponse;
>-import javax.servlet.http.HttpServletRequest;
>-
>-import org.apache.struts.config.ModuleConfig;
>-import org.apache.struts.config.ForwardConfig;
>-import org.apache.struts.Globals;
>-import org.apache.struts.util.MessageResources;
>-import org.apache.struts.util.RequestUtils;
>-
>-import static
org.apache.beehive.netui.pageflow.PageFlowConstants.ACTION_EXTENSION;
>-
>-
>-/**
>- * @deprecated This class has been replaced with an internal utility
([EMAIL PROTECTED] org.apache.beehive.netui.tags.internal.PageFlowTagUtils}).
It
will be removed in a future release.
>- */
>-public class PageflowTagUtils
>-{
>- private static final Logger logger = Logger.getInstance(
PageflowTagUtils.class );
>-
>- /**
>- * The message resources for this package.
>- */
>- private static MessageResources messages =
>-
MessageResources.getMessageResources("org.apache.struts.util.LocalString
s");
>-
>- public static String getRewrittenFormAction(HttpServletRequest
request, String action, PageContext pageContext)
>- {
>- HttpServletResponse response = (HttpServletResponse)
pageContext.getResponse();
>- String qualifiedAction =
PageflowTagUtils.qualifiedAction(pageContext.getServletContext(),action)
;
>- String actionUrl = createActionURL(request, qualifiedAction);
>-
>- actionUrl = prepareActionUrl(pageContext, actionUrl);
>-
>- return response.encodeURL(actionUrl);
>- }
>-
>- public static String prepareActionUrl(PageContext pageContext,
String url)
>- {
>- ServletContext servletContext =
pageContext.getServletContext();
>- ServletRequest request = pageContext.getRequest();
>- HttpServletResponse response = (HttpServletResponse)
pageContext.getResponse();
>-
>- String templateType = URLRewriter.ACTION_UNSECURE;
>-
>- if (URLRewriterService.needsSecure(request, servletContext,
url, true))
>- templateType = URLRewriter.ACTION_SECURE;
>-
>- url = URLRewriterService.rewriteURL(servletContext, request,
response, url, templateType);
>-
>- return response.encodeURL(url);
>- }
>-
>- public static String prepareResourceUrl(PageContext pageContext,
String url)
>- {
>- if ( FileUtils.isAbsoluteURI(url) )
>- {
>- return url;
>- }
>-
>- ServletContext servletContext =
pageContext.getServletContext();
>- HttpServletRequest request = (HttpServletRequest)
pageContext.getRequest();
>- HttpServletResponse response = (HttpServletResponse)
pageContext.getResponse();
>-
>-
>- if (!url.startsWith("/"))
>- {
>- String reqUri = request.getRequestURI();
>- String path = reqUri.substring(0, reqUri.lastIndexOf("/")
+ 1);
>- url = path + url;
>- }
>-
>- String templateType = URLRewriter.RESOURCE_UNSECURE;
>-
>- if (URLRewriterService.needsSecure(request, servletContext,
url, true))
>- templateType = URLRewriter.RESOURCE_SECURE;
>-
>- url = URLRewriterService.rewriteURL(servletContext, request,
response, url, templateType);
>-
>- return response.encodeURL(url);
>- }
>-
>- public static String createActionURL(HttpServletRequest
servletRequest, String qualifiedAction)
>- {
>- String pageURI = InternalUtils.getDecodedURI( servletRequest
);
>- int lastSlash = pageURI.lastIndexOf( '/' );
>- if ( lastSlash != -1 )
>- {
>- StringBuilder value = new
StringBuilder(qualifiedAction.length() + 16);
>- value.append( pageURI.substring( 0, lastSlash ) );
>- value.append(qualifiedAction);
>- return value.toString();
>- }
>- return qualifiedAction;
>- }
>-
>- public static String createActionPath(HttpServletRequest request,
String qualifiedAction)
>- {
>-
>- ModuleConfig appConfig = (ModuleConfig)
request.getAttribute(Globals.MODULE_KEY);
>- if (appConfig != null)
>- {
>- StringBuilder value = new
StringBuilder(qualifiedAction.length() + 16);
>- value.append(appConfig.getPrefix());
>- value.append(qualifiedAction);
>- return value.toString();
>- }
>- return qualifiedAction;
>- }
>-
>- public static String qualifiedAction(ServletContext
servletContext, String action)
>- {
>- StringBuilder sb = new StringBuilder(32);
>-
>- // Use our servlet mapping, if one is specified
>- String servletMapping = (String)
servletContext.getAttribute(Globals.SERVLET_KEY);
>- if (servletMapping != null)
>- {
>- String queryString = null;
>- int question = action.indexOf("?");
>- if (question >= 0)
>- {
>- queryString = action.substring(question);
>- }
>- String actionMapping =
URLRewriterService.getActionMappingName(action);
>- if (servletMapping.startsWith("*."))
>- {
>- sb.append(actionMapping);
>- sb.append(servletMapping.substring(1));
>- }
>- else if (servletMapping.endsWith("/*"))
>- {
>- sb.append(servletMapping.substring(0,
servletMapping.length() - 2));
>- sb.append(actionMapping);
>- }
>- else if (servletMapping.equals("/"))
>- {
>- sb.append(actionMapping);
>- }
>- if (queryString != null) {
>- sb.append(queryString);
>- }
>- }
>-
>- // Otherwise, assume extension mapping is in use and extension
is
>- // already included in the action property
>- else
>- {
>- if (!action.startsWith("/"))
>- {
>- sb.append("/");
>- }
>- sb.append(action);
>- }
>- return sb.toString();
>- }
>-
>- public static boolean isAction(HttpServletRequest request,
HttpServletResponse response, ServletContext servletContext, String
action)
>- {
>- boolean isAnAction = true;
>- FlowController flowController =
InternalUtils.getCurrentPageFlow(request, false);
>- if (flowController != null)
>- {
>- String checkAction = action;
>- if (checkAction.startsWith("/"))
>- checkAction = checkAction.substring(1);
>- if (checkAction.endsWith(ACTION_EXTENSION))
>- checkAction = checkAction.substring(0,
checkAction.length() - ACTION_EXTENSION.length());
>- isAnAction = flowController.isAction(checkAction);
>-
>- if (!isAnAction)
>- {
>- FlowController globalController =
>- FlowControllerFactory.getSharedFlowForRequest(
request, response, servletContext );
>- if (globalController != null)
>- isAnAction =
globalController.isAction(checkAction);
>- }
>- }
>-
>- return isAnAction;
>- }
>-
>-
>- // @struts : from org.apache.struts.util.RequestUtils RC 1.1
>- public static String computeURL
>- (
>- PageContext pageContext,
>- String forward,
>- String href,
>- String page,
>- Map params,
>- String anchor,
>- boolean redirect)
>- throws MalformedURLException {
>-
>- return computeURL(pageContext, forward, href, page, null,
params,
>- anchor, redirect);
>- }
>-
>- // @struts : from org.apache.struts.util.RequestUtils RC 1.1
>- public static String computeURL(
>- PageContext pageContext,
>- String forward,
>- String href,
>- String page,
>- String action,
>- Map params,
>- String anchor,
>- boolean redirect)
>- throws MalformedURLException
>- {
>-
>- String encoding =
pageContext.getResponse().getCharacterEncoding();
>-
>- // Validate that exactly one specifier was included
>- int n = 0;
>- if (forward != null) {
>- n++;
>- }
>- if (href != null) {
>- n++;
>- }
>- if (page != null) {
>- n++;
>- }
>- if (action != null) {
>- n++;
>- }
>- if (n != 1) {
>- throw new
MalformedURLException(messages.getMessage("computeURL.specifier"));
>- }
>-
>- HttpServletRequest request = (HttpServletRequest)
pageContext.getRequest();
>-
>- // Look up the module configuration for this request
>- ModuleConfig config =
>- (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
>- if (config == null) { // Backwards compatibility hack
>- config =
>- (ModuleConfig)
pageContext.getServletContext().getAttribute(Globals.MODULE_KEY);
>- InternalUtils.setCurrentModule( config, request );
>- }
>-
>- // Calculate the appropriate URL
>- StringBuilder url = new StringBuilder(32);
>- if (forward != null) {
>- ForwardConfig fc = config.findForwardConfig(forward);
>- if (fc == null) {
>- throw new
MalformedURLException(messages.getMessage("computeURL.forward",
forward));
>- }
>- if (fc.getRedirect()) {
>- redirect = true;
>- }
>- if (fc.getPath().startsWith("/")) {
>- url.append(request.getContextPath());
>- url.append(RequestUtils.forwardURL(request, fc));
>- } else {
>- url.append(fc.getPath());
>- }
>- } else if (href != null) {
>- url.append(href);
>- } else if (action != null) {
>- url.append(RequestUtils.getActionMappingURL(action,
pageContext));
>-
>- } else /* if (page != null) */ {
>- url.append(request.getContextPath());
>- url.append(RequestUtils.pageURL(request, page));
>- }
>-
>- // Add anchor if requested (replacing any existing anchor)
>- if (anchor != null) {
>- String temp = url.toString();
>- int hash = temp.indexOf('#');
>- if (hash >= 0) {
>- url.setLength(hash);
>- }
>- url.append('#');
>- url.append(encodeURL(anchor,encoding));
>- }
>-
>- // Add dynamic parameters if requested
>- if ((params != null) && (params.size() > 0)) {
>- addParameters(url,encoding,redirect,params);
>- }
>-
>- return (url.toString());
>- }
>-
>- //
>- public static void addParameters(StringBuilder url,String
encoding,
>- boolean redirect,Map params)
>- {
>- String anchor;
>- // Add dynamic parameters if requested
>- if ((params != null) && (params.size() > 0)) {
>-
>- // Save any existing anchor
>- String temp = url.toString();
>- int hash = temp.indexOf('#');
>- if (hash >= 0) {
>- anchor = temp.substring(hash + 1);
>- url.setLength(hash);
>- temp = url.toString();
>- } else {
>- anchor = null;
>- }
>-
>- // Define the parameter separator
>- String separator = "&";
>- if (redirect) {
>- separator = "&";
>- }
>-
>- // Add the required request parameters
>- boolean question = temp.indexOf('?') >= 0;
>- Iterator keys = params.keySet().iterator();
>- while (keys.hasNext()) {
>- String key = (String) keys.next();
>- Object value = params.get(key);
>- if (value == null) {
>- if (!question) {
>- url.append('?');
>- question = true;
>- } else {
>- url.append(separator);
>- }
>- url.append(encodeURL(key,encoding));
>- url.append('='); // Interpret null as "no value"
>- } else if (value instanceof String) {
>- if (!question) {
>- url.append('?');
>- question = true;
>- } else {
>- url.append(separator);
>- }
>- url.append(encodeURL(key,encoding));
>- url.append('=');
>- url.append(encodeURL((String) value,encoding));
>- } else if (value instanceof String[]) {
>- String values[] = (String[]) value;
>- for (int i = 0; i < values.length; i++) {
>- if (!question) {
>- url.append('?');
>- question = true;
>- } else {
>- url.append(separator);
>- }
>- url.append(encodeURL(key,encoding));
>- url.append('=');
>- url.append(encodeURL(values[i],encoding));
>- }
>- } else /* Convert other objects to a string */ {
>- if (!question) {
>- url.append('?');
>- question = true;
>- } else {
>- url.append(separator);
>- }
>- url.append(encodeURL(key,encoding));
>- url.append('=');
>- url.append(encodeURL(value.toString(),encoding));
>- }
>- }
>-
>- // Re-add the saved anchor (if any)
>- if (anchor != null) {
>- url.append('#');
>- url.append(encodeURL(anchor,encoding));
>- }
>- }
>- }
>-
>-
>- // @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.
>- public static String encodeURL(String url, String encoding)
>- {
>- String encodedURL = null;
>- try {
>- encodedURL = URLEncoder.encode(url,encoding);
>- }
>- catch (java.io.UnsupportedEncodingException e) {
>- logger.error( "Unsupported encoding:" + encoding, e );
>- // try this in utf-8 and log the exception
>- try {
>- encodedURL = URLEncoder.encode(url,"UTF-8");
>- }
>- catch (java.io.UnsupportedEncodingException ignore) {}
>- }
>- return encodedURL;
>- }
>-
>- /**
>- * Add a parameter to the given URL.
>- *
>- * @param url the URL to which to append.
>- * @param paramName the name of the parameter to add.
>- * @param paramVal the value of the parameter to add.
>- * @return the URL, with the given parameter added.
>- */
>- public static String addParam(String url, String paramName, String
paramVal)
>- {
>- return url + (url.indexOf('?') != -1 ? '&' : '?') + paramName
+ '=' + paramVal;
>- }
>-}
>Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterSer
vice.java
>===================================================================
>---
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterSer
vice.java (revision 109952)
>+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterSer
vice.java (working copy)
>@@ -159,6 +159,13 @@
> {
> request.setAttribute(URL_REWRITER_KEY, rewriter);
> org.apache.beehive.netui.core.urls.URLRewriter rewriterWrapper
= new OldURLRewriterWrapper(rewriter);
>+
>+ //
>+ // Note that the old URLRewriterService behavior only
registered a single rewriter.
>+ // We need to remove all the existing rewriters to avoid side
effects.
>+ //
>+ rewriterWrapper.setAllowOtherRewriters( false );
>+
org.apache.beehive.netui.core.urls.URLRewriterService.unregisterAllURLRe
writers(request);
>
org.apache.beehive.netui.core.urls.URLRewriterService.registerURLRewrite
r(request, rewriterWrapper);
> }
>
>Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.
java
>===================================================================
>---
netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.
java (revision 109952)
>+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.
java (working copy)
>@@ -155,7 +155,7 @@
> //
> // Register the default URLRewriter
> //
>- URLRewriterService.registerURLRewriter( request, new
DefaultURLRewriter() );
>+ URLRewriterService.registerURLRewriter( 0, request, new
DefaultURLRewriter() );
>
> try
> {
>Index:
netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
>===================================================================
>--- netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
(revision 109952)
>+++ netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
(working copy)
>@@ -28,12 +28,29 @@
> public abstract class URLRewriter
> {
> /**
>- * Passed to [EMAIL PROTECTED] #rewriteURL} for normal (non-resource) and
resource, non-secure and
>+ * Passed to [EMAIL PROTECTED] URLRewriter#rewriteURL} for normal
(non-resource) and resource, non-secure and
> * secure URLs.
> */
> public enum Type { ACTION, RESOURCE }
>
> /**
>+ * Flag indicating that other rewriters are allowed to be used in
the chain.
>+ * The URLRewriterService API will not allow more than one
URLRewriter in
>+ * the chain with this property equal to false.
>+ */
>+ private boolean _allowOtherRewriters = true;
>+
>+ public void setAllowOtherRewriters( boolean allowOtherRewriters )
>+ {
>+ _allowOtherRewriters = allowOtherRewriters;
>+ }
>+
>+ public boolean allowOtherRewriters()
>+ {
>+ return _allowOtherRewriters;
>+ }
>+
>+ /**
> * Rewrite the given query parameter name.
> *
> * @param servletContext the current ServletContext.
>@@ -65,7 +82,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 boolean allowParamsOnFormAction( ServletContext
servletContext, ServletRequest request )
> {
>Index:
netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.jav
a
>===================================================================
>---
netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.jav
a (revision 109952)
>+++
netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.jav
a (working copy)
>@@ -49,10 +49,20 @@
>
> if ( rewriters != null )
> {
>- for ( URLRewriter rewriter : rewriters )
>+ URLRewriter exclusiveRewriter = getExclusiveRewriter(
rewriters );
>+ if ( exclusiveRewriter == null )
> {
>- name = rewriter.rewriteName( servletContext, request,
name );
>+ // No exclusive rewriters registered. Run through the
chain.
>+ for ( URLRewriter rewriter : rewriters )
>+ {
>+ name = rewriter.rewriteName( servletContext,
request, name );
>+ }
> }
>+ else
>+ {
>+ // Use just the exclusive rewriter that was registered
>+ name = exclusiveRewriter.rewriteName( servletContext,
request, name );
>+ }
> }
>
> return name;
>@@ -81,10 +91,20 @@
>
> if ( rewriters != null )
> {
>- for ( URLRewriter rewriter : rewriters )
>+ URLRewriter exclusiveRewriter = getExclusiveRewriter(
rewriters );
>+ if ( exclusiveRewriter == null )
> {
>- rewriter.rewriteURL( servletContext, request,
response, url, type, needsToBeSecure );
>+ // No exclusive rewriters registered. Run through the
chain.
>+ for ( URLRewriter rewriter : rewriters )
>+ {
>+ rewriter.rewriteURL( servletContext, request,
response, url, type, needsToBeSecure );
>+ }
> }
>+ else
>+ {
>+ // Use just the exclusive rewriter that was registered
>+ exclusiveRewriter.rewriteURL( servletContext, request,
response, url, type, needsToBeSecure );
>+ }
> }
> }
>
>@@ -119,7 +139,10 @@
> }
> else
> {
>- if ( !rewriters.contains( rewriter ) ) { rewriters.add(
rewriter ); }
>+ if ( otherRewritersAllowed( rewriters ) )
>+ {
>+ if ( !rewriters.contains( rewriter ) ) {
rewriters.add( rewriter ); }
>+ }
> }
> }
>
>@@ -144,7 +167,10 @@
> }
> else
> {
>- if ( !rewriters.contains( rewriter ) ) { rewriters.add(
index, rewriter ); }
>+ if ( otherRewritersAllowed( rewriters ) )
>+ {
>+ if ( !rewriters.contains( rewriter ) ) {
rewriters.add( index, rewriter ); }
>+ }
> }
> }
>
>@@ -153,6 +179,32 @@
> return ( ArrayList< URLRewriter > )
ScopedServletUtils.getScopedRequestAttribute( URL_REWRITERS_KEY, request
);
> }
>
>+ private static boolean otherRewritersAllowed( ArrayList<
URLRewriter > rewriters )
>+ {
>+ for ( URLRewriter rewriter : rewriters )
>+ {
>+ if ( !rewriter.allowOtherRewriters() )
>+ {
>+ return false;
>+ }
>+ }
>+
>+ return true;
>+ }
>+
>+ private static URLRewriter getExclusiveRewriter( ArrayList<
URLRewriter > rewriters )
>+ {
>+ for ( URLRewriter rewriter : rewriters )
>+ {
>+ if ( !rewriter.allowOtherRewriters() )
>+ {
>+ return rewriter;
>+ }
>+ }
>+
>+ return null;
>+ }
>+
> /**
> * Unregister the URLRewriter (remove from the list) from the
request.
> *
>@@ -182,6 +234,16 @@
> }
>
> /**
>+ * Unregister the URLRewriter (remove from the list) from the
request.
>+ *
>+ * @param request the current ServletRequest.
>+ */
>+ public static void unregisterAllURLRewriters( ServletRequest
request )
>+ {
>+ request.removeAttribute( URL_REWRITERS_KEY );
>+ }
>+
>+ /**
> * Return the form action converted into an action mapping path.
The
> * value of the <code>action</code> property is manipulated as
follows in
> * computing the name of the requested mapping:
>
>