Author: germuska Date: Thu Jan 11 15:35:47 2007 New Revision: 495431 URL: http://svn.apache.org/viewvc?view=rev&rev=495431 Log: Fixes for TILES-1 (Rename PutTag to PutAttributeTag and AttributeTag to InsertAttributeTag) and TILES-2 (Correct implementation of PutListTag).
Added: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertAttributeTag.java - copied, changed from r495428, struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/AttributeTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutAttributeTag.java - copied, changed from r495428, struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java Removed: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/AttributeTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutListTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTagParent.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DefinitionTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tld/tiles-core.tld Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/ContainerTagSupport.java Thu Jan 11 15:35:47 2007 @@ -26,17 +26,12 @@ import org.apache.tiles.ComponentContext; import org.apache.tiles.TilesContainer; import org.apache.tiles.TilesException; -import org.apache.tiles.ComponentAttribute; import org.apache.tiles.access.TilesAccess; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.BodyTagSupport; -import javax.servlet.jsp.tagext.TryCatchFinally; import java.io.IOException; -import java.util.Map; -import java.util.HashMap; -import java.util.Iterator; /** * Base tag for the tiles tags which interact with the container. @@ -66,6 +61,17 @@ this.role = role; } + /** + * By default, all ContainerTags evaluate their body. Subclasses may choose to be more selective. + * In any case, children can rely upon the container and componentContext being initialized if they + * call <code>super.doStartTag()</code> + */ + public int doStartTag() { + container = TilesAccess.getContainer(pageContext.getServletContext()); + componentContext = container.getComponentContext(pageContext); + return EVAL_BODY_BUFFERED; + } + public int doEndTag() throws JspException { if (isAccessAllowed()) { Copied: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertAttributeTag.java (from r495428, struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/AttributeTag.java) URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertAttributeTag.java?view=diff&rev=495431&p1=struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/AttributeTag.java&r1=495428&p2=struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertAttributeTag.java&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/AttributeTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertAttributeTag.java Thu Jan 11 15:35:47 2007 @@ -25,11 +25,9 @@ import org.apache.tiles.ComponentAttribute; import org.apache.tiles.ComponentContext; import org.apache.tiles.TilesException; -import org.apache.tiles.context.jsp.JspUtil; import javax.servlet.jsp.JspException; import java.io.IOException; -import java.util.Map; /** * This is the tag handler for <tiles:attribute>, which defines an @@ -38,15 +36,13 @@ * * @version $Rev$ $Date$ */ -public class AttributeTag extends RenderTagSupport { +public class InsertAttributeTag extends RenderTagSupport { /** * Name to insert. */ protected String name; - protected String template; - public void setName(String value) { this.name = value; } @@ -55,19 +51,9 @@ return name; } - public String getTemplate() { - return template; - } - - public void setTemplate(String template) { - this.template = template; - } - - public void release() { super.release(); this.name = null; - this.template = null; } protected void render() throws JspException, TilesException, IOException { Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertDefinitionTag.java Thu Jan 11 15:35:47 2007 @@ -33,7 +33,7 @@ * * @version $Rev$ $Date$ */ -public class InsertDefinitionTag extends RenderTagSupport { +public class InsertDefinitionTag extends RenderTagSupport implements PutTagParent { private String name; Copied: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutAttributeTag.java (from r495428, struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java) URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutAttributeTag.java?view=diff&rev=495431&p1=struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java&r1=495428&p2=struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutAttributeTag.java&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutAttributeTag.java Thu Jan 11 15:35:47 2007 @@ -32,40 +32,48 @@ import javax.servlet.jsp.tagext.TagSupport; /** - * Put an attribute in enclosing attribute container tag. - * Enclosing attribute container tag can be : <insert> or <definition>. - * Exception is thrown if no appropriate tag can be found. - * Put tag can have following atributes : - * <li> - * <ul>name : Name of the attribute</ul> - * <ul>value : value to put as attribute</ul> - * <ul>type : value type. Only valid if value is a String and is set by + * <p><strong>Put an attribute in enclosing attribute container tag.</strong></p> + * <p>Enclosing attribute container tag can be : + * <ul> + * <li><initContainer></li> + * <li><definition></li> + * <li><insertAttribute></li> + * <li><insertDefinition></li> + * <li><putList></li> + * </ul> + * (or any other tag which implements the <code>[EMAIL PROTECTED] PutTagParent}</code> interface. + * Exception is thrown if no appropriate tag can be found.</p> + * <p>Put tag can have following atributes : + * <ul> + * <li>name : Name of the attribute</li> + * <li>value : value to put as attribute</li> + * <li>type : value type. Only valid if value is a String and is set by * value="something" or by a bean. * Possible type are : string (value is used as direct string), * template (value is used as a page url to insert), - * definition (value is used as a definition name to insert)</ul> - * <ul>direct : Specify if value is to be used as a direct string or as a + * definition (value is used as a definition name to insert)</li> + * <li>direct : Specify if value is to be used as a direct string or as a * page url to insert. This is another way to specify the type. It only apply - * if value is set as a string, and type is not present.</ul> - * <ul>beanName : Name of a bean used for setting value. Only valid if value is not set. + * if value is set as a string, and type is not present.</li> + * <li>beanName : Name of a bean used for setting value. Only valid if value is not set. * If property is specified, value come from bean's property. Otherwise, bean - * itself is used for value.</ul> - * <ul>beanProperty : Name of the property used for retrieving value.</ul> - * <ul>beanScope : Scope containing bean. </ul> - * <ul>role : Role to check when 'insert' will be called. If enclosing tag is + * itself is used for value.</li> + * <li>beanProperty : Name of the property used for retrieving value.</li> + * <li>beanScope : Scope containing bean. </li> + * <li>role : Role to check when 'insert' will be called. If enclosing tag is * <insert>, role is checked immediately. If enclosing tag is * <definition>, role will be checked when this definition will be - * inserted.</ul> - * </li> - * Value can also come from tag body. Tag body is taken into account only if + * inserted.</li> + * </ul></p> + * <p>Value can also come from tag body. Tag body is taken into account only if * value is not set by one of the tag attributes. In this case Attribute type is - * "string", unless tag body define another type. + * "string", unless tag body define another type.</p> * * @version $Rev$ $Date$ */ -public class PutTag extends ContainerTagSupport implements ComponentConstants { +public class PutAttributeTag extends ContainerTagSupport implements ComponentConstants { - private static final Log LOG = LogFactory.getLog(PutTag.class); + private static final Log LOG = LogFactory.getLog(PutAttributeTag.class); /** * Name of attribute to put in component context. Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutListTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutListTag.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutListTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutListTag.java Thu Jan 11 15:35:47 2007 @@ -28,25 +28,27 @@ import java.util.ArrayList; import java.util.List; +import javax.servlet.jsp.JspException; + /** * PutList tag implementation. * * @since Tiles 1.0 * @version $Rev$ $Date$ */ -public class PutListTag extends PutTag +public class PutListTag extends PutAttributeTag implements PutTagParent { public PutListTag() { - super.setValue(new ArrayList()); + super.setValue(new ArrayList<ComponentAttribute>()); } /** * Get list defined in tag. */ - public List getValue() { - return (List) super.getValue(); + public List<ComponentAttribute> getValue() { + return (List<ComponentAttribute>) super.getValue(); } public void setValue(Object object) { @@ -54,6 +56,15 @@ } /** + * PutListTag may not have any body, except for PutAttribute tags. + * + * @throws JspException if a JSP exception has occurred + */ + public int doAfterBody() throws JspException { + return (SKIP_BODY); + } + + /** * Release the state of this put list by * clearing the contents of the list. */ @@ -73,14 +84,15 @@ * * @param nestedTag the put tag desciendent. */ - public void processNestedTag(PutTag nestedTag) { + public void processNestedTag(PutAttributeTag nestedTag) { ComponentAttribute attribute = new ComponentAttribute( nestedTag.getValue(), nestedTag.getRole(), nestedTag.getType()); - componentContext.putAttribute( - nestedTag.getName(), - attribute - ); + this.addValue(attribute); } + + private void addValue( ComponentAttribute attribute ) { + this.getValue().add(attribute); + } } Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTagParent.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTagParent.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTagParent.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTagParent.java Thu Jan 11 15:35:47 2007 @@ -23,7 +23,7 @@ package org.apache.tiles.taglib; -import org.apache.tiles.taglib.PutTag; +import org.apache.tiles.taglib.PutAttributeTag; import javax.servlet.jsp.JspException; @@ -39,6 +39,6 @@ * * @param nestedTag Nested tag to process. */ - void processNestedTag(PutTag nestedTag) throws JspException; + void processNestedTag(PutAttributeTag nestedTag) throws JspException; } Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/RenderTagSupport.java Thu Jan 11 15:35:47 2007 @@ -25,8 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.tiles.ComponentAttribute; import org.apache.tiles.TilesException; -import org.apache.tiles.access.TilesAccess; -import org.apache.tiles.taglib.PutTag; +import org.apache.tiles.taglib.PutAttributeTag; import org.apache.tiles.taglib.PutTagParent; import javax.servlet.jsp.JspException; @@ -95,8 +94,7 @@ } public int doStartTag() { - container = TilesAccess.getContainer(pageContext.getServletContext()); - componentContext = container.getComponentContext(pageContext); + super.doStartTag(); cacheState(); return isAccessAllowed() ? EVAL_BODY_BUFFERED : SKIP_BODY; } @@ -145,7 +143,7 @@ * * @param nestedTag the put tag desciendent. */ - public void processNestedTag(PutTag nestedTag) { + public void processNestedTag(PutAttributeTag nestedTag) { ComponentAttribute attribute = new ComponentAttribute( nestedTag.getValue(), nestedTag.getRole(), nestedTag.getType()); Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DefinitionTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DefinitionTag.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DefinitionTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/DefinitionTag.java Thu Jan 11 15:35:47 2007 @@ -22,7 +22,7 @@ package org.apache.tiles.taglib.definition; import org.apache.tiles.taglib.PutTagParent; -import org.apache.tiles.taglib.PutTag; +import org.apache.tiles.taglib.PutAttributeTag; import org.apache.tiles.ComponentAttribute; import org.apache.tiles.TilesContainer; import org.apache.tiles.TilesException; @@ -149,7 +149,7 @@ * which invokes TagSupport.release(), which typically does nothing. */ - public void processNestedTag(PutTag nestedTag) throws JspException { + public void processNestedTag(PutAttributeTag nestedTag) throws JspException { ComponentAttribute attr = new ComponentAttribute(nestedTag.getValue(), nestedTag.getRole(), nestedTag.getType()); attr.setName(nestedTag.getName()); Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/definition/InitContainerTag.java Thu Jan 11 15:35:47 2007 @@ -31,7 +31,7 @@ import org.apache.tiles.factory.TilesContainerFactory; import org.apache.tiles.mgmt.MutableTilesContainer; import org.apache.tiles.taglib.PutTagParent; -import org.apache.tiles.taglib.PutTag; +import org.apache.tiles.taglib.PutAttributeTag; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; @@ -71,7 +71,7 @@ } - public void processNestedTag(PutTag nestedTag) throws JspException { + public void processNestedTag(PutAttributeTag nestedTag) throws JspException { initParameters.put(nestedTag.getName(), nestedTag.getValue().toString()); } Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tld/tiles-core.tld URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tld/tiles-core.tld?view=diff&rev=495431&r1=495430&r2=495431 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tld/tiles-core.tld (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tld/tiles-core.tld Thu Jan 11 15:35:47 2007 @@ -214,53 +214,35 @@ </attribute> </tag> <tag> - <name>attribute</name> - <tag-class>org.apache.tiles.taglib.AttributeTag</tag-class> + <name>insertAttribute</name> + <tag-class>org.apache.tiles.taglib.InsertAttributeTag</tag-class> <body-content>JSP</body-content> <description> <![CDATA[ - <p><strong>Defines an attribute.</strong></p> - <p>An attribute can be seen as a parameter in a method signature. You can - define attributes in "template" pages. You can then insert template pages - by:</p> - <ul> - <li>using <tiles:insertTemplate> and specifying the template page - in the <code>template</code> attribute,</li> - <li>defining a definition in a Tiles configuration file, or via the - <tiles:definition> tag and then using - <tiles:insertDefinition>.</li> - </ul> - <p>You must specify <code>name</code> tag attribute, surrounding tiles's - attribute name whose value is used.</p> + <p><strong>Inserts the value of an attribute into the page.</strong></p> + <p>This tag can be flexibly used to insert the value of an attribute into a page. + As in other usages in Tiles, every attribute can be determined to have a "type", + either set explicitly when it was defined, or "computed". If the type is not explicit, then + if the attribute value is a valid definition, it will be inserted as such. Otherwise, + if it begins with a "/" character, it will be treated as a "template". Finally, if it + has not otherwise been assigned a type, it will be treated as a String and included without + any special handling.</p> <p><strong>Example : </strong></p> <pre> <code> - <tiles:attribute name="body"> + <tiles:insertAttribute name="body"> </code> </pre> ]]> </description> <attribute> - <name>template</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - <description> - <![CDATA[ - <p>A string representing the URI of a template. It is useful only if - the attribute value is a definition, to override the template specified - by definition itself. - </p> - ]]> - </description> - </attribute> - <attribute> <name>name</name> <required>true</required> <rtexprvalue>true</rtexprvalue> <description> <![CDATA[ - <p>Name of the attribute to define.</p> + <p>Name of the attribute to insert.</p> ]]> </description> </attribute> @@ -382,25 +364,48 @@ </attribute> </tag> <tag> - <name>put</name> - <tag-class>org.apache.tiles.taglib.PutTag</tag-class> + <name>putAttribute</name> + <tag-class>org.apache.tiles.taglib.PutAttributeTag</tag-class> <body-content>JSP</body-content> <description> <![CDATA[ - <p><strong>Put an attribute into template context. - </strong></p> - <p>Define an attribute to pass to template. - This tag can only be used inside 'insert' or 'definition' tag. - Value (or content) is specified using attribute 'value' (or 'content'), - or using the tag body. - It is also possible to specify the type of the value :</p> - <ul> - <li>string : Content is written directly.</li> - <li>page | template : Content is included from specified URL. Name is used as an URL.</li> - <li>definition : Content come from specified definition (from factory). Name is used as definition name.</li> - </ul> - <p>If 'type' attribute is not specified, content is 'untyped', unless it comes from a typed bean.</p> - <p>Note that using 'direct="true"' is equivalent to 'type="string"'.</p> + <p><strong>Put an attribute in enclosing attribute container tag.</strong></p> + <p> + Enclosing attribute container tag can be : + <ul> + <li><initContainer></li> + <li><definition></li> + <li><insertAttribute></li> + <li><insertDefinition></li> + <li><putList></li> + </ul> + (or any other tag which implements the <code>[EMAIL PROTECTED] PutTagParent}</code> interface. + Exception is thrown if no appropriate tag can be found.</p> + <p>Put tag can have following atributes : + <ul> + <li>name : Name of the attribute</li> + <li>value : value to put as attribute</li> + <li>type : value type. Only valid if value is a String and is set by + value="something" or by a bean. + Possible type are : string (value is used as direct string), + template (value is used as a page url to insert), + definition (value is used as a definition name to insert)</li> + <li>direct : Specify if value is to be used as a direct string or as a + page url to insert. This is another way to specify the type. It only apply + if value is set as a string, and type is not present.</li> + <li>beanName : Name of a bean used for setting value. Only valid if value is not set. + If property is specified, value come from bean's property. Otherwise, bean + itself is used for value.</li> + <li>beanProperty : Name of the property used for retrieving value.</li> + <li>beanScope : Scope containing bean. </li> + <li>role : Role to check when 'insert' will be called. If enclosing tag is + <insert>, role is checked immediately. If enclosing tag is + <definition>, role will be checked when this definition will be + inserted.</li> + </ul></p> + <p>Value can also come from tag body. Tag body is taken into account only if + value is not set by one of the tag attributes. In this case Attribute type is + "string", unless tag body define another type.</p> ]]> </description> <attribute>