1 package fr.improve.struts.taglib.layout.layer; 2 3 import javax.servlet.jsp.JspException ; 4 5 import org.apache.struts.taglib.html.Constants; 6 import org.apache.struts.util.MessageResources; 7 8 import fr.improve.struts.taglib.layout.LayoutTag; 9 import fr.improve.struts.taglib.layout.LayoutTagSupport; 10 import fr.improve.struts.taglib.layout.el.Expression; 11 import fr.improve.struts.taglib.layout.event.EndLayoutEvent; 12 import fr.improve.struts.taglib.layout.event.StartLayoutEvent; 13 import fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent; 14 import fr.improve.struts.taglib.layout.formatter.FormatException; 15 import fr.improve.struts.taglib.layout.util.FormUtilsInterface; 16 import fr.improve.struts.taglib.layout.util.LayoutUtils; 17 import fr.improve.struts.taglib.layout.util.TagUtils; 18 19 public class LayerTag extends LayoutTagSupport implements LayoutTag { 20 21 24 protected static MessageResources messages = MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); 25 26 29 protected String name = null; 30 protected String jspName = null; 31 protected String styleClass = null; 32 protected String jspStyleclass = null; 33 protected String type; 34 35 protected StringBuffer results; 36 37 38 41 public String getStyleClass() { 42 return styleClass; 43 } 44 47 public void setStyleClass(String styleClass) { 48 this.styleClass = styleClass; 49 } 50 51 52 public String getName() { 53 return (this.name); 54 } 55 56 public void setName(String name) { 57 this.name = name; 58 } 59 60 63 protected String property = null; 64 65 public String getProperty() { 66 return (this.property); 67 } 68 69 public void setProperty(String property) { 70 this.property = property; 71 } 72 73 74 77 protected void initDynamicValues() { 78 jspStyleclass = styleClass; 79 if (styleClass==null){ 80 styleClass = LayoutUtils.getSkin(pageContext.getSession()).getProperty("styleclass.layer",null); 81 } 82 jspName = name; 83 name = Expression.evaluate(name,pageContext); 84 super.initDynamicValues(); 85 } 86 87 93 public int doStartLayoutTag() throws JspException { 94 Integer i = (Integer )pageContext.getRequest().getAttribute("layerId"); 95 if (i==null){ 96 i = new Integer (100); 97 } 98 i = new Integer (i.intValue()+1); 99 pageContext.getRequest().setAttribute("layerId",i); 100 101 results = new StringBuffer ("<DIV id='layer" + String.valueOf(i)+ "' style='position:absolute;top:0;left:0;visibility:hidden'>"); 102 results.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" "); 103 if (getStyleClass()!=null && getStyleClass().length()>0){ 104 results.append(" class=\""+ getStyleClass() +"\""); 105 } 106 results.append(">"); 107 results.append("<tr>"); 108 results.append("<td valign=top"); 109 if (getStyleClass()!=null && getStyleClass().length()>0){ 110 results.append(" class=\""+ getStyleClass() +"\""); 111 } 112 results.append(">"); 113 return (EVAL_BODY_INCLUDE); 115 } 116 117 123 public int doEndLayoutTag() throws JspException { 124 Integer i = (Integer )pageContext.getRequest().getAttribute("layerId"); 125 126 results.append("</td>"); 127 results.append("</tr>"); 128 results.append("</table></DIV>"); 129 TagUtils.write(pageContext, new StaticCodeIncludeLayoutEvent(this, results.toString()).send().toString()); 130 131 TagUtils.write(pageContext, "<a HREF=\"#\""); 132 TagUtils.write(pageContext, " onmouseover=\"showLayoutLayer('layer" + String.valueOf(i)+ "',event);\""); 133 TagUtils.write(pageContext, " onmouseout=\"hideLayoutLayer('layer" + String.valueOf(i)+ "');\">"); 134 135 Object lc_value = LayoutUtils.getBeanFromPageContext(pageContext, name,property); 136 if (type!=null) try { 137 lc_value = LayoutUtils.getSkin(pageContext.getSession()).getFormatter().format(lc_value, type, pageContext); 138 } catch (FormatException e) { 139 throw new JspException ("Format " + type + " failed: " + e.getMessage()); 140 } 141 TagUtils.write(pageContext, lc_value==null ? "" : lc_value.toString()); 142 TagUtils.write(pageContext, "</a>"); 143 return (EVAL_PAGE); 144 145 } 146 147 public void addContent(String in_content) { 148 results.append(in_content); 149 } 150 151 protected void reset() { 152 showLink = true; 153 name = jspName; 154 jspName = null; 155 styleClass = jspStyleclass; 156 jspStyleclass = null; 157 } 158 159 162 protected void beginLinkLayout(StringBuffer in_buffer) throws JspException { 163 in_buffer.append("<td> </td><td"); 164 in_buffer.append(">"); 170 } 171 172 175 protected void endLinkLayout(StringBuffer in_buffer) { 176 in_buffer.append("</td>"); 177 } 178 179 182 public void release() { 183 184 super.release(); 185 name = null; 186 property = null; 187 policy = null; 188 display = true; 189 type = null; 190 } 191 192 protected boolean display = true; 193 194 protected boolean showLink = true; 195 196 protected String policy = null; 197 198 203 public void setMode(String in_mode) { 204 if (in_mode == null || in_mode.length() != 5) { 205 throw new IllegalArgumentException ("The specified mode" + in_mode 206 + " is invalid"); 207 } 208 int lc_formMode = LayoutUtils.getSkin(pageContext.getSession()) 209 .getFormUtils().getFormDisplayMode(pageContext); 210 char lc_displayMode; 211 switch (lc_formMode) { 212 case FormUtilsInterface.CREATE_MODE: 213 lc_displayMode = in_mode.charAt(0); 214 break; 215 case FormUtilsInterface.EDIT_MODE: 216 lc_displayMode = in_mode.charAt(2); 217 break; 218 case FormUtilsInterface.INSPECT_MODE: 219 lc_displayMode = in_mode.charAt(4); 220 break; 221 default: 222 lc_displayMode = 'D'; 223 } 224 display = lc_displayMode == 'D' || lc_displayMode == 'd'; 225 } 226 227 230 public String getPolicy() { 231 return policy; 232 } 233 234 238 public void setPolicy(String policy) { 239 this.policy = policy; 240 } 241 242 public Object processEndLayoutEvent(EndLayoutEvent in_event) 243 throws JspException { 244 return Boolean.FALSE; 245 } 246 247 public Object processStartLayoutEvent(StartLayoutEvent in_event) 248 throws JspException { 249 return Boolean.FALSE; 250 } 251 252 public String getType() { 253 return type; 254 } 255 public void setType(String type) { 256 this.type = type; 257 } 258 } | Popular Tags |