Class HTTPHelper


  • public class HTTPHelper
    extends java.lang.Object
    This class contains some public utility methods that can be used for handling parameters included on collections such as the HttpServletRequest object, and the RequestKeys object.
    Since:
    MicroStrategy Web 7.3.1 or earlier
    • Constructor Detail

      • HTTPHelper

        public HTTPHelper()
    • Method Detail

      • fixString

        public static java.lang.String fixString​(RequestKeys rk,
                                                 java.lang.String param,
                                                 java.lang.String defaultValue,
                                                 boolean isZeroLengthValid)
        Searches for the asked parameter on the request object.
        Parameters:
        rk - RequestKeys object initialized
        param - String containing the name of the parameter to search for
        defaultValue - String with the default value of the parameter
        isZeroLengthValid - Boolean flag indicating if the value of the parameter can be zero-length
        Returns:
        the value of the parameter. If not found, or the length of the value is zero and this is not allowed, the default value will be used. Otherwise, the value found for the parameter will be the output of the method.
      • fixString

        public static java.lang.String fixString​(RequestKeys rk,
                                                 java.lang.String param,
                                                 java.lang.String defaultValue)
        Searches for the asked parameter on the request object.
        Parameters:
        rk - RequestKeys object initialized
        param - String containing the name of the parameter to search for
        defaultValue - String with the default value of the parameter
        Returns:
        the value of the parameter. If not found, or the length of the value is zero and since this is not allowed, the default value will be used. Otherwise, the value found for the parameter will be the output of the method.
      • fixInt

        public static int fixInt​(java.lang.String fixedValue,
                                 int defaultValue)
        Transforms the string sent as parameter into an int value.
        Parameters:
        fixedValue - String containing the value to transform into an integer
        defaultValue - int with the default value of the parameter
        Returns:
        the value of the parameter as an int. If an error is generated while the conversion the default value will be used.
      • fixInt

        public static int fixInt​(RequestKeys rk,
                                 java.lang.String param,
                                 int defaultValue,
                                 boolean isZeroLengthValid)
        Transforms the string sent as parameter into an int value.
        Parameters:
        rk - RequestKeys object initialized
        param - String containing the name of the parameter to search for
        defaultValue - String with the default value of the parameter
        isZeroLengthValid - boolean flag indicating if the value of the parameter can be zero-length
        Returns:
        the value of the parameter. If not found, or the length of the value is zero and this is not allowed, the default value will be used. Otherwise, the value found for the parameter will be the output of the method.
      • fixInt

        public static int fixInt​(RequestKeys rk,
                                 java.lang.String param,
                                 int defaultValue)
      • getEnumerationValue

        public static java.lang.String getEnumerationValue​(java.lang.String enumValue)
        Deprecated.
        This method is deprecated. Instead use ReflectionHelper.getEnumerationValue(String enumName).
        Returns the value of the constant defined in the Java fully qualified class name and constant name received as a parameter. The value is always returned as a String regardless of the original data type. If the class cannot be resolved or the data member does not exist, null is returned.
        Parameters:
        enumValue - FCN of the data member to resolved. i.e. com.microstrategy.web.beans.EnumReportBeanEvents.REPORT_EVENT_EXECUTE
        Returns:
        String object containing the value of the FCN memmber provided. For the previous example, the return value is "4001"
      • toSysBeanType

        public static int toSysBeanType​(java.lang.String sysBeanName)
      • toSysBeanName

        public static java.lang.String toSysBeanName​(int sysBeanType)
      • getDescriptor

        public static java.lang.String getDescriptor​(int key)
        Deprecated.
        Obtains the descriptor string corresponding to the indicated key
        Parameters:
        key - identifier to look for on the string database
        Returns:
        string corresponding to the indicated key
      • getDescriptor

        public static java.lang.String getDescriptor​(int key,
                                                     Messages messages)
        Obtains the descriptor string corresponding to the indicated key
        Parameters:
        key - identifier to look for on the string database
        messages - Messages instance where the descriptor string will be looked for.
        Returns:
        string corresponding to the indicated key
      • isKeyExisting

        public static boolean isKeyExisting​(RequestKeys keys,
                                            WebEvent event,
                                            int argID)
        Checks if the argument sent as parameter exists on the RequestKeys instance
        Parameters:
        keys - a RequestKeys initialized instance
        event - a WebEvent instance from where the argument name will be obtained
        argID - the identifier of the argument to search for
        Returns:
        True if the argument was found as a parameter on the RequestKeys, either as the exact name or with the '.x' or '.y' extension (passed as an image input).
      • isKeyExisting

        public static boolean isKeyExisting​(RequestKeys keys,
                                            java.lang.String argName)
        Checks if the argument sent as parameter exists on the RequestKeys instance
        Parameters:
        keys - a RequestKeys initialized instance
        argName - the name of the argument to search for
        Returns:
        True if the argument was found as a parameter on the RequestKeys, either as the exact name or with the '.x' or '.y' extension (passed as an image input).
      • getLastRowPosition

        public static java.lang.String getLastRowPosition​(ReportBean rb)
        Gets the position where the new attribute will be displayed
        Parameters:
        rb - a ReportBean instance initialized
        Returns:
        the last index (plus one) of the row axis on the template. If an error happens, returns 1 by default.
      • processApplyChanges

        public static void processApplyChanges​(WebComponent wc)
                                        throws WebException
        Handles the request for the instances of ReportBean and RWBean
        Parameters:
        wc - WebComponent
        Throws:
        WebException
        Since:
        MicroStrategy Web 8.0.0
      • processResetChanges

        public static void processResetChanges​(ReportBean rb)
                                        throws WebException
        Resets the changes om the ReportBean.
        Parameters:
        rb - ReportBean
        Throws:
        WebException
      • getOutputFormatToUse

        public static int getOutputFormatToUse​(AppContext appContext)
        Determines the output mode the beans should use when getting displayed based on the preferences as defined by the instance of AppContext.
        Parameters:
        appContext - AppContext
        Returns:
        int
      • getProjectAlias

        public static java.lang.String getProjectAlias​(java.lang.String serverName,
                                                       java.lang.String projectName)
        Utility method for obtaining the project alias string based on the Server and original Project name
        Parameters:
        serverName - String with the name of the I-Server of the project to look for
        projectName - String with the original project name to look for
        Returns:
        a String with the original project name if no alias was found, or the value of the alias found on the System Preferences for the given project.
        Since:
        MicroStrategy Web 7.5.3
      • getProjectAlias

        public static java.lang.String getProjectAlias​(java.lang.String serverName,
                                                       int serverPort,
                                                       java.lang.String projectName)
        Utility method for obtaining the project alias string based on the Server and original Project name.
        Parameters:
        serverName - String with the name of the I-Server of the project to look for
        serverPort - Port of I-Server.
        projectName - String with the original project name to look for
        Returns:
        a String with the original project name if no alias was found, or the value of the alias found on the System Preferences for the given project.
        Since:
        MicroStrategy Web 9.0.0
      • getProjectAlias

        public static java.lang.String getProjectAlias​(java.lang.String serverName,
                                                       int serverPort,
                                                       java.lang.String projectName,
                                                       java.util.Locale locale)
        Utility method for obtaining the project alias string based on the Server and original Project name.
        Parameters:
        serverName - String with the name of the I-Server of the project to look for
        serverPort - Port of I-Server.
        projectName - String with the original project name to look for
        locale - locale of the project alias to return
        Returns:
        a String with the original project name if no alias was found, or the value of the alias found on the System Preferences for the given project.
      • getProjectAlias

        public static java.lang.String getProjectAlias​(WebIServerSession session)
        Utility method for obtaining the project alias string based on the Server and original Project name.
        Parameters:
        session - session available for lookup.
        Returns:
        a String with the original project name if no alias was found, or the value of the alias found on the System Preferences for the given project.
        Since:
        MicroStrategy Web 9.0.0
      • isDefaultLocale

        public static boolean isDefaultLocale​(java.lang.String localeStr)
        Since:
        MicroStrategy Web 9.0.0
      • getLocale

        public static int getLocale​(java.lang.String localeStr,
                                    AppContext appContext)
        Since:
        MicroStrategy Web 9.0.0
      • getBrowserLocale

        public static int getBrowserLocale​(AppContext appContext)
        Since:
        MicroStrategy Web 9.0.0
      • isIFrameRequest

        public static boolean isIFrameRequest​(PageComponent mstrPage)
        Since:
        MicroStrategy Web 9.0.1
      • mimeEncode

        public static java.lang.String mimeEncode​(java.lang.String input)
        Utility method to encode the HTTP header value with RFC 2047.
        Parameters:
        input - HTTP header value which has non-ASCII characters.
        Returns:
        an encoded String
        Since:
        MicroStrategy Web 9.0.2
      • removeCrlf

        public static java.lang.String removeCrlf​(java.lang.String input)
        Utility method to remove CRLF "\r", "\n" and encoded CRLF "%0a %0A %0d %0D" from the HTTP header to fix: "CWE-113 : Improper Neutralization of CRLF sequences in HTTP Headers (‘HTTP Response splitting’)" For only non-encoded CRLF removal
        Parameters:
        input - HTTP header value which has CRLF characters.
        Returns:
        an String without CRLF characters
        See Also:
        StringUtils.removeCrlf(String value, boolean isRemoveEncodedCrlf)