Package org.opennms.web.api
Class Util
- java.lang.Object
-
- org.opennms.web.api.Util
-
public abstract class Util extends java.lang.Object
Provides convenience functions for web-based interfaces.- Author:
- Lawrence Karnowski , OpenNMS
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Util.IgnoreType
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String[]
hostHeaders
protected static char[]
substKeywords
ConstantsubstKeywords={ 's', 'h', 'p', 'x', 'c' }
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
calculateUrlBase(javax.servlet.http.HttpServletRequest request)
Return a string that represents the fully qualified URL for our servlet context, suitable for use in the HTML base tag.static java.lang.String
calculateUrlBase(javax.servlet.http.HttpServletRequest request, java.lang.String path)
static java.lang.String
convertToJsSafeString(java.lang.String str)
convertToJsSafeStringstatic EventProxy
createEventProxy()
Deprecated.Use dependency injection to wire in an instance of theEventProxy
insteadstatic java.lang.String
decode(java.lang.String string)
Encapsulate the deprecated decode method to fix it in one place.static java.lang.String
encode(java.lang.String string)
Encapsulate the deprecated encode method to fix it in one place.static java.lang.String
formatDateToUIString(java.util.Date date)
Deprecated.We should use thefmt:formatDate
taglib at the JSP level instead of convertingDate
instances intoString
instances inside the model code.static java.lang.String
getHostHeader(javax.servlet.http.HttpServletRequest request)
Obtains the host and port used by the end user.static java.lang.String
getParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
static java.lang.String
getParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String defaultValue)
static java.lang.String
htmlify(java.lang.String input)
htmlifystatic java.lang.String
makeHiddenTags(javax.servlet.http.HttpServletRequest request)
Creates hidden tags for all the parameters given in the request.static java.lang.String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.lang.String[] ignores)
Creates hidden tags for all the parameters given in the request.static java.lang.String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions)
Creates hidden tags for all the parameters given in the request.static java.lang.String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores)
Creates hidden tags for all the parameters given in the request plus the additions, except for the parameters and additions listed in the ignore list.static java.lang.String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores, Util.IgnoreType ignoreType)
Creates hidden tags for all the parameters given in the request plus the additions, except for the parmeters listed in the ignore list.static java.lang.String
makeQueryString(javax.servlet.http.HttpServletRequest request)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
.static java.lang.String
makeQueryString(javax.servlet.http.HttpServletRequest request, java.lang.String[] ignores)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
that is not listed in the ignore list.static java.lang.String
makeQueryString(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
.static java.lang.String
makeQueryString(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
that is not listed in the ignore list.static java.lang.String
makeQueryString(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores, Util.IgnoreType ignoreType)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
that is not listed in the ignore list.protected static java.lang.String
substituteUrl(javax.servlet.http.HttpServletRequest request, java.lang.String tmpl)
substituteUrl
-
-
-
Method Detail
-
calculateUrlBase
public static java.lang.String calculateUrlBase(javax.servlet.http.HttpServletRequest request)
Return a string that represents the fully qualified URL for our servlet context, suitable for use in the HTML base tag.As an example, suppose your host was www.mycompany.com, you are serving from port 80, and your web application name was "opennms," then this method would return:
http://www.mycompany.com:80/opennms/
If this guess is wrong, you can override it by setting the property
opennms.web.base-url
in opennms.properties (for embedded Jetty).- Parameters:
request
- the servlet request you are servicing- Returns:
- a
String
object.
-
calculateUrlBase
public static java.lang.String calculateUrlBase(javax.servlet.http.HttpServletRequest request, java.lang.String path)
-
substituteUrl
protected static java.lang.String substituteUrl(javax.servlet.http.HttpServletRequest request, java.lang.String tmpl)
substituteUrl
- Parameters:
request
- aHttpServletRequest
object.tmpl
- aString
object.- Returns:
- a
String
object.
-
getHostHeader
public static java.lang.String getHostHeader(javax.servlet.http.HttpServletRequest request)
Obtains the host and port used by the end user.- Parameters:
request
- aHttpServletRequest
object.- Returns:
- a
String
object.
-
encode
public static java.lang.String encode(java.lang.String string)
Encapsulate the deprecated encode method to fix it in one place.- Parameters:
string
- string to be encoded- Returns:
- encoded string
-
decode
public static java.lang.String decode(java.lang.String string)
Encapsulate the deprecated decode method to fix it in one place.- Parameters:
string
- string to be decoded- Returns:
- decoded string
-
makeHiddenTags
public static java.lang.String makeHiddenTags(javax.servlet.http.HttpServletRequest request)
Creates hidden tags for all the parameters given in the request.- Parameters:
request
- theHttpServletRequest
to read the parameters from- Returns:
- A string containing an HTML <input type="hidden" name="
paramName
" value="paramValue
" /> tag for each parameter.
-
makeHiddenTags
public static java.lang.String makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions)
Creates hidden tags for all the parameters given in the request.- Parameters:
request
- theHttpServletRequest
to read the parameters fromadditions
- a map of extra parameters to create hidden tags for- Returns:
- A string containing an HTML <input type="hidden" name="
paramName
" value="paramValue
" /> tag for each parameter.
-
makeHiddenTags
public static java.lang.String makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.lang.String[] ignores)
Creates hidden tags for all the parameters given in the request.- Parameters:
request
- theHttpServletRequest
to read the parameters fromignores
- A string array containing request parameters to ignore- Returns:
- A string containing an HTML <input type="hidden" name="
paramName
" value="paramValue
" /> tag for each parameter.
-
makeHiddenTags
public static java.lang.String makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores)
Creates hidden tags for all the parameters given in the request plus the additions, except for the parameters and additions listed in the ignore list.- Parameters:
request
- theHttpServletRequest
to read the parameters fromadditions
- a map of extra parameters to create hidden tags forignores
- the list of parameters not to create a hidden tag for- Returns:
- A string containing an HTML <input type="hidden" name="
paramName
" value="paramValue
" /> tag for each parameter not in the ignore list.
-
makeHiddenTags
public static java.lang.String makeHiddenTags(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores, Util.IgnoreType ignoreType)
Creates hidden tags for all the parameters given in the request plus the additions, except for the parmeters listed in the ignore list.- Parameters:
request
- theHttpServletRequest
to read the parameters fromadditions
- a map of extra parameters to create hidden tags forignores
- the list of parameters not to create a hidden tag forignoreType
- whether the ignore list applies to the request parameters, values in the additions map, or both- Returns:
- A string containing an HTML <input type="hidden" name="
paramName
" value="paramValue
" /> tag for each parameter not in the ignore list.
-
makeQueryString
public static java.lang.String makeQueryString(javax.servlet.http.HttpServletRequest request)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
.- Parameters:
request
- aHttpServletRequest
object.- Returns:
- a
String
object. - See Also:
makeQueryString( HttpServletRequest, Map, String[] )
-
makeQueryString
public static java.lang.String makeQueryString(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
.- Parameters:
request
- aHttpServletRequest
object.additions
- aMap
object.- Returns:
- a
String
object. - See Also:
makeQueryString( HttpServletRequest, Map, String[] )
-
makeQueryString
public static java.lang.String makeQueryString(javax.servlet.http.HttpServletRequest request, java.lang.String[] ignores)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
that is not listed in the ignore list.- Parameters:
request
- aHttpServletRequest
object.ignores
- an array ofString
objects.- Returns:
- a
String
object. - See Also:
makeQueryString( HttpServletRequest, Map, String[] )
-
makeQueryString
public static java.lang.String makeQueryString(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
that is not listed in the ignore list.- Parameters:
request
- theHttpServletRequest
to read the parameters fromadditions
- a mapping of strings to strings or string arrays to be included in the query stringignores
- the list of parameters and map entries not to include- Returns:
- A string in the x-www-form-urlencoded format that is suitable for adding to a URL as a query string.
-
makeQueryString
public static java.lang.String makeQueryString(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,java.lang.Object> additions, java.lang.String[] ignores, Util.IgnoreType ignoreType)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
that is not listed in the ignore list.- Parameters:
request
- theHttpServletRequest
to read the parameters fromadditions
- a mapping of strings to strings or string arrays to be included in the query stringignores
- the list of parameters and map entries not to includeignoreType
- aUtil.IgnoreType
object.- Returns:
- A string in the x-www-form-urlencoded format that is suitable for adding to a URL as a query string.
-
htmlify
public static java.lang.String htmlify(java.lang.String input)
htmlify
- Parameters:
input
- aString
object.- Returns:
- a
String
object.
-
createEventProxy
public static EventProxy createEventProxy()
Deprecated.Use dependency injection to wire in an instance of theEventProxy
insteadcreateEventProxy
- Returns:
- a
EventProxy
object.
-
formatDateToUIString
public static final java.lang.String formatDateToUIString(java.util.Date date)
Deprecated.We should use thefmt:formatDate
taglib at the JSP level instead of convertingDate
instances intoString
instances inside the model code.An utility method to format a 'Date' into a string in the local specific DEFALUT DateFormat style for both the date and time. This is used by the webui and a change here should get all time display in the webui changed.- Parameters:
date
- aDate
object.- Returns:
- a
String
object. - See Also:
DateFormat
-
convertToJsSafeString
public static java.lang.String convertToJsSafeString(java.lang.String str)
convertToJsSafeString
- Parameters:
str
- aString
object.- Returns:
- a
String
object.
-
getParameter
public static java.lang.String getParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
-
getParameter
public static java.lang.String getParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String defaultValue)
-
-