Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tapestry5.internal
Class TapestryInternalUtils

    java.lang.Object
      org.apache.tapestry5.internal.TapestryInternalUtils

    public class TapestryInternalUtils

extends java.lang.Object

Shared utility methods used by various implementation classes.

Field Summary
`static Mapper<Asset,StylesheetLink>` | `assetToStylesheetLink` Common mapper, used primarily with `Flow.map(org.apache.tapestry5.func.Mapper)`

Constructor Summary
`TapestryInternalUtils()`

Method Summary
`static void` | `copy(java.io.InputStream in, java.io.OutputStream out)` Copies some content from an input stream to an output stream.
`static java.lang.String` | `defaultLabel(java.lang.String id, Messages messages, java.lang.String propertyExpression)` Looks for a label within the messages based on the id.
`static java.lang.String` | `extractIdFromPropertyExpression(java.lang.String expression)` Used to convert a property expression into a key that can be used to locate various resources (Blocks, messages, etc.).
`static
`<K,V> V`
` | `getAndDeref(java.util.Map<K,? extends java.lang.ref.Reference<V>> map, K key)` Extracts a value from a map of references.
`static java.lang.String` | `getLabelForEnum(Messages messages, java.lang.Enum value)`
`static java.lang.String` | `getLabelForEnum(Messages messages, java.lang.String prefix, java.lang.Enum value)` Converts an enum to a label string, allowing for overrides from a message catalog.
`static boolean` | `isEqual(EventContext left, EventContext right)`
`static
`<T> boolean`
` | `isEqual(T left, T right)` Determines if the two values are equal.
`static java.lang.String` | `lastTerm(java.lang.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.
`static java.util.Map<java.lang.String,java.lang.String>` | `mapFromKeysAndValues(java.lang.String... keysAndValues)`
`static Orderable<java.lang.String>` | `mixinTypeAndOrder(java.lang.String mixinDef)`
`static KeyValue` | `parseKeyValue(java.lang.String input)` Parses a key/value pair where the key and the value are seperated by an equals sign.
`static void` | `performIO(OperationTracker tracker, java.lang.String description, IOOperation operation)` Performs an operation and re-throws the IOException that may occur.
`static java.lang.String[]` | `splitAtCommas(java.lang.String value)` Splits a value around commas.
`static java.lang.String[]` | `splitMixinConstraints(java.lang.String s)`
`static java.lang.String[]` | `splitPath(java.lang.String path)` Splits a path at each slash.
`static Asset2` | `toAsset2(Asset asset)` Converts an Asset to an Asset2 if necessary.
`static java.lang.String` | `toClassAttributeValue(java.util.List<java.lang.String> classes)` Converts an list of strings into a space-separated string combining them all, suitable for use as an HTML class attribute value.
`static java.lang.String` | `toFileSuffix(java.lang.String fileName)`
`static InternalPropertyConduit` | `toInternalPropertyConduit(PropertyConduit conduit)`
`static LinkCreationListener2` | `toLinkCreationListener2(LinkCreationListener delegate)`
`static OptionModel` | `toOptionModel(java.util.Map.Entry input)` Converts a map entry to an `OptionModel`.
`static OptionModel` | `toOptionModel(java.lang.Object input)` Converts an object to an `OptionModel`.
`static OptionModel` | `toOptionModel(java.lang.String input)` Converts a string to an `OptionModel`.
`static
`<E> java.util.List<OptionModel>`
` | `toOptionModels(java.util.List<E> input)` Processes a list input into a series of objects compatible with `toOptionModel(Object)`.
`static
`<K,V> java.util.List<OptionModel>`
` | `toOptionModels(java.util.Map<K,V> input)` Processes a map input into a series of map entries compatible with `toOptionModel(Map.Entry)`.
`static java.util.List<OptionModel>` | `toOptionModels(java.lang.String input)` Parses a string input into a series of value=label pairs compatible with `toOptionModel(String)`.
`static
`<E> SelectModel`
` | `toSelectModel(java.util.List<E> input)` Wraps the result of `toOptionModels(List)` as a `SelectModel` (with no option groups).
`static
`<K,V> SelectModel`
` | `toSelectModel(java.util.Map<K,V> input)` Wraps the result of `toOptionModels(Map)` as a `SelectModel` (with no option groups).
`static SelectModel` | `toSelectModel(java.lang.String input)` Wraps the result of `toOptionModels(String)` as a `SelectModel` (with no option groups).
`static java.lang.String` | `toUserPresentable(java.lang.String id)` Capitalizes the string, and inserts a space before each upper case character (or sequence of upper case characters).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### assetToStylesheetLink

    public static Mapper<Asset,StylesheetLink> assetToStylesheetLink

  Common mapper, used primarily with `Flow.map(org.apache.tapestry5.func.Mapper)`

  Since:
    5.2.0

Constructor Detail

### TapestryInternalUtils

    public TapestryInternalUtils()

Method Detail

### toUserPresentable

    public static java.lang.String toUserPresentable(java.lang.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".

### mapFromKeysAndValues

    public static java.util.Map<java.lang.String,java.lang.String> mapFromKeysAndValues(java.lang.String... keysAndValues)

### toOptionModel

    public static OptionModel toOptionModel(java.lang.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 java.util.List<OptionModel> toOptionModels(java.lang.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

### toSelectModel

    public static SelectModel toSelectModel(java.lang.String input)

  Wraps the result of `toOptionModels(String)` as a `SelectModel` (with no option groups).

### toOptionModel

    public static OptionModel toOptionModel(java.util.Map.Entry input)

  Converts a map entry to an `OptionModel`.

### toOptionModels

    public static <K,V> java.util.List<OptionModel> toOptionModels(java.util.Map<K,V> input)

  Processes a map input into a series of map entries compatible with `toOptionModel(Map.Entry)`.

  Parameters:
    `input` - map of elements
  Returns:
    list of option models

### toSelectModel

    public static <K,V> SelectModel toSelectModel(java.util.Map<K,V> input)

  Wraps the result of `toOptionModels(Map)` as a `SelectModel` (with no option groups).

### toOptionModel

    public static OptionModel toOptionModel(java.lang.Object input)

  Converts an object to an `OptionModel`.

### toOptionModels

    public static <E> java.util.List<OptionModel> toOptionModels(java.util.List<E> input)

  Processes a list input into a series of objects compatible with `toOptionModel(Object)`.

  Parameters:
    `input` - list of elements
  Returns:
    list of option models

### toSelectModel

    public static <E> SelectModel toSelectModel(java.util.List<E> input)

  Wraps the result of `toOptionModels(List)` as a `SelectModel` (with no option groups).

### parseKeyValue

    public static KeyValue parseKeyValue(java.lang.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 java.lang.String extractIdFromPropertyExpression(java.lang.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 java.lang.String defaultLabel(java.lang.String id,
                                                Messages messages,
                                                java.lang.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 java.lang.String lastTerm(java.lang.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 java.lang.String toClassAttributeValue(java.util.List<java.lang.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 java.lang.String getLabelForEnum(Messages messages,
                                                   java.lang.String prefix,
                                                   java.lang.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

### getLabelForEnum

    public static java.lang.String getLabelForEnum(Messages messages,
                                                   java.lang.Enum value)

### 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

### splitPath

    public static java.lang.String[] splitPath(java.lang.String path)

  Splits a path at each slash.

### splitAtCommas

    public static java.lang.String[] splitAtCommas(java.lang.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(java.io.InputStream in,
                            java.io.OutputStream out)
                     throws java.io.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:
    `java.io.IOException`
  Since:
    5.1.0.0

### isEqual

    public static boolean isEqual(EventContext left,
                                  EventContext right)

### toAsset2

    public static Asset2 toAsset2(Asset asset)

  Converts an Asset to an Asset2 if necessary. When actually wrapping an Asset as an Asset2, the asset is assumed to be variant (i.e., not cacheable).

  Since:
    5.1.0.0

### toInternalPropertyConduit

    public static InternalPropertyConduit toInternalPropertyConduit(PropertyConduit conduit)

### mixinTypeAndOrder

    public static Orderable<java.lang.String> mixinTypeAndOrder(java.lang.String mixinDef)

  Parameters:
    `mixinDef` - the original mixin definition.
  Returns:
    an Orderable whose id is the mixin name.

### splitMixinConstraints

    public static java.lang.String[] splitMixinConstraints(java.lang.String s)

### toLinkCreationListener2

    public static LinkCreationListener2 toLinkCreationListener2(LinkCreationListener delegate)

### toFileSuffix

    public static java.lang.String toFileSuffix(java.lang.String fileName)

  Since:
    5.3

### performIO

    public static void performIO(OperationTracker tracker,
                                 java.lang.String description,
                                 IOOperation operation)
                          throws java.io.IOException

  Performs an operation and re-throws the IOException that may occur.

  Throws:
    `java.io.IOException`

### getAndDeref

    public static <K,V> V getAndDeref(java.util.Map<K,? extends java.lang.ref.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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2012 The Apache Software Foundation.