org.opennms.web
Class Util

java.lang.Object
  extended by org.opennms.web.Util

public abstract class Util
extends Object

Provides convenience functions for web-based interfaces.

Author:
Lawrence Karnowski , OpenNMS

Nested Class Summary
static class Util.IgnoreType
           
 
Field Summary
protected static String[] hostHeaders
           
protected static char[] substKeywords
           
 
Constructor Summary
Util()
           
 
Method Summary
static String calculateUrlBase(HttpServletRequest request)
          Return a string that represents the fully qualified URL for our servlet context, suitable for use in the HTML base tag.
static EventProxy createEventProxy()
           
static 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)
          An utility method to format a 'Date' into a string in the local specific DEFALUT DateFormat style for both the date and time.
static String getHostHeader(HttpServletRequest request)
          Obtains the host and port used by the end user.
static String getHostname(String ipAddress)
          Deprecated. Please use NetworkElementFactory.getHostname instead.
static Map<String,String> getOrderedMap(String[][] names)
           
static String htmlify(String input)
           
static String makeHiddenTags(HttpServletRequest request)
          Creates hidden tags for all the parameters given in the request.
static String makeHiddenTags(HttpServletRequest request, Map additions)
          Creates hidden tags for all the parameters given in the request.
static String makeHiddenTags(HttpServletRequest request, Map 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(HttpServletRequest request, Map 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 makeHiddenTags(HttpServletRequest request, String[] ignores)
          Creates hidden tags for all the parameters given in the request.
static String makeQueryString(HttpServletRequest request)
          Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest.
static String makeQueryString(HttpServletRequest request, Map additions)
          Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest and key in given Map.
static String makeQueryString(HttpServletRequest request, Map additions, String[] ignores)
          Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest and key in given Map that is not listed in the ignore list.
static String makeQueryString(HttpServletRequest request, Map additions, String[] ignores, Util.IgnoreType ignoreType)
          Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest and key in given Map that is not listed in the ignore list.
static String makeQueryString(HttpServletRequest request, String[] ignores)
          Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest that is not listed in the ignore list.
static String resolveIpAddress(String ipAddress)
          Deprecated. Please use NetworkElementFactory.getHostname instead.
protected static String substituteUrl(HttpServletRequest request, String tmpl)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

substKeywords

protected static final char[] substKeywords

hostHeaders

protected static final String[] hostHeaders
Constructor Detail

Util

public Util()
Method Detail

calculateUrlBase

public static String calculateUrlBase(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) or WEB-INF/configuration.properties (for Tomcat).

Parameters:
request - the servlet request you are servicing

substituteUrl

protected static String substituteUrl(HttpServletRequest request,
                                      String tmpl)

getHostHeader

public static String getHostHeader(HttpServletRequest request)
Obtains the host and port used by the end user.


getHostname

public static String getHostname(String ipAddress)
Deprecated. Please use NetworkElementFactory.getHostname instead.

Convenience method for resolving the human-readable hostname for an IP address, if at all possible. If the hostname cannot be found, this method returns the IP address parameter.

Parameters:
ipAddress - the IP address for which you want the hostname

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

resolveIpAddress

public static String resolveIpAddress(String ipAddress)
Deprecated. Please use NetworkElementFactory.getHostname instead.

Convenience method for resolving the human-readable hostname for an IP address, if at all possible. If the hostname cannot be found, from the table, this method returns the IP address parameter. This method doesnt throw any exception.

Parameters:
ipAddress - the IP address for which you want the hostname

makeHiddenTags

public static String makeHiddenTags(HttpServletRequest request)
Creates hidden tags for all the parameters given in the request.

Parameters:
request - the HttpServletRequest 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(HttpServletRequest request,
                                    Map additions)
Creates hidden tags for all the parameters given in the request.

Parameters:
request - the HttpServletRequest to read the parameters from
additions - 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(HttpServletRequest request,
                                    String[] ignores)
Creates hidden tags for all the parameters given in the request.

Parameters:
request - the HttpServletRequest to read the parameters from
ignores - 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(HttpServletRequest request,
                                    Map 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 - the HttpServletRequest to read the parameters from
additions - a map of extra parameters to create hidden tags for
ignores - 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(HttpServletRequest request,
                                    Map 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 - the HttpServletRequest to read the parameters from
additions - a map of extra parameters to create hidden tags for
ignores - the list of parameters not to create a hidden tag for
ignoreType - 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(HttpServletRequest request)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest.

See Also:
makeQueryString( HttpServletRequest, Map, String[] )

makeQueryString

public static String makeQueryString(HttpServletRequest request,
                                     Map additions)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest and key in given Map.

See Also:
makeQueryString( HttpServletRequest, Map, String[] )

makeQueryString

public static String makeQueryString(HttpServletRequest request,
                                     String[] ignores)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest that is not listed in the ignore list.

See Also:
makeQueryString( HttpServletRequest, Map, String[] )

makeQueryString

public static String makeQueryString(HttpServletRequest request,
                                     Map additions,
                                     String[] ignores)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest and key in given Map that is not listed in the ignore list.

Parameters:
request - the HttpServletRequest to read the parameters from
additions - a mapping of strings to strings or string arrays to be included in the query string
ignores - 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(HttpServletRequest request,
                                     Map additions,
                                     String[] ignores,
                                     Util.IgnoreType ignoreType)
Creates a query string of the format "key1=value1&key2=value2" for each parameter in the given HttpServletRequest and key in given Map that is not listed in the ignore list.

Parameters:
request - the HttpServletRequest to read the parameters from
additions - a mapping of strings to strings or string arrays to be included in the query string
ignores - 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.

getOrderedMap

public static Map<String,String> getOrderedMap(String[][] names)

htmlify

public static String htmlify(String input)

createEventProxy

public static EventProxy createEventProxy()

formatDateToUIString

public static final String formatDateToUIString(Date date)
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.

See Also:
DateFormat


Copyright © 2009. All Rights Reserved.