|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectURLRewriterService
public class URLRewriterService
Methods for registering URL rewriters, adding URL rewriters to the chain, and for rewriting URLs using registered rewriters.
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.
The final step of the full rewriting process should be to run the
rewritten URI through the templated URL formatting process. See
getTemplatedURL(javax.servlet.ServletRequest, org.apache.beehive.netui.core.urls.MutableURI, java.lang.String, boolean)
Also note that this API allows a client to register their own templated URI formatter so they can manage their own templates and formatting.
Constructor Summary | |
---|---|
URLRewriterService()
|
Method Summary | |
---|---|
static boolean |
allowParamsOnFormAction(ServletContext servletContext,
ServletRequest request)
Tell whether rewritten form actions should be allowed to have query parameters. |
static void |
dumpURLRewriters(ServletRequest request,
PrintStream output)
Print out information about the chain of URLRewriters in this request. |
static String |
getNamePrefix(ServletContext servletContext,
ServletRequest request,
String name)
Get the prefix to use when rewriting a query parameter name. |
static String |
getTemplatedURL(ServletRequest request,
MutableURI url,
String key,
boolean forXML)
Format the given URI using a URL template, if defined in the URL template config file, WEB-INF/url-template-config.xml. |
static List<URLRewriter> |
getURLRewriters(ServletRequest request)
Get the unmodifiable list of URLRewriter objects in the request that will be used if rewriteURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, org.apache.beehive.netui.core.urls.MutableURI, org.apache.beehive.netui.core.urls.URLRewriter.URLType, boolean) is called. |
static void |
registerTemplatedURLFormatter(ServletRequest request,
TemplatedURLFormatter formatter)
Register a TemplatedURLFormatter in the request. |
static boolean |
registerURLRewriter(int index,
ServletRequest request,
URLRewriter rewriter)
Register a URLRewriter (add to a list) in the request. |
static boolean |
registerURLRewriter(ServletRequest request,
URLRewriter rewriter)
Register a URLRewriter (add to a list) in the request. |
static void |
rewriteURL(ServletContext servletContext,
ServletRequest request,
ServletResponse response,
MutableURI url,
URLRewriter.URLType type,
boolean needsToBeSecure)
Rewrite the given URL, looping through the list of registered URLRewriters. |
static void |
unregisterAllURLRewriters(ServletRequest request)
Unregister the URLRewriter (remove from the list) from the request. |
static void |
unregisterTemplatedURLFormatter(ServletRequest request)
Unregister the TemplatedURLFormatter from the request. |
static void |
unregisterURLRewriter(ServletRequest request,
URLRewriter rewriter)
Unregister the URLRewriter (remove from the list) from the request. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public URLRewriterService()
Method Detail |
---|
public static String getNamePrefix(ServletContext servletContext, ServletRequest request, String name)
servletContext
- the current ServletContext.request
- the current ServletRequest.name
- the name of the query parameter.
public static void rewriteURL(ServletContext servletContext, ServletRequest request, ServletResponse response, MutableURI url, URLRewriter.URLType type, boolean needsToBeSecure)
Once the MutableURI has been rewritten, and if it is an instance of
FreezableMutableURI
, then this method will set the URI to a frozen
state. I.e. immutable. If a user then tries to use a setter method on the
rewritten URI, the FreezableMutableURI will throw an IllegalStateException.
Note that after the rewritting the caller should run the rewritten URI
through the templated URI formatting process as the last step in rewriting.
See getTemplatedURL(javax.servlet.ServletRequest, org.apache.beehive.netui.core.urls.MutableURI, java.lang.String, boolean)
servletContext
- the current ServletContext.request
- the current ServletRequest.response
- the current ServletResponse.url
- the URL to be rewritten.type
- the type of URL to be rewritten. This is one of the following values:
action
: a standard (non-resource) URL
resource
: a resource (e.g., image) URL
needsToBeSecure
- a flag indicating whether the URL should be secure (SSL required) or notregisterURLRewriter(javax.servlet.ServletRequest, org.apache.beehive.netui.core.urls.URLRewriter)
public static List<URLRewriter> getURLRewriters(ServletRequest request)
rewriteURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, org.apache.beehive.netui.core.urls.MutableURI, org.apache.beehive.netui.core.urls.URLRewriter.URLType, boolean)
is called.
request
- the current ServletRequest.
public static boolean registerURLRewriter(ServletRequest request, URLRewriter rewriter)
rewriteURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, org.apache.beehive.netui.core.urls.MutableURI, org.apache.beehive.netui.core.urls.URLRewriter.URLType, boolean)
is called.
request
- the current ServletRequest.rewriter
- the URLRewriter to register.
false
if a URLRewriter has been registered
that does not allow other rewriters. Otherwise, true
if the URLRewriter was added to the chain or already exists in
the chain.public static boolean registerURLRewriter(int index, ServletRequest request, URLRewriter rewriter)
rewriteURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, org.apache.beehive.netui.core.urls.MutableURI, org.apache.beehive.netui.core.urls.URLRewriter.URLType, boolean)
is called.
index
- the place to insert the URLRewriterrequest
- the current ServletRequest.rewriter
- the URLRewriter to register.
false
if a URLRewriter has been registered
that does not allow other rewriters. Otherwise, true
if the URLRewriter was added to the chain or already exists in
the chain.public static void unregisterURLRewriter(ServletRequest request, URLRewriter rewriter)
request
- the current ServletRequest.rewriter
- the URLRewriter to unregisterregisterURLRewriter(javax.servlet.ServletRequest, org.apache.beehive.netui.core.urls.URLRewriter)
public static void unregisterAllURLRewriters(ServletRequest request)
request
- the current ServletRequest.public static boolean allowParamsOnFormAction(ServletContext servletContext, ServletRequest request)
false
, then a form-tag implementation should render query parameters into hidden
fields on the form instead of allowing them to remain in the URL.
public static void dumpURLRewriters(ServletRequest request, PrintStream output)
request
- the current HttpServletRequest.output
- a PrintStream to output chain of URLRewriters in this request.
If null, System.err
is used.
public static String getTemplatedURL(ServletRequest request, MutableURI url, String key, boolean forXML)
request
- the current ServletRequest.url
- the MutableURI to be formatted into a String.key
- the URL template type to use for formatting the URIforXML
- flag indicating that the query of the uri should be written
using the "&" entity for XML, rather than the character, '&'.public static void registerTemplatedURLFormatter(ServletRequest request, TemplatedURLFormatter formatter)
The TemplatedURLFormatter should be used as a final step in the rewriting process to format the rewritten URL as defined by a template in the WEB-INF/url-template-config.xml. There can only be one TemplatedURLFormatter, not a chain as with the URLRewriters.
request
- the current ServletRequest.formatter
- the TemplatedURLFormatter to register.public static void unregisterTemplatedURLFormatter(ServletRequest request)
request
- the current ServletRequest.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |