morgand 01/03/08 17:33:37
Modified: scopes/src/org/apache/taglibs/scopes BaseMultiTag.java
ExistsTag.java
Added: scopes/src/org/apache/taglibs/scopes EqualsTag.java
NotEqualTag.java NotExistTag.java
Removed: scopes/src/org/apache/taglibs/scopes NotExistsTag.java
Log:
added "equals" tag
Revision Changes Path
1.2 +23 -6
jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/BaseMultiTag.java
Index: BaseMultiTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/BaseMultiTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseMultiTag.java 2001/03/09 00:24:37 1.1
+++ BaseMultiTag.java 2001/03/09 01:33:37 1.2
@@ -59,22 +59,39 @@
package org.apache.taglibs.scopes;
+import javax.servlet.http.HttpServletRequest;
+
public abstract class BaseMultiTag extends BaseScopedTag {
- protected String _parameter = null;
- protected String _attribute = null;
- protected String _initParameter = null;
+ protected String _parameterName = null;
+ protected String _attributeName = null;
+ protected String _initParameterName = null;
public void setParameter(String parameter) {
- _parameter = parameter;
+ _parameterName = parameter;
}
public void setAttribute(String attribute) {
- _attribute = attribute;
+ _attributeName = attribute;
}
public void setInitParameter(String initParameter) {
- _initParameter = initParameter;
+ _initParameterName = initParameter;
+ }
+
+ protected String findInitParameter() {
+ return pageContext.getServletContext().getInitParameter(_initParameterName);
}
+ protected String findParameter() {
+ return
((HttpServletRequest)pageContext.getRequest()).getParameter(_parameterName);
+ }
+
+ protected Object findAttribute() {
+ if (_scopeSet == false) {
+ return pageContext.findAttribute(_attributeName);
+ } else {
+ return pageContext.getAttribute(_attributeName,_scope);
+ }
+ }
}
1.2 +6 -12
jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/ExistsTag.java
Index: ExistsTag.java
===================================================================
RCS file:
/home/cvs/jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/ExistsTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExistsTag.java 2001/03/09 00:24:41 1.1
+++ ExistsTag.java 2001/03/09 01:33:37 1.2
@@ -1,6 +1,5 @@
package org.apache.taglibs.scopes;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspTagException;
public class ExistsTag extends BaseMultiTag {
@@ -14,11 +13,11 @@
}
protected boolean exists() throws JspTagException {
- if (_parameter != null) {
+ if (_parameterName != null) {
return parameterExists();
- } else if (_attribute != null) {
+ } else if (_attributeName != null) {
return attributeExists();
- } else if (_initParameter != null) {
+ } else if (_initParameterName != null) {
return initParameterExists();
}
@@ -27,7 +26,7 @@
}
protected boolean initParameterExists() {
- if( pageContext.getServletContext().getInitParameter(_initParameter) != null ) {
+ if(findInitParameter() != null ) {
return true;
}
@@ -36,7 +35,7 @@
protected boolean parameterExists() {
// does the request parameter exist?
- String tmp =
((HttpServletRequest)pageContext.getRequest()).getParameter(_parameter);
+ String tmp = findParameter();
if ( tmp != null && tmp.length() > 0 ) {
return true;
}
@@ -46,12 +45,7 @@
protected boolean attributeExists() {
- Object o = null;
- if (_scopeSet == false) {
- o = pageContext.findAttribute(_attribute);
- } else {
- o = pageContext.getAttribute(_attribute,_scope);
- }
+ Object o = findAttribute();
if (o != null ) {
return true;
1.1
jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/EqualsTag.java
Index: EqualsTag.java
===================================================================
package org.apache.taglibs.scopes;
import javax.servlet.jsp.JspTagException;
public class EqualsTag extends BaseMultiTag {
protected String _match = null;
protected boolean _ignorecase = false;
public void setIgnoreCase(String str) {
_ignorecase = new Boolean(str).booleanValue();
}
public final void setMatch(String str) {
_match=str;
}
public int doStartTag() throws JspTagException {
if (equals()) {
return EVAL_BODY_INCLUDE;
}
return SKIP_BODY;
}
protected boolean equals() throws JspTagException {
if (_parameterName != null) {
return parameterEquals();
} else if (_attributeName != null) {
return attributeEquals();
} else if (_initParameterName != null) {
return initParameterEquals();
}
//must be an undefined attribute
throw new JspTagException();
}
protected boolean stringEqual(String value) {
if (value == null) {
return false;
}
if (_ignorecase) {
return value.equalsIgnoreCase(_match);
} else {
return value.equals(_match);
}
}
protected boolean parameterEquals() {
return stringEqual(findParameter());
}
protected boolean attributeEquals() {
return stringEqual(findAttribute().toString());
}
protected boolean initParameterEquals() {
return stringEqual(findInitParameter());
}
}
1.1
jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/NotEqualTag.java
Index: NotEqualTag.java
===================================================================
package org.apache.taglibs.scopes;
import javax.servlet.jsp.JspTagException;
public class NotEqualTag extends EqualsTag {
public int doStartTag() throws JspTagException {
if (equals() == false) {
return EVAL_BODY_INCLUDE;
}
return SKIP_BODY;
}
}
1.1
jakarta-taglibs/scopes/src/org/apache/taglibs/scopes/NotExistTag.java
Index: NotExistTag.java
===================================================================
package org.apache.taglibs.scopes;
import javax.servlet.jsp.JspTagException;
public class NotExistTag extends ExistsTag {
public int doStartTag() throws JspTagException {
if (exists() == false) {
return EVAL_BODY_INCLUDE;
}
return SKIP_BODY;
}
}