CVS: plexus-components/summit/src/java/org/apache/plexus/summit/util UriBuilder.java,1.4,1.5
[email protected] Thu, 1 May 2003 14:28:43 -0500
| Newsgroups | gmane.comp.java.plexus.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/plexus/plexus-components/summit/src/java/org/apache/plexus/summit/util
In directory eng.werken.com:/tmp/cvs-serv17379/src/java/org/apache/plexus/summit/util
Modified Files:
UriBuilder.java
Log Message:
o Removed the multiple View notion.
o Using a service manager instead of the components being service managers.
Index: UriBuilder.java
===================================================================
RCS file: /cvsroot/plexus/plexus-components/summit/src/java/org/apache/plexus/summit/util/UriBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- UriBuilder.java 18 Feb 2003 18:59:57 -0000 1.4
+++ UriBuilder.java 1 May 2003 19:28:40 -0000 1.5
@@ -92,7 +92,7 @@
public class UriBuilder
{
public static final String ROLE = UriBuilder.class.getName();
-
+
/** HTTP protocol. */
public static final String HTTP = "http";
@@ -142,12 +142,12 @@
/**
* Constructor that takes the <tt>RunData</tt> as an argument.
- *
+ *
* @param data The <tt>RunData</tt> associated with this builder.
*/
- public UriBuilder(RunData data)
+ public UriBuilder( RunData data )
{
- init(data);
+ init( data );
}
/**
@@ -164,7 +164,7 @@
*
* @param data
*/
- public void init(RunData data)
+ public void init( RunData data )
{
this.data = data;
this.res = this.data.getResponse();
@@ -182,19 +182,19 @@
* @param name A String with the name to add.
* @param value A String with the value to add.
*/
- protected void add(int type,
- String name,
- String value)
+ protected void add( int type,
+ String name,
+ String value )
{
- Object[] tmp = new Object[] { name, value };
+ Object[] tmp = new Object[]{name, value};
if ( type == PATH_INFO )
{
- this.pathInfo.add(tmp);
+ this.pathInfo.add( tmp );
}
else if ( type == QUERY_DATA )
{
- this.queryData.add(tmp);
+ this.queryData.add( tmp );
}
}
@@ -206,13 +206,13 @@
* @param name A String with the name to add.
* @param value A String with the value to add.
*/
- protected void addPair(ArrayList list,
- String name,
- String value)
+ protected void addPair( ArrayList list,
+ String name,
+ String value )
{
- Object[] tmp = new Object[] { name, value };
+ Object[] tmp = new Object[]{name, value};
- list.add(tmp);
+ list.add( tmp );
}
/**
@@ -222,21 +222,21 @@
* @param list The list of pairs to add to
* @param pp A RequestParameters.
*/
- protected void add(ArrayList list,
- RequestParameters pp)
+ protected void add( ArrayList list,
+ RequestParameters pp )
{
Iterator itr = pp.keys();
- while (itr.hasNext())
+ while ( itr.hasNext() )
{
String key = (String) itr.next();
- if (!key.equalsIgnoreCase(SummitConstants.ACTION) &&
- !key.equalsIgnoreCase(SummitConstants.TARGET))
+ if ( !key.equalsIgnoreCase( SummitConstants.ACTION ) &&
+ !key.equalsIgnoreCase( SummitConstants.TARGET ) )
{
- String[] values = pp.getStrings(key);
- for (int i = 0; i < values.length; i++)
+ String[] values = pp.getStrings( key );
+ for ( int i = 0; i < values.length; i++ )
{
- addPair(list, key, values[i]);
+ addPair( list, key, values[i] );
}
}
}
@@ -255,16 +255,16 @@
* @param type Type (P or Q) of insertion.
* @param pp A RequestParameters.
*/
- protected void add(int type,
- RequestParameters pp)
+ protected void add( int type,
+ RequestParameters pp )
{
if ( type == PATH_INFO )
{
- add( pathInfo, pp);
+ add( pathInfo, pp );
}
else if ( type == QUERY_DATA )
{
- add( queryData, pp);
+ add( queryData, pp );
}
}
@@ -274,9 +274,9 @@
* @param name A String with the name to add.
* @param value An Object with the value to add.
*/
- public UriBuilder addPathInfo(String name, Object value)
+ public UriBuilder addPathInfo( String name, Object value )
{
- addPathInfo(name, value.toString());
+ addPathInfo( name, value.toString() );
return this;
}
@@ -286,9 +286,9 @@
* @param name A String with the name to add.
* @param value A String with the value to add.
*/
- public UriBuilder addPathInfo(String name, String value)
+ public UriBuilder addPathInfo( String name, String value )
{
- addPair( pathInfo, name, value);
+ addPair( pathInfo, name, value );
return this;
}
@@ -298,9 +298,9 @@
* @param name A String with the name to add.
* @param value A double with the value to add.
*/
- public UriBuilder addPathInfo(String name, double value)
+ public UriBuilder addPathInfo( String name, double value )
{
- addPathInfo(name, Double.toString(value));
+ addPathInfo( name, Double.toString( value ) );
return this;
}
@@ -310,9 +310,9 @@
* @param name A String with the name to add.
* @param value An int with the value to add.
*/
- public UriBuilder addPathInfo(String name, int value)
+ public UriBuilder addPathInfo( String name, int value )
{
- addPathInfo(name, new Integer(value).toString());
+ addPathInfo( name, new Integer( value ).toString() );
return this;
}
@@ -322,9 +322,9 @@
* @param name A String with the name to add.
* @param value A long with the value to add.
*/
- public UriBuilder addPathInfo(String name, long value)
+ public UriBuilder addPathInfo( String name, long value )
{
- addPathInfo(name, new Long(value).toString());
+ addPathInfo( name, new Long( value ).toString() );
return this;
}
@@ -334,9 +334,9 @@
* @param name A String with the name to add.
* @param value A double with the value to add.
*/
- public UriBuilder addPathInfo(String name, boolean value)
+ public UriBuilder addPathInfo( String name, boolean value )
{
- addPathInfo(name, (value ? "true" : "false"));
+ addPathInfo( name, ( value ? "true" : "false" ) );
return this;
}
@@ -346,9 +346,9 @@
*
* @param pp A RequestParameters.
*/
- public UriBuilder addPathInfo(RequestParameters pp)
+ public UriBuilder addPathInfo( RequestParameters pp )
{
- add(pathInfo, pp);
+ add( pathInfo, pp );
return this;
}
@@ -358,9 +358,9 @@
* @param name A String with the name to add.
* @param value An Object with the value to add.
*/
- public UriBuilder addQueryData(String name, Object value)
+ public UriBuilder addQueryData( String name, Object value )
{
- addQueryData(name, value.toString());
+ addQueryData( name, value.toString() );
return this;
}
@@ -370,9 +370,9 @@
* @param name A String with the name to add.
* @param value A String with the value to add.
*/
- public UriBuilder addQueryData(String name, String value)
+ public UriBuilder addQueryData( String name, String value )
{
- addPair( queryData, name, value);
+ addPair( queryData, name, value );
return this;
}
@@ -382,9 +382,9 @@
* @param name A String with the name to add.
* @param value A double with the value to add.
*/
- public UriBuilder addQueryData(String name, double value)
+ public UriBuilder addQueryData( String name, double value )
{
- addQueryData(name, Double.toString(value));
+ addQueryData( name, Double.toString( value ) );
return this;
}
@@ -394,9 +394,9 @@
* @param name A String with the name to add.
* @param value An int with the value to add.
*/
- public UriBuilder addQueryData(String name, int value)
+ public UriBuilder addQueryData( String name, int value )
{
- addQueryData(name, new Integer(value).toString());
+ addQueryData( name, new Integer( value ).toString() );
return this;
}
@@ -406,9 +406,9 @@
* @param name A String with the name to add.
* @param value A long with the value to add.
*/
- public UriBuilder addQueryData(String name, long value)
+ public UriBuilder addQueryData( String name, long value )
{
- addQueryData(name, new Long(value).toString());
+ addQueryData( name, new Long( value ).toString() );
return this;
}
@@ -418,9 +418,9 @@
*
* @param pp A RequestParameters.
*/
- public UriBuilder addQueryData(RequestParameters pp)
+ public UriBuilder addQueryData( RequestParameters pp )
{
- add(queryData, pp);
+ add( queryData, pp );
return this;
}
@@ -440,22 +440,22 @@
* @param name A String with the name for the anchor.
* @return The anchor as a <A HREF="">name</A>.
*/
- public String getA(String name)
+ public String getA( String name )
{
- final String s = this.toString();
+ final String s = this.toString();
- // I'm being a pit picky about size here to avoid useless
- // StringBuffer reallocation
+ // I'm being a pit picky about size here to avoid useless
+ // StringBuffer reallocation
- final int size = ANCHOR_STATIC_PART_LENGTH + s.length() + name.length();
+ final int size = ANCHOR_STATIC_PART_LENGTH + s.length() + name.length();
- return new StringBuffer( size )
- .append("<a href=\"")
- .append(s)
- .append("\">")
- .append(name)
- .append("</a>")
- .toString();
+ return new StringBuffer( size )
+ .append( "<a href=\"" )
+ .append( s )
+ .append( "\">" )
+ .append( name )
+ .append( "</a>" )
+ .toString();
}
/**
@@ -467,7 +467,7 @@
{
return data.getScriptName();
}
-
+
/**
* Gets the server name.
*
@@ -477,7 +477,7 @@
{
return data.getServerName();
}
-
+
/**
* Gets the server port.
*
@@ -487,7 +487,7 @@
{
return data.getServerPort();
}
-
+
/**
* Gets the server scheme (HTTP or HTTPS).
*
@@ -508,8 +508,8 @@
* @param type Type (P or Q) of removal.
* @param name A String with the name to be removed.
*/
- protected void remove(int type,
- String name)
+ protected void remove( int type,
+ String name )
{
try
{
@@ -522,7 +522,7 @@
removeQueryData( name );
}
}
- catch (Exception e)
+ catch ( Exception e )
{
}
}
@@ -533,16 +533,16 @@
* @param pairs the list of pairs to look over for removal.
* @param name the name of the pair(s) to remove.
*/
- protected void removePairByName(ArrayList pairs, String name)
+ protected void removePairByName( ArrayList pairs, String name )
{
// CAUTION: the dynamic evaluation of the size is on purpose because
// elements may be removed on the fly.
- for (int i = 0; i < pairs.size(); i++)
+ for ( int i = 0; i < pairs.size(); i++ )
{
- Object[] pair = (Object[])pairs.get(i);
- if ( name.equals( (String)pair[0] ) )
+ Object[] pair = (Object[]) pairs.get( i );
+ if ( name.equals( (String) pair[0] ) )
{
- pairs.remove(i);
+ pairs.remove( i );
}
}
}
@@ -560,9 +560,10 @@
*
* @param name A String with the name to be removed.
*/
- public void removePathInfo(String name)
+ public void removePathInfo( String name )
{
- removePairByName( pathInfo, name );;
+ removePairByName( pathInfo, name );
+ ;
}
/**
@@ -578,7 +579,7 @@
*
* @param name A String with the name to be removed.
*/
- public void removeQueryData(String name)
+ public void removeQueryData( String name )
{
removePairByName( queryData, name );
}
@@ -591,11 +592,11 @@
* @return A String with the URL encoded data.
* @deprecated Prefer the ArrayList / StringBuffer form.
*/
- protected String renderPathInfo(Vector data)
+ protected String renderPathInfo( Vector data )
{
StringBuffer out = new StringBuffer();
- renderPathInfo(new ArrayList(data), out);
+ renderPathInfo( new ArrayList( data ), out );
return out.toString();
}
@@ -607,7 +608,7 @@
* @param pairs A Vector of key/value arrays.
* @param out Buffer to which encoded path info is written
*/
- protected void renderPathInfo(ArrayList pairs, StringBuffer out)
+ protected void renderPathInfo( ArrayList pairs, StringBuffer out )
{
renderPairs( pairs, out, '/', '/' );
}
@@ -620,11 +621,11 @@
* @return A String with the URL encoded data.
* @deprecated Prefer the ArrayList / StringBuffer form.
*/
- protected String renderQueryString(Vector data)
+ protected String renderQueryString( Vector data )
{
StringBuffer out = new StringBuffer();
- renderQueryString(new ArrayList(data), out);
+ renderQueryString( new ArrayList( data ), out );
return out.toString();
}
@@ -636,7 +637,7 @@
* @param data A Vector of key/value arrays.
* @param out Buffer to which encoded query string is written.
*/
- protected void renderQueryString(ArrayList data, StringBuffer out)
+ protected void renderQueryString( ArrayList data, StringBuffer out )
{
renderPairs( data, out, '&', '=' );
}
@@ -653,15 +654,15 @@
* @param keyValSep the character to use as a separator between
* key and value. For example for a query-like rendering, it would be '='.
*/
- protected void renderPairs(ArrayList pairs, StringBuffer out,
- char pairSep, char keyValSep)
+ protected void renderPairs( ArrayList pairs, StringBuffer out,
+ char pairSep, char keyValSep )
{
boolean first = true;
final int count = pairs.size();
- for (int i = 0; i < count; i++)
+ for ( int i = 0; i < count; i++ )
{
- Object[] pair = (Object[]) pairs.get(i);
+ Object[] pair = (Object[]) pairs.get( i );
if ( first )
{
@@ -669,12 +670,12 @@
}
else
{
- out.append(pairSep);
+ out.append( pairSep );
}
- writeFastEncoded((String) pair[0], out);
- out.append(keyValSep);
- writeFastEncoded((String) pair[1], out);
+ writeFastEncoded( (String) pair[0], out );
+ out.append( keyValSep );
+ writeFastEncoded( (String) pair[1], out );
}
}
@@ -687,9 +688,9 @@
* @param action A String with the action value.
* @return A UriBuilder (self).
*/
- public UriBuilder setAction(String action)
+ public UriBuilder setAction( String action )
{
- addPathInfo(SummitConstants.ACTION, action);
+ addPathInfo( SummitConstants.ACTION, action );
return this;
}
@@ -702,9 +703,9 @@
* @param template A String with the template value.
* @return A UriBuilder (self).
*/
- public UriBuilder setTarget(String template)
+ public UriBuilder setTarget( String template )
{
- addPathInfo(SummitConstants.TARGET, template);
+ addPathInfo( SummitConstants.TARGET, template );
return this;
}
@@ -714,7 +715,7 @@
* @param doRedirect True if it should redirect.
* @return A UriBuilder (self).
*/
- public UriBuilder setRedirect(boolean doRedirect)
+ public UriBuilder setRedirect( boolean doRedirect )
{
this.redirect = doRedirect;
return this;
@@ -727,10 +728,10 @@
*
* @return A UriBuilder (self).
* /
- public UriBuilder setSecure()
- {
- return setSecure(443);
- }*/
+ public UriBuilder setSecure()
+ {
+ return setSecure(443);
+ }*/
/**
* Method to specify that a URI should use SSL. Whether or not it
@@ -739,17 +740,17 @@
* @param port An int with the port number.
* @return A UriBuilder (self).
* /
- public UriBuilder setSecure(int port)
- {
- boolean isSSL = Turbine.getConfiguration()
- .getBoolean(Turbine.USE_SSL, true);
- if (isSSL)
- {
- data.setServerScheme(UriBuilder.HTTPS);
- data.setServerPort(port);
- }
- return this;
- }*/
+ public UriBuilder setSecure(int port)
+ {
+ boolean isSSL = Turbine.getConfiguration()
+ .getBoolean(Turbine.USE_SSL, true);
+ if (isSSL)
+ {
+ data.setServerScheme(UriBuilder.HTTPS);
+ data.setServerPort(port);
+ }
+ return this;
+ }*/
/**
* if true, the scheme, domain, and port will not be included in the
@@ -758,7 +759,7 @@
* @param b a <code>boolean</code>
* @return a <code>UriBuilder</code> (self)
*/
- public UriBuilder setRelative(boolean b)
+ public UriBuilder setRelative( boolean b )
{
isRelative = b;
return this;
@@ -781,7 +782,7 @@
* @param b a <code>boolean</code>
* @return a <code>UriBuilder</code> (self)
*/
- public UriBuilder setEncodeUrl(boolean b)
+ public UriBuilder setEncodeUrl( boolean b )
{
encodeUrl = b;
return this;
@@ -820,47 +821,47 @@
public String toString()
{
StringBuffer output = new StringBuffer();
- if (!isRelative())
+ if ( !isRelative() )
{
- output.append(data.getServerScheme());
- output.append("://");
- output.append(data.getServerName());
- if ((data.getServerScheme().equals(HTTP) &&
- data.getServerPort() != 80) ||
- (data.getServerScheme().equals(HTTPS) &&
- data.getServerPort() != 443))
+ output.append( data.getServerScheme() );
+ output.append( "://" );
+ output.append( data.getServerName() );
+ if ( ( data.getServerScheme().equals( HTTP ) &&
+ data.getServerPort() != 80 ) ||
+ ( data.getServerScheme().equals( HTTPS ) &&
+ data.getServerPort() != 443 ) )
{
- output.append(':');
- output.append(data.getServerPort());
+ output.append( ':' );
+ output.append( data.getServerPort() );
}
}
- output.append(data.getContextPath());
- output.append(data.getScriptName());
+ output.append( data.getContextPath() );
+ output.append( data.getScriptName() );
- if (this.hasPathInfo())
+ if ( this.hasPathInfo() )
{
- output.append('/');
- renderPathInfo(this.pathInfo, output);
+ output.append( '/' );
+ renderPathInfo( this.pathInfo, output );
}
- if (this.hasQueryData())
+ if ( this.hasQueryData() )
{
- output.append('?');
- renderQueryString(this.queryData, output);
+ output.append( '?' );
+ renderQueryString( this.queryData, output );
}
// There seems to be a bug in Apache JServ 1.0 where the
// session id is not appended to the end of the url when a
// cookie has not been set.
- if (this.res != null && isEncodeUrl())
+ if ( this.res != null && isEncodeUrl() )
{
- if (this.redirect)
+ if ( this.redirect )
{
- return res.encodeRedirectURL(output.toString());
+ return res.encodeRedirectURL( output.toString() );
}
else
{
- return res.encodeURL(output.toString());
+ return res.encodeURL( output.toString() );
}
}
else
@@ -879,9 +880,9 @@
* @param data A Turbine RunData object.
* @return A String with the URL representing the RunData.
*/
- public static String toString(RunData data)
+ public static String toString( RunData data )
{
- return toString(data, true);
+ return toString( data, true );
}
/**
@@ -895,46 +896,46 @@
* @param isAbsolute to determine absolute vs. relative links.
* @return A String with the URL representing the RunData.
*/
- public static String toString(RunData data, boolean isAbsolute)
+ public static String toString( RunData data, boolean isAbsolute )
{
StringBuffer output = new StringBuffer( 128 );
HttpServletRequest request = data.getRequest();
- if (isAbsolute)
+ if ( isAbsolute )
{
- output.append(data.getServerScheme());
- output.append("://");
- output.append(data.getServerName());
+ output.append( data.getServerScheme() );
+ output.append( "://" );
+ output.append( data.getServerName() );
- if ((data.getServerScheme().equals(HTTP) &&
- data.getServerPort() != 80) ||
- (data.getServerScheme().equals(HTTPS) &&
- data.getServerPort() != 443))
+ if ( ( data.getServerScheme().equals( HTTP ) &&
+ data.getServerPort() != 80 ) ||
+ ( data.getServerScheme().equals( HTTPS ) &&
+ data.getServerPort() != 443 ) )
{
- output.append(':');
- output.append(data.getServerPort());
+ output.append( ':' );
+ output.append( data.getServerPort() );
}
}
- output.append(data.getContextPath());
- output.append(data.getScriptName());
+ output.append( data.getContextPath() );
+ output.append( data.getScriptName() );
- if (request.getPathInfo() != null)
+ if ( request.getPathInfo() != null )
{
- output.append(request.getPathInfo());
+ output.append( request.getPathInfo() );
}
- if (request.getQueryString() != null)
+ if ( request.getQueryString() != null )
{
- output.append('?');
- output.append(request.getQueryString());
+ output.append( '?' );
+ output.append( request.getQueryString() );
}
return output.toString();
}
/**
* URL encodes <code>in</code> and writes it to <code>out</code>. If the
- * string is null, 'null' will be written.
+ * string is null, 'null' will be written.
* This method is faster if
* the string does not contain any characters needing encoding. It
* adds some penalty for strings which actually need to be encoded.
@@ -946,33 +947,33 @@
* @param in String to write.
* @param out Buffer to write to.
*/
- protected static final void writeFastEncoded(String in, StringBuffer out)
+ protected static final void writeFastEncoded( String in, StringBuffer out )
{
- if (in == null || in.length() == 0)
+ if ( in == null || in.length() == 0 )
{
- out.append("null");
+ out.append( "null" );
return;
}
char[] chars = in.toCharArray();
- for (int i = 0; i < chars.length; i++)
+ for ( int i = 0; i < chars.length; i++ )
{
char c = chars[i];
- if ( c < 128 && safe[ c ] )
+ if ( c < 128 && safe[c] )
{
- out.append(c);
+ out.append( c );
}
- else if (c == ' ')
+ else if ( c == ' ' )
{
- out.append('+');
+ out.append( '+' );
}
else
{
- // since we need to encode we will give up on
+ // since we need to encode we will give up on
// doing it the fast way and convert to bytes.
- writeEncoded(new String(chars, i, chars.length-i), out);
+ writeEncoded( new String( chars, i, chars.length - i ), out );
break;
}
}
@@ -985,11 +986,11 @@
* @param in String to write.
* @param out Buffer to write to.
*/
- protected static final void writeEncoded(String in, StringBuffer out)
+ protected static final void writeEncoded( String in, StringBuffer out )
{
- if (in == null || in.length() == 0)
+ if ( in == null || in.length() == 0 )
{
- out.append("null");
+ out.append( "null" );
return;
}
@@ -997,26 +998,26 @@
byte[] bytes = in.getBytes();
- for (int i = 0; i < bytes.length; i++)
+ for ( int i = 0; i < bytes.length; i++ )
{
char c = (char) bytes[i];
- if ( c < 128 && safe[ c ] )
+ if ( c < 128 && safe[c] )
{
- out.append(c);
+ out.append( c );
}
- else if (c == ' ')
+ else if ( c == ' ' )
{
- out.append('+');
+ out.append( '+' );
}
else
{
byte toEscape = bytes[i];
- out.append('%');
- int low = (int) (toEscape & 0x0f);
- int high = (int) ((toEscape & 0xf0) >> 4);
- out.append(hexadecimal[high]);
- out.append(hexadecimal[low]);
+ out.append( '%' );
+ int low = (int) ( toEscape & 0x0f );
+ int high = (int) ( ( toEscape & 0xf0 ) >> 4 );
+ out.append( hexadecimal[high] );
+ out.append( hexadecimal[low] );
}
}
}
@@ -1026,7 +1027,7 @@
*/
public boolean hasPathInfo()
{
- return ! pathInfo.isEmpty();
+ return !pathInfo.isEmpty();
}
/**
@@ -1034,7 +1035,7 @@
*/
public boolean hasQueryData()
{
- return ! queryData.isEmpty();
+ return !queryData.isEmpty();
}
// ------------------------------------- private constants for url encoding
@@ -1052,22 +1053,22 @@
* Characters that need not be encoded. This is much faster than using a
* BitSet, and for such a small array the space cost seems justified.
*/
- private static boolean[] safe = new boolean[ 128 ];
+ private static boolean[] safe = new boolean[128];
/** Static initializer for {@link #safe} */
static
{
- for (int i = 'a'; i <= 'z'; i++)
+ for ( int i = 'a'; i <= 'z'; i++ )
{
- safe[ i ] = true;
+ safe[i] = true;
}
- for (int i = 'A'; i <= 'Z'; i++)
+ for ( int i = 'A'; i <= 'Z'; i++ )
{
- safe[ i ] = true;
+ safe[i] = true;
}
- for (int i = '0'; i <= '9'; i++)
+ for ( int i = '0'; i <= '9'; i++ )
{
- safe[ i ] = true;
+ safe[i] = true;
}
safe['-'] = true;