001    package railo.runtime.ext.tag;
002    
003    import javax.servlet.jsp.JspException;
004    import javax.servlet.jsp.tagext.Tag;
005    
006    import railo.commons.lang.StringUtil;
007    import railo.runtime.PageContext;
008    import railo.runtime.PageContextImpl;
009    import railo.runtime.exp.ApplicationException;
010    
011    /**
012     * Implementation of the Tag
013     */
014    public abstract class TagImpl implements Tag {
015    
016            protected PageContext pageContext; 
017            private Tag parent;
018               
019            /**
020             * sets a Railo PageContext
021             * @param pageContext
022             */
023            public void setPageContext(PageContextImpl pageContext) {
024                    this.pageContext=pageContext;
025            }
026            @Override
027            public void setPageContext(javax.servlet.jsp.PageContext pageContext) {
028                    this.pageContext=(PageContext) pageContext;
029            }
030    
031            @Override
032            public void setParent(Tag parent) {
033            this.parent=parent;
034            }
035    
036            @Override
037            public Tag getParent() {
038            return parent;
039            }
040    
041            @Override
042            public int doStartTag() throws JspException {
043                    return SKIP_BODY;
044            }
045    
046            @Override
047            public int doEndTag() throws JspException {
048                    return EVAL_PAGE;
049            }
050    
051            @Override
052            public void release() {
053                    pageContext=null;
054                    parent=null;
055            }    
056            
057            /**
058             * check if value is not empty
059             * @param tagName
060             * @param attributeName
061             * @param attribute
062             * @throws ApplicationException
063             */
064            public void required(String tagName, String actionName, String attributeName, Object attribute) throws ApplicationException {
065                if(attribute==null)
066                    throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
067        
068            }
069            public void required(String tagName, String attributeName, Object attribute) throws ApplicationException {
070                if(attribute==null)
071                    throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required");
072        
073            }
074            
075            public void required(String tagName, String actionName, String attributeName, String attribute,boolean trim) throws ApplicationException {
076                if(StringUtil.isEmpty(attribute,trim))
077                    throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
078        }
079            
080            public void required(String tagName, String actionName, String attributeName, double attributeValue, double nullValue) throws ApplicationException {
081                if(attributeValue==nullValue)
082                    throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
083        }
084            
085            
086            
087    }