1 package fr.improve.struts.taglib.layout; 2 3 import javax.servlet.jsp.JspException ; 4 5 import fr.improve.struts.taglib.layout.el.Expression; 6 import fr.improve.struts.taglib.layout.event.EndLayoutEvent; 7 import fr.improve.struts.taglib.layout.event.LayoutEventListener; 8 import fr.improve.struts.taglib.layout.event.StartLayoutEvent; 9 import fr.improve.struts.taglib.layout.field.AbstractModeFieldTag; 10 import fr.improve.struts.taglib.layout.policy.AbstractPolicy; 11 import fr.improve.struts.taglib.layout.skin.Skin; 12 import fr.improve.struts.taglib.layout.util.FormUtils; 13 import fr.improve.struts.taglib.layout.util.LayoutUtils; 14 import fr.improve.struts.taglib.layout.util.ParentFinder; 15 import fr.improve.struts.taglib.layout.util.TagUtils; 16 17 25 public abstract class ActionTag extends BaseHandlerTag implements LayoutEventListener { 26 27 protected String property; 28 protected boolean display = true; 29 protected String valign; 30 private String mode; 31 protected String policy = null; 32 protected boolean cell = false; 33 34 protected String jspMode; 35 protected boolean jspDisabled; 36 protected String jspOnclick; 37 38 public final int doStartTag() throws JspException { 39 ParentFinder.registerTag(pageContext, this); 40 initDynamicValues(); 41 return doStartLayoutTag(); 42 } 43 44 public final int doEndTag() throws JspException { 45 try { 46 return doEndLayoutTag(); 47 } finally { 48 reset(); 49 ParentFinder.deregisterTag(pageContext); 50 } 51 } 52 53 56 public int doEndLayoutTag() throws JspException { 57 if (!display) { 59 display = true; 60 return EVAL_PAGE; 61 } 62 63 if (cell) { 64 cell = false; 65 return EVAL_PAGE; 66 } 67 68 int ret = tag.doEndTag(); 70 71 StringBuffer lc_buffer = new StringBuffer (""); 73 endActionLayout(lc_buffer); 74 new EndLayoutEvent(this, lc_buffer.toString()).send(); 75 return ret; 76 } 77 78 81 public int doStartLayoutTag() throws JspException { 82 if (policy != null) { 84 Skin lc_currentSkin = LayoutUtils.getSkin(getPageContext().getSession()); 85 AbstractPolicy lc_policy = lc_currentSkin.getPolicy(); 86 switch (lc_policy.getAuthorizedDisplayMode(getPolicy(), getReqCode(), getProperty(), getPageContext())) { 87 case AbstractPolicy.MODE_EDIT: 88 break; 89 case AbstractPolicy.MODE_NODISPLAY: 90 display = false; 91 break; 92 case AbstractPolicy.MODE_DISABLED: 93 display = true; 94 setDisabled(true); 95 break; 96 case AbstractPolicy.MODE_CELL: 97 cell = true; 98 break; 99 default: 100 throw new IllegalStateException (lc_policy.getClass().getName() + " returns an illegal value"); 101 } 102 } 103 104 if (!display) { 106 return SKIP_BODY; 107 } 108 109 if (cell) { 111 return doCellMode(); 112 } 113 114 StringBuffer lc_buffer = new StringBuffer (""); 116 beginActionLayout(lc_buffer); 117 new StartLayoutEvent(this, lc_buffer.toString()).send(); 118 119 copyProperties(); 121 String onclick = null; 122 if (reqCode != null) { 123 onclick = getRequestCode(); 124 } 125 if (onclick!=null) { 126 String previousOnclick = getOnclick(); 127 if (previousOnclick != null) 128 onclick += ";" + previousOnclick; 129 130 tag.setOnclick(onclick); 131 } 132 return tag.doStartTag(); 133 } 134 135 138 protected int doCellMode() throws JspException { 139 new StartLayoutEvent(this, null).send(); 140 TagUtils.write(pageContext, "<th colspan=\""); 141 TagUtils.write(pageContext, String.valueOf(LayoutUtils.getSkin(pageContext.getSession()).getFieldInterface().getColumnNumber())); 142 if (getStyleClass()!=null) { 143 TagUtils.write(pageContext, "\" class=\""); 144 TagUtils.write(pageContext, getStyleClass()); 145 } 146 TagUtils.write(pageContext, "\"> </th>"); 147 new EndLayoutEvent(this, null).send(); 148 return SKIP_BODY; 149 } 150 151 152 156 public void setMode(String in_mode) { 157 mode = in_mode; 158 } 159 160 public String getProperty() { 161 return property; 162 } 163 164 167 protected void initDynamicValues() { 168 jspMode = mode; 170 mode = Expression.evaluate(mode, pageContext); 171 172 jspDisabled = getDisabled(); 174 if (mode!=null) { 175 int lc_visible = FormUtils.computeVisibilityMode(pageContext, mode); 176 switch(lc_visible) { 177 case AbstractModeFieldTag.MODE_EDIT: 178 display = true; 179 break; 180 case AbstractModeFieldTag.MODE_NODISPLAY: 181 display = false; 182 break; 183 case AbstractModeFieldTag.MODE_DISABLED: 184 display = true; 185 setDisabled(true); 186 break; 187 case AbstractModeFieldTag.MODE_CELL: 188 cell = true; 189 break; 190 } 191 } 192 193 jspOnclick = getOnclick(); 195 setOnclick(Expression.evaluate(jspOnclick, pageContext)); 196 } 197 198 201 protected void reset() { 202 mode = jspMode; 203 jspMode = null; 204 setDisabled(jspDisabled); 205 display = true; 206 cell = false; 207 208 setOnclick(jspOnclick); 209 jspOnclick = null; 210 } 211 212 public void release() { 213 super.release(); 214 tag.release(); 215 policy = null; 216 property = null; 217 valign = null; 218 mode = null; 219 } 220 221 224 protected void beginActionLayout(StringBuffer in_buffer) throws JspException { 225 in_buffer.append("<td> </td><td"); 226 if (valign!=null) { 227 in_buffer.append(" valign=\""); 228 in_buffer.append(valign); 229 in_buffer.append("\""); 230 } 231 in_buffer.append(">"); 232 } 233 234 237 protected void endActionLayout(StringBuffer in_buffer) { 238 in_buffer.append("</td>"); 239 } 240 241 public void setProperty(String property) { 242 this.property = property; 243 } 244 248 public void setValign(String valign) { 249 this.valign = valign; 250 } 251 252 255 public Object processEndLayoutEvent(EndLayoutEvent in_event) throws JspException { 256 return Boolean.FALSE; 257 } 258 259 262 public Object processStartLayoutEvent(StartLayoutEvent in_event) throws JspException { 263 return Boolean.FALSE; 264 } 265 266 269 public String getPolicy() 270 { 271 return policy; 272 } 273 276 public void setPolicy(String policy) 277 { 278 this.policy = policy; 279 } 280 281 protected void copyProperties() throws JspException { 282 LayoutUtils.copyProperties(tag, this); 283 } 284 285 } | Popular Tags |