1/*2 * $Id: PutAttributeTag.java 739526 2009-01-31 08:50:58Z 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 javax.servlet.jsp.tagext.TagSupport;
2526/***27 * <p><strong>Put an attribute in enclosing attribute container tag.</strong></p>28 * <p>Enclosing attribute container tag can be :29 * <ul>30 * <li><initContainer></li>31 * <li><definition></li>32 * <li><insertAttribute></li>33 * <li><insertDefinition></li>34 * <li><putList></li>35 * </ul>36 * (or any other tag which implements the <code>{@link PutAttributeTagParent}</code> interface.37 * Exception is thrown if no appropriate tag can be found.</p>38 * <p>Put tag can have following atributes :39 * <ul>40 * <li>name : Name of the attribute</li>41 * <li>value : value to put as attribute</li>42 * <li>type : value type. Only valid if value is a String and is set by43 * value="something" or by a bean.44 * Possible type are : string (value is used as direct string),45 * template (value is used as a page url to insert),46 * definition (value is used as a definition name to insert)</li>47 * <li>direct : Specify if value is to be used as a direct string or as a48 * page url to insert. This is another way to specify the type. It only apply49 * if value is set as a string, and type is not present.</li>50 * <li>beanName : Name of a bean used for setting value. Only valid if value is not set.51 * If property is specified, value come from bean's property. Otherwise, bean52 * itself is used for value.</li>53 * <li>beanProperty : Name of the property used for retrieving value.</li>54 * <li>beanScope : Scope containing bean. </li>55 * <li>role : Role to check when 'insert' will be called. If enclosing tag is56 * <insert>, role is checked immediately. If enclosing tag is57 * <definition>, role will be checked when this definition will be58 * inserted.</li>59 * </ul></p>60 * <p>Value can also come from tag body. Tag body is taken into account only if61 * value is not set by one of the tag attributes. In this case Attribute type is62 * "string", unless tag body define another type.</p>63 *64 * @version $Rev: 739526 $ $Date: 2009-01-31 09:50:58 +0100 (sab, 31 gen 2009) $65 */66publicclassPutAttributeTagextendsAddAttributeTag {
6768/***69 * Name of attribute to put in attribute context.70 */71protected String name = null;
7273/***74 * If <code>true</code>, the attribute will be cascaded to all nested75 * definitions.76 */77privateboolean cascade = false;
7879/***80 * Returns the name of the attribute.81 *82 * @return The name of the attribute.83 */84public String getName() {
85return name;
86 }
8788/***89 * Sets the name of the attribute.90 *91 * @param name The name of the attribute.92 */93publicvoid setName(String name) {
94this.name = name;
95 }
9697/***98 * Checks if the attribute should be cascaded to nested definitions.99 *100 * @return <code>true</code> if the attribute will be cascaded.101 * @since 2.1.0102 */103publicboolean isCascade() {
104return cascade;
105 }
106107/***108 * Sets the property that tells if the attribute should be cascaded to109 * nested definitions.110 *111 * @param cascade <code>true</code> if the attribute will be cascaded.112 * @since 2.1.0113 */114publicvoid setCascade(boolean cascade) {
115this.cascade = cascade;
116 }
117118/*** {@inheritDoc} */119 @Override
120protectedvoid reset() {
121super.reset();
122 name = null;
123 cascade = false;
124 }
125126/*** {@inheritDoc} */127 @Override
128protectedvoid execute() throws TilesJspException {
129PutAttributeTagParent parent = (PutAttributeTagParent)
130 TagSupport.findAncestorWithClass(this, PutAttributeTagParent.class);
131132133if (parent == null) {
134thrownewTilesJspException(
135"Error: no enclosing tag accepts 'putAttribute' tag.");
136 }
137138 parent.processNestedTag(this);
139 }
140 }