You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/07/14 01:50:50 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/logic PresentTag.java

dgraham     2003/07/13 16:50:50

  Modified:    src/share/org/apache/struts/taglib/logic PresentTag.java
  Log:
  Refactored condition() into smaller methods.
  
  Revision  Changes    Path
  1.15      +46 -28    jakarta-struts/src/share/org/apache/struts/taglib/logic/PresentTag.java
  
  Index: PresentTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/PresentTag.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PresentTag.java	24 Mar 2003 04:33:42 -0000	1.14
  +++ PresentTag.java	13 Jul 2003 23:50:50 -0000	1.15
  @@ -59,17 +59,16 @@
    *
    */
   
  -
   package org.apache.struts.taglib.logic;
   
  -
   import java.security.Principal;
   import java.util.StringTokenizer;
  +
   import javax.servlet.http.Cookie;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.jsp.JspException;
  -import org.apache.struts.util.RequestUtils;
   
  +import org.apache.struts.util.RequestUtils;
   
   /**
    * Evalute the nested body content of this tag if the specified value
  @@ -78,7 +77,6 @@
    * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    */
  -
   public class PresentTag extends ConditionalTagBase {
   
   
  @@ -118,32 +116,14 @@
           HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
           
           if (cookie != null) {
  -            Cookie cookies[] = request.getCookies();
  -            if (cookies != null) {
  -                for (int i = 0; i < cookies.length; i++) {
  -                    if (cookie.equals(cookies[i].getName())) {
  -                        present = true;
  -                        break;
  -                    }
  -                }
  -            }
  +            present = this.isCookiePresent(request);
               
           } else if (header != null) {
               String value = request.getHeader(header);
               present = (value != null);
               
           } else if (name != null) {
  -            Object value = null;
  -            try {
  -                if (property != null) {
  -                    value = RequestUtils.lookup(pageContext, name, property, scope);
  -                } else {
  -                    value = RequestUtils.lookup(pageContext, name, scope);
  -                }
  -            } catch (JspException e) {
  -                value = null;
  -            }
  -            present = (value != null);
  +            present = this.isBeanPresent();
               
           } else if (parameter != null) {
               String value = request.getParameter(parameter);
  @@ -168,6 +148,44 @@
   
           return (present == desired);
   
  +    }
  +
  +    /**
  +     * Returns true if the bean given in the <code>name</code> attribute is found.
  +     * @since Struts 1.2
  +     */
  +    protected boolean isBeanPresent() {
  +        Object value = null;
  +        try {
  +            if (this.property != null) {
  +                value = RequestUtils.lookup(pageContext, name, this.property, scope);
  +            } else {
  +                value = RequestUtils.lookup(pageContext, name, scope);
  +            }
  +        } catch (JspException e) {
  +            value = null;
  +        }
  +        
  +        return (value != null);
  +    }
  +
  +    /**
  +     * Returns true if the cookie is present in the request.
  +     * @since Struts 1.2
  +     */
  +    protected boolean isCookiePresent(HttpServletRequest request) {
  +        Cookie cookies[] = request.getCookies();
  +        if (cookies == null) {
  +            return false;
  +        }
  +        
  +        for (int i = 0; i < cookies.length; i++) {
  +            if (this.cookie.equals(cookies[i].getName())) {
  +                return true;
  +            }
  +        }
  +
  +        return false;
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org