Class Util

    • 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
      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 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)
      convertToJsSafeString
      static EventProxy createEventProxy()
      Deprecated.
      Use dependency injection to wire in an instance of the EventProxy instead
      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)
      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 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)
      htmlify
      static 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 given HttpServletRequest.
      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 given HttpServletRequest 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 given HttpServletRequest and key in given Map.
      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 given HttpServletRequest and key in given Map 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 given HttpServletRequest and key in given Map 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
        Constant substKeywords={ 's', 'h', 'p', 'x', 'c' }
      • hostHeaders

        protected static final String[] hostHeaders
    • Constructor Detail

      • Util

        public Util()
    • 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

        Parameters:
        request - a HttpServletRequest object.
        tmpl - a String object.
        Returns:
        a String object.
      • getHostHeader

        public static 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 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 - 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​(javax.servlet.http.HttpServletRequest request,
                                            Map<String,​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 String makeHiddenTags​(javax.servlet.http.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​(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 - 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​(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 - 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​(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 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 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 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 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 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 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​(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 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 String htmlify​(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 String formatDateToUIString​(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 String convertToJsSafeString​(String str)

        convertToJsSafeString

        Parameters:
        str - a String object.
        Returns:
        a String object.
      • getParameter

        public static String getParameter​(javax.servlet.http.HttpServletRequest request,
                                          String name)
      • getParameter

        public static String getParameter​(javax.servlet.http.HttpServletRequest request,
                                          String name,
                                          String defaultValue)