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

1   /*
2    * $Id: PutListAttributeTag.java 727715 2008-12-18 13:06: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  import org.apache.tiles.Attribute.AttributeType;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  import javax.servlet.jsp.JspException;
31  
32  /***
33   * PutList tag implementation.
34   *
35   * @since Tiles 1.0
36   * @version $Rev: 727715 $ $Date: 2008-12-18 14:06:06 +0100 (Thu, 18 Dec 2008) $
37   */
38  public class PutListAttributeTag extends PutAttributeTag
39      implements AddAttributeTagParent {
40  
41      /***
42       * Get list defined in tag.
43       *
44       * @return The value of this list attribute.
45       */
46      @SuppressWarnings("unchecked")
47      public List<Attribute> getAttributes() {
48          return (List<Attribute>) super.getValue();
49      }
50  
51      /*** {@inheritDoc} */
52      @Override
53      public void setValue(Object object) {
54          throw new IllegalStateException("The value of the PutListAttributeTag must be the originally defined list.");
55      }
56  
57      /*** {@inheritDoc} */
58      @Override
59      public int doStartTag() throws JspException {
60          super.setValue(new ArrayList<Attribute>());
61          return super.doStartTag();
62      }
63  
64      /***
65       * PutListAttributeTag may not have any body, except for PutAttribute tags.
66       *
67       * @return <code>SKIP_BODY</code>.
68       * @throws JspException if a JSP exception has occurred
69       */
70      public int doAfterBody() throws JspException {
71          return (SKIP_BODY);
72      }
73  
74      /*** {@inheritDoc} */
75      @Override
76      protected void reset() {
77          super.reset();
78      }
79  
80      /***
81       * Process nested &lg;putAttribute&gt; tag.
82       * <p/>
83       * Places the value of the nested tag within the
84       * {@link org.apache.tiles.AttributeContext}.It is the responsibility
85       * of the descendent to check security.  Tags extending
86       * the {@link org.apache.tiles.jsp.taglib.ContainerTagSupport} will automatically provide
87       * the appropriate security.
88       *
89       * @param nestedTag the put tag desciendent.
90       */
91      public void processNestedTag(AddAttributeTag nestedTag) {
92          Attribute attribute = new Attribute(
93              nestedTag.getValue(), nestedTag.getRole(),
94              AttributeType.getType(nestedTag.getType()));
95  
96          this.addValue(attribute);
97      }
98  
99      /***
100      * Adds an attribute value to the list.
101      *
102      * @param attribute The attribute to add.
103      */
104     private void addValue(Attribute attribute) {
105         this.getAttributes().add(attribute);
106     }
107 }