1 64 65 package com.jcorporate.expresso.ext.struts.taglib.html; 66 67 import com.jcorporate.expresso.core.controller.ControllerElement; 68 import com.jcorporate.expresso.core.controller.Transition; 69 import com.jcorporate.expresso.core.misc.StringUtil; 70 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 71 import org.apache.struts.taglib.html.Constants; 72 import org.apache.struts.taglib.html.ImageTag; 73 import org.apache.struts.util.ResponseUtils; 74 75 import javax.servlet.http.HttpServletResponse ; 76 import javax.servlet.jsp.JspException ; 77 import java.util.Hashtable ; 78 79 80 85 public class ExImageTag 86 extends ImageTag { 87 protected String name = null; 88 89 90 public String getName() { 91 return (this.name); 92 } 93 94 public void setName(String name) { 95 this.name = name; 96 } 97 98 104 public int doStartTag() 105 throws JspException { 106 Transition myTransition = null; 107 String nameToUse = name; 108 String propertyToUse = property; 109 110 if (StringUtil.notNull(nameToUse).equals(Constants.BEAN_KEY)) { 111 nameToUse = null; 112 } 113 if (nameToUse == null) { 114 myTransition = ControllerUtils.findTransition(pageContext, 115 propertyToUse); 116 } else { 117 ControllerElement ce = ControllerUtils.findElement(pageContext, 118 nameToUse, 119 propertyToUse); 120 121 if (ce instanceof Transition) { 122 myTransition = (Transition) ce; 123 } else { 124 throw new JspException ("Element '" + propertyToUse + 125 "' in bean '" + nameToUse + 126 "' is not a transition element - it is a '" + 127 ce.getClass().getName() + "'"); 128 } 129 } 130 131 Hashtable params = myTransition.getParams(); 132 133 if (params != null) { 134 135 ResponseUtils.write(pageContext, 137 myTransition.getHTMLParamString() + "\n"); 138 } 139 140 this.text = null; 141 142 return (EVAL_BODY_BUFFERED); 144 } 145 146 152 public int doEndTag() 153 throws JspException { 154 Transition myTransition = null; 155 String nameToUse = name; 156 String propertyToUse = property; 157 158 if (nameToUse == null) { 159 myTransition = ControllerUtils.findTransition(pageContext, 160 propertyToUse); 161 } else { 162 ControllerElement ce = ControllerUtils.findElement(pageContext, 163 nameToUse, 164 propertyToUse); 165 166 if (ce instanceof Transition) { 167 myTransition = (Transition) ce; 168 } else { 169 throw new JspException ("Element '" + propertyToUse + 170 "' in bean '" + nameToUse + 171 "' is not a transition element - it is a '" + 172 ce.getClass().getName() + "'"); 173 } 174 } 175 176 HttpServletResponse response = (HttpServletResponse ) pageContext.getResponse(); 178 String tmp = null; 179 StringBuffer results = new StringBuffer (); 180 results.append("<input type=\"image\" name=\"button_"); 181 results.append(myTransition.getName()); 182 results.append("\""); 183 tmp = src(); 184 185 if (tmp != null) { 186 results.append(" SRC=\""); 187 results.append(response.encodeURL(tmp)); 188 results.append("\""); 189 } 190 191 tmp = null; 193 194 if (tmp != null) { 195 results.append(" alt=\""); 196 results.append(tmp); 197 results.append("\""); 198 } 199 if (border != null) { 200 results.append(" border=\""); 201 results.append(border); 202 results.append("\""); 203 } 204 if (value != null) { 205 results.append(" value=\""); 206 results.append(value); 207 results.append("\""); 208 } 209 if (accesskey != null) { 210 results.append(" accesskey=\""); 211 results.append(accesskey); 212 results.append("\""); 213 } 214 if (tabindex != null) { 215 results.append(" tabindex=\""); 216 results.append(tabindex); 217 results.append("\""); 218 } 219 220 results.append(prepareEventHandlers()); 221 results.append(prepareStyles()); 222 results.append(">"); 223 224 ResponseUtils.write(pageContext, results.toString()); 226 227 return (EVAL_PAGE); 229 } 230 } 231 | Popular Tags |