Author: apetrelli
Date: Sat Mar  1 05:58:36 2008
New Revision: 632592

URL: http://svn.apache.org/viewvc?rev=632592&view=rev
Log:
TILES-259
Added template, preparer and roles to AttributeContext and 
BasicAttributeContext. Modified BasicAttributeContextTest accordingly.
Modified JSP tag classes to use the container, especially InsertTemplateTag.

TILES-260
Refactored JSP tag classes to be simpler and to use the container better.

Modified:
    
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java
    
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java
    
tiles/framework/trunk/tiles-api/src/test/java/org/apache/tiles/BasicAttributeContextTest.java
    
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddListAttributeTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ContainerTagSupport.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertAttributeTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertDefinitionTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutAttributeTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutListAttributeTag.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RenderTagSupport.java
    
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java

Modified: 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java
 (original)
+++ 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/BasicAttributeContext.java
 Sat Mar  1 05:58:36 2008
@@ -102,6 +102,12 @@
         if (context instanceof BasicAttributeContext) {
             copyBasicAttributeContext((BasicAttributeContext) context);
         } else {
+            this.template = context.getTemplate();
+            Set<String> roles = context.getRoles();
+            if (roles != null && !roles.isEmpty()) {
+                this.roles = new HashSet<String>(roles);
+            }
+            this.preparer = context.getPreparer();
             this.attributes = new HashMap<String, Attribute>();
             for (String name : context.getLocalAttributeNames()) {
                 attributes.put(name, context.getLocalAttribute(name));
@@ -426,6 +432,12 @@
      * @param context The context to copy.
      */
     private void copyBasicAttributeContext(BasicAttributeContext context) {
+        template = context.template;
+        Set<String> roles = context.roles;
+        if (roles != null && !roles.isEmpty()) {
+            this.roles = new HashSet<String>(roles);
+        }
+        preparer = context.preparer;
         if (context.attributes != null && !context.attributes.isEmpty()) {
             attributes = new HashMap<String, Attribute>(context.attributes);
         }

Modified: 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java 
(original)
+++ 
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Definition.java 
Sat Mar  1 05:58:36 2008
@@ -59,9 +59,6 @@
     public Definition(Definition definition) {
         super(definition);
         this.name = definition.name;
-        this.template = definition.template;
-        this.roles = definition.roles;
-        this.preparer = definition.preparer;
         this.inherit = definition.inherit;
     }
 

Modified: 
tiles/framework/trunk/tiles-api/src/test/java/org/apache/tiles/BasicAttributeContextTest.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/test/java/org/apache/tiles/BasicAttributeContextTest.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-api/src/test/java/org/apache/tiles/BasicAttributeContextTest.java
 (original)
+++ 
tiles/framework/trunk/tiles-api/src/test/java/org/apache/tiles/BasicAttributeContextTest.java
 Sat Mar  1 05:58:36 2008
@@ -21,6 +21,7 @@
 package org.apache.tiles;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
@@ -91,8 +92,19 @@
                 new Attribute("value3")).anyTimes();
         EasyMock.expect(toCopy.getCascadedAttribute("cascaded2")).andReturn(
                 new Attribute("value4")).anyTimes();
+        EasyMock.expect(toCopy.getTemplate()).andReturn("/template.jsp");
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        EasyMock.expect(toCopy.getRoles()).andReturn(roles);
+        
EasyMock.expect(toCopy.getPreparer()).andReturn("my.preparer.Preparer");
         EasyMock.replay(toCopy);
         BasicAttributeContext context = new BasicAttributeContext(toCopy);
+        assertEquals("The template has not been set correctly",
+                "/template.jsp", context.getTemplate());
+        assertEquals("The roles are not the same", roles, context.getRoles());
+        assertEquals("The preparer has not been set correctly",
+                "my.preparer.Preparer", context.getPreparer());
         Attribute attribute = context.getLocalAttribute("local1");
         assertNotNull("Attribute local1 not found", attribute);
         assertEquals("Attribute local1 has not been set correctly", "value1",
@@ -119,7 +131,18 @@
         AttributeContext toCopy = new BasicAttributeContext();
         toCopy.putAttribute("name1", new Attribute("value1"), false);
         toCopy.putAttribute("name2", new Attribute("value2"), true);
+        toCopy.setTemplate("/template.jsp");
+        Set<String> roles = new HashSet<String>();
+        roles.add("role1");
+        roles.add("role2");
+        toCopy.setRoles(roles);
+        toCopy.setPreparer("my.preparer.Preparer");
         AttributeContext context = new BasicAttributeContext(toCopy);
+        assertEquals("The template has not been set correctly",
+                "/template.jsp", context.getTemplate());
+        assertEquals("The roles are not the same", roles, context.getRoles());
+        assertEquals("The preparer has not been set correctly",
+                "my.preparer.Preparer", context.getPreparer());
         Attribute attribute = context.getLocalAttribute("name1");
         assertNotNull("Attribute name1 not found", attribute);
         assertEquals("Attribute name1 has not been set correctly", "value1",

Modified: 
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
 (original)
+++ 
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
 Sat Mar  1 05:58:36 2008
@@ -600,7 +600,11 @@
             throw new NoSuchDefinitionException(definitionName);
         }
 
-        if (!isPermitted(request, definition.getRoles())) {
+        AttributeContext originalContext = getAttributeContext(request);
+        BasicAttributeContext subContext = new 
BasicAttributeContext(originalContext);
+        subContext.inherit(definition);
+
+        if (!isPermitted(request, subContext.getRoles())) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Access to definition '" + definitionName
                         + "' denied.  User not in role '"
@@ -609,13 +613,10 @@
             return;
         }
 
-        AttributeContext originalContext = getAttributeContext(request);
-        BasicAttributeContext subContext = new 
BasicAttributeContext(originalContext);
-        subContext.inherit(definition);
         pushContext(subContext, request);
 
         try {
-            render(request, definition);
+            render(request, subContext);
         } finally {
             popContext(request);
         }
@@ -625,29 +626,28 @@
      * Renders the specified attribute context.
      *
      * @param request The request context.
-     * @param definition The context to render.
+     * @param attributeContext The context to render.
      * @throws TilesException If something goes wrong during rendering.
      */
-    private void render(TilesRequestContext request, AttributeContext 
definition)
-        throws TilesException {
+    private void render(TilesRequestContext request,
+            AttributeContext attributeContext) throws TilesException {
 
         try {
-            if (definition.getPreparer() != null) {
-                prepare(request, definition.getPreparer(), true);
+            if (attributeContext.getPreparer() != null) {
+                prepare(request, attributeContext.getPreparer(), true);
             }
 
-            String dispatchPath = definition.getTemplate();
+            String dispatchPath = attributeContext.getTemplate();
 
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Dispatching to definition path '"
-                        + definition.getTemplate() + " '");
+                        + attributeContext.getTemplate() + " '");
             }
             request.dispatch(dispatchPath);
 
             // tiles exception so that it doesn't need to be rethrown.
         } catch (IOException e) {
             LOG.error("Error rendering tile", e);
-            // TODO it would be nice to make the preparerInstance throw a more 
specific
             throw new TilesException(e.getMessage(), e);
         }
     }

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddAttributeTag.java
 Sat Mar  1 05:58:36 2008
@@ -25,7 +25,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.jsp.taglib.definition.DefinitionTagParent;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
 import javax.servlet.jsp.tagext.TagSupport;
 
 /**
@@ -57,8 +59,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class AddAttributeTag extends RoleSecurityTagSupport implements
-        DefinitionTagParent {
+public class AddAttributeTag extends BodyTagSupport implements 
DefinitionTagParent {
 
     /**
      * The logging object.
@@ -66,6 +67,12 @@
     private static final Log LOG = LogFactory.getLog(AddAttributeTag.class);
 
     /**
+     * The role to check. If the user is in the specified role, the tag is 
taken
+     * into account; otherwise, the tag is ignored (skipped).
+     */
+    protected String role;
+
+    /**
      * Associated attribute value.
      */
     private Object value = null;
@@ -76,6 +83,26 @@
     private String type = null;
 
     /**
+     * Returns the role to check. If the user is in the specified role, the 
tag is
+     * taken into account; otherwise, the tag is ignored (skipped).
+     *
+     * @return The role to check.
+     */
+    public String getRole() {
+        return role;
+    }
+
+    /**
+     * Sets the role to check. If the user is in the specified role, the tag is
+     * taken into account; otherwise, the tag is ignored (skipped).
+     *
+     * @param role The role to check.
+     */
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    /**
      * Returns the attribute value.
      *
      * @return Attribute value. Can be a String or Object.
@@ -138,7 +165,7 @@
      */
     @Override
     public void release() {
-        super.release();
+        role = null;
         value = null;
         type = null;
     }
@@ -158,6 +185,15 @@
     }
 
     /** [EMAIL PROTECTED] */
+    public int doEndTag() throws JspException {
+        if (isAccessAllowed()) {
+            execute();
+        }
+
+        return EVAL_PAGE;
+    }
+
+    /** [EMAIL PROTECTED] */
     public void processNestedDefinitionName(String definitionName)
             throws JspException {
         value = definitionName;
@@ -171,7 +207,6 @@
         AddAttributeTagParent parent = (AddAttributeTagParent)
             TagSupport.findAncestorWithClass(this, 
AddAttributeTagParent.class);
 
-
         if (parent == null) {
             String message = "Error: enclosing tag '"
                     + getParent().getClass().getName()
@@ -181,5 +216,16 @@
         }
 
         parent.processNestedTag(this);
+    }
+
+    /**
+     * Checks if the user is inside the specified role.
+     *
+     * @return <code>true</code> if the user is allowed to have the tag
+     * rendered.
+     */
+    protected boolean isAccessAllowed() {
+        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
+        return (role == null || req.isUserInRole(role));
     }
 }

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddListAttributeTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddListAttributeTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddListAttributeTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AddListAttributeTag.java
 Sat Mar  1 05:58:36 2008
@@ -83,9 +83,8 @@
      * <p/>
      * Places the value of the nested tag within the
      * [EMAIL PROTECTED] org.apache.tiles.AttributeContext}.It is the 
responsibility
-     * of the descendent to check security.  Tags extending
-     * the [EMAIL PROTECTED] org.apache.tiles.jsp.taglib.ContainerTagSupport} 
will automatically provide
-     * the appropriate security.
+     * of the descendent to check security.  Security will be managed by called
+     * tags.
      *
      * @param nestedTag the put tag desciendent.
      */

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ContainerTagSupport.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ContainerTagSupport.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ContainerTagSupport.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/ContainerTagSupport.java
 Sat Mar  1 05:58:36 2008
@@ -36,6 +36,7 @@
  *
  * @since Tiles 2.0
  * @version $Rev$ $Date$
+ * @deprecated Use [EMAIL PROTECTED] RenderTagSupport}.
  */
 public abstract class ContainerTagSupport extends RoleSecurityTagSupport {
 

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertAttributeTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertAttributeTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertAttributeTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertAttributeTag.java
 Sat Mar  1 05:58:36 2008
@@ -25,6 +25,7 @@
 import org.apache.tiles.AttributeContext;
 import org.apache.tiles.TilesException;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
 
@@ -99,6 +100,13 @@
 
     /** [EMAIL PROTECTED] */
     protected void render() throws JspException, TilesException, IOException {
+        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
+
+        // Checks if the attribute can be rendered with the current user.
+        if (role != null && !req.isUserInRole(role)) {
+            return;
+        }
+
         Attribute attr = (Attribute) value;
         if (attr == null && evaluatingContext != null) {
             attr = evaluatingContext.getAttribute(name);

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertDefinitionTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertDefinitionTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertDefinitionTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertDefinitionTag.java
 Sat Mar  1 05:58:36 2008
@@ -31,7 +31,8 @@
  *
  * @version $Rev$ $Date$
  */
-public class InsertDefinitionTag extends RenderTagSupport implements 
PutAttributeTagParent {
+public class InsertDefinitionTag extends InsertTemplateTag implements
+        PutAttributeTagParent {
 
     /**
      * The definition name.
@@ -57,9 +58,16 @@
         this.name = name;
     }
 
+    /** [EMAIL PROTECTED] */
+    @Override
+    public void release() {
+        super.release();
+        name = null;
+    }
 
     /** [EMAIL PROTECTED] */
-    protected void render() throws JspException, TilesException {
+    @Override
+    protected void renderContext() throws JspException, TilesException {
         container.render(name, pageContext);
     }
 }

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertTemplateTag.java
 Sat Mar  1 05:58:36 2008
@@ -34,19 +34,22 @@
  *
  * @version $Rev$ $Date$
  */
-public class InsertTemplateTag extends RenderTagSupport
-    implements PutAttributeTagParent {
+public class InsertTemplateTag extends RenderTagSupport implements
+        PutAttributeTagParent {
 
     /**
      * A string representing the URI of a template (for example, a JSP page).
+     *
+     * @since 2.1.0
      */
-    private String template;
+    protected String template;
 
     /**
      * Returns a string representing the URI of a template (for example, a JSP
      * page).
      *
      * @return The template URI.
+     * @since 2.1.0
      */
     public String getTemplate() {
         return template;
@@ -57,22 +60,34 @@
      * page).
      *
      * @param template The template URI.
+     * @since 2.1.0
      */
     public void setTemplate(String template) {
         this.template = template;
     }
 
     /** [EMAIL PROTECTED] */
-    protected void render() throws JspException {
+    @Override
+    protected void render() throws JspException, TilesException, IOException {
+        attributeContext.setTemplate(template);
+        attributeContext.setPreparer(preparer);
+        attributeContext.setRole(role);
+        renderContext();
+    }
+
+    /**
+     * Renders the current context.
+     *
+     * @throws TilesException if a prepare or render exception occurs.
+     * @throws JspException if a jsp exception occurs.
+     * @throws IOException if an io exception occurs.
+     */
+    protected void renderContext() throws JspException, TilesException,
+            IOException {
         JspUtil.setForceInclude(pageContext, true);
         try {
             attributeContext.setTemplate(template);
             container.renderContext(pageContext);
-            if (flush) {
-                pageContext.getOut().flush();
-            }
-        } catch (IOException e) {
-            throw new JspException("Error during flush", e);
         } catch (TilesException e) {
             throw new JspException("Error during rendering of template '"
                     + template + "'", e);

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutAttributeTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutAttributeTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutAttributeTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutAttributeTag.java
 Sat Mar  1 05:58:36 2008
@@ -23,7 +23,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.tiles.jsp.taglib.definition.DefinitionTagParent;
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.TagSupport;
@@ -68,8 +67,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class PutAttributeTag extends RoleSecurityTagSupport implements
-        DefinitionTagParent {
+public class PutAttributeTag extends AddAttributeTag {
 
     /**
      * The logging object.
@@ -82,16 +80,6 @@
     protected String name = null;
 
     /**
-     * Associated attribute value.
-     */
-    private Object value = null;
-
-    /**
-     * Requested type for the value.
-     */
-    private String type = null;
-
-    /**
      * If <code>true</code>, the attribute will be cascaded to all nested
      * definitions.
      */
@@ -116,68 +104,6 @@
     }
 
     /**
-     * Returns the Attribute value. Could be a String or an Object. Value can
-     * come from a direct assignment (value="aValue") or from a bean. One of
-     * 'value' 'content' or 'beanName' must be present.
-     *
-     * @return The attribute value.
-     */
-    public Object getValue() {
-        return value;
-    }
-
-    /**
-     * Sets the Attribute value. Could be a String or an Object. Value can
-     * come from a direct assignment (value="aValue") or from a bean. One of
-     * 'value' 'content' or 'beanName' must be present.
-     *
-     * @param value The attribute value.
-     */
-    public void setValue(Object value) {
-        this.value = value;
-    }
-
-    /**
-     * <p>
-     * Returns the content type: string, template or definition.
-     * </p>
-     * <ul>
-     * <li>String : Content is printed directly.</li>
-     * <li>template : Content is included from specified URL. Value is used as
-     * an URL.</li>
-     * <li>definition : Value is the name of a definition defined in factory
-     * (xml file). Definition will be searched in the inserted tile, in a
-     * <code>&lt;tiles:insert attribute="attributeName"&gt;</code> tag, where
-     * 'attributeName' is the name used for this tag.</li>
-     * </ul>
-     *
-     * @return The attribute type.
-     */
-    public String getType() {
-        return type;
-    }
-
-    /**
-     * <p>
-     * Sets the content type: string, template or definition.
-     * </p>
-     * <ul>
-     * <li>String : Content is printed directly.</li>
-     * <li>template : Content is included from specified URL. Value is used as
-     * an URL.</li>
-     * <li>definition : Value is the name of a definition defined in factory
-     * (xml file). Definition will be searched in the inserted tile, in a
-     * <code>&lt;tiles:insert attribute="attributeName"&gt;</code> tag, where
-     * 'attributeName' is the name used for this tag.</li>
-     * </ul>
-     *
-     * @param type The attribute type.
-     */
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    /**
      * Checks if the attribute should be cascaded to nested definitions.
      *
      * @return <code>true</code> if the attribute will be cascaded.
@@ -204,32 +130,7 @@
     public void release() {
         super.release();
         name = null;
-        value = null;
-        type = null;
         cascade = false;
-    }
-
-    /**
-     * Save the body content of this tag (if any).
-     *
-     * @return <code>SKIP_BODY</code>.
-     * @throws JspException if a JSP exception has occurred
-     */
-    public int doAfterBody() throws JspException {
-        if (value == null && bodyContent != null) {
-            value = bodyContent.getString();
-            type = "string";
-        }
-        return (SKIP_BODY);
-    }
-
-    /** [EMAIL PROTECTED] */
-    public void processNestedDefinitionName(String definitionName)
-            throws JspException {
-        value = definitionName;
-        if (type == null) {
-            type = "definition";
-        }
     }
 
     /** [EMAIL PROTECTED] */

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutListAttributeTag.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutListAttributeTag.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutListAttributeTag.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/PutListAttributeTag.java
 Sat Mar  1 05:58:36 2008
@@ -84,9 +84,8 @@
      * <p/>
      * Places the value of the nested tag within the
      * [EMAIL PROTECTED] org.apache.tiles.AttributeContext}.It is the 
responsibility
-     * of the descendent to check security.  Tags extending
-     * the [EMAIL PROTECTED] org.apache.tiles.jsp.taglib.ContainerTagSupport} 
will automatically provide
-     * the appropriate security.
+     * of the descendent to check security.  Security will be managed by called
+     * tags.
      *
      * @param nestedTag the put tag desciendent.
      */

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RenderTagSupport.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RenderTagSupport.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RenderTagSupport.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RenderTagSupport.java
 Sat Mar  1 05:58:36 2008
@@ -20,15 +20,24 @@
  */
 package org.apache.tiles.jsp.taglib;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.Attribute;
+import org.apache.tiles.AttributeContext;
+import org.apache.tiles.TilesContainer;
 import org.apache.tiles.TilesException;
+import org.apache.tiles.access.TilesAccess;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
 import java.io.IOException;
 
 /**
  * <p>
- * Support for all tags which render (a template, or definition).
+ * Support for all tags which render (an attribute, a template, or definition).
  * </p>
  * <p>
  * Properly invokes the defined preparer and invokes the abstract render method
@@ -42,8 +51,19 @@
  * @since Tiles 2.0
  * @version $Rev$ $Date$
  */
-public abstract class RenderTagSupport extends ContainerTagSupport
-    implements PutAttributeTagParent {
+public abstract class RenderTagSupport extends BodyTagSupport implements
+        PutAttributeTagParent {
+
+    /**
+     * The log instance for this tag.
+     */
+    private static final Log LOG = LogFactory.getLog(RenderTagSupport.class);
+
+    /**
+     * The role to check. If the user is in the specified role, the tag is 
taken
+     * into account; otherwise, the tag is ignored (skipped).
+     */
+    protected String role;
 
     /**
      * The view preparer to use before the rendering.
@@ -62,6 +82,36 @@
     protected boolean ignore;
 
     /**
+     * The Tiles container that can be used inside the tag.
+     */
+    protected TilesContainer container;
+
+    /**
+     * The attribute context to use to store and read attribute values.
+     */
+    protected AttributeContext attributeContext;
+
+    /**
+     * Returns the role to check. If the user is in the specified role, the 
tag is
+     * taken into account; otherwise, the tag is ignored (skipped).
+     *
+     * @return The role to check.
+     */
+    public String getRole() {
+        return role;
+    }
+
+    /**
+     * Sets the role to check. If the user is in the specified role, the tag is
+     * taken into account; otherwise, the tag is ignored (skipped).
+     *
+     * @param role The role to check.
+     */
+    public void setRole(String role) {
+        this.role = role;
+    }
+
+    /**
      * Returns the preparer name.
      *
      * @return The preparer name.
@@ -129,13 +179,42 @@
         preparer = null;
         flush = false;
         ignore = false;
-        super.release();
+        container = null;
+        attributeContext = null;
+        role = null;
     }
 
     /** [EMAIL PROTECTED] */
     public int doStartTag() throws JspException {
-        super.doStartTag();
-        return isAccessAllowed() ? EVAL_BODY_BUFFERED : SKIP_BODY;
+        container = TilesAccess.getContainer(pageContext.getServletContext());
+        if (container != null) {
+            startContext(pageContext);
+            return EVAL_BODY_BUFFERED;
+        } else {
+            throw new JspException("TilesContainer not initialized");
+        }
+    }
+
+    /** [EMAIL PROTECTED] */
+    public int doEndTag() throws JspException {
+        try {
+            render();
+            if (flush) {
+                pageContext.getOut().flush();
+            }
+
+            return EVAL_PAGE;
+        } catch (TilesException e) {
+            String message = "Error executing tag: " + e.getMessage();
+            LOG.error(message, e);
+            throw new JspException(message, e);
+        } catch (IOException io) {
+            String message = "IO Error executing tag: " + io.getMessage();
+            LOG.error(message, io);
+            throw new JspException(message, io);
+        } finally {
+            endContext(pageContext);
+        }
     }
 
     /**
@@ -145,6 +224,7 @@
      * @throws TilesException if a prepare or render exception occurs.
      * @throws JspException if a jsp exception occurs.
      * @throws IOException if an io exception occurs.
+     * @deprecated Use [EMAIL PROTECTED] #render()}.
      */
     protected void execute() throws TilesException, JspException, IOException {
         if (preparer != null) {
@@ -166,15 +246,36 @@
     protected abstract void render() throws JspException, TilesException, 
IOException;
 
     /**
+     * Starts the context when entering the tag.
+     *
+     * @param context The page context to use.
+     */
+    protected void startContext(PageContext context) {
+        if (container != null) {
+            attributeContext = container.startContext(pageContext);
+        }
+    }
+
+    /**
+     * Ends the context when exiting the tag.
+     *
+     * @param context The page context to use.
+     */
+    protected void endContext(PageContext context) {
+        if (attributeContext != null && container != null) {
+            container.endContext(pageContext);
+        }
+    }
+
+    /**
      * <p>
      * Process nested &lg;put&gt; tag.
      * <p/>
      * <p>
      * Places the value of the nested tag within the
      * [EMAIL PROTECTED] org.apache.tiles.AttributeContext}.It is the 
responsibility
-     * of the descendent to check security.  Tags extending
-     * the [EMAIL PROTECTED] ContainerTagSupport} will automatically provide
-     * the appropriate security.
+     * of the descendent to check security. Security will be managed by
+     * called tags.
      * </p>
      *
      * @param nestedTag the put tag desciendent.
@@ -186,5 +287,17 @@
 
         attributeContext.putAttribute(nestedTag.getName(), attribute, nestedTag
                 .isCascade());
+    }
+
+    /**
+     * Checks if the user is inside the specified role.
+     *
+     * @return <code>true</code> if the user is allowed to have the tag
+     * rendered.
+     * @deprecated Implement access allowance in your own tag.
+     */
+    protected boolean isAccessAllowed() {
+        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
+        return (role == null || req.isUserInRole(role));
     }
 }

Modified: 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java?rev=632592&r1=632591&r2=632592&view=diff
==============================================================================
--- 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java
 (original)
+++ 
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java
 Sat Mar  1 05:58:36 2008
@@ -34,6 +34,7 @@
  *
  * @since Tiles 2.0
  * @version $Rev$ $Date$
+ * @deprecated Use [EMAIL PROTECTED] AddAttributeTag} and [EMAIL PROTECTED] 
PutAttributeTag} directly.
  */
 public abstract class RoleSecurityTagSupport extends BodyTagSupport {
 


Reply via email to