Class TapestryInternalUtils

    • Method Detail

      • toUserPresentable

        public static String toUserPresentable​(String id)
        Capitalizes the string, and inserts a space before each upper case character (or sequence of upper case characters). Thus "userId" becomes "User Id", etc. Also, converts underscore into space (and capitalizes the following word), thus "user_id" also becomes "User Id".
      • toOptionModel

        public static OptionModel toOptionModel​(String input)
        Converts a string to an OptionModel. The string is of the form "value=label". If the equals sign is omitted, then the same value is used for both value and label.
      • toOptionModels

        public static List<OptionModeltoOptionModels​(String input)
        Parses a string input into a series of value=label pairs compatible with toOptionModel(String). Splits on commas. Ignores whitespace around commas.
        Parameters:
        input - comma seperated list of terms
        Returns:
        list of option models
      • parseKeyValue

        public static KeyValue parseKeyValue​(String input)
        Parses a key/value pair where the key and the value are seperated by an equals sign. The key and value are trimmed of leading and trailing whitespace, and returned as a KeyValue.
      • extractIdFromPropertyExpression

        public static String extractIdFromPropertyExpression​(String expression)
        Used to convert a property expression into a key that can be used to locate various resources (Blocks, messages, etc.). Strips out any punctuation characters, leaving just words characters (letters, number and the underscore).
        Parameters:
        expression - a property expression
        Returns:
        the expression with punctuation removed
      • defaultLabel

        public static String defaultLabel​(String id,
                                          Messages messages,
                                          String propertyExpression)
        Looks for a label within the messages based on the id. If found, it is used, otherwise the name is converted to a user presentable form.
      • lastTerm

        public static String lastTerm​(String input)
        Strips a dotted sequence (such as a property expression, or a qualified class name) down to the last term of that expression, by locating the last period ('.') in the string.
      • toClassAttributeValue

        public static String toClassAttributeValue​(List<String> classes)
        Converts an list of strings into a space-separated string combining them all, suitable for use as an HTML class attribute value.
        Parameters:
        classes - classes to combine
        Returns:
        the joined classes, or null if classes is empty
      • getLabelForEnum

        public static String getLabelForEnum​(Messages messages,
                                             String prefix,
                                             Enum value)
        Converts an enum to a label string, allowing for overrides from a message catalog.
        • As key prefix.name if present. Ex: "ElementType.LOCAL_VARIABLE"
        • As key name if present, i.e., "LOCAL_VARIABLE".
        • As a user-presentable version of the name, i.e., "Local Variable".
        Parameters:
        messages - the messages to search for the label
        prefix - prepended to key
        value - to get a label for
        Returns:
        the label
      • isEqual

        public static <T> boolean isEqual​(T left,
                                          T right)
        Determines if the two values are equal. They are equal if they are the exact same value (including if they are both null). Otherwise standard equals() comparison is used.
        Parameters:
        left - value to compare, possibly null
        right - value to compare, possibly null
        Returns:
        true if same value, both null, or equal
      • splitAtCommas

        public static String[] splitAtCommas​(String value)
        Splits a value around commas. Whitespace around the commas is removed, as is leading and trailing whitespace.
        Since:
        5.1.0.0
      • copy

        public static void copy​(InputStream in,
                                OutputStream out)
                         throws IOException
        Copies some content from an input stream to an output stream. It is the caller's responsibility to close the streams.
        Parameters:
        in - source of data
        out - sink of data
        Throws:
        IOException
        Since:
        5.1.0.0
      • mixinTypeAndOrder

        public static Orderable<StringmixinTypeAndOrder​(String mixinDef)
        Parameters:
        mixinDef - the original mixin definition.
        Returns:
        an Orderable whose id is the mixin name.
      • getAndDeref

        public static <K,​V> V getAndDeref​(Map<K,​? extends Reference<V>> map,
                                                K key)
        Extracts a value from a map of references. Handles the case where the reference does not exist, and the case where the reference itself now contains null.
        Since:
        5.3
      • getAllThreads

        public static Thread[] getAllThreads()
        Gathers together an array containing all the threads.
        Since:
        5.4