1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.util.internal.InternalStringBuilder; 21 22 import org.apache.beehive.netui.util.Bundle; 23 import org.apache.beehive.netui.pageflow.internal.InternalUtils; 24 import org.apache.struts.Globals; 25 import org.apache.struts.action.ActionMessage; 26 import org.apache.struts.action.ActionMessages; 27 import org.apache.struts.util.RequestUtils; 28 29 import javax.servlet.jsp.JspException ; 30 import javax.servlet.jsp.PageContext ; 31 import java.util.Iterator ; 32 33 73 public class Errors extends ErrorBaseTag 74 { 75 78 public String getTagName() 79 { 80 return "Errors"; 81 } 82 83 87 public void doTag() 88 throws JspException 89 { 90 PageContext pageContext = getPageContext(); 91 92 ActionMessages errors = null; 94 try { 95 errors = RequestUtils.getActionMessages(pageContext, Globals.ERROR_KEY); 96 } 97 catch (JspException e) { 98 RequestUtils.saveException(pageContext, e); 99 throw e; 100 } 101 102 if ((errors == null) || errors.isEmpty()) { 103 if (hasErrors()) 104 reportErrors(); 105 return; 106 } 107 108 String qualifiedBundle = InternalUtils.getQualifiedBundleName(_bundleName, pageContext.getRequest()); 109 110 boolean headerPresent = false; 111 boolean footerPresent = false; 112 boolean prefixPresent = false; 113 boolean suffixPresent = false; 114 115 String locale = _locale; 116 if (!isMissingUserDefaultMessages(pageContext)) { 117 try { 118 headerPresent = 120 RequestUtils.present(pageContext, qualifiedBundle, locale, "errors.header"); 121 footerPresent = 122 RequestUtils.present(pageContext, qualifiedBundle, locale, "errors.footer"); 123 prefixPresent = 124 RequestUtils.present(pageContext, qualifiedBundle, locale, "errors.prefix"); 125 suffixPresent = 126 RequestUtils.present(pageContext, qualifiedBundle, locale, "errors.suffix"); 127 } 128 catch (JspException e) { 129 String s = Bundle.getString("Tags_ErrorsException", 130 new Object []{e.getMessage()}); 131 registerTagError(s, null); 132 reportErrors(); 133 return; 134 } 135 } 136 137 InternalStringBuilder results = new InternalStringBuilder(128); 139 boolean headerDone = false; 140 String message = null; 141 Iterator reports = null; 142 reports = errors.get(); 143 144 while (reports.hasNext()) { 145 ActionMessage report = (ActionMessage) reports.next(); 146 if (!headerDone) { 147 if (headerPresent) { 148 message = RequestUtils.message(pageContext, qualifiedBundle, locale, "errors.header"); 149 results.append(message); 150 results.append("\r\n"); 151 } 152 headerDone = true; 153 } 154 if (prefixPresent) { 155 message = RequestUtils.message(pageContext, qualifiedBundle, locale, "errors.prefix"); 156 results.append(message); 157 } 158 message = getErrorMessage(report, qualifiedBundle); 159 if (message != null) { 160 results.append(message); 161 results.append("\r\n"); 162 } 163 if (suffixPresent) { 164 message = RequestUtils.message(pageContext, qualifiedBundle, locale, "errors.suffix"); 165 results.append(message); 166 } 167 } 168 if (headerDone && footerPresent) { 169 message = RequestUtils.message(pageContext, qualifiedBundle, locale, "errors.footer"); 170 results.append(message); 171 results.append("\r\n"); 172 } 173 174 if (hasErrors()) 175 reportErrors(); 176 177 write(results.toString()); 179 } 180 } 181 | Popular Tags |