dmkarr 2002/10/24 21:45:01
Modified: contrib/struts-el/doc/userGuide struts-logic-el.xml
contrib/struts-el/web/exercise-taglib index.jsp
logic-present.jsp
Added: contrib/struts-el/src/share/org/apache/strutsel/taglib/logic
ELNotPresentTag.java ELPresentTag.java
Log:
Added logic-el:present and logic-el:notPresent because of their role functionality
Revision Changes Path
1.1
jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/logic/ELNotPresentTag.java
Index: ELNotPresentTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/logic/ELNotPresentTag.java,v
1.1 2002/10/25 04:45:01 dmkarr Exp $
* $Revision: 1.1 $
* $Date: 2002/10/25 04:45:01 $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.strutsel.taglib.logic;
import org.apache.struts.taglib.logic.NotPresentTag;
import javax.servlet.jsp.JspException;
import org.apache.strutsel.taglib.utils.EvalHelper;
import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
/**
* Evaluates the nested body content of this tag if the specified value is
* not present for this request.
*<p>
* This class is a subclass of the class
* <code>org.apache.struts.taglib.logic.NotPresentTag</code> which
* provides most of the described functionality. This subclass allows all
* attribute values to be specified as expressions utilizing the JavaServer
* Pages Standard Library expression language.
*
* @author David M. Karr
* @version $Revision: 1.1 $
*/
public class ELNotPresentTag extends NotPresentTag {
/**
* Process the start tag.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
evaluateExpressions();
return (super.doStartTag());
}
/**
* Evaluates and returns a single attribute value, given the attribute
* name, attribute value, and attribute type. It uses the
* <code>EvalHelper</code> class to interface to
* <code>ExpressionUtil.evalNotNull</code> to do the actual evaluation, and
* it passes to this the name of the current tag, the <code>this</code>
* pointer, and the current pageContext.
*
* @param attrName attribute name being evaluated
* @param attrValue String value of attribute to be evaluated using EL
* @param attrType Required resulting type of attribute value
* @exception NullAttributeException if either the <code>attrValue</code>
* was null, or the resulting evaluated value was null.
* @return Resulting attribute value
*/
private Object evalAttr(String attrName,
String attrValue,
Class attrType)
throws JspException, NullAttributeException
{
return (EvalHelper.eval("notPresent", attrName, attrValue, attrType,
this, pageContext));
}
/**
* Processes all attribute values which use the JSTL expression evaluation
* engine to determine their values. If any evaluation fails with a
* <code>NullAttributeException</code> it will just use <code>null</code>
* as the value.
*
* @exception JspException if a JSP exception has occurred
*/
private void evaluateExpressions() throws JspException {
try {
setCookie((String) evalAttr("cookie", getCookie(), String.class));
} catch (NullAttributeException ex) {
setCookie(null);
}
try {
setHeader((String) evalAttr("header", getHeader(),
String.class));
} catch (NullAttributeException ex) {
setHeader(null);
}
try {
setName((String) evalAttr("name", getName(), String.class));
} catch (NullAttributeException ex) {
setName(null);
}
try {
setParameter((String) evalAttr("parameter", getParameter(),
String.class));
} catch (NullAttributeException ex) {
setParameter(null);
}
try {
setProperty((String) evalAttr("property", getProperty(),
String.class));
} catch (NullAttributeException ex) {
setProperty(null);
}
try {
setRole((String) evalAttr("role", getRole(), String.class));
} catch (NullAttributeException ex) {
setRole(null);
}
try {
setScope((String) evalAttr("scope", getScope(), String.class));
} catch (NullAttributeException ex) {
setScope(null);
}
try {
setUser((String) evalAttr("user", getUser(), String.class));
} catch (NullAttributeException ex) {
setUser(null);
}
}
}
1.1
jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/logic/ELPresentTag.java
Index: ELPresentTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/logic/ELPresentTag.java,v
1.1 2002/10/25 04:45:01 dmkarr Exp $
* $Revision: 1.1 $
* $Date: 2002/10/25 04:45:01 $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.strutsel.taglib.logic;
import org.apache.struts.taglib.logic.PresentTag;
import javax.servlet.jsp.JspException;
import org.apache.strutsel.taglib.utils.EvalHelper;
import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
/**
* Evaluates the nested body content of this tag if the specified value is
* present for this request.
*<p>
* This class is a subclass of the class
* <code>org.apache.struts.taglib.logic.PresentTag</code> which
* provides most of the described functionality. This subclass allows all
* attribute values to be specified as expressions utilizing the JavaServer
* Pages Standard Library expression language.
*
* @author David M. Karr
* @version $Revision: 1.1 $
*/
public class ELPresentTag extends PresentTag {
/**
* Process the start tag.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
evaluateExpressions();
return (super.doStartTag());
}
/**
* Evaluates and returns a single attribute value, given the attribute
* name, attribute value, and attribute type. It uses the
* <code>EvalHelper</code> class to interface to
* <code>ExpressionUtil.evalNotNull</code> to do the actual evaluation, and
* it passes to this the name of the current tag, the <code>this</code>
* pointer, and the current pageContext.
*
* @param attrName attribute name being evaluated
* @param attrValue String value of attribute to be evaluated using EL
* @param attrType Required resulting type of attribute value
* @exception NullAttributeException if either the <code>attrValue</code>
* was null, or the resulting evaluated value was null.
* @return Resulting attribute value
*/
private Object evalAttr(String attrName,
String attrValue,
Class attrType)
throws JspException, NullAttributeException
{
return (EvalHelper.eval("present", attrName, attrValue, attrType,
this, pageContext));
}
/**
* Processes all attribute values which use the JSTL expression evaluation
* engine to determine their values. If any evaluation fails with a
* <code>NullAttributeException</code> it will just use <code>null</code>
* as the value.
*
* @exception JspException if a JSP exception has occurred
*/
private void evaluateExpressions() throws JspException {
try {
setCookie((String) evalAttr("cookie", getCookie(), String.class));
} catch (NullAttributeException ex) {
setCookie(null);
}
try {
setHeader((String) evalAttr("header", getHeader(),
String.class));
} catch (NullAttributeException ex) {
setHeader(null);
}
try {
setName((String) evalAttr("name", getName(), String.class));
} catch (NullAttributeException ex) {
setName(null);
}
try {
setParameter((String) evalAttr("parameter", getParameter(),
String.class));
} catch (NullAttributeException ex) {
setParameter(null);
}
try {
setProperty((String) evalAttr("property", getProperty(),
String.class));
} catch (NullAttributeException ex) {
setProperty(null);
}
try {
setRole((String) evalAttr("role", getRole(), String.class));
} catch (NullAttributeException ex) {
setRole(null);
}
try {
setScope((String) evalAttr("scope", getScope(), String.class));
} catch (NullAttributeException ex) {
setScope(null);
}
try {
setUser((String) evalAttr("user", getUser(), String.class));
} catch (NullAttributeException ex) {
setUser(null);
}
}
}
1.2 +211 -0
jakarta-struts/contrib/struts-el/doc/userGuide/struts-logic-el.xml
Index: struts-logic-el.xml
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/struts-el/doc/userGuide/struts-logic-el.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- struts-logic-el.xml 26 Sep 2002 04:54:39 -0000 1.1
+++ struts-logic-el.xml 25 Oct 2002 04:45:01 -0000 1.2
@@ -635,6 +635,217 @@
</tag>
+ <tag>
+
+ <name>notPresent</name>
+ <summary>
+ Generate the nested body content of this tag if the specified
+ value is not present in this request.
+ </summary>
+ <tagclass>org.apache.strutsel.taglib.logic.ELNotPresentTag</tagclass>
+ <bodycontent>JSP</bodycontent>
+ <info>
+ <p>Depending on which attribute is specified, this tag checks the
+ current request, and evaluates the nested body content of this tag
+ only if the specified value <strong>is not</strong> present. Only one
+ of the attributes may be used in one occurrence of this tag, unless
+ you use the <code>property</code> attribute, in which case the
+ <code>name</code> attribute is also required.</p>
+ </info>
+
+ <attribute>
+ <name>cookie</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of a cookie with the specified name.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>header</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of an HTTP header with the specified
+ name. The name match is performed in a case insensitive manner.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>name</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of a JSP bean, in any scope, with the
+ specified name. If <code>property</code> is also specified, checks
+ for a non-null property value for the specified property.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>parameter</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of at least one occurrence of the
+ specified request parameter on this request, even if the parameter
+ value is a zero-length string.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>property</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of a non-null property value, returned
+ by a property getter method on the JSP bean (in any scope) that is
+ specified by the <code>name</code> attribute. Property references
+ can be simple, nested, and/or indexed.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>role</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks whether the currently authenticated user (if any) has been
+ associated with the specified security role.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>scope</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>The bean scope within which to search for the bean named by the
+ <code>name</code> property, or "any scope" if not specified.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>user</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks whether the currently authenticated user principal has the
+ specified name.</p>
+ </info>
+ </attribute>
+
+ </tag>
+
+
+ <tag>
+
+ <name>present</name>
+ <summary>
+ Generate the nested body content of this tag if the specified
+ value is present in this request.
+ </summary>
+ <tagclass>org.apache.strutsel.taglib.logic.ELPresentTag</tagclass>
+ <bodycontent>JSP</bodycontent>
+ <info>
+ <p>Depending on which attribute is specified, this tag checks the
+ current request, and evaluates the nested body content of this tag
+ only if the specified value <strong>is</strong> present. Only one
+ of the attributes may be used in one occurrence of this tag, unless
+ you use the <code>property</code> attribute, in which case the
+ <code>name</code> attribute is also required.</p>
+ </info>
+
+ <attribute>
+ <name>cookie</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of a cookie with the specified name.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>header</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of an HTTP header with the specified
+ name. The name match is performed in a case insensitive manner.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>name</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of a JSP bean, in any scope, with the
+ specified name. If <code>property</code> is also specified, checks
+ for a non-null property value for the specified property.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>parameter</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of at least one occurrence of the
+ specified request parameter on this request, even if the parameter
+ value is a zero-length string.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>property</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks for the existence of a non-null property value, returned
+ by a property getter method on the JSP bean (in any scope) that is
+ specified by the <code>name</code> attribute. Property references
+ can be simple, nested, and/or indexed.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>role</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks whether the currently authenticated user (if any) has been
+ associated with any of the specified security roles. Use a comma-delimited
+ list to check for multiple roles. Example:
+ <code><logic-el:present role="role1,role2,role3">
+ code.....
+ </logic-el:present></code></p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>scope</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>The bean scope within which to search for the bean named by the
+ <code>name</code> property, or "any scope" if not specified.</p>
+ </info>
+ </attribute>
+
+ <attribute>
+ <name>user</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <info>
+ <p>Checks whether the currently authenticated user principal has the
+ specified name.</p>
+ </info>
+ </attribute>
+
+ </tag>
+
<tag>
<name>redirect</name>
1.4 +1 -1 jakarta-struts/contrib/struts-el/web/exercise-taglib/index.jsp
Index: index.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/contrib/struts-el/web/exercise-taglib/index.jsp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- index.jsp 14 Oct 2002 03:25:19 -0000 1.3
+++ index.jsp 25 Oct 2002 04:45:01 -0000 1.4
@@ -32,6 +32,7 @@
<ul>
<li><a href="logic-iterate.jsp">Iterate Tag</a>[<a
href="showSource.jsp?path=/logic-iterate.jsp">Source</a>]</li>
<li><a href="logic-match.jsp?param1=value1">Match Tags</a>[<a
href="showSource.jsp?path=/logic-match.jsp">Source</a>]</li>
+<li><a href="logic-present.jsp?param1=value1">Presence Tags</a>[<a
href="showSource.jsp?path=/logic-present.jsp">Source</a>]</li>
<li><a href="logic-redirect.jsp"><logic:redirect></a>[<a
href="showSource.jsp?path=/logic-redirect.jsp">Source</a>]</li>
</ul>
@@ -48,7 +49,6 @@
<h3>LOGIC Tags</h3>
<ul>
<li><a href="logic-compare.jsp">Comparison Tags</a>[<a
href="showSource.jsp?path=/logic-compare.jsp">Source</a>]</li>
-<li><a href="logic-present.jsp?param1=value1">Presence Tags</a>[<a
href="showSource.jsp?path=/logic-present.jsp">Source</a>]</li>
<li><a href="logic-empty.jsp">Emptiness Tags</a>[<a
href="showSource.jsp?path=/logic-empty.jsp">Source</a>]</li>
</ul>
</body>
1.2 +15 -2
jakarta-struts/contrib/struts-el/web/exercise-taglib/logic-present.jsp
Index: logic-present.jsp
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/struts-el/web/exercise-taglib/logic-present.jsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- logic-present.jsp 26 Sep 2002 04:54:41 -0000 1.1
+++ logic-present.jsp 25 Oct 2002 04:45:01 -0000 1.2
@@ -2,15 +2,16 @@
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
+<%@ taglib uri="/WEB-INF/struts-logic-el.tld" prefix="logic-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<html-el:html>
<head>
-<title>Test Replacements for struts presence tags</title>
+<title>Test Struts presence tags and Replacements</title>
</head>
<body bgcolor="white">
<div align="center">
-<h1>Test Replacements for struts presence tags</h1>
+<h1>Test Struts presence tags and Replacements</h1>
</div>
<jsp:useBean id="bean" scope="page"
class="org.apache.struts.webapp.exercise.TestBean"/>
@@ -20,6 +21,18 @@
<th>Test Type</th>
<th>Correct Value</th>
<th>Test Result</th>
+ </tr>
+ <tr>
+ <td>Role</td>
+ <td>notPresent</td>
+ <td>
+ <logic-el:present role="fubar">
+ present
+ </logic-el:present>
+ <logic-el:notPresent role="fubar">
+ notPresent
+ </logic-el:notPresent>
+ </td>
</tr>
<tr>
<td>Bean</td>
--
To unsubscribe, e-mail: <mailto:struts-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@;jakarta.apache.org>