|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ehsbe.commons.action.ActionFactory
public class ActionFactory
Parses in [composite] actions and action lists from an XML stream source.
The correctness of the xml stream is not completely enforced (i.e. not validated via the action DTD), since the developers usually know, what they do - so we rather prefer to get a little bit better performance.
If you are unsure about the correctness of your xml source, you may validate it before you putting it into the production.
The following tags/attributes are subject of translation, if an appropriate resource bundle has been submitted and the appropriate tag/attribute has not been set:
Translator
Constructor Summary | |
---|---|
ActionFactory()
|
Method Summary | |
---|---|
static HashMap<String,Object> |
getAttributes(XMLStreamReader reader)
Get all attributes pairs from the given reader. |
static Action |
getDefaultAction(Locale locale,
String cmd)
Get the default action for the given Locale. |
static HashMap<String,Action> |
getDefaultActions(Locale locale)
Get a set of default actions. |
static void |
load(StreamSource src,
Translator i18n,
String resPath,
HashMap<String,Action> actionMap,
HashMap<String,List<Object>> actionLists)
Read a action set from the given stream source. |
static String |
parseAction(XMLStreamReader reader,
Translator i18n,
String resPath,
HashMap<String,Action> actionMap)
Parse an <action ... |
static String |
parseComposite(XMLStreamReader reader,
Translator i18n,
String resPath,
HashMap<String,Action> actionMap)
Parse a <composite ... |
static String |
parseList(XMLStreamReader reader,
Translator i18n,
String resPath,
HashMap<String,Action> actionMap,
HashMap<String,List<Object>> listMap)
Parse a <list ... |
static String |
translate(String id,
String attr,
String val,
Translator i18n,
boolean selected)
Try to i18n the given value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ActionFactory()
Method Detail |
---|
public static void load(StreamSource src, Translator i18n, String resPath, HashMap<String,Action> actionMap, HashMap<String,List<Object>> actionLists)
src
- stream to read and parsei18n
- bundle to use for i18nresPath
- base path for resolving relative pathes to iconsactionMap
- where to put the new actionsactionLists
- where to put the new action listspublic static String parseList(XMLStreamReader reader, Translator i18n, String resPath, HashMap<String,Action> actionMap, HashMap<String,List<Object>> listMap) throws XMLStreamException
reader
- where to read from. Reader's cursor MUST point to
the start of list
element.i18n
- translator to use for i18nresPath
- where to lookup imagesactionMap
- where to lookup referenced actions and to put new actionslistMap
- where to lookup referenced action lists and to put new action
lists. This maps value are always lists containing the
follwoing elements, only:
action names, null
or a list of the same type.
XMLStreamException
NullPointerException
- if the reader or the supplied action map or
list is null
public static String parseComposite(XMLStreamReader reader, Translator i18n, String resPath, HashMap<String,Action> actionMap) throws XMLStreamException
reader
- where to read from. Reader's cursor MUST point to
the start of composite
element.i18n
- translator to use for i18nresPath
- where to lookup imagesactionMap
- where to lookup referenced actions and to put new actions
XMLStreamException
NullPointerException
- if the reader or the supplied action ap or
list is null
public static String parseAction(XMLStreamReader reader, Translator i18n, String resPath, HashMap<String,Action> actionMap) throws XMLStreamException
reader
- where to read from. Reader's cursor MUST point to
the start of action
element.i18n
- translator to use for i18nresPath
- where to lookup imagesactionMap
- where to lookup referenced actions and to put new actions
XMLStreamException
NullPointerException
- if the reader or the supplied action map or
list is null
public static final String translate(String id, String attr, String val, Translator i18n, boolean selected)
If the given resource bundle is null
, val
will be returned. Otherwise:
If val is NOT null
: If the lookup
in the given bundle returns a valid string, the result of the lookup
is returned. Otherwise val will be returned.
If selected is true
, lookup
id.
attr.selected
. If
it returns a valid String, the result will be returned. Otherwise:
If the lookup for the key id.
attr
returns a valid String, the result of the lookup will be returned.
Otherwise val will be returned.
id
- the i18n key prefix to use.attr
- the i18n suffix to use.val
- the value to lookup (highest priority). Might be null
.i18n
- resource bundle to use for key lookup.
Might be null
(i.e. do no lookup).selected
- if true
, lookup the i18n key
id.
attr.selected
first (if i18n is not null
).
null
if val is null
,
otherwise the result of the i18n lookup or the given val
itself.public static HashMap<String,Object> getAttributes(XMLStreamReader reader)
reader
- where to read from. The reader's cursor MUST
point to the start of an element.
NullPointerException
- if the reader is null
public static final Action getDefaultAction(Locale locale, String cmd)
locale
- locale to use. If null
, default locale
is used.cmd
- command to use, for looking up the action in question
null
if not found, a copy of the default action otherwise.public static HashMap<String,Action> getDefaultActions(Locale locale)
locale
- Locale to use for i18n. If null
, the default
locale will be used.
|
ehsbe CommonsTM Version 1.1.0rc3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |