Class 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
      Constant substKeywords={ '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)
      convertToJsSafeString
      static EventProxy createEventProxy()
      Deprecated.
      Use dependency injection to wire in an instance of the EventProxy instead
      static 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 the fmt:formatDate taglib at the JSP level instead of converting Date instances into String 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)
      htmlify
      static 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 given HttpServletRequest.
      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 given HttpServletRequest 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 given HttpServletRequest and key in given Map.
      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 given HttpServletRequest and key in given Map 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 given HttpServletRequest and key in given Map that is not listed in the ignore list.
      protected static java.lang.String substituteUrl​(javax.servlet.http.HttpServletRequest request, java.lang.String tmpl)
      substituteUrl
      • 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
        Constant substKeywords={ 's', 'h', 'p', 'x', 'c' }
      • hostHeaders

        protected static final java.lang.String[] hostHeaders
    • Constructor Detail

      • Util

        public Util()
    • 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 - a HttpServletRequest object.
        tmpl - a String 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 - a HttpServletRequest 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 - 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 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 - 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 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 - 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 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 - 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 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 - 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 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 given HttpServletRequest.
        Parameters:
        request - a HttpServletRequest 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 given HttpServletRequest and key in given Map.
        Parameters:
        request - a HttpServletRequest object.
        additions - a Map 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 given HttpServletRequest that is not listed in the ignore list.
        Parameters:
        request - a HttpServletRequest object.
        ignores - an array of String 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 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 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 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
        ignoreType - a Util.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 - a String object.
        Returns:
        a String object.
      • createEventProxy

        public static EventProxy createEventProxy()
        Deprecated.
        Use dependency injection to wire in an instance of the EventProxy instead

        createEventProxy

        Returns:
        a EventProxy object.
      • formatDateToUIString

        public static final java.lang.String formatDateToUIString​(java.util.Date date)
        Deprecated.
        We should use the fmt:formatDate taglib at the JSP level instead of converting Date instances into String 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 - a Date object.
        Returns:
        a String object.
        See Also:
        DateFormat
      • convertToJsSafeString

        public static java.lang.String convertToJsSafeString​(java.lang.String str)

        convertToJsSafeString

        Parameters:
        str - a String 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)