1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import com.jcorporate.expresso.core.controller.ControllerResponse; 68 import com.jcorporate.expresso.core.controller.ErrorCollection; 69 import com.jcorporate.expresso.core.i18n.Messages; 70 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 71 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 72 import org.apache.struts.action.ActionMessage; 73 74 import javax.servlet.http.HttpServletRequest ; 75 import javax.servlet.jsp.JspTagException ; 76 import javax.servlet.jsp.JspWriter ; 77 import javax.servlet.jsp.PageContext ; 78 import java.util.Iterator ; 79 80 81 90 public class ErrorTag 91 extends ExpressoTagSupport { 92 private ErrorCollection errorCollection = null; 93 private String name = null; 94 private String property = null; 95 private String nameToUse = null; 96 private String cssClass = null; 97 98 101 public ErrorTag() { 102 super(); 103 } 104 105 110 public int doEndTag() 111 throws javax.servlet.jsp.JspTagException { 112 nameToUse = name; 113 114 try { 115 if (nameToUse == null) { 116 nameToUse = ErrorCollection.ERRORCOLLECTIONKEY; } 118 119 errorCollection = (ErrorCollection) pageContext.getAttribute(nameToUse, PageContext.REQUEST_SCOPE); 120 121 ControllerResponse myResponse = ControllerUtils.getResponse(pageContext); 122 123 if (errorCollection != null) { 124 FastStringBuffer fsb = FastStringBuffer.getInstance(); 125 try { 126 if (errorCollection.getErrorCount() > 0) { 127 128 JspWriter writer = pageContext.getOut(); 130 try { 131 fsb.append(myResponse.getString("errors.header")); 132 } catch (java.lang.IllegalArgumentException ex) { 133 fsb.append(Messages.getString(com.jcorporate.expresso.core.ExpressoSchema.class.getName(), 136 (HttpServletRequest ) pageContext.getRequest(), 137 "errors.header", new Object []{})); 138 } 139 141 ActionMessage oneError = null; 142 Iterator iter = null; 143 144 if (property == null) { 145 iter = errorCollection.get(); 146 } else { 147 iter = errorCollection.get(property); 148 } 149 while (iter.hasNext()) { 150 oneError = (ActionMessage) iter.next(); 151 fsb.append(" <li>"); 152 if (cssClass != null) { 153 fsb.append("<span class="); 154 fsb.append(cssClass); 155 fsb.append(">"); 156 } 157 fsb.append(myResponse.getString(oneError.getKey(), oneError.getValues())); 158 if (cssClass != null) { 159 fsb.append("</span>"); 160 } 161 fsb.append("</li>\n"); 162 } 164 165 try { 166 String footer = myResponse.getString("errors.footer"); 167 if (footer != null && footer.length() > 0) { 168 fsb.append(footer); 169 fsb.append("\n"); 170 } 171 } catch (java.lang.IllegalArgumentException ex) { 172 String footer = Messages.getString( 175 com.jcorporate.expresso.core.ExpressoSchema.class.getName(), 176 (HttpServletRequest ) pageContext.getRequest(), 177 "errors.footer", new Object []{}); 178 if (footer != null && footer.length() > 0) { 179 fsb.append(footer); 180 fsb.append("\n"); 181 } 182 } 183 writer.print(fsb.toString()); 184 } 185 } finally { 186 fsb.release(); 187 } 188 } 189 } catch (Exception e) { 190 throw new JspTagException ("ErrorTag: " + e.getMessage()); 191 } 192 193 return EVAL_PAGE; 194 } 195 196 197 204 public int doStartTag() 205 throws javax.servlet.jsp.JspTagException { 206 return SKIP_BODY; 207 } 208 209 210 215 public String getName() { 216 return nameToUse; 217 } 218 219 220 public String getProperty() { 221 return property; 222 } 223 224 230 public void setName(java.lang.String newName) { 231 name = newName; 232 } 233 234 235 public void setProperty(String newProperty) { 236 property = newProperty; 237 } 238 239 public void setClass(String newClass) { 240 cssClass = newClass; 241 } 242 243 } 244 | Popular Tags |