Please use this patch file instead. I had a problem with
the junit test included in the other patch.
Thanks again.
Carlin
Carlin Rogers wrote:
The following patch file contains the following changes
for beehive NetUI.
- Changed Type enum to URLType in URLRewriter.
- Modified URLRewriterService.registerURLRewriter() to log
a message when an exclusive (allowOtherRewriters == false)
rewriter has been registered and return false. When an
exclusive rewriter does get registered it will remove the
other rewriters and log a message about removing other
rewriters, if necessary.
- Implemented a simple diagnostic method to dump the chain
of URLRewriters to a PrintStream.
- Added some more Javadoc to URLRewriterService and
MutableURI.
- Added the character encoding, used to encode unencoded
parameters of a query, as member data of the MutableURI.
- Added a new JUnit test for the MutableURI class and
included it in the NetUI
DRT/BVT: NetUI (WinXP)
BB: self (WinXP)
Thanks,
Carlin
Index: netui/test/ant/junitCore.xml
===================================================================
--- netui/test/ant/junitCore.xml (revision 111546)
+++ netui/test/ant/junitCore.xml (working copy)
@@ -42,6 +42,7 @@
<sysproperty key="netuidrt.logdir" path="${testout.dir}"/>
<test name="org.apache.beehive.netui.test.util.type.TypeUtilsTest"
todir="${testout.dir}"/>
<test name="org.apache.beehive.netui.test.util.config.ConfigTest"
todir="${testout.dir}"/>
+ <test
name="org.apache.beehive.netui.test.core.urls.MutableURITest"
todir="${testout.dir}"/>
<test
name="org.apache.beehive.netui.test.databinding.expression.IndexedNameTest"
todir="${testout.dir}"/>
<test
name="org.apache.beehive.netui.test.script.simpleaction.InternalExpressionUtilsTest"
todir="${testout.dir}"/>
<batchtest fork="yes" todir="${testout.dir}">
@@ -75,4 +76,4 @@
<java classpathref="test.classpath" classname="${test.name}"/>
</target>
-</project>
\ No newline at end of file
+</project>
Index:
netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/MutableURITest.java
===================================================================
---
netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/MutableURITest.java
(revision 0)
+++
netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/MutableURITest.java
(revision 0)
@@ -0,0 +1,506 @@
+/*
+ * 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.test.core.urls;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.beehive.netui.core.urls.MutableURI;
+
+/**
+ * MutableURI JUnit TestCase.
+ */
+public class MutableURITest extends TestCase
+{
+ private static final String DEFAULT_ENCODING = "UTF-8";
+
+ //
+ // Strings for tests. Elements are...
+ // encoding, scheme, user info, host, port, path, query, fragment, result
+ //
+ private String[][] _tests =
+ {
+ // test the ftp scheme + host + path
+ { "ftp", null, "ftp.is.co.za", null,
+ "/rfc/rfc1808.txt", null, null,
+ "ftp://ftp.is.co.za/rfc/rfc1808.txt" },
+
+ // include user info
+ { "telnet", "user:pword", "bogus-machine.com", null,
+ "", null, null,
+ "telnet://user:[EMAIL PROTECTED]" },
+
+ // test for IPv6 addresses
+ { "http", null, "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]", "80",
+ "/index.html", null, null,
+ "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html" },
+
+ // test for relative path + query
+ { null, null, null, null,
+ "../test/start.jsp", "skip=true", null,
+ "../test/start.jsp?skip=true" },
+
+ // test for path + query
+ { null, null, null, null,
+ "/portal/MockPortal.jsp",
+ "smokeTestAaltAction=goNested&smokeTestA_submit=true", null,
+
"/portal/MockPortal.jsp?smokeTestAaltAction=goNested&smokeTestA_submit=true" },
+
+ // test for scheme + host + path
+ { "https", null, "localhost", null,
+ "/tomcat-docs/jasper/docs/api/index.html", null, null,
+ "https://localhost/tomcat-docs/jasper/docs/api/index.html" },
+
+ // test for fragment only
+ { null, null, null, null,
+ "", null, "myFragment", "#myFragment" },
+
+ // test for scheme + host + path + fragment
+ { "http", null, "localhost", "8080", "/",
+ null, "myFragment", "http://localhost:8080/#myFragment" },
+
+ // test for empty path with fragment
+ { "http", null, "localhost", "8080", "",
+ null, "myFragment", "http://localhost:8080#myFragment" },
+
+ // test for query parameter names without values and multiple
+ // instances of the same parameter name
+ { "http", null, "localhost", "8080",
+ "/test-servlet/TestServlet", "param1¶m1=¶m2", null,
+
"http://localhost:8080/test-servlet/TestServlet?param1¶m1=¶m2" },
+
+ // test URI with a session ID
+ { "http", null, "localhost", "8080",
+ "/Web/d/newAction1.do;jsessionid=F0C07D10C0E8CD22618ED1178F0F62C8",
+ null, null,
+
"http://localhost:8080/Web/d/newAction1.do;jsessionid=F0C07D10C0E8CD22618ED1178F0F62C8"
},
+
+ // test for query with escaped characters
+ { "http", null, "localhost", "8080",
+ "/test-servlet/TestServlet",
+
"textId=%C4%F3%BD%D0%BA%D1%A4%DF&spacesAmpQuotes=%22text%20space1%20%26%20space2%22&tags=%3CsomeTag%3E&percent=100%25tilda=%7Etilda",
null,
+
"http://localhost:8080/test-servlet/TestServlet?textId=%C4%F3%BD%D0%BA%D1%A4%DF&spacesAmpQuotes=%22text%20space1%20%26%20space2%22&tags=%3CsomeTag%3E&percent=100%25tilda=%7Etilda"
}
+ };
+
+ public MutableURITest( String name )
+ {
+ super( name );
+ }
+
+ public static void main( String[] args )
+ {
+ junit.textui.TestRunner.run( suite() );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( MutableURITest.class );
+ }
+
+ protected void setUp()
+ {
+ }
+
+ protected void tearDown()
+ {
+ }
+
+ public void testConstructors()
+ {
+ for (int i = 0; i < _tests.length; i++ )
+ {
+ String scheme = _tests[i][0];
+ String userInfo = _tests[i][1];
+ String host = _tests[i][2];
+ int port = MutableURI.UNDEFINED_PORT;
+ String integer = _tests[i][3];
+ if ( integer != null && integer.trim().length() > 0 )
+ {
+ port = Integer.parseInt( integer );
+ }
+ String path = _tests[i][4];
+ String query = _tests[i][5];
+ String fragment = _tests[i][6];
+ String uriString = _tests[i][7];
+
+ try
+ {
+ MutableURI uri = new MutableURI( scheme, userInfo, host, port,
+ path, query, fragment );
+ assertEquals( uriString, uri.toString() );
+ MutableURI other = new MutableURI( uriString );
+ assertEquals( uri, other );
+ other = new MutableURI( new URI( uriString ) );
+ assertEquals( uri, other );
+ }
+ catch ( URISyntaxException e )
+ {
+ fail( "Test failed for URI, \"" + uriString + "\", with a
URISyntaxException: " + e.getMessage() );
+ }
+ }
+ }
+
+ public void testSetters()
+ {
+ for (int i = 0; i < _tests.length; i++ )
+ {
+ String scheme = _tests[i][0];
+ String userInfo = _tests[i][1];
+ String host = _tests[i][2];
+ int port = MutableURI.UNDEFINED_PORT;
+ String integer = _tests[i][3];
+ if ( integer != null && integer.trim().length() > 0 )
+ {
+ port = Integer.parseInt( integer );
+ }
+ String path = _tests[i][4];
+ String query = _tests[i][5];
+ String fragment = _tests[i][6];
+ String uriString = _tests[i][7];
+
+ try
+ {
+ MutableURI uri = new MutableURI();
+ uri.setScheme( scheme );
+ uri.setHost( host );
+ uri.setUserInfo( userInfo );
+ uri.setPort( port );
+ uri.setPath( path );
+ uri.setQuery( query );
+ uri.setFragment( fragment );
+ assertEquals( uriString, uri.toString() );
+
+ MutableURI other = new MutableURI( uriString );
+ assertEquals( uri, other );
+ }
+ catch ( URISyntaxException e )
+ {
+ fail( "Test failed for URI, \"" + uriString + "\", with a
URISyntaxException: " + e.getMessage() );
+ }
+ }
+ }
+
+ public void testGetters()
+ {
+ for (int i = 0; i < _tests.length; i++ )
+ {
+ String scheme = _tests[i][0];
+ String userInfo = _tests[i][1];
+ String host = _tests[i][2];
+ int port = MutableURI.UNDEFINED_PORT;
+ String integer = _tests[i][3];
+ if ( integer != null && integer.trim().length() > 0 )
+ {
+ port = Integer.parseInt( integer );
+ }
+ String path = _tests[i][4];
+ String query = _tests[i][5];
+ String fragment = _tests[i][6];
+ String uriString = _tests[i][7];
+
+ try
+ {
+ MutableURI uri = new MutableURI( uriString );
+ assertEquals( uriString, uri.toString() );
+ assertEquals( uri.getScheme(), scheme );
+ assertEquals( uri.getHost(), host );
+ assertEquals( uri.getUserInfo(), userInfo );
+ assertEquals( uri.getPort(), port );
+ assertEquals( uri.getPath(), path );
+ assertEquals( uri.getQuery( "&" ), query );
+ assertEquals( uri.getFragment(), fragment );
+ }
+ catch ( URISyntaxException e )
+ {
+ fail( "Test failed for URI, \"" + uriString + "\", with a
URISyntaxException: " + e.getMessage() );
+ }
+ }
+ }
+
+ public void testIsAbsolute()
+ {
+ try
+ {
+ MutableURI uri = new MutableURI(
"http://localhost/test?param1=true" );
+ assertTrue( uri.isAbsolute() );
+ uri = new MutableURI( "/test?param1=true" );
+ assertFalse( uri.isAbsolute() );
+ }
+ catch ( URISyntaxException e )
+ {
+ fail( "Test failed with a URISyntaxException: " + e.getMessage() );
+ }
+ }
+
+ public void testQueryParameters()
+ {
+ MutableURI origURI = new MutableURI();
+ origURI.setEncoding( DEFAULT_ENCODING );
+ MutableURI uri = new MutableURI();
+ uri.setEncoding( DEFAULT_ENCODING );
+ String path = "/path";
+ String name = "paramName";
+ String value = "paramValue";
+ String query = name + "=" + value;
+ origURI.setPath( path );
+ uri.setPath( path );
+ origURI.setQuery( query );
+ uri.setQuery( query );
+ assertEquals( uri.getParameter( name ), value );
+
+ // now use addParameter() to set the query
+ uri.setQuery( null );
+ uri.addParameter( name, value, true );
+ assertEquals( uri, origURI );
+ assertEquals( uri.getParameter( name ), value );
+ assertEquals( uri.getParameters( name ).size(), 1 );
+ assertEquals( uri.getParameters().size(), 1 );
+
+ // remove the parameter
+ uri.removeParameter( name );
+ assertFalse( uri.equals( origURI ) );
+ assertEquals( uri.getParameters( name ).size(), 0 );
+ assertEquals( uri.getParameters().size(), 0 );
+
+ // add a parameter with a null value (just a name)
+ uri.addParameter( name, null, true );
+ List< String > values = uri.getParameters( name );
+ assertEquals( values.size(), 1 );
+ assertEquals( values.get( 0 ), null );
+
+ // ask for a parameter that does not exist
+ values = uri.getParameters( "bogus name" );
+ assertEquals( values.size(), 0 );
+
+ // add a parameter values with the same name
+ String[] initValues = { "", null, "value1", "value2" };
+ uri.setQuery( null );
+ int i = 0;
+
+ for ( i = 0; i < initValues.length; i++ )
+ {
+ uri.addParameter( name, initValues[i], true );
+ }
+
+ assertEquals( uri.getParameter( name ), initValues[0] );
+ values = uri.getParameters( name );
+ assertEquals( values.size(), initValues.length );
+ assertEquals( uri.getParameters().size(), 1 );
+ i = 0;
+
+ for ( String v : values )
+ {
+ assertEquals( v, initValues[i++] );
+ }
+
+ // and add a bunch of paramters
+ String[][] initParams =
+ {
+ { "param1", "value1" }, { "param2", "value2" },
+ { "param3", "value3" }, { "param4", "value4" },
+ { "param5", "value5" }, { "param6", "value6" },
+ { "param7", "value7" }, { "param8", "value8" },
+ { "param9", "value9" }, { "param10", "value10" },
+ { "param11", "value11" }, { "param12", "value12" }
+ };
+
+ uri.setQuery( null );
+ HashMap map = new HashMap();
+
+ for ( i = 0; i < initParams.length; i++ )
+ {
+ map.put( initParams[i][0], initParams[i][1] );
+ }
+
+ uri.addParameters( map, true );
+ assertEquals( uri.getParameters( initParams[0][0] ).size(), 1 );
+ assertEquals( uri.getParameters().size(), initParams.length );
+ Map< String, List< String > > params = uri.getParameters();
+ i = 0;
+
+ for ( String n : params.keySet() )
+ {
+ for ( String v : params.get( n ) )
+ {
+ assertTrue( map.containsKey( n ) );
+ assertEquals( v, map.get( n ) );
+ }
+ i++;
+ }
+ }
+
+ public void testEncoding()
+ {
+ String path = "/path";
+
+ MutableURI utf8EncodedUri = new MutableURI();
+ utf8EncodedUri.setEncoding( DEFAULT_ENCODING );
+ utf8EncodedUri.setPath( path );
+
+ MutableURI eucJPEncodedUri = new MutableURI();
+ eucJPEncodedUri.setEncoding( "EUC_JP" );
+ eucJPEncodedUri.setPath( path );
+
+ // test encoding of URI reserved characters, etc.
+ String reserved = "semi;slash/quest?colon:[EMAIL
PROTECTED]&equ=plus+doller$comm,";
+ String mark = "hyph-un_per.ex!tilda~ast*ap'lp(rp)";
+ utf8EncodedUri.addParameter( reserved, mark, false );
+ eucJPEncodedUri.addParameter( reserved, mark, false );
+ assertEquals( utf8EncodedUri.toString(), eucJPEncodedUri.toString() );
+ assertEquals( utf8EncodedUri.getQuery( "&" ),
+
"semi%3Bslash%2Fquest%3Fcolon%3Aat%40and%26equ%3Dplus%2Bdoller%24comm%2C"
+ + "=" + "hyph-un_per.ex%21tilda%7East*ap%27lp%28rp%29" );
+
+ utf8EncodedUri.setQuery( null );
+ eucJPEncodedUri.setQuery( null );
+ String unwise = "lcb{rcb}bar|bs\\ctr^lb[rb]lq`";
+ String delims = "lt<gt>lb#perc%\"quotes\"";
+ String excluded = "space " + delims;
+ utf8EncodedUri.addParameter( unwise, excluded, false );
+ eucJPEncodedUri.addParameter( unwise, excluded, false );
+ assertEquals( utf8EncodedUri.toString(), eucJPEncodedUri.toString() );
+ assertEquals( utf8EncodedUri.getQuery( "&" ),
+ "lcb%7Brcb%7Dbar%7Cbs%5Cctr%5Elb%5Brb%5Dlq%60"
+ + "=" + "space+lt%3Cgt%3Elb%23perc%25%22quotes%22" );
+
+ // test encoding of mu;tibyte characters in a URI.
+ utf8EncodedUri.setQuery( null );
+ eucJPEncodedUri.setQuery( null );
+ String name = "name";
+ String japaneseUnicode = "\u63d0\u51fa\u6e08\u307f";
+ utf8EncodedUri.addParameter( name, japaneseUnicode, false );
+ eucJPEncodedUri.addParameter( name, japaneseUnicode, false );
+ assertFalse( utf8EncodedUri.toString().equals(
eucJPEncodedUri.toString() ) );
+ assertEquals( utf8EncodedUri.getQuery( "&" ),
+ name + "=" + "%E6%8F%90%E5%87%BA%E6%B8%88%E3%81%BF" );
+ assertEquals( eucJPEncodedUri.getQuery( "&" ),
+ name + "=" + "%C4%F3%BD%D0%BA%D1%A4%DF" );
+ }
+
+ public void testToXMLString()
+ {
+ MutableURI uri = new MutableURI();
+ uri.setScheme( "https" );
+ uri.setHost( "localhost" );
+ uri.setPort( 443 );
+ uri.setPath( "/test" );
+ uri.setQuery( "param1¶m2¶m3=¶m3=true¶m4=true" );
+ String xmlString =
"https://localhost:443/test?param1&param2&param3=&param3=true&param4=true";
+ assertEquals( uri.toXMLString(), xmlString );
+ }
+
+ public void testEquals()
+ {
+ //
+ // Note that the current implementation MutableURI, with query
+ // parameters stored in a LinkedHashMap of Lists, has the
+ // potential to change order of params in the query... such
+ // as this example. So the resulting string has params in a
+ // different order. However equality should still hold true.
+ //
+ String uriString =
"https://localhost:443/test?param1¶m1=¶m1=true¶m2¶m3=true";
+
+ try
+ {
+ MutableURI uriA = new MutableURI();
+ uriA.setScheme( "https" );
+ uriA.setHost( "localhost" );
+ uriA.setPort( 443 );
+ uriA.setPath( "/test" );
+ uriA.setQuery( "param1¶m2¶m1=¶m3=true¶m1=true" );
+
+ MutableURI uriB = new MutableURI( uriString );
+ assertEquals( uriA.toString(), uriString );
+ assertEquals( uriA.toString(), uriB.toString() );
+
+ MutableURI uriC = new MutableURI( new URI( uriString ) );
+
+ // Test all properties of equality...
+ // 1. hashCodes are equal
+ assertEquals( uriA.hashCode(), uriA.hashCode() );
+
+ // 2. reflexive
+ assertTrue( uriA.equals( uriA ) );
+
+ // 3. symmetric
+ assertTrue( uriA.equals( uriB ) );
+ assertTrue( uriB.equals( uriA ) );
+
+ // 4. transitive
+ assertTrue( uriA.equals( uriB ) );
+ assertTrue( uriB.equals( uriC ) );
+ assertTrue( uriC.equals( uriA ) );
+
+ // 5. consistent
+ uriC.setPath( "/differentPath" );
+ assertFalse( uriC.equals( uriA ) );
+
+ // 6. x.equals(null) should return false.
+ assertFalse( uriA.equals( null ) );
+
+ // and subclasses return false as not to break the symmetric
property
+ class AnotherMutableURI extends MutableURI
+ {
+ boolean reference = true;
+
+ AnotherMutableURI( URI uri ) { super( uri ); }
+
+ void setReference( boolean ref ) { reference = ref; }
+
+ boolean isReference() { return reference; }
+ }
+
+ AnotherMutableURI another = new AnotherMutableURI( new URI(
uriString ) );
+ assertFalse( uriA.equals( another ) );
+
+ }
+ catch ( URISyntaxException e )
+ {
+ fail( "Test failed for URI, \"" + uriString + "\", with a
URISyntaxException: " + e.getMessage() );
+ }
+ }
+
+ // basic diagnostic utility when writing tests
+ private void dumpURI( MutableURI uri )
+ {
+ if ( uri == null )
+ {
+ System.out.println( "uri == null" );
+ }
+ else
+ {
+ System.out.println( "string: " + uri.toString() );
+ System.out.println( "XML string: " + uri.toXMLString() );
+ System.out.println( "scheme: " + uri.getScheme() );
+ System.out.println( "user info: " + uri.getUserInfo() );
+ System.out.println( "host: " + uri.getHost() );
+ System.out.println( "port: " + uri.getPort() );
+ System.out.println( "path: " + uri.getPath() );
+ System.out.println( "query: " + uri.getQuery( "&" ) );
+ System.out.println( "fragment: " + uri.getFragment() );
+ System.out.println( "encoding: " + uri.getEncoding() );
+ }
+ }
+}
Property changes on:
netui/test/src/junitTests/org/apache/beehive/netui/test/core/urls/MutableURITest.java
___________________________________________________________________
Name: svn:eol-style
+ native
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 111546)
+++ netui/src/tags-html/org/apache/beehive/netui/tags/html/RewriteURL.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.core.urls.URLRewriter;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
import org.apache.beehive.netui.core.urls.URLRewriterService;
import org.apache.beehive.netui.tags.AbstractClassicTag;
import org.apache.beehive.netui.tags.internal.PageFlowTagUtils;
@@ -92,13 +92,13 @@
try {
boolean needsToBeSecure = false;
uri = new MutableURI(url);
+ uri.setEncoding( response.getCharacterEncoding() );
if (!uri.isAbsolute() && PageFlowTagUtils.needsSecure(context,
request, url, true)) {
needsToBeSecure = true;
}
- URLRewriterService.rewriteURL(context, request, response, uri,
URLRewriter.Type.ACTION, needsToBeSecure);
- //TODO... why no call to response.encodeURL(uri.toString()) for
session ID?
- write(uri.toString());
+ URLRewriterService.rewriteURL(context, request, response, uri,
URLType.ACTION, needsToBeSecure);
+ write(response.encodeURL(uri.toString()));
}
catch (URISyntaxException e) {
// report the error...
Index:
netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
===================================================================
---
netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
(revision 111546)
+++
netui/src/tags-html/org/apache/beehive/netui/tags/internal/PageFlowTagUtils.java
(working copy)
@@ -18,7 +18,7 @@
package org.apache.beehive.netui.tags.internal;
import org.apache.beehive.netui.core.urls.MutableURI;
-import org.apache.beehive.netui.core.urls.URLRewriter;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
import org.apache.beehive.netui.core.urls.URLRewriterService;
import org.apache.beehive.netui.pageflow.FlowController;
import org.apache.beehive.netui.pageflow.FlowControllerFactory;
@@ -51,7 +51,7 @@
/**
* Create a mutable url object from an initial action url with query
parameters
* and an anchor (location on page), checking if it needs to be secure
then call
- * the rewriter service using a type of [EMAIL PROTECTED]
URLRewriter.Type.ACTION}.
+ * the rewriter service using a type of [EMAIL PROTECTED] URLType.ACTION}.
*
* @param pageContext the current PageContext.
* @param action the action url to rewrite.
@@ -68,18 +68,18 @@
String qualifiedAction = InternalUtils.qualifyAction( servletContext,
action );
String actionUrl = InternalUtils.createActionURL( ( HttpServletRequest
) request, qualifiedAction );
MutableURI uri = new MutableURI( actionUrl );
+ uri.setEncoding( response.getCharacterEncoding() );
if ( params != null )
{
- String encoding = response.getCharacterEncoding();
- uri.addParameters( params, false, encoding );
+ uri.addParameters( params, false );
}
if ( location != null ) { uri.setFragment( location ); }
boolean needsToBeSecure = needsSecure( servletContext, request,
actionUrl, true );
URLRewriterService.rewriteURL( servletContext, request, response, uri,
- URLRewriter.Type.ACTION,
needsToBeSecure );
+ URLType.ACTION, needsToBeSecure );
return uri;
}
@@ -87,7 +87,7 @@
/**
* Create a mutable url object from an initial href url with query
parameters
* and an anchor (location on page), checking if it needs to be secure
then call
- * the rewriter service using a type of [EMAIL PROTECTED]
URLRewriter.Type.ACTION}.
+ * the rewriter service using a type of [EMAIL PROTECTED] URLType.ACTION}.
*
* @param pageContext the current PageContext.
* @param url the href url to rewrite.
@@ -98,13 +98,13 @@
public static MutableURI rewriteHrefURL( PageContext pageContext, String
url, Map params, String location )
throws URISyntaxException
{
- return rewriteResourceOrHrefURL( pageContext, url, params, location,
URLRewriter.Type.ACTION );
+ return rewriteResourceOrHrefURL( pageContext, url, params, location,
URLType.ACTION );
}
/**
* Create a mutable url object from an initial resource url with query
parameters
* and an anchor (location on page), checking if it needs to be secure
then call
- * the rewriter service using a type of [EMAIL PROTECTED]
URLRewriter.Type.RESOURCE}.
+ * the rewriter service using a type of [EMAIL PROTECTED]
URLType.RESOURCE}.
*
* @param pageContext the current PageContext.
* @param url the resource url to rewrite.
@@ -115,19 +115,20 @@
public static MutableURI rewriteResourceURL( PageContext pageContext,
String url, Map params, String location )
throws URISyntaxException
{
- return rewriteResourceOrHrefURL( pageContext, url, params, location,
URLRewriter.Type.RESOURCE );
+ return rewriteResourceOrHrefURL( pageContext, url, params, location,
URLType.RESOURCE );
}
private static MutableURI rewriteResourceOrHrefURL( PageContext
pageContext, String url, Map params,
- String location,
URLRewriter.Type type )
+ String location,
URLType type )
throws URISyntaxException
{
HttpServletResponse response = ( HttpServletResponse )
pageContext.getResponse();
MutableURI uri = new MutableURI( url );
+ uri.setEncoding( response.getCharacterEncoding() );
+
if ( params != null )
{
- String encoding = response.getCharacterEncoding();
- uri.addParameters( params, false, encoding );
+ uri.addParameters( params, false );
}
if ( location != null ) { uri.setFragment( location ); }
Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java
===================================================================
---
netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java
(revision 111546)
+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/internal/DefaultURLRewriter.java
(working copy)
@@ -27,6 +27,7 @@
import org.apache.beehive.netui.core.urls.MutableURI;
import org.apache.beehive.netui.core.urls.URLRewriter;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
import org.apache.beehive.netui.pageflow.ServerAdapter;
import org.apache.beehive.netui.pageflow.util.TemplateHelper;
import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
@@ -43,7 +44,7 @@
}
public void rewriteURL( ServletContext servletContext, ServletRequest
request,
- ServletResponse response, MutableURI url, Type
type, boolean needsToBeSecure )
+ ServletResponse response, MutableURI url, URLType
type, boolean needsToBeSecure )
{
// TODO... fix/modify TemplateHelper to use MutableURI or figure out a
way for it subclass
// MutableURI. This is just the old code from the depricate
DefaultURLRewriter.
@@ -52,7 +53,7 @@
// do the lookup to get the right template.
// Apply the value to the template.
String templateType =
org.apache.beehive.netui.pageflow.util.URLRewriter.ACTION_UNSECURE;
- if ( type.equals( URLRewriter.Type.ACTION ) )
+ if ( type.equals( URLType.ACTION ) )
{
if ( needsToBeSecure )
{
@@ -63,7 +64,7 @@
templateType =
org.apache.beehive.netui.pageflow.util.URLRewriter.ACTION_UNSECURE;
}
}
- else if ( type.equals( URLRewriter.Type.RESOURCE ) )
+ else if ( type.equals( URLType.RESOURCE ) )
{
if ( needsToBeSecure )
{
@@ -91,7 +92,7 @@
url.setPort( uri.getPort() );
url.setPath( uri.getPath() );
url.setQuery( null );
- url.addParameters( uri.getParameters(), true, null );
+ url.addParameters( uri.getParameters(), true );
url.setFragment( uri.getFragment() );
}
catch ( URISyntaxException e )
@@ -161,7 +162,7 @@
List< String > parameters = url.getParameters(
ScopedServletUtils.SCOPE_ID_PARAM );
if ( parameters != null && !parameters.contains( scopeID ) )
{
- url.addParameter( ScopedServletUtils.SCOPE_ID_PARAM, scopeID,
true, null );
+ url.addParameter( ScopedServletUtils.SCOPE_ID_PARAM, scopeID,
true );
}
}
}
Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java
===================================================================
---
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java
(revision 111546)
+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/OldURLRewriterWrapper.java
(working copy)
@@ -63,12 +63,12 @@
public void rewriteURL( ServletContext servletContext, ServletRequest
request,
ServletResponse response, MutableURI uri,
-
org.apache.beehive.netui.core.urls.URLRewriter.Type type,
+
org.apache.beehive.netui.core.urls.URLRewriter.URLType type,
boolean needsToBeSecure )
{
String tempType = URLRewriter.RESOURCE_UNSECURE;
- if ( type.equals(
org.apache.beehive.netui.core.urls.URLRewriter.Type.ACTION ) )
+ if ( type.equals(
org.apache.beehive.netui.core.urls.URLRewriter.URLType.ACTION ) )
{
if ( needsToBeSecure )
{
@@ -79,7 +79,7 @@
tempType = URLRewriter.ACTION_UNSECURE;
}
}
- else if ( type.equals(
org.apache.beehive.netui.core.urls.URLRewriter.Type.RESOURCE ) )
+ else if ( type.equals(
org.apache.beehive.netui.core.urls.URLRewriter.URLType.RESOURCE ) )
{
if ( needsToBeSecure )
{
@@ -102,7 +102,7 @@
uri.setPort( newURI.getPort() );
uri.setPath( newURI.getPath() );
uri.setQuery( null );
- uri.addParameters( newURI.getParameters(), true, null );
+ uri.addParameters( newURI.getParameters(), true );
uri.setFragment( newURI.getFragment() );
}
catch ( java.net.URISyntaxException e )
Index:
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java
===================================================================
---
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java
(revision 111546)
+++
netui/src/pageflow/org/apache/beehive/netui/pageflow/util/URLRewriterService.java
(working copy)
@@ -113,17 +113,18 @@
MutableURI mutableUri = null;
try {
mutableUri = new MutableURI( url );
- org.apache.beehive.netui.core.urls.URLRewriter.Type tempType =
-
org.apache.beehive.netui.core.urls.URLRewriter.Type.RESOURCE;
+ mutableUri.setEncoding( response.getCharacterEncoding() );
+ org.apache.beehive.netui.core.urls.URLRewriter.URLType tempType =
+
org.apache.beehive.netui.core.urls.URLRewriter.URLType.RESOURCE;
boolean needsToBeSecure = false;
if ( type.equals( URLRewriter.ACTION_UNSECURE ) )
{
- tempType =
org.apache.beehive.netui.core.urls.URLRewriter.Type.ACTION;
+ tempType =
org.apache.beehive.netui.core.urls.URLRewriter.URLType.ACTION;
}
else if ( type.equals( URLRewriter.ACTION_SECURE ) )
{
- tempType =
org.apache.beehive.netui.core.urls.URLRewriter.Type.ACTION;
+ tempType =
org.apache.beehive.netui.core.urls.URLRewriter.URLType.ACTION;
needsToBeSecure = true;
}
else if ( type.equals( URLRewriter.RESOURCE_SECURE ) )
Index: netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
===================================================================
--- netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
(revision 111546)
+++ netui/src/util/org/apache/beehive/netui/core/urls/URLRewriter.java
(working copy)
@@ -31,7 +31,7 @@
* Passed to [EMAIL PROTECTED] URLRewriter#rewriteURL} for normal
(non-resource) and resource, non-secure and
* secure URLs.
*/
- public enum Type { ACTION, RESOURCE }
+ public enum URLType { ACTION, RESOURCE }
/**
* Flag indicating that other rewriters are allowed to be used in the
chain.
@@ -75,7 +75,7 @@
* @param needsToBeSecure a flag indicating whether the URL should be
secure (SSL required) or not
*/
public abstract void rewriteURL( ServletContext servletContext,
ServletRequest request,
- ServletResponse response, MutableURI url,
Type type,
+ ServletResponse response, MutableURI url,
URLType type,
boolean needsToBeSecure );
/**
Index: netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java
===================================================================
--- netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java
(revision 111546)
+++ netui/src/util/org/apache/beehive/netui/core/urls/URLRewriterService.java
(working copy)
@@ -17,11 +17,14 @@
*/
package org.apache.beehive.netui.core.urls;
+import org.apache.beehive.netui.core.urls.URLRewriter.URLType;
import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
+import org.apache.beehive.netui.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.io.PrintStream;
import javax.servlet.ServletRequest;
import javax.servlet.ServletContext;
import javax.servlet.ServletResponse;
@@ -30,13 +33,22 @@
/**
* Methods for registering URL rewriters, adding URL rewriters
* to the chain, and for rewriting URLs using registered rewriters.
+ *
+ * <p> Note that when a URLRewriter is registered with this service
+ * it is added to a chain (a List) of rewriters. When rewriting
+ * occurs, we loop through each rewriter in the list. The only exception
+ * to this is when a rewriter that does not allow other rewriters
+ * to be used is registered. This then becomes the exclusive rewriter
+ * to use and no other rewriters can be registered. </p>
*/
public class URLRewriterService
{
+ private static final Logger _log = Logger.getInstance(
URLRewriterService.class );
+
private static String URL_REWRITERS_KEY = "url_rewriters";
/**
- * Rewrite the given parameter name, using the registered URLRewriter.
+ * Rewrite the given parameter name, looping through the list of
registered URLRewriters.
*
* @param servletContext the current ServletContext.
* @param request the current ServletRequest.
@@ -49,27 +61,17 @@
if ( rewriters != null )
{
- URLRewriter exclusiveRewriter = getExclusiveRewriter( rewriters );
- if ( exclusiveRewriter == null )
+ for ( URLRewriter rewriter : rewriters )
{
- // No exclusive rewriters registered. Run through the chain.
- for ( URLRewriter rewriter : rewriters )
- {
- name = rewriter.rewriteName( servletContext, request, name
);
- }
+ name = rewriter.rewriteName( servletContext, request, name );
}
- else
- {
- // Use just the exclusive rewriter that was registered
- name = exclusiveRewriter.rewriteName( servletContext, request,
name );
- }
}
return name;
}
/**
- * Rewrite the given URL, using the list of registered URLRewriter objects.
+ * Rewrite the given URL, looping through the list of registered
URLRewriters.
*
* @param servletContext the current ServletContext.
* @param request the current ServletRequest.
@@ -84,27 +86,17 @@
* @see #registerURLRewriter
*/
public static void rewriteURL( ServletContext servletContext,
ServletRequest request,
- ServletResponse response, MutableURI url,
URLRewriter.Type type,
+ ServletResponse response, MutableURI url,
URLType type,
boolean needsToBeSecure )
{
ArrayList< URLRewriter > rewriters = getRewriters( request );
if ( rewriters != null )
{
- URLRewriter exclusiveRewriter = getExclusiveRewriter( rewriters );
- if ( exclusiveRewriter == null )
+ for ( URLRewriter rewriter : rewriters )
{
- // No exclusive rewriters registered. Run through the chain.
- for ( URLRewriter rewriter : rewriters )
- {
- rewriter.rewriteURL( servletContext, request, response,
url, type, needsToBeSecure );
- }
+ 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 );
- }
}
}
@@ -126,8 +118,12 @@
*
* @param request the current ServletRequest.
* @param rewriter the URLRewriter to register.
+ * @return <code>false</code> if a URLRewriter has been registered
+ * that does not allow other rewriters. Otherwise,
<code>true</code>
+ * if the URLRewriter was added to the chain or already exists in
+ * the chain.
*/
- public static void registerURLRewriter( ServletRequest request,
URLRewriter rewriter )
+ public static boolean registerURLRewriter( ServletRequest request,
URLRewriter rewriter )
{
ArrayList< URLRewriter > rewriters = getRewriters( request );
@@ -139,11 +135,10 @@
}
else
{
- if ( otherRewritersAllowed( rewriters ) )
- {
- if ( !rewriters.contains( rewriter ) ) { rewriters.add(
rewriter ); }
- }
+ return addRewriter( rewriters, rewriter, rewriters.size() );
}
+
+ return true;
}
/**
@@ -154,8 +149,12 @@
* @param index the place to insert the URLRewriter
* @param request the current ServletRequest.
* @param rewriter the URLRewriter to register.
+ * @return <code>false</code> if a URLRewriter has been registered
+ * that does not allow other rewriters. Otherwise,
<code>true</code>
+ * if the URLRewriter was added to the chain or already exists in
+ * the chain.
*/
- public static void registerURLRewriter( int index, ServletRequest request,
URLRewriter rewriter )
+ public static boolean registerURLRewriter( int index, ServletRequest
request, URLRewriter rewriter )
{
ArrayList< URLRewriter > rewriters = getRewriters( request );
@@ -167,11 +166,10 @@
}
else
{
- if ( otherRewritersAllowed( rewriters ) )
- {
- if ( !rewriters.contains( rewriter ) ) { rewriters.add( index,
rewriter ); }
- }
+ return addRewriter( rewriters, rewriter, index );
}
+
+ return true;
}
private static ArrayList< URLRewriter > getRewriters( ServletRequest
request )
@@ -179,30 +177,55 @@
return ( ArrayList< URLRewriter > )
ScopedServletUtils.getScopedRequestAttribute( URL_REWRITERS_KEY, request );
}
- private static boolean otherRewritersAllowed( ArrayList< URLRewriter >
rewriters )
+ private static boolean addRewriter( ArrayList< URLRewriter > rewriters,
URLRewriter rewriter, int index )
{
- for ( URLRewriter rewriter : rewriters )
+ if ( otherRewritersAllowed( rewriters ) )
{
- if ( !rewriter.allowOtherRewriters() )
+ if ( !rewriters.contains( rewriter ) )
{
- return false;
+ if ( !rewriter.allowOtherRewriters() )
+ {
+ rewriters.clear();
+
+ if ( rewriters.size() > 0 && _log.isInfoEnabled() )
+ {
+ StringBuilder message = new StringBuilder();
+ message.append( "Register exclusive URLRewriter, \"");
+ message.append( rewriter.getClass().getName() );
+ message.append( "\". This removes any other
URLRewriter objects already registered in the chain." );
+ _log.info( message.toString() );
+ }
+ }
+ rewriters.add( index, rewriter );
}
}
+ else
+ {
+ if ( _log.isInfoEnabled() )
+ {
+ StringBuilder message = new StringBuilder();
+ message.append( "Cannot register URLRewriter, \"");
+ message.append( rewriter.getClass().getName() );
+ message.append( "\". The URLRewriter, \"" );
+ message.append( rewriters.get( 0 ).getClass().getName() );
+ message.append( "\", is already registered and does not allow
other rewriters." );
+ _log.info( message.toString() );
+ }
+ return false;
+ }
+
return true;
}
- private static URLRewriter getExclusiveRewriter( ArrayList< URLRewriter >
rewriters )
+ private static boolean otherRewritersAllowed( ArrayList< URLRewriter >
rewriters )
{
- for ( URLRewriter rewriter : rewriters )
+ if ( rewriters != null && rewriters.size() == 1 && !rewriters.get( 0
).allowOtherRewriters() )
{
- if ( !rewriter.allowOtherRewriters() )
- {
- return rewriter;
- }
+ return false;
}
- return null;
+ return true;
}
/**
@@ -247,8 +270,6 @@
* Tell whether rewritten form actions should be allowed to have query
parameters. If this returns
* <code>false</code>, then a form-tag implementation should render query
parameters into hidden
* fields on the form instead of allowing them to remain in the URL.
- *
- * @exclude
*/
public static boolean allowParamsOnFormAction( ServletContext
servletContext, ServletRequest request )
{
@@ -264,4 +285,34 @@
return true;
}
+
+ /**
+ * Print out information about the chain of URLRewriters in this request.
+ *
+ * @param request the current HttpServletRequest.
+ * @param output a PrintStream to output chain of URLRewriters in this
request.
+ * If <code>null</null>, <code>System.err</code> is used.
+ */
+ public static void dumpURLRewriters( ServletRequest request, PrintStream
output )
+ {
+ ArrayList< URLRewriter > rewriters = getRewriters( request );
+
+ if ( output == null ) output = System.err;
+ output.println( "*** List of URLRewriter objects: " + rewriters );
+
+ if ( rewriters != null )
+ {
+ int count = 0;
+ for ( URLRewriter rewriter : rewriters )
+ {
+ output.println( " " + count++ + ". " +
rewriter.getClass().getName() );
+ output.println( " allows other rewriters: " +
rewriter.allowOtherRewriters() );
+ output.println( " rewriter: " + rewriter );
+ }
+ }
+ else
+ {
+ output.println( " No URLRewriter objects are registered
with this request." );
+ }
+ }
}
Index: netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java
===================================================================
--- netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java
(revision 111546)
+++ netui/src/util/org/apache/beehive/netui/core/urls/MutableURI.java
(working copy)
@@ -31,16 +31,41 @@
import java.util.HashMap;
/**
- * Class for creating URIs.
+ * Mutable class for creating URIs.
*
+ * <p> There is no checking that an instance of this class produces a legal
+ * URI reference as defined by <a href="http://www.ietf.org/rfc/rfc2396.txt">
+ * <i>RFC 2396: Uniform Resource Identifiers (URI): Generic
Syntax</i></a>.
+ * The only minimal checking for syntax is on constructors that take a String
+ * representation or the URI, a [EMAIL PROTECTED] URI}, or a [EMAIL PROTECTED]
URL}.
+ * To avoid the cost of continually checking the syntax, it is up to the
+ * user to ensure that the components are set correctly. </p>
+ *
+ * <p> The setters of this class also assume that the data components are
+ * already encoded correctly for the given encoding of this URI, unless noted
+ * otherwise as in the methods to add unecoded parameters to the query.
+ * Then this class will handle the encoding.
+ * See [EMAIL PROTECTED] #addParameter( String name, String value, boolean
encoded )}
+ * and [EMAIL PROTECTED] #addParameters( Map newParams, boolean encoded )}
+ * </p>
+ *
+ * <p> There is static convenience method in this class so callers can
+ * easily encode unencoded components before setting in this URI. </p>
+ *
* TODO... We need to implement some conditions for opaque URIs like mailto,
etc.
- * TODO... determine what to do about constructor and initialization of path
when (path == null) => opaque and URI.getPath() would return "" for non-opaue
URIs.
+ * TODO... and determine what to do about constructor and init of path when
(path == null) => opaque and URI.getPath() would return "" for non-opaue URIs.
*/
public class MutableURI
{
/** Value used to set the port as undefined. */
public static final int UNDEFINED_PORT = -1;
+ /** Value used to set the port as undefined. */
+ public static final String DEFAULT_ENCODING = "UTF-8";
+
+ /** Character encoding used for the URI. */
+ private String _encoding;
+
/** Protocol scheme. */
private String _scheme;
@@ -92,7 +117,7 @@
throw new IllegalArgumentException( "The URI cannot be null." );
}
- // Parse this url into its component parts
+ // Parse this string into its components using URI
URI uri = new URI( uriString );
setScheme( uri.getScheme() );
setUserInfo( uri.getRawUserInfo() );
@@ -151,7 +176,7 @@
* Constructs a <code>MutableURI</code>.
*
* <p> This is just a convenience constructor that functions the same as
- * [EMAIL PROTECTED] #MutableURI(java.net.URI)} constructor with
+ * [EMAIL PROTECTED] #MutableURI(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
@@ -182,6 +207,26 @@
}
/**
+ * Set the encoding used when adding unencoded parameters.
+ *
+ * @param encoding
+ */
+ public void setEncoding( String encoding )
+ {
+ _encoding = encoding;
+ }
+
+ /**
+ * Returns the encoding that is used when adding unencoded parameters.
+ *
+ * @return encoding
+ */
+ public String getEncoding()
+ {
+ return _encoding;
+ }
+
+ /**
* Sets the protocol/scheme.
*
* @param scheme protocol/scheme
@@ -368,11 +413,11 @@
int eq = queryItem.indexOf( '=' );
if ( eq != -1 )
{
- addParameter( queryItem.substring( 0, eq ).trim() ,
queryItem.substring( eq + 1 ).trim(), true, null );
+ addParameter( queryItem.substring( 0, eq ).trim() ,
queryItem.substring( eq + 1 ).trim(), true );
}
else
{
- addParameter( queryItem, null, true, null );
+ addParameter( queryItem, null, true );
}
}
}
@@ -380,8 +425,12 @@
/**
* Returns the query string (encoded).
*
+ * <p> It takes a String to be used to separate the parameters, usually
+ * either "&" or "&amp;". The later option
+ * is typical when writing valid XML. See [EMAIL PROTECTED]
#toXMLString()} </p>
+ *
* @param paramSeparator The string used to separate the parameters in the
- * query. ("&" or
"&amp;")
+ * query.
* @return encoded query string.
*/
public String getQuery( String paramSeparator )
@@ -423,8 +472,9 @@
* <p> If the encoded flag is true then this method assumes that
* the name and value do not need encoding or are already encoded
* correctly. Otherwise, it translates the name and value with the
- * character encoding and adds them to the set of parameters for
- * the query. </p>
+ * character encoding of this URI and adds them to the set of
+ * parameters for the query. If the encoding for this URI has
+ * not been set, then the default encoding used is "UTF-8". </p>
* <p> Multiple values for the same parameter can be set by
* calling this method multiple times with the same name. </p>
*
@@ -432,9 +482,8 @@
* @param value value
* @param encoded Flag indicating whether the names and values are
* already encoded.
- * @param encoding The name of a supported character encoding.
*/
- public void addParameter( String name, String value, boolean encoded,
String encoding )
+ public void addParameter( String name, String value, boolean encoded )
{
if ( name == null )
{
@@ -443,8 +492,8 @@
if ( !encoded )
{
- name = encode( name, encoding );
- value = encode( value, encoding );
+ name = encode( name, _encoding );
+ value = encode( value, _encoding );
}
if ( _params == null )
@@ -467,15 +516,15 @@
* <p> If the encoded flag is true then this method assumes that
* the name and value do not need encoding or are already encoded
* correctly. Otherwise, it translates the name and value with the
- * character encoding and adds them to the set of parameters for
- * the query. </p>
+ * character encoding of this URI and adds them to the set of
+ * parameters for the query. If the encoding for this URI has
+ * not been set, then the default encoding used is "UTF-8". </p>
*
* @param newParams the map of new parameters to add to the URI
* @param encoded Flag indicating whether the names and values are
* already encoded.
- * @param encoding The name of a supported character encoding.
*/
- public void addParameters( Map newParams, boolean encoded, String encoding
)
+ public void addParameters( Map newParams, boolean encoded )
{
if ( newParams == null )
{
@@ -498,7 +547,7 @@
String name = ( String ) keys.next();
String encodedName = name;
- if ( !encoded ) { encodedName = encode( name, encoding ); }
+ if ( !encoded ) { encodedName = encode( name, _encoding ); }
List< String > values = _params.get( encodedName );
if ( values == null )
@@ -514,14 +563,14 @@
}
else if ( newValue instanceof String )
{
- addValue( values, ( String ) newValue, encoded, encoding );
+ addValue( values, ( String ) newValue, encoded );
}
else if ( newValue instanceof String[] )
{
String newValues[] = ( String[] ) newValue;
for ( int i = 0; i < newValues.length; i++ )
{
- addValue( values, newValues[i], encoded, encoding );
+ addValue( values, newValues[i], encoded );
}
}
else if ( newValue instanceof List )
@@ -529,21 +578,21 @@
Iterator newValues = ( ( List ) newValue ).iterator();
while ( newValues.hasNext() )
{
- addValue( values, newValues.next().toString(), encoded,
encoding );
+ addValue( values, newValues.next().toString(), encoded );
}
}
else /* Convert other objects to a string */
{
- addValue( values, newValue.toString(), encoded, encoding );
+ addValue( values, newValue.toString(), encoded );
}
}
}
- private static void addValue( List< String > list, String value, boolean
encoded, String encoding )
+ private void addValue( List< String > list, String value, boolean encoded )
{
if ( !encoded )
{
- value = encode( value, encoding );
+ value = encode( value, _encoding );
}
list.add( value );
@@ -586,7 +635,16 @@
}
else
{
- return Collections.unmodifiableList( _params.get( name ) );
+ List< String > values = _params.get( name );
+
+ if ( values == null )
+ {
+ return EMPTY_LIST;
+ }
+ else
+ {
+ return Collections.unmodifiableList( values );
+ }
}
}
@@ -757,8 +815,14 @@
}
// @struts : from org.apache.struts.util.RequestUtils RC 1.1
- // This has been modified from the strut to assume 1.4 because we ship
- // with that.
+ // This has been modified to assume 1.4
+ /**
+ * Convenience method to encode unencoded components of a URI.
+ *
+ * @param url the string to be encoded by [EMAIL PROTECTED]
URLEncoder}
+ * @param encoding the character encoding to use
+ * @return the encoded string
+ */
public static String encode( String url, String encoding )
{
String encodedURL = null;
@@ -771,7 +835,7 @@
// try utf-8 as a default encoding
try
{
- encodedURL = URLEncoder.encode( url, "UTF-8" );
+ encodedURL = URLEncoder.encode( url, DEFAULT_ENCODING );
}
catch ( java.io.UnsupportedEncodingException ignore )
{
@@ -804,12 +868,13 @@
( _host == testURI.getHost() || ( _host != null &&
_host.equalsIgnoreCase( testURI.getHost() ) ) ) &&
_port == testURI.getPort() &&
( _path == testURI.getPath() || ( _path != null &&
_path.equals( testURI.getPath() ) ) ) &&
- ( _fragment == testURI.getFragment() || ( _fragment != null &&
_fragment.equals( testURI.getFragment() ) ) ) )
+ ( _fragment == testURI.getFragment() || ( _fragment != null &&
_fragment.equals( testURI.getFragment() ) ) ) &&
+ ( _encoding == testURI.getEncoding() || ( _encoding != null &&
_encoding.equals( testURI.getEncoding() ) ) ) )
{
+ Map< String, List< String > > params = getParameters();
Map< String, List< String > > testParams = testURI.getParameters();
- if ( ( _params == null && testParams == null ) ||
- ( _params != null && _params.equals( testParams ) ) ) {
+ if ( params == testParams || ( params != null && params.equals(
testParams ) ) ) {
return true;
}
}