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 classUtil.IgnoreType
-
Field Summary
Fields Modifier and Type Field Description protected static String[]hostHeadersprotected static char[]substKeywordsConstantsubstKeywords={ '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 StringcalculateUrlBase(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 StringcalculateUrlBase(javax.servlet.http.HttpServletRequest request, String path)static StringconvertToJsSafeString(String str)convertToJsSafeStringstatic EventProxycreateEventProxy()Deprecated.Use dependency injection to wire in an instance of theEventProxyinsteadstatic Stringdecode(String string)Encapsulate the deprecated decode method to fix it in one place.static Stringencode(String string)Encapsulate the deprecated encode method to fix it in one place.static StringformatDateToUIString(Date date)static StringgetHostHeader(javax.servlet.http.HttpServletRequest request)Obtains the host and port used by the end user.static StringgetParameter(javax.servlet.http.HttpServletRequest request, String name)static StringgetParameter(javax.servlet.http.HttpServletRequest request, String name, String defaultValue)static Stringhtmlify(String input)htmlifystatic StringmakeHiddenTags(javax.servlet.http.HttpServletRequest request)Creates hidden tags for all the parameters given in the request.static StringmakeHiddenTags(javax.servlet.http.HttpServletRequest request, String[] ignores)Creates hidden tags for all the parameters given in the request.static StringmakeHiddenTags(javax.servlet.http.HttpServletRequest request, Map<String,Object> additions)Creates hidden tags for all the parameters given in the request.static StringmakeHiddenTags(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 StringmakeHiddenTags(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 StringmakeQueryString(javax.servlet.http.HttpServletRequest request)Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequest.static StringmakeQueryString(javax.servlet.http.HttpServletRequest request, String[] ignores)Creates a query string of the format "key1=value1&key2=value2" for each parameter in the givenHttpServletRequestthat is not listed in the ignore list.static StringmakeQueryString(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 givenHttpServletRequestand key in givenMap.static StringmakeQueryString(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 givenHttpServletRequestand key in givenMapthat is not listed in the ignore list.static StringmakeQueryString(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 givenHttpServletRequestand key in givenMapthat is not listed in the ignore list.protected static StringsubstituteUrl(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-urlin opennms.properties (for embedded Jetty).- Parameters:
request- the servlet request you are servicing- Returns:
- a
Stringobject.
-
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- aHttpServletRequestobject.- Returns:
- a
Stringobject.
-
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- theHttpServletRequestto 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- theHttpServletRequestto 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- theHttpServletRequestto 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- theHttpServletRequestto 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- theHttpServletRequestto 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- aHttpServletRequestobject.- Returns:
- a
Stringobject. - 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 givenHttpServletRequestand key in givenMap.- Parameters:
request- aHttpServletRequestobject.additions- aMapobject.- Returns:
- a
Stringobject. - 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 givenHttpServletRequestthat is not listed in the ignore list.- Parameters:
request- aHttpServletRequestobject.ignores- an array ofStringobjects.- Returns:
- a
Stringobject. - 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 givenHttpServletRequestand key in givenMapthat is not listed in the ignore list.- Parameters:
request- theHttpServletRequestto 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 givenHttpServletRequestand key in givenMapthat is not listed in the ignore list.- Parameters:
request- theHttpServletRequestto 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.IgnoreTypeobject.- 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 theEventProxyinsteadcreateEventProxy
- Returns:
- a
EventProxyobject.
-
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- aDateobject.- Returns:
- a
Stringobject. - See Also:
DateFormat
-
getParameter
public static String getParameter(javax.servlet.http.HttpServletRequest request, String name)
-
-