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