1/*2 * $Id: PutListAttributeTag.java 734389 2009-01-14 13:38:06Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122package org.apache.tiles.jsp.taglib;
2324import org.apache.tiles.Attribute;
2526import java.util.ArrayList;
27import java.util.List;
2829import javax.servlet.jsp.tagext.TagSupport;
3031/***32 * PutList tag implementation.33 *34 * @since Tiles 1.035 * @version $Rev: 734389 $ $Date: 2009-01-14 14:38:06 +0100 (mer, 14 gen 2009) $36 */37publicclassPutListAttributeTagextendsPutAttributeTag38 implements AddAttributeTagParent {
3940/***41 * If true, the attribute will put the elements of the attribute with the42 * same name of the parent definition before the ones specified here. By43 * default, it is 'false'.44 */45privateboolean inherit = false;
4647/***48 * If true, the attribute will put the elements of the attribute with the49 * same name of the parent definition before the ones specified here. By50 * default, it is 'false'51 *52 * @param inherit The "inherit" value.53 * @since 2.1.054 */55publicvoid setInherit(boolean inherit) {
56this.inherit = inherit;
57 }
5859/***60 * If true, the attribute will put the elements of the attribute with the61 * same name of the parent definition before the ones specified here. By62 * default, it is 'false'63 *64 * @return The "inherit" value.65 * @since 2.1.066 */67publicboolean getInherit() {
68return inherit;
69 }
7071/***72 * Get list defined in tag.73 *74 * @return The value of this list attribute.75 */76 @SuppressWarnings("unchecked")
77public List<Attribute> getAttributes() {
78return (List<Attribute>) super.getValue();
79 }
8081/*** {@inheritDoc} */82 @Override
83publicvoid setValue(Object object) {
84thrownew IllegalStateException("The value of the PutListAttributeTag must be the originally defined list.");
85 }
8687/*** {@inheritDoc} */88 @Override
89publicint doStartTag() {
90super.setValue(new ArrayList<Attribute>());
91return EVAL_BODY_BUFFERED;
92 }
9394/***95 * PutListAttributeTag may not have any body, except for PutAttribute tags.96 *97 * @return <code>SKIP_BODY</code>.98 */99publicint doAfterBody() {
100return (SKIP_BODY);
101 }
102103/*** {@inheritDoc} */104 @Override
105protectedvoid reset() {
106super.reset();
107 inherit = false;
108 }
109110/***111 * Process nested ≶putAttribute> tag.112 * <p/>113 * Places the value of the nested tag within the114 * {@link org.apache.tiles.AttributeContext}.It is the responsibility115 * of the descendent to check security. Security will be managed by called116 * tags.117 *118 * @param nestedTag the put tag desciendent.119 */120publicvoid processNestedTag(AddAttributeTag nestedTag) {
121 Attribute attribute = new Attribute(nestedTag.getValue(), null, nestedTag
122 .getRole(), nestedTag.getType());
123124this.addValue(attribute);
125 }
126127/***128 * Adds an attribute value to the list.129 *130 * @param attribute The attribute to add.131 */132privatevoid addValue(Attribute attribute) {
133this.getAttributes().add(attribute);
134 }
135136/*** {@inheritDoc} */137 @Override
138protectedvoid execute() throws TilesJspException {
139PutListAttributeTagParent parent = (PutListAttributeTagParent) TagSupport
140 .findAncestorWithClass(this, PutListAttributeTagParent.class);
141142if (parent == null) {
143// Try with the old method.144super.execute();
145 }
146147 parent.processNestedTag(this);
148 }
149 }