|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.plexus.summit.util.UriBuilder
This creates a Dynamic URI for use within the Turbine system
If you use this class to generate all of your href tags as well as all of your URI's, then you will not need to worry about having session data setup for you or using HttpServletRequest.encodeUrl() since this class does everything for you.
UriBuilder dui = new UriBuilder (data, "UserScreen" );
dui.setName("Click Here").addPathInfo("user","jon");
dui.getA();
The above call to getA() would return the String:
<A HREF="http://www.server.com:80/servlets/Turbine/screen=UserScreen&user=jon">Click Here</A>
Field Summary | |
static int |
ANCHOR_STATIC_PART_LENGTH
Length of static part of an A tag |
protected RunData |
data
The RunData object. |
private boolean |
encodeUrl
true=url will be rewritten with session_id if needed; false=url will not be encoded |
private static char[] |
hexadecimal
Array mapping hexadecimal values to the corresponding ASCII characters. |
static java.lang.String |
HTTP
HTTP protocol. |
static java.lang.String |
HTTPS
HTTPS protocol. |
private boolean |
isRelative
true=relative url's; false=absolute url's |
protected static int |
PATH_INFO
P = 0 for path info. |
protected java.util.ArrayList |
pathInfo
A Vector that contains all the path info if any. |
protected static int |
QUERY_DATA
Q = 1 for query data. |
protected java.util.ArrayList |
queryData
A Vectory that contains all the query data if any. |
protected boolean |
redirect
Whether we want to redirect or not. |
javax.servlet.http.HttpServletResponse |
res
Servlet response interface. |
static java.lang.String |
ROLE
|
private static boolean[] |
safe
Characters that need not be encoded. |
Constructor Summary | |
UriBuilder()
Default constructor - the init() method must be called befroe use. |
|
UriBuilder(RunData data)
Constructor that takes the RunData as an argument. |
Method Summary | |
protected void |
add(java.util.ArrayList list,
RequestParameters pp)
Method for a quick way to add all the parameters in a RequestParameters to a given List |
protected void |
add(int type,
RequestParameters pp)
Method for a quick way to add all the parameters in a RequestParameters. |
protected void |
add(int type,
java.lang.String name,
java.lang.String value)
If the type is P (0), then add name/value to the pathInfo hashtable. |
protected void |
addPair(java.util.ArrayList list,
java.lang.String name,
java.lang.String value)
Add a key value pair (in the form of a 2 object array) to the provided list |
UriBuilder |
addPathInfo(RequestParameters pp)
Adds a name=value pair for every entry in a RequestParameters object to the path_info string. |
UriBuilder |
addPathInfo(java.lang.String name,
boolean value)
Adds a name=value pair to the path_info string. |
UriBuilder |
addPathInfo(java.lang.String name,
double value)
Adds a name=value pair to the path_info string. |
UriBuilder |
addPathInfo(java.lang.String name,
int value)
Adds a name=value pair to the path_info string. |
UriBuilder |
addPathInfo(java.lang.String name,
long value)
Adds a name=value pair to the path_info string. |
UriBuilder |
addPathInfo(java.lang.String name,
java.lang.Object value)
Adds a name=value pair to the path_info string. |
UriBuilder |
addPathInfo(java.lang.String name,
java.lang.String value)
Adds a name=value pair to the path_info string. |
UriBuilder |
addQueryData(RequestParameters pp)
Adds a name=value pair for every entry in a RequestParameters object to the query string. |
UriBuilder |
addQueryData(java.lang.String name,
double value)
Adds a name=value pair to the query string. |
UriBuilder |
addQueryData(java.lang.String name,
int value)
Adds a name=value pair to the query string. |
UriBuilder |
addQueryData(java.lang.String name,
long value)
Adds a name=value pair to the query string. |
UriBuilder |
addQueryData(java.lang.String name,
java.lang.Object value)
Adds a name=value pair to the query string. |
UriBuilder |
addQueryData(java.lang.String name,
java.lang.String value)
Adds a name=value pair to the query string. |
java.lang.String |
getA(java.lang.String name)
Create an anchor object. |
java.lang.String |
getScriptName()
Gets the script name (/servlets/Turbine). |
java.lang.String |
getServerName()
Gets the server name. |
int |
getServerPort()
Gets the server port. |
java.lang.String |
getServerScheme()
Gets the server scheme (HTTP or HTTPS). |
boolean |
hasPathInfo()
Does this URI have path info. |
boolean |
hasQueryData()
Does this URI have query data. |
void |
init()
Initializes the builder for use by clearing any previous state. |
void |
init(RunData data)
Initialize with a RunData object |
boolean |
isEncodeUrl()
Will a call to toString() add session info if needed to maintain a session. |
boolean |
isRelative()
Will a call to toString() generate a relative url? where relative means no scheme, domain, and port info |
protected void |
remove(int type,
java.lang.String name)
If the type is P (0), then remove name/value from the pathInfo hashtable. |
protected void |
removePairByName(java.util.ArrayList pairs,
java.lang.String name)
Helper method to remove one or more pairs by its name (ie key). |
void |
removePathInfo()
Removes all the path info elements. |
void |
removePathInfo(java.lang.String name)
Removes a name=value pair from the path info. |
void |
removeQueryData()
Removes all the query string elements. |
void |
removeQueryData(java.lang.String name)
Removes a name=value pair from the query string. |
protected void |
renderPairs(java.util.ArrayList pairs,
java.lang.StringBuffer out,
char pairSep,
char keyValSep)
This method takes a List of key/value arrays and converts it into a URL encoded key/value pair format with the appropriate separator. |
protected void |
renderPathInfo(java.util.ArrayList pairs,
java.lang.StringBuffer out)
This method takes a Vector of key/value arrays and writes it to the supplied StringBuffer as encoded path info. |
protected java.lang.String |
renderPathInfo(java.util.Vector data)
Deprecated. Prefer the ArrayList / StringBuffer form. |
protected void |
renderQueryString(java.util.ArrayList data,
java.lang.StringBuffer out)
This method takes a List of key/value arrays and writes it to the provided StringBuffer in encoded query string format. |
protected java.lang.String |
renderQueryString(java.util.Vector data)
Deprecated. Prefer the ArrayList / StringBuffer form. |
UriBuilder |
setAction(java.lang.String action)
Sets the action= value for this URL. |
UriBuilder |
setEncodeUrl(boolean b)
Can be used to disable url rewriting. |
UriBuilder |
setRedirect(boolean doRedirect)
Sets whether we want to redirect or not. |
UriBuilder |
setRelative(boolean b)
if true, the scheme, domain, and port will not be included in the String representation of this uri.. |
UriBuilder |
setTarget(java.lang.String template)
Sets the target = value for this URL. |
java.lang.String |
toString()
Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl(). |
static java.lang.String |
toString(RunData data)
Given a RunData object, get a URI for the request. |
static java.lang.String |
toString(RunData data,
boolean isAbsolute)
Given a RunData object, get a URI for the request. |
protected static void |
writeEncoded(java.lang.String in,
java.lang.StringBuffer out)
URL encodes in and writes it to out . |
protected static void |
writeFastEncoded(java.lang.String in,
java.lang.StringBuffer out)
URL encodes in and writes it to out . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String ROLE
public static final java.lang.String HTTP
public static final java.lang.String HTTPS
public static final int ANCHOR_STATIC_PART_LENGTH
protected RunData data
public javax.servlet.http.HttpServletResponse res
protected java.util.ArrayList pathInfo
protected java.util.ArrayList queryData
protected boolean redirect
protected static final int PATH_INFO
protected static final int QUERY_DATA
private boolean isRelative
private boolean encodeUrl
private static final char[] hexadecimal
private static boolean[] safe
Constructor Detail |
public UriBuilder()
public UriBuilder(RunData data)
data
- The RunData associated with this builder.Method Detail |
public void init()
public void init(RunData data)
data
- protected void add(int type, java.lang.String name, java.lang.String value)
If the type is P (0), then add name/value to the pathInfo hashtable.
If the type is Q (1), then add name/value to the queryData hashtable.
type
- Type (P or Q) of insertion.name
- A String with the name to add.value
- A String with the value to add.protected void addPair(java.util.ArrayList list, java.lang.String name, java.lang.String value)
list
- List to add to.name
- A String with the name to add.value
- A String with the value to add.protected void add(java.util.ArrayList list, RequestParameters pp)
list
- The list of pairs to add topp
- A RequestParameters.protected void add(int type, RequestParameters pp)
If the type is P (0), then add name/value to the pathInfo hashtable.
If the type is Q (1), then add name/value to the queryData hashtable.
type
- Type (P or Q) of insertion.pp
- A RequestParameters.public UriBuilder addPathInfo(java.lang.String name, java.lang.Object value)
name
- A String with the name to add.value
- An Object with the value to add.public UriBuilder addPathInfo(java.lang.String name, java.lang.String value)
name
- A String with the name to add.value
- A String with the value to add.public UriBuilder addPathInfo(java.lang.String name, double value)
name
- A String with the name to add.value
- A double with the value to add.public UriBuilder addPathInfo(java.lang.String name, int value)
name
- A String with the name to add.value
- An int with the value to add.public UriBuilder addPathInfo(java.lang.String name, long value)
name
- A String with the name to add.value
- A long with the value to add.public UriBuilder addPathInfo(java.lang.String name, boolean value)
name
- A String with the name to add.value
- A double with the value to add.public UriBuilder addPathInfo(RequestParameters pp)
pp
- A RequestParameters.public UriBuilder addQueryData(java.lang.String name, java.lang.Object value)
name
- A String with the name to add.value
- An Object with the value to add.public UriBuilder addQueryData(java.lang.String name, java.lang.String value)
name
- A String with the name to add.value
- A String with the value to add.public UriBuilder addQueryData(java.lang.String name, double value)
name
- A String with the name to add.value
- A double with the value to add.public UriBuilder addQueryData(java.lang.String name, int value)
name
- A String with the name to add.value
- An int with the value to add.public UriBuilder addQueryData(java.lang.String name, long value)
name
- A String with the name to add.value
- A long with the value to add.public UriBuilder addQueryData(RequestParameters pp)
pp
- A RequestParameters.public java.lang.String getA(java.lang.String name)
UriBuilder dui = new UriBuilder (data, "UserScreen" );
dui.setName("Click Here").addPathInfo("user","jon");
dui.getA();
would return the String:
<A HREF="http://www.server.com:80/servlets/Turbine/screen=UserScreen&user=jon">Click Here</A>
name
- A String with the name for the anchor.
public java.lang.String getScriptName()
public java.lang.String getServerName()
public int getServerPort()
public java.lang.String getServerScheme()
protected void remove(int type, java.lang.String name)
If the type is P (0), then remove name/value from the pathInfo hashtable.
If the type is Q (1), then remove name/value from the queryData hashtable.
type
- Type (P or Q) of removal.name
- A String with the name to be removed.protected void removePairByName(java.util.ArrayList pairs, java.lang.String name)
pairs
- the list of pairs to look over for removal.name
- the name of the pair(s) to remove.public void removePathInfo()
public void removePathInfo(java.lang.String name)
name
- A String with the name to be removed.public void removeQueryData()
public void removeQueryData(java.lang.String name)
name
- A String with the name to be removed.protected java.lang.String renderPathInfo(java.util.Vector data)
data
- A Vector of key/value arrays.
protected void renderPathInfo(java.util.ArrayList pairs, java.lang.StringBuffer out)
pairs
- A Vector of key/value arrays.out
- Buffer to which encoded path info is writtenprotected java.lang.String renderQueryString(java.util.Vector data)
data
- A Vector of key/value arrays.
protected void renderQueryString(java.util.ArrayList data, java.lang.StringBuffer out)
data
- A Vector of key/value arrays.out
- Buffer to which encoded query string is written.protected void renderPairs(java.util.ArrayList pairs, java.lang.StringBuffer out, char pairSep, char keyValSep)
out
- the buffer to write the pairs to.pairs
- A List of key/value arrays.pairSep
- the character to use as a separator between pairs.
For example for a query-like rendering it would be '&'.keyValSep
- the character to use as a separator between
key and value. For example for a query-like rendering, it would be '='.public UriBuilder setAction(java.lang.String action)
By default it adds the information to the path_info instead of the query data.
action
- A String with the action value.
public UriBuilder setTarget(java.lang.String template)
By default it adds the information to the path_info instead of the query data.
template
- A String with the template value.
public UriBuilder setRedirect(boolean doRedirect)
doRedirect
- True if it should redirect.
public UriBuilder setRelative(boolean b)
b
- a boolean
UriBuilder
(self)public boolean isRelative()
boolean
public UriBuilder setEncodeUrl(boolean b)
b
- a boolean
UriBuilder
(self)public boolean isEncodeUrl()
boolean
public java.lang.String toString()
UriBuilder dui = new UriBuilder (data, "UserScreen" );
dui.addPathInfo("user","jon");
dui.toString();
The above call to toString() would return the String:
http://www.server.com/servlets/Turbine/screen/UserScreen/user/jon
public static java.lang.String toString(RunData data)
data
- A Turbine RunData object.
public static java.lang.String toString(RunData data, boolean isAbsolute)
data
- A Turbine RunData object.isAbsolute
- to determine absolute vs. relative links.
protected static final void writeFastEncoded(java.lang.String in, java.lang.StringBuffer out)
in
and writes it to out
. If the
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.
for short strings ~20 characters the upside is a 75% decrease. while
the penalty is a 10% increase. As many query parameters do not need
encoding even in i18n applications it should be much better to
delay the byte conversion.
in
- String to write.out
- Buffer to write to.protected static final void writeEncoded(java.lang.String in, java.lang.StringBuffer out)
in
and writes it to out
. If the
string is null, 'null' will be written.
in
- String to write.out
- Buffer to write to.public boolean hasPathInfo()
public boolean hasQueryData()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |