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