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 java.io.File;
020    
021    import org.apache.commons.latka.Validator;
022    import org.apache.commons.latka.validators.GoldenFileValidator;
023    
024    import org.apache.log4j.Category;
025    
026    /**
027     * A class to compare an HTTP response to a golden
028     * file
029     * 
030     * @author Morgan Delagrange
031     * @version $Id: GoldenFileTag.java 155424 2005-02-26 13:09:29Z dirkv $
032     */
033    public class GoldenFileTag extends HttpValidatorTagSupport {
034        
035        protected String  _fileName = null;
036        protected boolean _ignoreWhitespace = false;
037    
038        protected static final Category _log = Category.getInstance(GoldenFileTag.class);
039    
040        /**
041         * return the golden file validator
042         * 
043         * @return golden file validator
044         */
045        public Validator getValidator() {
046            GoldenFileValidator validator =
047              new GoldenFileValidator(_label, new File(_fileName));
048            validator.setIgnoreWhitespace(_ignoreWhitespace);
049    
050            return validator;
051        }
052            
053        /**
054         * whether or not to ignore whitespace
055         * 
056         * @param ignoreWhitespace
057         *               whether or not to ignore whitespace
058         */
059        public void setIgnoreWhitespace(boolean ignoreWhitespace) {
060            _ignoreWhitespace = ignoreWhitespace;
061        }
062        
063        /**
064         * set the file name for the golden file
065         * 
066         * @param fileName golden file name
067         */
068        public void setFileName(String fileName) {
069            _fileName = fileName;
070        }
071        
072    }