public final class WebConsoleUtil
extends java.lang.Object
WebConsoleUtil
provides various utility methods for use
by Web Console plugins.Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escapeHtml(java.lang.String text)
Escapes HTML special chars like: <>&\r\n and space
|
static java.lang.String |
getParameter(HttpServletRequest request,
java.lang.String name)
An utility method, that is used to filter out simple parameter from file
parameter when multipart transfer encoding is used.
|
static int |
getParameterInt(HttpServletRequest request,
java.lang.String name,
int _default)
Retrieves a request parameter and converts it to int.
|
static VariableResolver |
getVariableResolver(ServletRequest request)
Returns the
VariableResolver for the given request. |
static void |
sendRedirect(HttpServletRequest request,
HttpServletResponse response,
java.lang.String redirectUrl)
Utility method to handle relative redirects.
|
static void |
setNoCache(HttpServletResponse response)
Sets response headers to force the client to not cache the response
sent back.
|
static void |
setVariableResolver(ServletRequest request,
VariableResolver resolver)
Sets the
VariableResolver as the
WebConsoleConstants.ATTR_CONSOLE_VARIABLE_RESOLVER
attribute in the given request. |
static java.lang.String |
toString(java.lang.Object value)
This method will stringify a Java object.
|
static java.lang.String |
urlDecode(java.lang.String value)
Decode the given value expected to be URL encoded.
|
public static VariableResolver getVariableResolver(ServletRequest request)
VariableResolver
for the given request.
If no resolver has yet be created for the requests, an instance of the
DefaultVariableResolver
is created with preset properties,
placed into the request and returned. The preset properties are
appRoot
set to the value of the
WebConsoleConstants.ATTR_APP_ROOT
request attribute and
pluginRoot
set to the value of the
WebConsoleConstants.ATTR_PLUGIN_ROOT
request attribute.
Note: An object not implementing the VariableResolver
interface already stored as the
WebConsoleConstants.ATTR_CONSOLE_VARIABLE_RESOLVER
attribute
will silently be replaced by the DefaultVariableResolver
instance.
request
- The request whose attribute is returned (or set)VariableResolver
for the given request.public static void setVariableResolver(ServletRequest request, VariableResolver resolver)
VariableResolver
as the
WebConsoleConstants.ATTR_CONSOLE_VARIABLE_RESOLVER
attribute in the given request. An attribute of that name already
existing is silently replaced.request
- The request whose attribute is setresolver
- The VariableResolver
to place into the requestpublic static final java.lang.String getParameter(HttpServletRequest request, java.lang.String name)
AbstractWebConsolePlugin.ATTR_FILEUPLOAD
. The attribute value is a Map
where the key is a String specifying the field name and the value
is a FileItem
.request
- the HTTP request coming from the username
- the name of the parameternull
if not set. If multipart is used,
and the specified parameter is field - then the value of the parameter
is returned.public static final void sendRedirect(HttpServletRequest request, HttpServletResponse response, java.lang.String redirectUrl) throws java.io.IOException
request
- the HTTP request coming from the userresponse
- the HTTP response, where data is renderedredirectUrl
- the redirect URI.java.io.IOException
- If an input or output exception occursjava.lang.IllegalStateException
- If the response was committed or if a partial
URL is given and cannot be converted into a valid URLpublic static final void setNoCache(HttpServletResponse response)
This method sets the Cache-Control
, Expires
,
and Pragma
headers.
response
- The response for which to set the cache preventionpublic static final java.lang.String escapeHtml(java.lang.String text)
text
- the text to escapepublic static final int getParameterInt(HttpServletRequest request, java.lang.String name, int _default)
request
- the HTTP requestname
- the name of the request parameter_default
- the default value returned if the parameter is not set or is not a valid integer.public static java.lang.String urlDecode(java.lang.String value)
This method first tries to use the Java 1.4 method
URLDecoder.decode(String, String)
method and falls back to
the now deprecated URLDecoder.decode(String, String)
which uses the platform character set to decode the string. This is
because the platforms before 1.4 and most notably some OSGi Execution
Environments (such as Minimum EE) do not provide the newer method.
value
- the value to decodepublic static final java.lang.String toString(java.lang.Object value)
value
- the value to convert"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"