1 18 package org.apache.beehive.netui.tags.databinding.repeater; 19 20 import java.io.IOException ; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspWriter ; 23 import javax.servlet.jsp.tagext.Tag ; 24 import javax.servlet.jsp.tagext.BodyContent ; 25 26 import org.apache.beehive.netui.tags.AbstractClassicTag; 27 import org.apache.beehive.netui.util.Bundle; 28 import org.apache.beehive.netui.util.logging.Logger; 29 30 38 public abstract class RepeaterComponent 39 extends AbstractClassicTag { 40 41 private static final Logger LOGGER = Logger.getInstance(RepeaterComponent.class); 42 43 private Repeater _repeater = null; 44 45 61 public int doStartTag() 62 throws JspException { 63 64 int ret = SKIP_BODY; 65 try { 66 Tag parent = getParent(); 67 Class validContainer = Repeater.class; 68 69 if((validContainer != null && parent == null) || 70 validContainer != null && !validContainer.isAssignableFrom(parent.getClass())) { 71 if(LOGGER.isErrorEnabled()) { 72 LOGGER.error("A tag of type \"" + getClass().getName() + "\" must be nested within a tag of type \"" + Repeater.class.getName() + "\""); 73 } 74 75 String msg = Bundle.getString("Tags_RepeaterComponent_invalidParent", new Object []{getClass().getName(), Repeater.class.getName()}); 76 registerTagError(msg, null); 77 } 78 79 if(LOGGER.isDebugEnabled()) 80 LOGGER.debug("verifyStructure: hasErrors=" + hasErrors()); 81 82 if(hasErrors()) { 83 reportErrors(); 84 return SKIP_BODY; 85 } 86 87 88 _repeater = (Repeater)getParent(); 89 90 verifyAttributes(); 91 92 _repeater.registerChildTag(this); 93 94 if(LOGGER.isDebugEnabled()) 95 LOGGER.debug("verifyAttributes: hasErrors=" + hasErrors()); 96 97 if(hasErrors()) { 98 reportErrors(); 99 return SKIP_BODY; 100 } 101 102 if(shouldRender()) 103 ret = EVAL_BODY_BUFFERED; 104 else 105 ret = SKIP_BODY; 106 } 107 catch(Exception e) { 108 String msg = Bundle.getString("Tags_RepeaterComponent_startTagError", new Object []{getTagName(), e}); 109 110 if(LOGGER.isErrorEnabled()) 111 LOGGER.error("An error occurred rendering the startTag of the tag \"" + getTagName() + "\". Cause: " + e, e); 112 113 registerTagError(msg, e); 114 reportErrors(); 115 ret = SKIP_BODY; 116 } 117 118 return ret; 119 } 120 121 126 public int doAfterBody() 127 throws JspException { 128 assert _repeater != null; 129 _repeater.addContent(bodyContent.getString()); 130 return SKIP_BODY; 131 } 132 133 141 public int doEndTag() 142 throws JspException { 143 147 if(hasErrors()) { 148 149 localRelease(); 150 return EVAL_PAGE; 151 } 152 153 int ret = EVAL_PAGE; 154 try { 155 int state = _repeater.getRenderState(); 156 ret = renderEndTag(state); 157 } 158 catch(Exception e) { 159 String msg = Bundle.getString("Tags_RepeaterComponent_endTagError", new Object []{getTagName(), e.toString()}); 160 registerTagError(msg, e); 161 reportErrors(); 162 ret = EVAL_PAGE; 163 } 164 165 localRelease(); 166 return ret; 167 } 168 169 174 protected final Repeater getRepeater() { 175 return _repeater; 176 } 177 178 181 protected void localRelease() { 182 super.localRelease(); 183 _repeater = null; 184 } 185 186 protected abstract boolean shouldRender(); 187 188 protected void verifyAttributes() 189 throws JspException { 190 } 191 192 protected int renderEndTag(int state) 193 throws JspException { 194 return EVAL_PAGE; 195 } 196 } 197 | Popular Tags |