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 2007/03/08 16:33:49 UTC
svn commit: r516073 - in
/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib:
./ definition/
Author: apetrelli
Date: Thu Mar 8 07:33:47 2007
New Revision: 516073
URL: http://svn.apache.org/viewvc?view=rev&rev=516073
Log:
TILES-135
Refactored JSP tags that deal with attributes, because they do not need the container.
TILES-134
Now a JspException is thrown if there is no container when it is needed.
Added:
tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java (with props)
Modified:
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/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/definition/DefinitionTag.java
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?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- 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 Thu Mar 8 07:33:47 2007
@@ -23,12 +23,10 @@
package org.apache.tiles.jsp.taglib;
import org.apache.tiles.ComponentConstants;
-import org.apache.tiles.jsp.taglib.ContainerTagSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
@@ -60,7 +58,8 @@
*
* @version $Rev$ $Date$
*/
-public class AddAttributeTag extends ContainerTagSupport implements ComponentConstants {
+public class AddAttributeTag extends RoleSecurityTagSupport implements
+ ComponentConstants {
private static final Log LOG = LogFactory.getLog(AddAttributeTag.class);
@@ -110,18 +109,6 @@
type = "string";
}
return (SKIP_BODY);
- }
-
- @Override
- protected void startContext(PageContext context) {
- if (container != null) {
- componentContext = container.getComponentContext(context);
- }
- }
-
- @Override
- protected void endContext(PageContext context) {
- // Do nothing
}
protected void execute() throws JspException {
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?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- 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 Thu Mar 8 07:33:47 2007
@@ -28,7 +28,6 @@
import java.util.List;
import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
/**
* AddListAttribute tag implementation.
@@ -51,7 +50,7 @@
throw new IllegalStateException("The value of the PutListAttributeTag must be the originally defined list.");
}
- public int doStartTag() {
+ public int doStartTag() throws JspException {
super.setValue(new ArrayList<ComponentAttribute>());
return super.doStartTag();
}
@@ -90,18 +89,6 @@
nestedTag.getType());
this.addValue(attribute);
- }
-
- @Override
- protected void startContext(PageContext context) {
- if (container != null) {
- componentContext = container.getComponentContext(context);
- }
- }
-
- @Override
- protected void endContext(PageContext context) {
- // Do nothing
}
private void addValue( ComponentAttribute attribute ) {
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?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- 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 Thu Mar 8 07:33:47 2007
@@ -25,14 +25,10 @@
import org.apache.commons.logging.LogFactory;
import org.apache.tiles.ComponentContext;
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;
/**
* Base tag for the tiles tags which interact with the container.
@@ -43,71 +39,46 @@
* @since Tiles 2.0
* @version $Rev$ $Date$
*/
-public abstract class ContainerTagSupport extends BodyTagSupport {
+public abstract class ContainerTagSupport extends RoleSecurityTagSupport {
/**
* The log instance for this tag.
*/
private static final Log LOG = LogFactory.getLog(ContainerTagSupport.class);
- private String role;
protected TilesContainer container;
protected ComponentContext componentContext;
- public String getRole() {
- return role;
- }
-
- public void setRole(String role) {
- 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() {
+ public int doStartTag() throws JspException {
container = TilesAccess.getContainer(pageContext.getServletContext());
- startContext(pageContext);
- return EVAL_BODY_BUFFERED;
+ if (container != null) {
+ startContext(pageContext);
+ return EVAL_BODY_BUFFERED;
+ } else {
+ throw new JspException("TilesContainer not initialized");
+ }
}
public int doEndTag() throws JspException {
try {
- if (isAccessAllowed()) {
- execute();
- }
- } 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);
+ return super.doEndTag();
} finally {
endContext(pageContext);
}
-
- return EVAL_PAGE;
}
public void release() {
super.release();
- this.role = null;
this.container = null;
this.componentContext = null;
- }
-
- protected abstract void execute() throws TilesException, JspException, IOException;
-
- protected boolean isAccessAllowed() {
- HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
- return (role == null || req.isUserInRole(role));
}
protected void startContext(PageContext context) {
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?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- 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 Thu Mar 8 07:33:47 2007
@@ -23,13 +23,11 @@
package org.apache.tiles.jsp.taglib;
import org.apache.tiles.ComponentConstants;
-import org.apache.tiles.jsp.taglib.ContainerTagSupport;
import org.apache.tiles.jsp.taglib.PutAttributeTagParent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
@@ -72,7 +70,7 @@
*
* @version $Rev$ $Date$
*/
-public class PutAttributeTag extends ContainerTagSupport implements ComponentConstants {
+public class PutAttributeTag extends RoleSecurityTagSupport implements ComponentConstants {
private static final Log LOG = LogFactory.getLog(PutAttributeTag.class);
@@ -137,18 +135,6 @@
type = "string";
}
return (SKIP_BODY);
- }
-
- @Override
- protected void startContext(PageContext context) {
- if (container != null) {
- componentContext = container.getComponentContext(context);
- }
- }
-
- @Override
- protected void endContext(PageContext context) {
- // Do nothing
}
protected void execute() throws JspException {
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?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- 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 Thu Mar 8 07:33:47 2007
@@ -28,7 +28,6 @@
import java.util.List;
import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.PageContext;
/**
* PutList tag implementation.
@@ -51,7 +50,7 @@
throw new IllegalStateException("The value of the PutListAttributeTag must be the originally defined list.");
}
- public int doStartTag() {
+ public int doStartTag() throws JspException {
super.setValue(new ArrayList<ComponentAttribute>());
return super.doStartTag();
}
@@ -90,18 +89,6 @@
nestedTag.getType());
this.addValue(attribute);
- }
-
- @Override
- protected void startContext(PageContext context) {
- if (container != null) {
- componentContext = container.getComponentContext(context);
- }
- }
-
- @Override
- protected void endContext(PageContext context) {
- // Do nothing
}
private void addValue( ComponentAttribute attribute ) {
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?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- 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 Thu Mar 8 07:33:47 2007
@@ -88,7 +88,7 @@
super.release();
}
- public int doStartTag() {
+ public int doStartTag() throws JspException {
super.doStartTag();
return isAccessAllowed() ? EVAL_BODY_BUFFERED : SKIP_BODY;
}
Added: 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?view=auto&rev=516073
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java (added)
+++ tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java Thu Mar 8 07:33:47 2007
@@ -0,0 +1,87 @@
+/*
+ * $Id$
+ *
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tiles.TilesException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import java.io.IOException;
+
+/**
+ * Base tag for the tiles tags which provides standard support for security.
+ *
+ * @since Tiles 2.0
+ * @version $Rev$ $Date$
+ */
+public abstract class RoleSecurityTagSupport extends BodyTagSupport {
+
+ /**
+ * The log instance for this tag.
+ */
+ private static final Log LOG = LogFactory.getLog(RoleSecurityTagSupport.class);
+
+ private String role;
+
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+
+ public int doEndTag() throws JspException {
+ try {
+ if (isAccessAllowed()) {
+ execute();
+ }
+ } 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);
+ }
+
+ return EVAL_PAGE;
+ }
+
+
+
+ public void release() {
+ super.release();
+ this.role = null;
+ }
+
+ protected abstract void execute() throws TilesException, JspException, IOException;
+
+ protected boolean isAccessAllowed() {
+ HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
+ return (role == null || req.isUserInRole(role));
+ }
+}
Propchange: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RoleSecurityTagSupport.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/DefinitionTag.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/DefinitionTag.java?view=diff&rev=516073&r1=516072&r2=516073
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/DefinitionTag.java (original)
+++ tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/definition/DefinitionTag.java Thu Mar 8 07:33:47 2007
@@ -113,6 +113,9 @@
TilesContainer c =
TilesAccess.getContainer(pageContext.getServletContext());
+ if (c == null) {
+ throw new JspException("TilesContainer not initialized");
+ }
if(!(c instanceof MutableTilesContainer)) {
throw new JspException("Unable to define definition for a " +
"container which does not implement MutableTilesContainer");