Package org.opennms.web.api
Class Util
- java.lang.Object
-
- org.opennms.web.api.Util
-
public abstract class Util extends 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 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 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 String
calculateUrlBase(javax.servlet.http.HttpServletRequest request, String path)
static String
convertToJsSafeString(String str)
convertToJsSafeStringstatic EventProxy
createEventProxy()
Deprecated.Use dependency injection to wire in an instance of theEventProxy
insteadstatic String
decode(String string)
Encapsulate the deprecated decode method to fix it in one place.static String
encode(String string)
Encapsulate the deprecated encode method to fix it in one place.static String
formatDateToUIString(Date date)
static String
getHostHeader(javax.servlet.http.HttpServletRequest request)
Obtains the host and port used by the end user.static String
getParameter(javax.servlet.http.HttpServletRequest request, String name)
static String
getParameter(javax.servlet.http.HttpServletRequest request, String name, String defaultValue)
static String
htmlify(String input)
htmlifystatic String
makeHiddenTags(javax.servlet.http.HttpServletRequest request)
Creates hidden tags for all the parameters given in the request.static String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, String[] ignores)
Creates hidden tags for all the parameters given in the request.static String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions)
Creates hidden tags for all the parameters given in the request.static String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 String
makeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 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 String
makeQueryString(javax.servlet.http.HttpServletRequest request, 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 String
makeQueryString(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest
and key in givenMap
.static String
makeQueryString(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 String
makeQueryString(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 String
substituteUrl(javax.servlet.http.HttpServletRequest request, String tmpl)
substituteUrl
-
-
-
Field Detail
-
substKeywords
protected static final char[] substKeywords
ConstantsubstKeywords={ 's', 'h', 'p', 'x', 'c' }
-
hostHeaders
protected static final String[] hostHeaders
-
-
Method Detail
-
calculateUrlBase
public static 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 String calculateUrlBase(javax.servlet.http.HttpServletRequest request, String path)
-
substituteUrl
protected static String substituteUrl(javax.servlet.http.HttpServletRequest request, String tmpl)
substituteUrl
-
getHostHeader
public static 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 String encode(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 String decode(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 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 String makeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,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 String makeHiddenTags(javax.servlet.http.HttpServletRequest request, 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 String makeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 String makeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 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 String makeQueryString(javax.servlet.http.HttpServletRequest request, Map<String,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 String makeQueryString(javax.servlet.http.HttpServletRequest request, 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 String makeQueryString(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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 String makeQueryString(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions, 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.
-
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 String formatDateToUIString(Date date)
Deprecated.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
-
getParameter
public static String getParameter(javax.servlet.http.HttpServletRequest request, String name)
-
-