You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@locus.apache.org on 2000/09/07 03:35:37 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/logic CompareTagBase.java ConditionalTagBase.java EqualTag.java ForwardTag.java GreaterEqualTag.java GreaterThanTag.java IterateTag.java IterateTei.java LessEqualTag.java LessThanTag.java LocalStrings.properties MatchTag.java NotEqualTag.java NotMatchTag.java NotPresentTag.java PresentTag.java RedirectTag.java
craigmcc 00/09/06 18:35:37
Added: src/share/org/apache/struts/taglib/logic CompareTagBase.java
ConditionalTagBase.java EqualTag.java
ForwardTag.java GreaterEqualTag.java
GreaterThanTag.java IterateTag.java IterateTei.java
LessEqualTag.java LessThanTag.java
LocalStrings.properties MatchTag.java
NotEqualTag.java NotMatchTag.java
NotPresentTag.java PresentTag.java RedirectTag.java
Log:
Add the initial tags for the new "struts-logic.tld" library. These tags
include:
- Conditional execution based on comparison of a specified variable
to a specified constant value [equal, greaterEqual, greaterThan,
lessEqual, lessThan, notEqual].
- Conditional execution based on substring matching (match, notMatch).
- Conditional execution based on presence or absence of a particular
item (bean, cookie, header, parameter, or bean property) [present,
notPresent]
- Control flow and looping [forward, iterate, redirect]
This library, and the related "beans and properties" library, has an
associated test suite in the struts-test.war web application, so you can
validate that they individually work for you.
Revision Changes Path
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/CompareTagBase.java
Index: CompareTagBase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/CompareTagBase.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.BeanUtils;
import org.apache.struts.util.PropertyUtils;
/**
* Abstract base class for comparison tags. Concrete subclasses need only
* define values for desired1 and desired2.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public abstract class CompareTagBase extends ConditionalTagBase {
// ----------------------------------------------------- Instance Variables
/**
* We will do a double/float comparison.
*/
protected static final int DOUBLE_COMPARE = 0;
/**
* We will do a long/int comparison.
*/
protected static final int LONG_COMPARE = 1;
/**
* We will do a String comparison.
*/
protected static final int STRING_COMPARE = 2;
// ------------------------------------------------------------ Properties
/**
* The value to which the variable specified by other attributes of this
* tag will be compared.
*/
public String value = null;
public String getValue() {
return (this.value);
}
public void setValue(String value) {
this.value = value;
}
// --------------------------------------------------------- Public Methods
/**
* Reset custom attributes to their default state.
*/
public void releaseCustomAttributes() {
super.releaseCustomAttributes();
value = null;
}
// ------------------------------------------------------ Protected Methods
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected abstract boolean condition() throws JspException;
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @param desired1 First desired value for a true result (-1, 0, +1)
* @param desired2 Second desired value for a true result (-1, 0, +1)
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition(int desired1, int desired2)
throws JspException {
// Acquire the value and determine the test type
int type = -1;
double doubleValue = 0.0;
long longValue = 0;
if ((type < 0) && (value.length() > 0)) {
try {
doubleValue = Double.parseDouble(value);
type = DOUBLE_COMPARE;
} catch (NumberFormatException e) {
;
}
}
if ((type < 0) && (value.length() > 0)) {
try {
longValue = Long.parseLong(value);
type = LONG_COMPARE;
} catch (NumberFormatException e) {
;
}
}
if (type < 0) {
type = STRING_COMPARE;
}
// Acquire the unconverted variable value
Object variable = null;
if (cookie != null) {
Cookie cookies[] =
((HttpServletRequest) pageContext.getRequest()).
getCookies();
if (cookies == null)
cookies = new Cookie[0];
for (int i = 0; i < cookies.length; i++) {
if (cookie.equals(cookies[i].getName())) {
variable = cookies[i].getValue();
break;
}
}
} else if (header != null) {
variable =
((HttpServletRequest) pageContext.getRequest()).
getHeader(header);
} else if (name != null) {
Object bean = BeanUtils.lookup(pageContext, name, null);
if (property != null) {
if (bean == null)
throw new JspException
(messages.getMessage("logic.bean", name));
try {
variable = PropertyUtils.getProperty(bean, property);
} catch (Throwable t) {
throw new JspException
(messages.getMessage("logic.property", name, property,
t.toString()));
}
} else {
variable = bean;
}
} else if (parameter != null) {
variable =
pageContext.getRequest().getParameter(parameter);
} else
throw new JspException
(messages.getMessage("logic.selector"));
if (variable == null)
throw new JspException
(messages.getMessage("logic.variable", value));
// Perform the appropriate comparison
int result = 0;
if (type == DOUBLE_COMPARE) {
try {
double doubleVariable =
Double.parseDouble(variable.toString());
if (doubleVariable < doubleValue)
result = -1;
else if (doubleVariable > doubleValue)
result = +1;
} catch (NumberFormatException e) {
result = variable.toString().compareTo(value);
}
} else if (type == LONG_COMPARE) {
try {
long longVariable = Long.parseLong(variable.toString());
if (longVariable < longValue)
result = -1;
else if (longVariable > longValue)
result = +1;
} catch (NumberFormatException e) {
result = variable.toString().compareTo(value);
}
} else {
result = variable.toString().compareTo(value);
}
// Normalize the result
if (result < 0)
result = -1;
else if (result > 0)
result = +1;
// Return true if the result matches either desired value
return ((result == desired1) || (result == desired2));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/ConditionalTagBase.java
Index: ConditionalTagBase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/ConditionalTagBase.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.util.MessageResources;
/**
* Abstract base class for the various conditional evaluation tags.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public abstract class ConditionalTagBase extends TagSupport {
// ------------------------------------------------------------- Properties
/**
* The name of the cookie to be used as a variable.
*/
protected String cookie = null;
public String getCookie() {
return (this.cookie);
}
public void setCookie(String cookie) {
this.cookie = cookie;
}
/**
* The name of the HTTP request header to be used as a variable.
*/
protected String header = null;
public String getHeader() {
return (this.header);
}
public void setHeader(String header) {
this.header = header;
}
/**
* The message resources for this package.
*/
protected static MessageResources messages =
MessageResources.getMessageResources
("org.apache.struts.taglib.logic.LocalStrings");
/**
* The name of the JSP bean to be used as a variable (if
* <code>property</code> is not specified), or whose property is to be
* accessed (if <code>property</code> is specified).
*/
protected String name = null;
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
}
/**
* The name of the HTTP request parameter to be used as a variable.
*/
protected String parameter = null;
public String getParameter() {
return (this.parameter);
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
/**
* The name of the bean property to be used as a variable.
*/
protected String property = null;
public String getProperty() {
return (this.property);
}
public void setProperty(String property) {
this.property = property;
}
// --------------------------------------------------------- Public Methods
/**
* Perform the test required for this particular tag, and either evaluate
* or skip the body of this tag.
*
* @exception JspException if a JSP exception occurs
*/
public int doStartTag() throws JspException {
if (condition())
return (EVAL_BODY_INCLUDE);
else
return (SKIP_BODY);
}
/**
* Evaluate the remainder of the current page normally.
*
* @exception JspException if a JSP exception occurs
*/
public int doEndTag() throws JspException {
return (EVAL_PAGE);
}
/**
* Reset custom attributes to their default state.
*/
public void releaseCustomAttributes() {
cookie = null;
header = null;
name = null;
parameter = null;
property = null;
}
// ------------------------------------------------------ Protected Methods
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected abstract boolean condition() throws JspException;
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/EqualTag.java
Index: EqualTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/EqualTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evaluate the nested body content of this tag if the specified variable
* and value are equal.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class EqualTag extends CompareTagBase {
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(0, 0));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/ForwardTag.java
Index: ForwardTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/ForwardTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForwards;
import org.apache.struts.util.MessageResources;
/**
* Perform a forward or redirect to a page that is looked up in the global
* ActionForwards collection associated with our application.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class ForwardTag extends TagSupport {
// ----------------------------------------------------------- Properties
/**
* The message resources for this package.
*/
private static MessageResources messages =
MessageResources.getMessageResources
("org.apache.struts.taglib.logic.LocalStrings");
/**
* The logical name of the <code>ActionForward</code> entry to be
* looked up.
*/
private String name = null;
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
}
// ------------------------------------------------------- Public Methods
/**
* Defer processing until the end of this tag is encountered.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
return (SKIP_BODY);
}
/**
* Look up the ActionForward associated with the specified name,
* and perform a forward or redirect to that path as indicated.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
// Look up the desired ActionForward entry
ActionForward forward = null;
ActionForwards forwards =
(ActionForwards) pageContext.getAttribute
(Action.FORWARDS_KEY, PageContext.APPLICATION_SCOPE);
if (forwards != null)
forward = forwards.findForward(name);
if (forward == null)
throw new JspException
(messages.getMessage("forward.lookup", name));
// Forward or redirect to the corresponding actual path
String path = forward.getPath();
if (forward.getRedirect()) {
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
try {
response.sendRedirect(response.encodeRedirectURL(path));
} catch (Exception e) {
throw new JspException
(messages.getMessage("forward.redirect",
name, e.toString()));
}
} else {
try {
pageContext.forward(path);
} catch (Exception e) {
throw new JspException
(messages.getMessage("forward.forward",
name, e.toString()));
}
}
// Skip the remainder of this page
return (SKIP_PAGE);
}
/**
* Reset custom attributes to their default state.
*/
public void releaseCustomAttributes() {
name = null;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/GreaterEqualTag.java
Index: GreaterEqualTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/GreaterEqualTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evaluate the nested body content of this tag if the specified variable
* is greater than or equal to the specified value.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class GreaterEqualTag extends CompareTagBase {
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(+1, 0));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/GreaterThanTag.java
Index: GreaterThanTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/GreaterThanTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evaluate the nested body content of this tag if the specified variable
* is greater than the specified value.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class GreaterThanTag extends CompareTagBase {
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(+1, +1));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java
Index: IterateTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.PropertyUtils;
/**
* Custom tag that iterates the elements of a collection, which can be
* either an attribute or the property of an attribute. The collection
* can be any of the following: an array of objects, an Iterator,
* a Collection (which includes Lists, Sets and Vectors), or a Map
* (which includes Hashtables) whose elements will be iterated over.
* <p>
* <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or later) platform.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class IterateTag extends BodyTagSupport {
// ----------------------------------------------------- Instance Variables
/**
* Iterator of the elements of this collection, while we are actually
* running.
*/
private Iterator iterator = null;
/**
* The number of elements we have already rendered.
*/
private int lengthCount = 0;
/**
* The actual length value (calculated in the start tag).
*/
private int lengthValue = 0;
/**
* The message resources for this package.
*/
protected static MessageResources messages =
MessageResources.getMessageResources
("org.apache.struts.taglib.LocalStrings");
/**
* The actual offset value (calculated in the start tag).
*/
private int offsetValue = 0;
// ------------------------------------------------------------- Properties
/**
* The collection over which we will be iterating.
*/
private Object collection = null;
public Object getCollection() {
return (this.collection);
}
public void setCollection(Object collection) {
this.collection = collection;
}
/**
* The name of the scripting variable to be exposed.
*/
private String id = null;
public String getId() {
return (this.id);
}
public void setId(String id) {
this.id = id;
}
/**
* The length value or attribute name (<=0 means no limit).
*/
private String length = null;
public String getLength() {
return (this.length);
}
public void setLength(String length) {
this.length = length;
}
/**
* The name of the collection or owning bean.
*/
private String name = null;
public String getName() {
return (this.name);
}
public void setName(String name) {
this.name = name;
}
/**
* The starting offset (zero relative).
*/
private String offset = null;
public String getOffset() {
return (this.offset);
}
public void setOffset(String offset) {
this.offset = offset;
}
/**
* The property name containing the collection.
*/
private String property = null;
public String getProperty() {
return (this.property);
}
public void setProperty(String property) {
this.property = property;
}
/**
* The Java class of each exposed element of the collection.
*/
private String type = null;
public String getType() {
return (this.type);
}
public void setType(String type) {
this.type = type;
}
// --------------------------------------------------------- Public Methods
/**
* Construct an iterator for the specified collection, and begin
* looping through the body once per element.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Acquire the collection we are going to iterate over (if necessary)
Object collection = this.collection;
if (collection == null) {
try {
Object bean = pageContext.findAttribute(name);
if (bean == null)
throw new JspException
(messages.getMessage("iterate.bean", name));
if (property == null)
collection = bean;
else
collection =
PropertyUtils.getProperty(bean, property);
if (collection == null)
throw new JspException
(messages.getMessage("iterate.property",
name, property));
} catch (IllegalAccessException e) {
throw new JspException
(messages.getMessage("iterate.access", name, property));
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
throw new JspException
(messages.getMessage("iterate.target",
name, property, t.toString()));
} catch (NoSuchMethodException e) {
throw new JspException
(messages.getMessage("iterate.method", name, property));
}
}
// Construct an iterator for this collection
if (collection.getClass().isArray())
collection = Arrays.asList((Object[]) collection);
if (collection instanceof Collection)
iterator = ((Collection) collection).iterator();
else if (collection instanceof Iterator)
iterator = (Iterator) collection;
else if (collection instanceof Map)
iterator = ((Map) collection).entrySet().iterator();
else
throw new JspException
(messages.getMessage("iterate.iterator", name, property));
// Calculate the starting offset
if (offset == null)
offsetValue = 0;
else {
try {
offsetValue = Integer.parseInt(offset);
} catch (NumberFormatException e) {
Integer offsetObject =
(Integer) pageContext.findAttribute(offset);
if (offsetObject == null)
offsetValue = 0;
else
offsetValue = offsetObject.intValue();
}
}
if (offsetValue < 0)
offsetValue = 0;
// Calculate the rendering length
if (length == null)
lengthValue = 0;
else {
try {
lengthValue = Integer.parseInt(length);
} catch (NumberFormatException e) {
Integer lengthObject =
(Integer) pageContext.findAttribute(length);
if (lengthObject == null)
lengthValue = 0;
else
lengthValue = lengthObject.intValue();
}
}
if (lengthValue < 0)
lengthValue = 0;
lengthCount = 0;
// Skip the leading elements up to the starting offset
for (int i = 0; i < offsetValue; i++) {
if (iterator.hasNext()) {
Object element = iterator.next();
}
}
// Store the first value and evaluate, or skip the body if none
if (iterator.hasNext()) {
Object element = iterator.next();
pageContext.setAttribute(id, element);
lengthCount++;
return (EVAL_BODY_TAG);
} else
return (SKIP_BODY);
}
/**
* Make the next collection element available and loop, or
* finish the iterations if there are no more elements.
*
* @exception JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
// Render the output from this iteration to the output stream
if (bodyContent != null) {
try {
JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
bodyContent.clearBody();
} catch (IOException e) {
throw new JspException
(messages.getMessage("iterate.io", e.toString()));
}
}
// Decide whether to iterate or quit
if ((lengthValue > 0) && (lengthCount >= lengthValue))
return (SKIP_BODY);
if (iterator.hasNext()) {
Object element = iterator.next();
pageContext.setAttribute(id, element);
lengthCount++;
return (EVAL_BODY_TAG);
} else
return (SKIP_BODY);
}
/**
* Clean up after processing this enumeration.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
// Continue processing this page
return (EVAL_PAGE);
}
/**
* Release any acquired resources.
*/
public void release() {
super.release();
iterator = null;
lengthCount = 0;
lengthValue = 0;
offsetValue = 0;
}
/**
* Reset custom attributes to their default state.
*/
public void releaseCustomAttributes() {
id = null;
collection = null;
length = null;
name = null;
offset = null;
property = null;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTei.java
Index: IterateTei.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTei.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;
/**
* Implementation of <code>TagExtraInfo</code> for the <b>iterate</b>
* tag, identifying the scripting object(s) to be made visible.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class IterateTei extends TagExtraInfo {
/**
* Return information about the scripting variables to be created.
*/
public VariableInfo[] getVariableInfo(TagData data) {
String type = data.getAttributeString("type");
if (type == null)
type = "java.lang.Object";
return new VariableInfo[] {
new VariableInfo(data.getAttributeString("id"),
type,
true,
VariableInfo.AT_BEGIN)
};
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/LessEqualTag.java
Index: LessEqualTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/LessEqualTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evaluate the nested body content of this tag if the specified variable
* is less than or equal to the specified value.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class LessEqualTag extends CompareTagBase {
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(-1, 0));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/LessThanTag.java
Index: LessThanTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/LessThanTag.java,v 1.1 2000/09/07 01:35:35 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:35 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evaluate the nested body content of this tag if the specified variable
* is less than the specified value.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:35 $
*/
public final class LessThanTag extends CompareTagBase {
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(-1, -1));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
forward.forward=Exception forwarding for name {0}: {1}
forward.lookup=Cannot find global ActionForward for name {0}
forward.redirect=Exception redirecting for name {0}: {1}
iterate.access=Illegal access exception for bean {0} and property {1}
iterate.bean=No bean found under attribute key {0}
iterate.io=I/O exception: {0}
iterate.iterator=Cannot create iterator for bean {0} and property {0}
iterate.method=No getter method for bean {0} and property {1}
iterator.property=Null property {1} for bean {0}
iterator.target=Invocation target exception for bean {0} and property {1}: {2}
logic.bean=No bean found under attribute key {0}
logic.location=Invalid match location {0}
logic.property=Exception accessing property {1} for bean {0}: {2}
logic.selector=No selector attribute (cookie/header/name/parameter) was specified
logic.variable=Cannot compare null variable to value {0}
redirect.redirect=Exception redirecting to {0}: {1}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/MatchTag.java
Index: MatchTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/MatchTag.java,v 1.1 2000/09/07 01:35:36 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.BeanUtils;
import org.apache.struts.util.PropertyUtils;
/**
* Evalute the nested body content of this tag if the specified value
* is a substring of the specified variable.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:36 $
*/
public class MatchTag extends ConditionalTagBase {
// ------------------------------------------------------------- Properties
/**
* The location where the match must exist (<code>start</code> or
* <code>end</code>), or <code>null</code> for anywhere.
*/
public String location = null;
public String getLocation() {
return (this.location);
}
public void setLocation(String location) {
this.location = location;
}
/**
* The value to which the variable specified by other attributes of this
* tag will be matched.
*/
public String value = null;
public String getValue() {
return (this.value);
}
public void setValue(String value) {
this.value = value;
}
// --------------------------------------------------------- Public Methods
/**
* Reset custom attributes to their default state.
*/
public void releaseCustomAttributes() {
super.releaseCustomAttributes();
location = null;
value = null;
}
// ------------------------------------------------------ Protected Methods
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(true));
}
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @param desired Desired value for a true result
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition(boolean desired) throws JspException {
// Acquire the specified variable
String variable = null;
if (cookie != null) {
Cookie cookies[] =
((HttpServletRequest) pageContext.getRequest()).
getCookies();
if (cookies == null)
cookies = new Cookie[0];
for (int i = 0; i < cookies.length; i++) {
if (cookie.equals(cookies[i].getName())) {
variable = cookies[i].getValue();
break;
}
}
} else if (header != null) {
variable =
((HttpServletRequest) pageContext.getRequest()).
getHeader(header);
} else if (name != null) {
Object bean = BeanUtils.lookup(pageContext, name, null);
if (bean == null)
throw new JspException
(messages.getMessage("logic.bean", name));
if (property != null) {
Object propertyValue = null;
try {
propertyValue = PropertyUtils.getProperty(bean, property);
} catch (Throwable t) {
throw new JspException
(messages.getMessage("logic.property", name, property,
t.toString()));
}
if (propertyValue != null)
variable = propertyValue.toString();
} else {
variable = bean.toString();
}
} else if (parameter != null) {
variable = pageContext.getRequest().getParameter(parameter);
} else {
throw new JspException
(messages.getMessage("logic.selector"));
}
if (variable == null) {
throw new JspException
(messages.getMessage("logic.variable", value));
}
// Perform the comparison requested by the location attribute
boolean matched = false;
if (location == null) {
matched = (variable.indexOf(value) >= 0);
} else if (location.equals("start")) {
matched = variable.startsWith(value);
} else if (location.equals("end")) {
matched = variable.endsWith(value);
} else {
throw new JspException
(messages.getMessage("logic.location", location));
}
// Return the final result
return (matched == desired);
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/NotEqualTag.java
Index: NotEqualTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/NotEqualTag.java,v 1.1 2000/09/07 01:35:36 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evaluate the nested body content of this tag if the specified variable
* and value are not equal.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:36 $
*/
public final class NotEqualTag extends CompareTagBase {
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(-1, +1));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/NotMatchTag.java
Index: NotMatchTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/NotMatchTag.java,v 1.1 2000/09/07 01:35:36 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evalute the nested body content of this tag if the specified value
* is not a substring of the specified variable.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:36 $
*/
public class NotMatchTag extends MatchTag {
// ------------------------------------------------------ Protected Methods
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(false));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/NotPresentTag.java
Index: NotPresentTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/NotPresentTag.java,v 1.1 2000/09/07 01:35:36 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.jsp.JspException;
/**
* Evalute the nested body content of this tag if the specified value
* is not present for this request.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:36 $
*/
public final class NotPresentTag extends PresentTag {
// ------------------------------------------------------ Protected Methods
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(false));
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/PresentTag.java
Index: PresentTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/PresentTag.java,v 1.1 2000/09/07 01:35:36 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.BeanUtils;
import org.apache.struts.util.PropertyUtils;
/**
* Evalute the nested body content of this tag if the specified value
* is present for this request.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:36 $
*/
public class PresentTag extends ConditionalTagBase {
// ------------------------------------------------------ Protected Methods
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition() throws JspException {
return (condition(true));
}
/**
* Evaluate the condition that is being tested by this particular tag,
* and return <code>true</code> if the nested body content of this tag
* should be evaluated, or <code>false</code> if it should be skipped.
* This method must be implemented by concrete subclasses.
*
* @param desired Desired outcome for a true result
*
* @exception JspException if a JSP exception occurs
*/
protected boolean condition(boolean desired) throws JspException {
// Evaluate the presence of the specified value
boolean present = false;
if (cookie != null) {
Cookie cookies[] =
((HttpServletRequest) pageContext.getRequest()).
getCookies();
if (cookies == null)
cookies = new Cookie[0];
for (int i = 0; i < cookies.length; i++) {
if (cookie.equals(cookies[i].getName())) {
present = true;
break;
}
}
} else if (header != null) {
String value =
((HttpServletRequest) pageContext.getRequest()).
getHeader(header);
present = (value != null);
} else if (name != null) {
Object bean = BeanUtils.lookup(pageContext, name, null);
if (property != null) {
if (bean == null)
throw new JspException
(messages.getMessage("logic.bean", name));
Object value = null;
try {
value = PropertyUtils.getProperty(bean, property);
} catch (Throwable t) {
throw new JspException
(messages.getMessage("logic.property", name, property,
t.toString()));
}
present = (value != null);
} else {
present = (bean != null);
}
} else if (parameter != null) {
String value =
pageContext.getRequest().getParameter(parameter);
present = (value != null);
} else
throw new JspException
(messages.getMessage("logic.selector"));
return (present == desired);
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java
Index: RedirectTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java,v 1.1 2000/09/07 01:35:36 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/09/07 01:35:36 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 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 acknowlegement:
* "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", "Tomcat", 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 apache@apache.org.
*
* 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.struts.taglib.logic;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.util.BeanUtils;
import org.apache.struts.util.MessageResources;
/**
* Perform a sendRedirect() to the specified URL, and skip evaluating
* the remainder of the current page.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/09/07 01:35:36 $
*/
public final class RedirectTag extends TagSupport {
// ------------------------------------------------------------- Properties
/**
* The relative or absolute URL to which the client should be redirected.
*/
private String href = null;
public String getHref() {
return (this.href);
}
public void setHref(String href) {
this.href = href;
}
/**
* The message resources for this package.
*/
protected static MessageResources messages =
MessageResources.getMessageResources
("org.apache.struts.taglib.logic.LocalStrings");
// --------------------------------------------------------- Public Methods
/**
* Defer processing until the end of this tag is encountered.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
return (SKIP_BODY);
}
/**
* Render a redirect to the specified hyperlink, and skip the
* remainder of the current page.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
// Perform the requested redirect
HttpServletResponse response =
(HttpServletResponse) pageContext.getResponse();
try {
response.sendRedirect(response.encodeRedirectURL(href));
} catch (IOException e) {
throw new JspException
(messages.getMessage("redirect.redirect", href, e.toString()));
}
// Skip the remainder of the current page
return (SKIP_PAGE);
}
/**
* Reset custom attributes to their default state.
*/
public void releaseCustomAttributes() {
href = null;
}
}