|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.text.Format
|
+--org.openide.util.MapFormat
A text format similar to MessageFormat
but using string rather than numeric keys.
You might use use this formatter like this:
MapFormat.format("Hello {name}", map);
Or to have more control over it:
Map m = new HashMap ();
m.put ("KEY", "value");
MapFormat f = new MapFormat (m);
f.setLeftBrace ("__");
f.setRightBrace ("__");
String result = f.format ("the __KEY__ here");
MessageFormat, Serialized Form| Constructor Summary | |
MapFormat(Map arguments)
Constructor. |
|
| Method Summary | |
StringBuffer |
format(Object pat,
StringBuffer result,
FieldPosition fpos)
Formats the parsed string by inserting table's values. |
static String |
format(String pattern,
Map arguments)
Designated method. |
String |
getLeftBrace()
Returns string used as left brace |
Map |
getMap()
Returns argument map |
String |
getRightBrace()
Returns string used as right brace |
boolean |
isExactMatch()
Do you require both brackets in expression? If not, use setExactMatch(false) and formatter will ignore missing right bracket. |
String |
parse(String source)
Parses the string. |
Object |
parseObject(String text,
ParsePosition status)
Parses the string. |
protected Object |
processKey(String key)
Returns the value for given key. |
String |
processPattern(String newPattern)
Scans the pattern and prepares internal variables. |
void |
setExactMatch(boolean flag)
Do you require both brackets in expression? If not, use setExactMatch(false) and formatter will ignore missing right bracket. |
void |
setLeftBrace(String delimiter)
Sets string used as left brace |
void |
setMap(Map map)
Sets argument map This map should contain key-value pairs with key values used in formatted string expression. |
void |
setRightBrace(String delimiter)
Sets string used as right brace |
void |
setThrowExceptionIfKeyWasNotFound(boolean flag)
Should formatter throw exception if object for key was not found? If given map does not contain object for key specified, it could throw an exception. |
boolean |
willThrowExceptionIfKeyWasNotFound()
Should formatter throw exception if object for key was not found? If given map does not contain object for key specified, it could throw an exception. |
| Methods inherited from class java.text.Format |
clone, format, parseObject |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public MapFormat(Map arguments)
format(pattern, arguments) .pattern - String to be parsed.| Method Detail |
public static String format(String pattern,
Map arguments)
pattern
for {} brackets, then parses enclosed string and replaces it
with argument's get() value.pattern - String to be parsed.arguments - Map with key-value pairs to replace.protected Object processKey(String key)
key - Key.
public String processPattern(String newPattern)
throws IllegalArgumentException
newPattern - String to be parsed.IllegalArgumentException - if number of arguments exceeds BUFSIZE or
parser found unmatched brackets (this exception should be switched off
using setExactMatch(false)).
public StringBuffer format(Object pat,
StringBuffer result,
FieldPosition fpos)
format in class Formattable - Map with key-value pairs to replace.result - Buffer to be used for result.
public Object parseObject(String text,
ParsePosition status)
parseObject in class Formatpublic String parse(String source)
public boolean willThrowExceptionIfKeyWasNotFound()
public void setThrowExceptionIfKeyWasNotFound(boolean flag)
flag - If true, formatter throws IllegalArgumentException.public boolean isExactMatch()
public void setExactMatch(boolean flag)
flag - If true, formatter will ignore missing right bracket (default = false)public String getLeftBrace()
public void setLeftBrace(String delimiter)
delimiter - Left brace.public String getRightBrace()
public void setRightBrace(String delimiter)
delimiter - Right brace.public Map getMap()
public void setMap(Map map)
delimiter - Right brace.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||