This project has retired. For details please refer to its Attic page.
PutListAttributeTag xref
View Javadoc

1   /*
2    * $Id: PutListAttributeTag.java 734389 2009-01-14 13:38:06Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 &lg;putAttribute&gt; 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             // Try with the old method.
144             super.execute();
145         }
146 
147         parent.processNestedTag(this);
148     }
149 }