You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2008/03/16 12:22:42 UTC

svn commit: r637577 - in /tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib: InsertAttributeTag.java NoSuchAttributeException.java

Author: apetrelli
Date: Sun Mar 16 04:22:39 2008
New Revision: 637577

URL: http://svn.apache.org/viewvc?rev=637577&view=rev
Log:
TILES-263
Now the attribute is got directly, instead of storing the current context.

Added:
    tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/NoSuchAttributeException.java
Modified:
    tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/InsertAttributeTag.java

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=637577&r1=637576&r2=637577&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 Sun Mar 16 04:22:39 2008
@@ -49,9 +49,11 @@
     protected Object value = null;
 
     /**
-     * The context used to evaluate the attribute.
+     * The evaluated attribute.
+     *
+     * @since 2.1.0
      */
-    protected AttributeContext evaluatingContext;
+    protected Attribute attribute;
 
     /**
      * Sets the name of the attribute.
@@ -90,10 +92,21 @@
     }
 
     /** {@inheritDoc} */
+    @Override
+    public int doStartTag() throws TilesJspException {
+        if (value == null && name == null) {
+            throw new TilesJspException(
+                    "No attribute name or value has been provided.");
+        }
+        return super.doStartTag();
+    }
+
+    /** {@inheritDoc} */
     public void release() {
         super.release();
         this.name = null;
         this.value = null;
+        this.attribute = null;
     }
 
     /** {@inheritDoc} */
@@ -104,32 +117,24 @@
         if (role != null && !req.isUserInRole(role)) {
             return;
         }
-
-        Attribute attr = (Attribute) value;
-        if (attr == null && evaluatingContext != null) {
-            attr = evaluatingContext.getAttribute(name);
-        }
-        if (attr == null && ignore) {
-            return;
-        }
-
-        if (attr == null) {
-            if (name != null) {
-                throw new TilesJspException("Attribute '" + name + "' not found.");
-            } else {
-                throw new TilesJspException("No attribute name or value has been provided.");
-            }
-        }
-        render(attr);
+        render(attribute);
     }
 
     /** {@inheritDoc} */
     @Override
     protected void startContext(PageContext context) {
+        attribute = (Attribute) value;
 
-        if (container != null) {
-            evaluatingContext = container.getAttributeContext(context);
+        if (attribute == null) {
+            AttributeContext evaluatingContext = container
+                    .getAttributeContext(context);
+            attribute = evaluatingContext.getAttribute(name);
+            if (attribute == null && !ignore) {
+                throw new NoSuchAttributeException("Attribute '" + name
+                        + "' not found.");
+            }
         }
+
         super.startContext(context);
     }
 

Added: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/NoSuchAttributeException.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/NoSuchAttributeException.java?rev=637577&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/NoSuchAttributeException.java (added)
+++ tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/NoSuchAttributeException.java Sun Mar 16 04:22:39 2008
@@ -0,0 +1,72 @@
+/*
+ * $Id: TilesAccessException.java 637434 2008-03-15 15:48:38Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.jsp.taglib;
+
+import org.apache.tiles.TilesException;
+
+/**
+ * Indicates that a named attribute has not been found.
+ *
+ * @version $Rev: 637434 $ $Date: 2008-03-15 15:48:38 +0000 (sab, 15 mar 2008) $
+ * @since 2.1.0
+ */
+public class NoSuchAttributeException extends TilesException {
+
+    /**
+     * Constructor.
+     *
+     * @since 2.1.0
+     */
+    public NoSuchAttributeException() {
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param message The detail message.
+     * @since 2.1.0
+     */
+    public NoSuchAttributeException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param e The exception to be wrapped.
+     * @since 2.1.0
+     */
+    public NoSuchAttributeException(Exception e) {
+        super(e);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param message The detail message.
+     * @param e The exception to be wrapped.
+     * @since 2.1.0
+     */
+    public NoSuchAttributeException(String message, Exception e) {
+        super(message, e);
+    }
+
+}