1 64 package com.jcorporate.expresso.ext.taglib; 65 66 import com.jcorporate.expresso.core.controller.ControllerResponse; 67 import com.jcorporate.expresso.core.controller.ErrorCollection; 68 import com.jcorporate.expresso.core.i18n.Messages; 69 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 70 import org.apache.struts.action.ActionError; 71 72 import javax.servlet.http.HttpServletRequest ; 73 import javax.servlet.jsp.JspTagException ; 74 import javax.servlet.jsp.JspWriter ; 75 import javax.servlet.jsp.PageContext ; 76 import java.util.Iterator ; 77 import java.util.Locale ; 78 import java.util.Stack ; 79 80 81 88 public class ErrorMessageBundleTag extends ExpressoTagSupport { 89 90 93 public ErrorMessageBundleTag() { 94 super(); 95 } 96 97 private ErrorCollection errorCollection = null; 98 private String name = null; 99 100 private String nameToUse = null; 101 102 105 106 107 112 public void setName(java.lang.String newName) { 113 name = newName; 114 } 115 116 119 120 125 public String getName() { 126 return nameToUse; 127 } 128 129 132 133 140 public int doEndTag() 141 throws javax.servlet.jsp.JspTagException { 142 143 nameToUse = name; 144 145 try { 146 if (nameToUse == null) { 147 nameToUse = ErrorCollection.ERRORCOLLECTIONKEY; 148 } 150 errorCollection = (ErrorCollection) pageContext.getAttribute(nameToUse, PageContext.REQUEST_SCOPE); 151 152 if (errorCollection == null) { 153 errorCollection = (ErrorCollection) pageContext.getAttribute(nameToUse, PageContext.SESSION_SCOPE); 154 } 155 156 ControllerResponse myResponse = 157 ControllerUtils.getResponse(pageContext); 158 159 Locale locale = (Locale ) pageContext.getAttribute(Messages.LOCALE_KEY, 160 PageContext.SESSION_SCOPE); 161 162 if (errorCollection != null) { 163 if (errorCollection.getErrorCount() > 0) { 164 JspWriter writer = pageContext.getOut(); 166 167 try { 170 writer.println(myResponse.getString("errors.header")); 171 } catch (java.lang.IllegalArgumentException ex) { 172 writer.println(Messages.getString(com.jcorporate.expresso.core.ExpressoSchema.class.getName(), 175 (HttpServletRequest ) pageContext.getRequest(), 176 "errors.header", new Object []{})); 177 } 178 ActionError oneError = null; 179 180 Iterator iter = iter = errorCollection.get(); 181 182 while (iter.hasNext()) { 183 oneError = (ActionError) iter.next(); 184 try { 185 Stack s = myResponse.getSchemaStack(); 186 187 writer.println(Messages.getString(s, locale, "errors.item.header", null)); 188 writer.println(Messages.getString(s, locale, oneError.getKey(), oneError.getValues())); 189 writer.println(Messages.getString(s, locale, "errors.item.footer", null)); 190 } catch (Exception nokey) { 191 writer.println(oneError.getKey()); 192 } 193 } 194 195 try { 198 writer.println(myResponse.getString("errors.footer")); 199 } catch (java.lang.IllegalArgumentException ex) { 200 writer.println(Messages.getString(com.jcorporate.expresso.core.ExpressoSchema.class.getName(), 203 (HttpServletRequest ) pageContext.getRequest(), 204 "errors.footer", new Object []{})); 205 } 206 } 207 } 208 } catch (Exception e) { 209 throw new JspTagException ("ErrorMessageBundleTag: " + e.getMessage()); 210 } 211 212 return EVAL_PAGE; 213 } 214 215 218 219 228 public int doStartTag() 229 throws javax.servlet.jsp.JspTagException { 230 231 return SKIP_BODY; 232 } 233 236 237 238 } 239 240 243 244 | Popular Tags |