001 /* 002 * Copyright 1999-2001,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.latka.jelly.validators; 018 019 import org.apache.commons.latka.Validator; 020 import org.apache.commons.latka.validators.CookieValidator; 021 022 import org.apache.log4j.Category; 023 024 /** 025 * A class to check for the existence and value of cookies 026 * 027 * @author Morgan Delagrange 028 * @version $Id: CookieTag.java 155424 2005-02-26 13:09:29Z dirkv $ 029 */ 030 public class CookieTag extends HttpValidatorTagSupport { 031 032 protected boolean _cond = true; 033 protected String _name = null; 034 protected String _value = null; 035 036 protected static final Category _log = Category.getInstance(CookieTag.class); 037 038 public Validator getValidator() { 039 CookieValidator validator = 040 new CookieValidator(_label); 041 042 if (_name != null) { 043 validator.setCookieName(_name); 044 } 045 if (_value != null) { 046 validator.setCookieValue(_value); 047 } 048 049 validator.setCondition(_cond); 050 051 return validator; 052 } 053 054 /** 055 * Setter the cookie name. 056 * 057 * @param name cookie name to look for 058 */ 059 public void setName(String name) { 060 _name = name; 061 } 062 063 /** 064 * Set the cookie value 065 * 066 * @param value cookie value 067 */ 068 public void setValue(String value) { 069 _value = value; 070 } 071 072 /** 073 * sets whether or not this cookie is expected 074 * 075 * @param cond true if the cookie is epected, false otherwise 076 */ 077 public void setCond(boolean cond) { 078 _cond = cond; 079 } 080 081 }