commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka/jelly LatkaTagLibrary.java
Date Tue, 09 Jul 2002 17:22:40 GMT
dion        2002/07/09 10:22:40

  Modified:    latka/src/java/org/apache/commons/latka/jelly/validators
                        ValidatorTag.java ByteLengthTag.java
               latka/src/java/org/apache/commons/latka/jelly
                        LatkaTagLibrary.java
  Added:       latka/src/java/org/apache/commons/latka/jelly/validators
                        CookieTag.java
  Log:
  - Added Cookie Tag
  - Made ValidatorTag's default behaviour just to check for requestId
  
  Revision  Changes    Path
  1.2       +8 -5      jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/validators/ValidatorTag.java
  
  Index: ValidatorTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/validators/ValidatorTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatorTag.java	9 Jul 2002 11:27:34 -0000	1.1
  +++ ValidatorTag.java	9 Jul 2002 17:22:39 -0000	1.2
  @@ -62,6 +62,7 @@
   package org.apache.commons.latka.jelly.validators;
   
   import org.apache.commons.httpclient.HttpUrlMethod;
  +import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.latka.jelly.LatkaTag;
   
  @@ -87,7 +88,9 @@
        * @throws Exception when any error occurs
        */
       public void doTag(XMLOutput xmlOutput) throws Exception {
  -        invokeBody(xmlOutput);
  +        if (getRequestId() == null) {
  +            throw new MissingAttributeException("requestId not provided");
  +        }
       }
   
       /**
  
  
  
  1.2       +4 -3      jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/validators/ByteLengthTag.java
  
  Index: ByteLengthTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/validators/ByteLengthTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ByteLengthTag.java	9 Jul 2002 11:27:34 -0000	1.1
  +++ ByteLengthTag.java	9 Jul 2002 17:22:39 -0000	1.2
  @@ -88,6 +88,7 @@
        * @throws Exception when any error occurs
        */
       public void doTag(XMLOutput xmlOutput) throws Exception {
  +        super.doTag(xmlOutput);
           String text = getBodyText();
           HttpUrlMethod method = getRequest();
           long responseLength = method.getResponseBodyAsString().length();
  
  
  
  1.1                  jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/validators/CookieTag.java
  
  Index: CookieTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/validators/CookieTag.java,v
1.1 2002/07/09 17:22:39 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2002/07/09 17:22:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 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", "Commons", 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.commons.latka.jelly.validators;
  
  import org.apache.commons.httpclient.Header;
  import org.apache.commons.httpclient.HeaderElement;
  import org.apache.commons.httpclient.HttpUrlMethod;
  import org.apache.commons.httpclient.NameValuePair;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  
  /**
   * A class to validate that a response contains a cookie
   *
   * @author  dion
   * @version $Id: CookieTag.java,v 1.1 2002/07/09 17:22:39 dion Exp $
   */
  public class CookieTag extends ValidatorTag {
      
      /** name of the cookie */
      private String _name;
      /** value it must have (if null, the presence is all that's required */
      private String _value;
      
      /** Creates a new instance of CookieTag */
      public CookieTag() {
      }
  
      /**
       *  Check for a cookie held in shared state, if so, evaluate the body
       *
       * @param xmlOutput a place to write output
       * @throws Exception when any error occurs
       */
      public void doTag(XMLOutput xmlOutput) throws Exception {
          super.doTag(xmlOutput);
          if (getName() != null) {
              // check the Set-Cookie header is present
              Header cookieHeader = getRequest().getResponseHeader("Set-Cookie");
              if (cookieHeader != null) {
                  // get the elements of the set-cookie header and look for 
                  // one with the same name
                  HeaderElement[] elements = cookieHeader.getValues();
                  for (int index = 0; index < elements.length; index++) {
                      if (elements[index].getName().equals(getName())) {
                          if (getValue() == null ||
                              getValue().equals(elements[index].getValue())) {
                              return;
                          }
                      }
                  }
                  invokeBody(xmlOutput);
              }
          } else {
              throw new MissingAttributeException("name attribute not set");
          }
      }
    
      /** Getter for property name.
       * @return Value of property name.
       */
      public String getName() {
          return _name;
      }
      
      /** Setter for property name.
       * @param name New value of property name.
       */
      public void setName(String name) {
          _name = name;
      }
      
      /** Getter for property value.
       * @return Value of property value.
       */
      public String getValue() {
          return _value;
      }
      
      /** Setter for property value.
       * @param value New value of property value.
       */
      public void setValue(String value) {
          _value = value;
      }
      
  }
  
  
  
  1.14      +6 -4      jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/LatkaTagLibrary.java
  
  Index: LatkaTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/jelly/LatkaTagLibrary.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- LatkaTagLibrary.java	9 Jul 2002 11:27:34 -0000	1.13
  +++ LatkaTagLibrary.java	9 Jul 2002 17:22:40 -0000	1.14
  @@ -65,6 +65,7 @@
   
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.latka.jelly.validators.ByteLengthTag;
  +import org.apache.commons.latka.jelly.validators.CookieTag;
   
   /**
    * The set of jelly tags provided by Latka
  @@ -90,6 +91,7 @@
           registerTag("header", HeaderTag.class);
           registerTag("body", BodyTag.class);
           registerTag("bytelength", ByteLengthTag.class);
  +        registerTag("cookie", CookieTag.class);
       }
       
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message