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.ext.tag;
020
021import javax.servlet.jsp.JspException;
022import javax.servlet.jsp.tagext.Tag;
023
024import lucee.commons.lang.StringUtil;
025import lucee.runtime.PageContext;
026import lucee.runtime.PageContextImpl;
027import lucee.runtime.exp.ApplicationException;
028
029/**
030 * Implementation of the Tag
031 */
032public abstract class TagImpl implements Tag {
033
034        protected PageContext pageContext; 
035        private Tag parent;
036           
037        /**
038         * sets a Lucee PageContext
039         * @param pageContext
040         */
041        public void setPageContext(PageContextImpl pageContext) {
042                this.pageContext=pageContext;
043        }
044        @Override
045        public void setPageContext(javax.servlet.jsp.PageContext pageContext) {
046                this.pageContext=(PageContext) pageContext;
047        }
048
049        @Override
050        public void setParent(Tag parent) {
051        this.parent=parent;
052        }
053
054        @Override
055        public Tag getParent() {
056        return parent;
057        }
058
059        @Override
060        public int doStartTag() throws JspException {
061                return SKIP_BODY;
062        }
063
064        @Override
065        public int doEndTag() throws JspException {
066                return EVAL_PAGE;
067        }
068
069        @Override
070        public void release() {
071                pageContext=null;
072                parent=null;
073        }    
074        
075        /**
076         * check if value is not empty
077         * @param tagName
078         * @param attributeName
079         * @param attribute
080         * @throws ApplicationException
081         */
082        public void required(String tagName, String actionName, String attributeName, Object attribute) throws ApplicationException {
083            if(attribute==null)
084                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
085    
086        }
087        public void required(String tagName, String attributeName, Object attribute) throws ApplicationException {
088            if(attribute==null)
089                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required");
090    
091        }
092        
093        public void required(String tagName, String actionName, String attributeName, String attribute,boolean trim) throws ApplicationException {
094            if(StringUtil.isEmpty(attribute,trim))
095                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
096    }
097        
098        public void required(String tagName, String actionName, String attributeName, double attributeValue, double nullValue) throws ApplicationException {
099            if(attributeValue==nullValue)
100                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
101    }
102        
103        
104        
105}