com.ibm.commerce.tools.util

Class Util

  • java.lang.Object
    • com.ibm.commerce.tools.util.Util


  • public class Util
    extends java.lang.Object
    Contains commonly used functions.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      static java.util.Vector arrayToVector(java.lang.Object[] arr)
      Converts an array to a vector of string.
      static void chmod(java.lang.String strFile, java.lang.String strPerm, boolean recursive)
      Change file permission on UNIX system.
      static void chmoddeep400(java.lang.String path, java.lang.String perm, java.lang.String start, java.lang.String server, java.lang.String user, java.lang.String pwd)
      Change file permission on remote i5/OS server.
      static boolean compareStrings(java.lang.String x, java.lang.String y)
      Compares the two strings after any space is trimmed.
      static java.lang.String convertFilename(java.lang.String filename)
      Converts separators '/' and '.' to File.separator.
      static boolean convertToBoolean(java.lang.Object value)
      Converts the given string to a boolean value.
      static java.util.Hashtable convertToHashtable(java.lang.Object key, java.lang.Object x)
      Converts an object to a Hashtable.
      static java.util.Vector convertToVector(java.lang.Object x)
      Converts an object to a Vector.
      static java.io.File copyFile(java.lang.String fileInput, java.lang.String fileOutput)
      Makes a copy of input file to an output file.
      static java.util.Hashtable copyHashtable(java.util.Hashtable table)
      Makes a recursive copy of a hashtable.
      static java.util.Vector copyVector(java.util.Vector v)
      Makes a recursive copy of a vector.
      static java.io.File findFile(java.lang.String filename, java.lang.String path)
      Searches the given path for the given file name.
      static java.io.File findFileFromClassLoader(java.lang.String filename)
      Searches the given file name using the class loader's classpath.
      static java.util.Hashtable flatten(java.util.Hashtable h1, java.util.Hashtable h2)
      Consolidates the given hashtables into a single hashtable.
      static java.util.Hashtable getAllRoles()
      Reads all roles (member groups) from Roles.xml into a hashtable.
      static java.util.Vector getRoles(UserAccessBean uab, java.lang.Long owner_id)
      Reads the roles for a particular user on a particular store.
      static java.lang.String hexToString(java.lang.String text)
      This method takes a hexadecimal string and returns the corresponding character String object.
      static java.lang.String insert(java.lang.String target, java.lang.String insertStr, int pos)
      Inserts a given substring at a given position
      static boolean isAS400OS()
      Checks whether the operating system is AS/400.
      static boolean isDoubleByteLocale(java.util.Locale locale)
      Checks to see whether the locale is a double-byte character.
      static boolean isIE(javax.servlet.http.HttpServletRequest request)
      Checks to see whether the browser is Internet Explorer.
      static boolean isLinuxOS()
      Checks whether the operating system is Linux.
      static boolean isLowerCase(java.lang.String target)
      Tests to see if a string is lower case.
      static boolean isLowerCase(java.lang.String str, int start, int length)
      Tests to see if a substring is lower case.
      static boolean isNetscape(javax.servlet.http.HttpServletRequest request)
      Checks to see whether the browser is Netscape.
      static boolean isUnixOS()
      Checks whether the operating system is UNIX.
      static boolean isUpperCase(java.lang.String str)
      Tests to see if a string is upper case.
      static boolean isUpperCase(java.lang.String str, int start, int length)
      Tests to see if a substring is upper case.
      static boolean isWindowsOS()
      Checks whether the operating system is Windows.
      static java.util.Vector merge(java.lang.Object value1, java.lang.Object value2)
      Merges the given objects into a single vector.
      static int occurencesOf(java.lang.String target)
      Returns the number of occurrences of " \t\n".
      static int occurencesOf(java.lang.String target, java.lang.String characters)
      Returns the number of occurrences of a substring.
      static java.lang.String replace(java.lang.String source, char pattern, char replacement)
      Replaces the occurrences of a given pattern character with a given replacement character in the source string.
      static java.lang.String replace(java.lang.String source, java.lang.String pattern, java.lang.String replacement)
      Replaces the occurrences of a given pattern string with a given replacement string in the source string.
      static java.lang.String reverse(java.lang.String source)
      Returns the reversal of the source string.
      static void setLastXMLPath(java.lang.String xmlPath)
      Deprecated.  
      static java.lang.String stringToHex(java.lang.String text)
      Converts the given string to a hexadecimal representation.
      static java.lang.String strip(java.lang.String target)
      Strips the leading and trailing characters.
      static java.lang.String stripLeading(java.lang.String target)
      Strips leading characters " \t\n".
      static java.lang.String stripLeading(java.lang.String target, java.lang.String characters)
      Strips the given leading characters.
      static java.lang.String stripTrailing(java.lang.String target)
      Strips trailing characters " \t\n".
      static java.lang.String stripTrailing(java.lang.String target, java.lang.String characters)
      Strips the given trailing characters.
      static java.lang.String[] tokenize(java.lang.String source, java.lang.String delimiter)
      Tokenizes a string.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • arrayToVector

        public static final java.util.Vector arrayToVector(java.lang.Object[] arr)
        Converts an array to a vector of string.
        Parameters:
        arr - array to be converted
        Returns:
        The vector converted from an input array.
        null if the array is empty.
      • compareStrings

        public static final boolean compareStrings(java.lang.String x,
                                                   java.lang.String y)
        Compares the two strings after any space is trimmed.
        Parameters:
        x - the first string
        y - second string
        Returns:
        true if two strings are identical.
        false otherwise.
      • convertFilename

        public static final java.lang.String convertFilename(java.lang.String filename)
        Converts separators '/' and '.' to File.separator. Note: for '.' it converts all but the last '.'.
        Parameters:
        filename - the original file name.
        Returns:
        The proper file name.
      • convertToBoolean

        public static final boolean convertToBoolean(java.lang.Object value)
        Converts the given string to a boolean value.
        Parameters:
        value - a string or boolean value to be converted
        Returns:
        A boolean value of the object.
        false if the original value is null.
      • convertToHashtable

        public static final java.util.Hashtable convertToHashtable(java.lang.Object key,
                                                                   java.lang.Object x)
        Converts an object to a Hashtable.
        Parameters:
        key - the key associated with the hashtable
        x - the object to be converted
        Returns:
        null if x is null.
        The original value of x if x is an instance of Hashtable.
        Otherwise, returns a new hashtable with key and x put into it.
      • convertToVector

        public static final java.util.Vector convertToVector(java.lang.Object x)
        Converts an object to a Vector.
        Parameters:
        x - the object to be converted
        Returns:
        null if x is null.
        The original value of x if x is an instance of Vector.
        Otherwise, returns a new vector with x put into it.
      • copyFile

        public static final java.io.File copyFile(java.lang.String fileInput,
                                                  java.lang.String fileOutput)
                                           throws java.io.IOException
        Makes a copy of input file to an output file. It does not check for existence of the output file, and will overwrite if it does exist.
        Parameters:
        fileInput - source file name
        fileOutput - destination file name
        Returns:
        The destination File object.
        Throws:
        java.io.IOException - If file I/O exception is encountered.
      • copyHashtable

        public static final java.util.Hashtable copyHashtable(java.util.Hashtable table)
        Makes a recursive copy of a hashtable.
        Parameters:
        table - the hashtable to be copied
        Returns:
        A clone of the original hashtable.
      • copyVector

        public static final java.util.Vector copyVector(java.util.Vector v)
        Makes a recursive copy of a vector.
        Parameters:
        v - the vector to be copied
        Returns:
        A clone of the original vector.
      • findFile

        public static final java.io.File findFile(java.lang.String filename,
                                                  java.lang.String path)
        Searches the given path for the given file name.
        Parameters:
        filename - the given file name to be searched
        path - the searching path
        Returns:
        The file object.
        null if not found.
      • findFileFromClassLoader

        public static final java.io.File findFileFromClassLoader(java.lang.String filename)
        Searches the given file name using the class loader's classpath.
        Parameters:
        filename - the given file name to be searched
        Returns:
        The file object.
        null if not found.
      • flatten

        public static final java.util.Hashtable flatten(java.util.Hashtable h1,
                                                        java.util.Hashtable h2)
        Consolidates the given hashtables into a single hashtable.
        Parameters:
        h1 - the first hashtable
        h2 - the second hashtable
        Returns:
        The consolidated hashtable.
      • getAllRoles

        public static final java.util.Hashtable getAllRoles()
                                                     throws ECSystemException
        Reads all roles (member groups) from Roles.xml into a hashtable.
        Returns:
        The roles in Hashtable.
        Throws:
        ECSystemException - If an exception is caught while reading the XML file.
      • getRoles

        public static final java.util.Vector getRoles(UserAccessBean uab,
                                                      java.lang.Long owner_id)
                                               throws ECSystemException
        Reads the roles for a particular user on a particular store.
        Parameters:
        uab - the user access bean
        owner_id - the owner of the store
        Returns:
        A vector of role IDs that this user has on the store.
        Throws:
        ECSystemException - If error occurs while reading the roles from database.
      • hexToString

        public static final java.lang.String hexToString(java.lang.String text)
        This method takes a hexadecimal string and returns the corresponding character String object.
        Parameters:
        text - the hexadecimal string
        Returns:
        The converted string.
      • insert

        public static final java.lang.String insert(java.lang.String target,
                                                    java.lang.String insertStr,
                                                    int pos)
        Inserts a given substring at a given position
        Parameters:
        target - the target string
        insertStr - the string to be inserted
        pos - the inserted position
        Returns:
        The final string.
      • isAS400OS

        public static boolean isAS400OS()
        Checks whether the operating system is AS/400.
        Returns:
        true if it is AS/400.
        false otherwise.
      • isDoubleByteLocale

        public static boolean isDoubleByteLocale(java.util.Locale locale)
        Checks to see whether the locale is a double-byte character.
        Parameters:
        locale - the locale to be checked
        Returns:
        true if the locale is DBCS. false otherwise.
      • isIE

        public static boolean isIE(javax.servlet.http.HttpServletRequest request)
        Checks to see whether the browser is Internet Explorer.
        Parameters:
        request - the HTTP request
        Returns:
        true if the browser is Internet Explorer; false otherwise.
      • isLowerCase

        public static final boolean isLowerCase(java.lang.String target)
        Tests to see if a string is lower case.
        Parameters:
        target - the string to be checked
        Returns:
        true if the string is lower case; false otherwise.
      • isLowerCase

        public static final boolean isLowerCase(java.lang.String str,
                                                int start,
                                                int length)
        Tests to see if a substring is lower case.
        Parameters:
        str - the string to be checked
        start - the start position of the substring
        length - the length of the substring to be checked
        Returns:
        true if the string is lower case;
        false otherwise or if the string is null.
      • isNetscape

        public static boolean isNetscape(javax.servlet.http.HttpServletRequest request)
        Checks to see whether the browser is Netscape.
        Parameters:
        request - the HTTP request
        Returns:
        true if the browser is Netscape; false otherwise.
      • isUnixOS

        public static boolean isUnixOS()
        Checks whether the operating system is UNIX.
        Returns:
        true if it is UNIX; false otherwise.
      • isLinuxOS

        public static boolean isLinuxOS()
        Checks whether the operating system is Linux.
        Returns:
        true if it is Linux; false otherwise.
      • isUpperCase

        public static final boolean isUpperCase(java.lang.String str)
        Tests to see if a string is upper case.
        Parameters:
        str - the string to be checked
        Returns:
        true if the string is upper case; false otherwise.
      • isUpperCase

        public static final boolean isUpperCase(java.lang.String str,
                                                int start,
                                                int length)
        Tests to see if a substring is upper case.
        Parameters:
        str - the string to be checked
        start - the start position of the substring
        length - the length of the substring to be checked
        Returns:
        true if the string is upper case; false otherwise or if the string is null.
      • isWindowsOS

        public static boolean isWindowsOS()
        Checks whether the operating system is Windows.
        Returns:
        true if it is Windows; false otherwise.
      • merge

        public static final java.util.Vector merge(java.lang.Object value1,
                                                   java.lang.Object value2)
        Merges the given objects into a single vector.
        Parameters:
        value1 - the first object to be merged
        value2 - the second object to be merged
        Returns:
        The merged vector.
      • occurencesOf

        public static final int occurencesOf(java.lang.String target)
        Returns the number of occurrences of " \t\n".
        Parameters:
        target - the source string
        Returns:
        The number of occurrences.
      • occurencesOf

        public static final int occurencesOf(java.lang.String target,
                                             java.lang.String characters)
        Returns the number of occurrences of a substring.
        Parameters:
        target - the source string
        characters - the substring to be searched
        Returns:
        The number of occurrences.
      • replace

        public static final java.lang.String replace(java.lang.String source,
                                                     char pattern,
                                                     char replacement)
        Replaces the occurrences of a given pattern character with a given replacement character in the source string.
        Parameters:
        source - the source string
        pattern - the pattern character to be replaced
        replacement - the replacement character
        Returns:
        The string after replacement.
      • replace

        public static final java.lang.String replace(java.lang.String source,
                                                     java.lang.String pattern,
                                                     java.lang.String replacement)
        Replaces the occurrences of a given pattern string with a given replacement string in the source string.
        Parameters:
        source - the source string
        pattern - the pattern string to be replaced
        replacement - the replacement string
        Returns:
        The string after replacement.
      • reverse

        public static final java.lang.String reverse(java.lang.String source)
        Returns the reversal of the source string.
        Parameters:
        source - the source string
        Returns:
        The reversed string.
      • stringToHex

        public static final java.lang.String stringToHex(java.lang.String text)
        Converts the given string to a hexadecimal representation.
        Parameters:
        text - the source string
        Returns:
        The converted string.
      • strip

        public static final java.lang.String strip(java.lang.String target)
        Strips the leading and trailing characters.
        Parameters:
        target - the source string
        Returns:
        The string after stripping of the characters; returns an empty string if the source string is null.
      • stripLeading

        public static final java.lang.String stripLeading(java.lang.String target)
        Strips leading characters " \t\n".
        Parameters:
        target - the source string
        Returns:
        The string after stripping of the characters.
      • stripLeading

        public static final java.lang.String stripLeading(java.lang.String target,
                                                          java.lang.String characters)
        Strips the given leading characters.
        Parameters:
        target - the source string
        characters - the character set to be stripped
        Returns:
        The string after stripping of the characters.
      • stripTrailing

        public static final java.lang.String stripTrailing(java.lang.String target)
        Strips trailing characters " \t\n".
        Parameters:
        target - the source string
        Returns:
        The string after stripping of the characters.
      • stripTrailing

        public static final java.lang.String stripTrailing(java.lang.String target,
                                                           java.lang.String characters)
        Strips the given trailing characters.
        Parameters:
        target - the source string
        characters - the character set to be stripped
        Returns:
        The string after stripping of the characters.
      • tokenize

        public static java.lang.String[] tokenize(java.lang.String source,
                                                  java.lang.String delimiter)
        Tokenizes a string.
        Parameters:
        source - the source string
        delimiter - the delimiter used
        Returns:
        The "tokenized" string array.
      • setLastXMLPath

        public static void setLastXMLPath(java.lang.String xmlPath)
        Deprecated. 
        This method was introduced to workaround a limitation in the findFile method. That limitation has been removed, and there is no longer a need to call this method.
        Parameters:
        xmlPath - - The path with which lastXMLPath should be updated.
      • chmod

        public static void chmod(java.lang.String strFile,
                                 java.lang.String strPerm,
                                 boolean recursive)
                          throws java.io.IOException,
                                 java.lang.InterruptedException
        Change file permission on UNIX system.
        Parameters:
        strFile - the file name.
        strPerm - the permission string.
        recursive - if true, chmod recursively.
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • chmoddeep400

        public static void chmoddeep400(java.lang.String path,
                                        java.lang.String perm,
                                        java.lang.String start,
                                        java.lang.String server,
                                        java.lang.String user,
                                        java.lang.String pwd)
                                 throws ECSystemException,
                                        com.ibm.as400.access.AS400SecurityException,
                                        com.ibm.as400.access.ErrorCompletingRequestException,
                                        java.io.IOException,
                                        java.lang.InterruptedException,
                                        java.beans.PropertyVetoException
        Change file permission on remote i5/OS server. (this command currently only chmod to 755).
        Parameters:
        path - the full path of a file.
        perm - the file permission string, the param is currently ignored, default set to 755.
        start - from where in the path to change file permission.
        server - the i5/OS server name
        user - the user profile to log on the server
        pwd - the password for the user on the server
        Throws:
        ECSystemException
        com.ibm.as400.access.AS400SecurityException
        com.ibm.as400.access.ErrorCompletingRequestException
        java.io.IOException
        java.lang.InterruptedException
        java.beans.PropertyVetoException