You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/05/16 01:43:42 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/html ErrorsTag.java
dgraham 2003/05/15 16:43:42
Modified: src/share/org/apache/struts/taglib/html ErrorsTag.java
Log:
Formatting fixes and deprecated unused defaultLocale variable.
Revision Changes Path
1.21 +54 -49 jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java
Index: ErrorsTag.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ErrorsTag.java 10 Mar 2003 01:03:02 -0000 1.20
+++ ErrorsTag.java 15 May 2003 23:43:42 -0000 1.21
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,10 +59,8 @@
*
*/
-
package org.apache.struts.taglib.html;
-
import java.util.Iterator;
import java.util.Locale;
@@ -76,7 +74,6 @@
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;
-
/**
* Custom tag that renders error messages if an appropriate request attribute
* has been created. The tag looks for a request attribute with a reserved
@@ -100,13 +97,10 @@
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/
-
public class ErrorsTag extends TagSupport {
-
// ----------------------------------------------------------- Properties
-
/**
* The servlet context attribute key for our resources.
*/
@@ -120,19 +114,17 @@
this.bundle = bundle;
}
-
/**
* The default locale on our server.
+ * @deprecated Use Locale.getDefault() directly.
*/
protected static Locale defaultLocale = Locale.getDefault();
-
/**
* The line ending string.
*/
protected static String lineEnd = System.getProperty("line.separator");
-
/**
* The session attribute key for our locale.
*/
@@ -146,13 +138,11 @@
this.locale = locale;
}
-
/**
* The message resources for this package.
*/
protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
-
+ MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
/**
* The request attribute key for our error messages (if any).
@@ -160,14 +150,13 @@
protected String name = Globals.ERROR_KEY;
public String getName() {
- return (this.name);
+ return (this.name);
}
public void setName(String name) {
- this.name = name;
+ this.name = name;
}
-
/**
* The name of the property for which error messages should be returned,
* or <code>null</code> to return all errors.
@@ -182,11 +171,8 @@
this.property = property;
}
-
-
// ------------------------------------------------------- Public Methods
-
/**
* Render the specified error messages if there are any.
*
@@ -194,79 +180,98 @@
*/
public int doStartTag() throws JspException {
- // Were any error messages specified?
- ActionErrors errors = null;
- try {
+ // Were any error messages specified?
+ ActionErrors errors = null;
+ try {
errors = RequestUtils.getActionErrors(pageContext, name);
} catch (JspException e) {
RequestUtils.saveException(pageContext, e);
throw e;
}
+
if ((errors == null) || errors.isEmpty()) {
- return (EVAL_BODY_INCLUDE);
+ return (EVAL_BODY_INCLUDE);
}
- // Check for presence of header and footer message keys
boolean headerPresent =
RequestUtils.present(pageContext, bundle, locale, "errors.header");
+
boolean footerPresent =
RequestUtils.present(pageContext, bundle, locale, "errors.footer");
+
boolean prefixPresent =
RequestUtils.present(pageContext, bundle, locale, "errors.prefix");
+
boolean suffixPresent =
RequestUtils.present(pageContext, bundle, locale, "errors.suffix");
// Render the error messages appropriately
- StringBuffer results = new StringBuffer();
+ StringBuffer results = new StringBuffer();
boolean headerDone = false;
String message = null;
- Iterator reports = null;
- if (property == null) {
- reports = errors.get();
- } else {
- reports = errors.get(property);
- }
+ Iterator reports = (property == null) ? errors.get() : errors.get(property);
+
while (reports.hasNext()) {
ActionError report = (ActionError) reports.next();
if (!headerDone) {
if (headerPresent) {
- message = RequestUtils.message(pageContext, bundle,
- locale, "errors.header");
+ message =
+ RequestUtils.message(
+ pageContext,
+ bundle,
+ locale,
+ "errors.header");
+
results.append(message);
results.append(lineEnd);
}
headerDone = true;
}
+
if (prefixPresent) {
- message = RequestUtils.message(pageContext, bundle,
- locale, "errors.prefix");
+ message =
+ RequestUtils.message(
+ pageContext,
+ bundle,
+ locale,
+ "errors.prefix");
results.append(message);
}
- message = RequestUtils.message(pageContext, bundle,
- locale, report.getKey(),
- report.getValues());
+
+ message =
+ RequestUtils.message(
+ pageContext,
+ bundle,
+ locale,
+ report.getKey(),
+ report.getValues());
+
if (message != null) {
results.append(message);
results.append(lineEnd);
}
+
if (suffixPresent) {
- message = RequestUtils.message(pageContext, bundle,
- locale, "errors.suffix");
+ message =
+ RequestUtils.message(
+ pageContext,
+ bundle,
+ locale,
+ "errors.suffix");
results.append(message);
}
}
+
if (headerDone && footerPresent) {
- message = RequestUtils.message(pageContext, bundle,
- locale, "errors.footer");
+ message =
+ RequestUtils.message(pageContext, bundle, locale, "errors.footer");
results.append(message);
results.append(lineEnd);
}
- // Print the results to our output writer
ResponseUtils.write(pageContext, results.toString());
- // Continue processing this page
- return (EVAL_BODY_INCLUDE);
+ return (EVAL_BODY_INCLUDE);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org