public class DesignFormatter extends Object implements Serializable
Design
. An instance of this
class is used by DesignAttributeHandler
.Constructor and Description |
---|
DesignFormatter()
Creates the formatter with default types already mapped.
|
Modifier and Type | Method and Description |
---|---|
protected <T> void |
addConverter(Class<?> type,
Converter<String,?> converter)
Adds a converter for a given type.
|
boolean |
canConvert(Class<?> type)
Checks whether or not a value of a given type can be converted.
|
static String |
decodeFromTextNode(String input)
Decodes HTML entities in a text from text node and replaces them with
actual characters.
|
static String |
encodeForTextNode(String input)
Encodes some special characters in a given input String to make
it ready to be written as contents of a text node.
|
protected <T> Converter<String,T> |
findConverterFor(Class<? extends T> sourceType)
Finds a converter for a given type.
|
protected <T> Converter<String,T> |
findConverterFor(Class<? extends T> sourceType,
boolean strict)
Finds a converter for a given type.
|
String |
format(Object object)
Finds a formatter for a given object and attempts to format it.
|
<T> String |
format(T object,
Class<? extends T> type)
Formats an object according to a converter suitable for a given type.
|
protected Set<Class<?>> |
getRegisteredClasses()
Returns a set of classes that have a converter registered.
|
protected void |
mapDefaultTypes()
Maps default types to their converters.
|
<T> T |
parse(String value,
Class<? extends T> type)
Parses a given string as a value of given type.
|
protected void |
removeConverter(Class<?> type)
Removes the converter for given type, if it was present.
|
public DesignFormatter()
protected void mapDefaultTypes()
protected <T> void addConverter(Class<?> type, Converter<String,?> converter)
type
- Type to convert to/from.converter
- Converter.protected void removeConverter(Class<?> type)
type
- Type to remove converter for.protected Set<Class<?>> getRegisteredClasses()
public <T> T parse(String value, Class<? extends T> type)
value
- String value to convert.type
- Expected result type.public String format(Object object)
object
- Object to format.public <T> String format(T object, Class<? extends T> type)
object
- Object to format.type
- Type of the object.public boolean canConvert(Class<?> type)
type
- Type to check.protected <T> Converter<String,T> findConverterFor(Class<? extends T> sourceType, boolean strict)
strict
is false.sourceType
- Type to find a converter for.strict
- Whether or not search should be strict. When this is
false, a converter for a superclass of given type may
be returned.protected <T> Converter<String,T> findConverterFor(Class<? extends T> sourceType)
sourceType
- Type to find a converter for.public static String encodeForTextNode(String input)
Encodes some special characters in a given input String to make it ready to be written as contents of a text node. WARNING: this will e.g. encode "<someTag>" to "<someTag>" as this method doesn't do any parsing and assumes that there are no intended HTML elements in the input. Only some entities are actually encoded: &,<, > It's assumed that other entities are taken care of by Jsoup.
Typically, this method will be used by components to encode data (like
option items in AbstractSelect
) when dumping to HTML format
input
- String to be encodedpublic static String decodeFromTextNode(String input)
Decodes HTML entities in a text from text node and replaces them with actual characters.
Typically this method will be used by components to read back data (like
option items in AbstractSelect
) from HTML. Note that this method
unencodes more characters than encodeForTextNode(String)
encodes
input
- Copyright © 2018 Vaadin Ltd. All rights reserved.