Package org.apache.tapestry5.internal
Class TapestryInternalUtils
-
- org.apache.tapestry5.internal.TapestryInternalUtils
-
public class TapestryInternalUtils extends
Shared utility methods used by various implementation classes.
-
-
Field Summary
Fields Modifier and Type Field Description static Mapper<Asset,StylesheetLink>
assetToStylesheetLink
Common mapper, used primarily withFlow.map(org.apache.tapestry5.func.Mapper)
-
Constructor Summary
Constructors Constructor Description TapestryInternalUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
in, out)
Copies some content from an input stream to an output stream.static
id, Messages messages, propertyExpression)
Looks for a label within the messages based on the id.static
expression)
Used to convert a property expression into a key that can be used to locate various resources (Blocks, messages, etc.).static []
getAllThreads()
Gathers together an array containing all the threads.static <K,V>
V<K,? extends <V>> map, K key)
Extracts a value from a map of references.static
getLabelForEnum(Messages messages, value)
static
getLabelForEnum(Messages messages, prefix, 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
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 <,>
... keysAndValues)
static >
mixinDef)
static KeyValue
input)
Parses a key/value pair where the key and the value are seperated by an equals sign.static []
value)
Splits a value around commas.static []
s)
static []
path)
Splits a path at each slash.static
<> classes)
Converts an list of strings into a space-separated string combining them all, suitable for use as an HTML class attribute value.static
fileName)
static InternalPropertyConduit
toInternalPropertyConduit(PropertyConduit conduit)
static LinkCreationListener2
toLinkCreationListener2(LinkCreationListener delegate)
static OptionModel
input)
Converts an object to anOptionModel
.static OptionModel
input)
Converts a string to anOptionModel
.static OptionModel
input)
Converts a map entry to anOptionModel
.static <OptionModel>
input)
Parses a string input into a series of value=label pairs compatible withtoOptionModel(String)
.static <E> <OptionModel>
<E> input)
Processes a list input into a series of objects compatible withtoOptionModel(Object)
.static <K,V>
<OptionModel><K,V> input)
Processes a map input into a series of map entries compatible withtoOptionModel(Map.Entry)
.static SelectModel
input)
Wraps the result oftoOptionModels(String)
as aSelectModel
(with no option groups).static <E> SelectModel
<E> input)
Wraps the result oftoOptionModels(List)
as aSelectModel
(with no option groups).static <K,V>
SelectModel<K,V> input)
Wraps the result oftoOptionModels(Map)
as aSelectModel
(with no option groups).static
id)
Capitalizes the string, and inserts a space before each upper case character (or sequence of upper case characters).
-
-
-
Field Detail
-
assetToStylesheetLink
public static Mapper<Asset,StylesheetLink> assetToStylesheetLink
Common mapper, used primarily withFlow.map(org.apache.tapestry5.func.Mapper)
- Since:
- 5.2.0
-
-
Constructor Detail
-
TapestryInternalUtils
public TapestryInternalUtils()
-
-
Method Detail
-
toUserPresentable
public static 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 <,> ... keysAndValues)
-
toOptionModel
public static input)
Converts a string to anOptionModel
. 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 < input)
Parses a string input into a series of value=label pairs compatible withtoOptionModel(String)
. Splits on commas. Ignores whitespace around commas.- Parameters:
input
- comma seperated list of terms- Returns:
- list of option models
-
toSelectModel
public static input)
Wraps the result oftoOptionModels(String)
as aSelectModel
(with no option groups). See TAP5-2184 for why this ends up causing some trouble!
-
toOptionModel
public static input)
Converts a map entry to anOptionModel
.
-
toOptionModels
public static <K,V> <<K,V> input)
Processes a map input into a series of map entries compatible withtoOptionModel(Map.Entry)
.- Parameters:
input
- map of elements- Returns:
- list of option models
-
toSelectModel
public static <K,V> <K,V> input)
Wraps the result oftoOptionModels(Map)
as aSelectModel
(with no option groups).
-
toOptionModel
public static input)
Converts an object to anOptionModel
.
-
toOptionModels
public static <E> <<E> input)
Processes a list input into a series of objects compatible withtoOptionModel(Object)
.- Parameters:
input
- list of elements- Returns:
- list of option models
-
toSelectModel
public static <E> <E> input)
Wraps the result oftoOptionModels(List)
as aSelectModel
(with no option groups).
-
parseKeyValue
public static 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 aKeyValue
.
-
extractIdFromPropertyExpression
public static 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 id, Messages messages, 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 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 <> 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 getLabelForEnum(Messages messages, prefix, 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 labelprefix
- prepended to keyvalue
- to get a label for- Returns:
- the label
-
getLabelForEnum
public static getLabelForEnum(Messages messages, 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 nullright
- value to compare, possibly null- Returns:
- true if same value, both null, or equal
-
splitPath
public static [] path)
Splits a path at each slash.
-
splitAtCommas
public static [] 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 in, out) throws
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 dataout
- sink of data- Throws:
- Since:
- 5.1.0.0
-
isEqual
public static boolean isEqual(EventContext left, EventContext right)
-
toInternalPropertyConduit
public static InternalPropertyConduit toInternalPropertyConduit(PropertyConduit conduit)
-
mixinTypeAndOrder
public static > mixinDef)
- Parameters:
mixinDef
- the original mixin definition.- Returns:
- an Orderable whose id is the mixin name.
-
splitMixinConstraints
public static [] s)
-
toLinkCreationListener2
public static LinkCreationListener2 toLinkCreationListener2(LinkCreationListener delegate)
-
toFileSuffix
public static fileName)
- Since:
- 5.3
-
getAndDeref
public static <K,V> V <K,? extends <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 [] getAllThreads()
Gathers together an array containing all the threads.- Since:
- 5.4
-
-