001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.tag;
020
021import lucee.runtime.exp.ApplicationException;
022import lucee.runtime.exp.PageException;
023import lucee.runtime.ext.tag.TagImpl;
024
025/**
026* Tests for a parameter's existence, tests its data type, and provides a default value if one 
027*   is not assigned.
028*
029*
030*
031**/
032public final class Param extends TagImpl {
033
034        /** The type of parameter that is required. The default is 'any'. */
035        private String type="any";
036
037        /** Default value to set the parameter to if it does not exist. */
038        private Object _default;
039
040        /** The name of the parameter to test, such as Client.Email or Cookie.BackgroundColor. If 
041        **              you omit the DEFAULT attribute, an error occurs if the specified parameter does not exist */
042        private String name;
043
044        private double min;
045        private double max;
046        private String pattern;
047        
048        @Override
049        public void release()   {
050                super.release();
051                type="any";
052                _default=null;
053                name=null;
054                
055                min=-1;
056                max=-1;
057                pattern=null;
058        }
059        
060        public Param() throws ApplicationException {
061                throw new ApplicationException("this Tag Implemenation is deprecated and replaced with a Translation Time Transformer");
062        }
063
064
065
066        /** set the value type
067        *  The type of parameter that is required. The default is 'any'.
068        * @param type value to set
069        **/
070        public void setType(String type)        {
071                this.type=type.trim().toLowerCase();
072        }
073
074        /** set the value default
075        *  Default value to set the parameter to if it does not exist.
076        * @param _default value to set
077        **/
078        public void setDefault(Object _default) {
079                this._default=_default;
080        }
081
082        /**
083         * @param max the max to set
084         */
085        public void setMax(double max) {
086                this.max = max;
087        }
088
089        /**
090         * @param min the min to set
091         */
092        public void setMin(double min) {
093                this.min = min;
094        }
095
096        /**
097         * @param pattern the pattern to set
098         */
099        public void setPattern(String pattern) {
100                this.pattern = pattern;
101        }
102
103        /** set the value name
104        *  The name of the parameter to test, such as Client.Email or Cookie.BackgroundColor. If 
105        *               you omit the DEFAULT attribute, an error occurs if the specified parameter does not exist
106        * @param name value to set
107        **/
108        public void setName(String name)        {
109                this.name=name;
110        }
111
112
113        @Override
114        public int doStartTag() throws PageException    {
115                if("range".equals(type))
116                        pageContext.param(type, name, _default,min,max);
117                else if("regex".equals(type) || "regular_expression".equals(type))
118                        pageContext.param(type, name, _default,pattern);
119                else 
120                        pageContext.param(type, name, _default);
121                return SKIP_BODY;
122        }
123        
124}