dgraham     2003/03/23 20:19:21

  Modified:    src/share/org/apache/struts/taglib/logic PresentTag.java
  Log:
  Simplified code, added if braces.
  
  Revision  Changes    Path
  1.13      +22 -25    
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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PresentTag.java   23 Sep 2002 05:22:08 -0000      1.12
  +++ PresentTag.java   24 Mar 2003 04:19:21 -0000      1.13
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -113,32 +113,31 @@
        * @exception JspException if a JSP exception occurs
        */
       protected boolean condition(boolean desired) throws JspException {
  -
           // Evaluate the presence of the specified value
           boolean present = false;
  +        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
  +        
           if (cookie != null) {
  -            Cookie cookies[] =
  -                ((HttpServletRequest) pageContext.getRequest()).
  -                getCookies();
  -            if (cookies == null)
  +            Cookie cookies[] = request.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);
  +            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);
  +                    value = RequestUtils.lookup(pageContext, name, property, scope);
                   } else {
                       value = RequestUtils.lookup(pageContext, name, scope);
                   }
  @@ -146,23 +145,21 @@
                   value = null;
               }
               present = (value != null);
  +            
           } else if (parameter != null) {
  -            String value =
  -                pageContext.getRequest().getParameter(parameter);
  +            String value = request.getParameter(parameter);
               present = (value != null);
  +            
           } else if (role != null) {
  -            HttpServletRequest request = (HttpServletRequest)
  -                                                       pageContext.getRequest();
               StringTokenizer st = new StringTokenizer(role, ROLE_DELIMITER, false);
  -            while(!present && st.hasMoreTokens()){
  -             present = request.isUserInRole(st.nextToken());
  +            while (!present && st.hasMoreTokens()) {
  +                present = request.isUserInRole(st.nextToken());
               }
  +            
           } else if (user != null) {
  -            HttpServletRequest request =
  -                (HttpServletRequest) pageContext.getRequest();
               Principal principal = request.getUserPrincipal();
  -            present = (principal != null) &&
  -                user.equals(principal.getName());
  +            present = (principal != null) && user.equals(principal.getName());
  +            
           } else {
               JspException e = new JspException
                   (messages.getMessage("logic.selector"));
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to