1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.jsp.taglib;
23
24 import org.apache.tiles.Attribute;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import javax.servlet.jsp.tagext.TagSupport;
30
31 /***
32 * PutList tag implementation.
33 *
34 * @since Tiles 1.0
35 * @version $Rev: 734389 $ $Date: 2009-01-14 14:38:06 +0100 (mer, 14 gen 2009) $
36 */
37 public class PutListAttributeTag extends PutAttributeTag
38 implements AddAttributeTagParent {
39
40 /***
41 * If true, the attribute will put the elements of the attribute with the
42 * same name of the parent definition before the ones specified here. By
43 * default, it is 'false'.
44 */
45 private boolean inherit = false;
46
47 /***
48 * If true, the attribute will put the elements of the attribute with the
49 * same name of the parent definition before the ones specified here. By
50 * default, it is 'false'
51 *
52 * @param inherit The "inherit" value.
53 * @since 2.1.0
54 */
55 public void setInherit(boolean inherit) {
56 this.inherit = inherit;
57 }
58
59 /***
60 * If true, the attribute will put the elements of the attribute with the
61 * same name of the parent definition before the ones specified here. By
62 * default, it is 'false'
63 *
64 * @return The "inherit" value.
65 * @since 2.1.0
66 */
67 public boolean getInherit() {
68 return inherit;
69 }
70
71 /***
72 * Get list defined in tag.
73 *
74 * @return The value of this list attribute.
75 */
76 @SuppressWarnings("unchecked")
77 public List<Attribute> getAttributes() {
78 return (List<Attribute>) super.getValue();
79 }
80
81 /*** {@inheritDoc} */
82 @Override
83 public void setValue(Object object) {
84 throw new IllegalStateException("The value of the PutListAttributeTag must be the originally defined list.");
85 }
86
87 /*** {@inheritDoc} */
88 @Override
89 public int doStartTag() {
90 super.setValue(new ArrayList<Attribute>());
91 return EVAL_BODY_BUFFERED;
92 }
93
94 /***
95 * PutListAttributeTag may not have any body, except for PutAttribute tags.
96 *
97 * @return <code>SKIP_BODY</code>.
98 */
99 public int doAfterBody() {
100 return (SKIP_BODY);
101 }
102
103 /*** {@inheritDoc} */
104 @Override
105 protected void reset() {
106 super.reset();
107 inherit = false;
108 }
109
110 /***
111 * Process nested ≶putAttribute> tag.
112 * <p/>
113 * Places the value of the nested tag within the
114 * {@link org.apache.tiles.AttributeContext}.It is the responsibility
115 * of the descendent to check security. Security will be managed by called
116 * tags.
117 *
118 * @param nestedTag the put tag desciendent.
119 */
120 public void processNestedTag(AddAttributeTag nestedTag) {
121 Attribute attribute = new Attribute(nestedTag.getValue(), null, nestedTag
122 .getRole(), nestedTag.getType());
123
124 this.addValue(attribute);
125 }
126
127 /***
128 * Adds an attribute value to the list.
129 *
130 * @param attribute The attribute to add.
131 */
132 private void addValue(Attribute attribute) {
133 this.getAttributes().add(attribute);
134 }
135
136 /*** {@inheritDoc} */
137 @Override
138 protected void execute() throws TilesJspException {
139 PutListAttributeTagParent parent = (PutListAttributeTagParent) TagSupport
140 .findAncestorWithClass(this, PutListAttributeTagParent.class);
141
142 if (parent == null) {
143
144 super.execute();
145 }
146
147 parent.processNestedTag(this);
148 }
149 }