Class StringUtil


  • public final class StringUtil
    extends java.lang.Object
    Author:
    Sebastian Menski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DB_MAX_STRING_LENGTH
      Note: String.length() counts Unicode supplementary characters twice, so for a String consisting only of those, the limit is effectively MAX_LONG_STRING_LENGTH / 2
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String fromBytes​(byte[] bytes)
      Converts a byte array into a string using the current process engines default charset as returned by ProcessEngineConfigurationImpl.getDefaultCharset().
      static java.lang.String fromBytes​(byte[] bytes, ProcessEngine processEngine)
      Converts a byte array into a string using the current process engines default charset as returned by ProcessEngineConfigurationImpl.getDefaultCharset().
      static boolean hasAnySuffix​(java.lang.String text, java.lang.String[] suffixes)  
      static boolean hasText​(java.lang.String string)  
      static boolean isCompositeExpression​(java.lang.String text, ExpressionManager expressionManager)
      Checks whether a String seams to be a composite expression or not.
      static boolean isExpression​(java.lang.String text)
      Checks whether a String seams to be an expression or not Note: In most cases you should check for composite expressions.
      static java.lang.String join​(java.util.Iterator<java.lang.String> iterator)  
      static java.lang.String joinDbEntityIds​(java.util.Collection<? extends DbEntity> dbEntities)  
      static java.lang.String joinProcessElementInstanceIds​(java.util.Collection<? extends ProcessElementInstance> processElementInstances)  
      static java.io.Reader readerFromBytes​(byte[] bytes)  
      static java.lang.String[] split​(java.lang.String text, java.lang.String regex)  
      static byte[] toByteArray​(java.lang.String string)
      Gets the bytes from a string using the current process engine's default charset
      static byte[] toByteArray​(java.lang.String string, ProcessEngine processEngine)
      Gets the bytes from a string using the provided process engine's default charset
      static java.lang.String trimToMaximumLengthAllowed​(java.lang.String string)
      Trims the input to the maxium length allowed for persistence with our default database schema
      static java.io.Writer writerForStream​(java.io.OutputStream outStream)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DB_MAX_STRING_LENGTH

        public static int DB_MAX_STRING_LENGTH
        Note: String.length() counts Unicode supplementary characters twice, so for a String consisting only of those, the limit is effectively MAX_LONG_STRING_LENGTH / 2
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • isExpression

        public static boolean isExpression​(java.lang.String text)
        Checks whether a String seams to be an expression or not Note: In most cases you should check for composite expressions. See isCompositeExpression(String, ExpressionManager) for more information.
        Parameters:
        text - the text to check
        Returns:
        true if the text seams to be an expression false otherwise
      • isCompositeExpression

        public static boolean isCompositeExpression​(java.lang.String text,
                                                    ExpressionManager expressionManager)
        Checks whether a String seams to be a composite expression or not. In contrast to an eval expression is the composite expression also allowed to consist of a combination of literal and eval expressions, e.g., "Welcome ${customer.name} to our site". Note: If you just want to allow eval expression, then the expression must always start with "#{" or "${". Use isExpression(String) to conduct these kind of checks.
      • split

        public static java.lang.String[] split​(java.lang.String text,
                                               java.lang.String regex)
      • hasAnySuffix

        public static boolean hasAnySuffix​(java.lang.String text,
                                           java.lang.String[] suffixes)
      • fromBytes

        public static java.lang.String fromBytes​(byte[] bytes)
        Converts a byte array into a string using the current process engines default charset as returned by ProcessEngineConfigurationImpl.getDefaultCharset(). The converted string is empty if the provided byte array is empty or null.
        Parameters:
        bytes - the byte array
        Returns:
        a string representing the bytes, empty String if byte array is null
      • fromBytes

        public static java.lang.String fromBytes​(byte[] bytes,
                                                 ProcessEngine processEngine)
        Converts a byte array into a string using the current process engines default charset as returned by ProcessEngineConfigurationImpl.getDefaultCharset(). The converted string is empty if the provided byte array is empty or null.
        Parameters:
        bytes - the byte array
        processEngine - the process engine
        Returns:
        a string representing the bytes, empty String if byte array is null
      • readerFromBytes

        public static java.io.Reader readerFromBytes​(byte[] bytes)
      • writerForStream

        public static java.io.Writer writerForStream​(java.io.OutputStream outStream)
      • toByteArray

        public static byte[] toByteArray​(java.lang.String string)
        Gets the bytes from a string using the current process engine's default charset
        Parameters:
        string - the string to get the bytes form
        Returns:
        the byte array
      • toByteArray

        public static byte[] toByteArray​(java.lang.String string,
                                         ProcessEngine processEngine)
        Gets the bytes from a string using the provided process engine's default charset
        Parameters:
        string - the string to get the bytes form
        processEngine - the process engine to use
        Returns:
        the byte array
      • trimToMaximumLengthAllowed

        public static java.lang.String trimToMaximumLengthAllowed​(java.lang.String string)
        Trims the input to the maxium length allowed for persistence with our default database schema
        Parameters:
        string - the input that might be trimmed if maximum length is exceeded
        Returns:
        the input, eventually trimmed to DB_MAX_STRING_LENGTH
      • joinDbEntityIds

        public static java.lang.String joinDbEntityIds​(java.util.Collection<? extends DbEntity> dbEntities)
      • joinProcessElementInstanceIds

        public static java.lang.String joinProcessElementInstanceIds​(java.util.Collection<? extends ProcessElementInstance> processElementInstances)
      • hasText

        public static boolean hasText​(java.lang.String string)
        Parameters:
        string - the String to check.
        Returns:
        a boolean TRUE if the String is not null and not empty. FALSE otherwise.
      • join

        public static java.lang.String join​(java.util.Iterator<java.lang.String> iterator)