01: /*
02: * Created on May 16, 2006
03: */
04: package uk.org.ponder.rsf.components.decorators;
05:
06: import java.util.HashMap;
07: import java.util.Map;
08:
09: /**
10: * Allows free interception of *all* XML attributes in the rendered output. This
11: * decorator is virtually as dangerous as
12: * {@link uk.org.ponder.rsf.components.UIVerbatim} and the dire warnings of
13: * sufferings for users at the head of that class should be repeated.
14: *
15: * The attribute list will be applied <i>on top of</i> attributes inherited
16: * from the template, but will be <i>overwritten by</i> any component-specific
17: * attributes applied by the renderer for the component to which this decorator
18: * is attached.
19: *
20: * Please try to think of technology-neutral abstractions rather than using this
21: * class, wherever possible.
22: *
23: * @author Antranig Basman (antranig@caret.cam.ac.uk)
24: */
25:
26: public class UIFreeAttributeDecorator implements UIDecorator {
27: /** A map of String attribute names to String attribute values which will be
28: * used to override any attributes taken from the template.
29: */
30: public Map attributes;
31:
32: public UIFreeAttributeDecorator() {
33: }
34:
35: public UIFreeAttributeDecorator(Map attributes) {
36: this .attributes = attributes;
37: }
38:
39: /** Creates a decorator representing the single supplied key/value pair **/
40: public UIFreeAttributeDecorator(String key, String value) {
41: attributes = new HashMap();
42: attributes.put(key, value);
43: }
44:
45: /** Supplied with key and value arrays of equal lengths, which will form the
46: * decorator through selecting keys and values pairwise.
47: */
48: public UIFreeAttributeDecorator(String[] keys, String[] values) {
49: attributes = new HashMap();
50: for (int i = 0; i < keys.length; ++i) {
51: attributes.put(keys[i], values[i]);
52: }
53: }
54: }
|