use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.
the class MessagesTag method doStartTag.
/**
* Construct an iterator for the specified collection, and begin looping
* through the body once per element.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Initialize for a new request.
processed = false;
// Were any messages specified?
ActionMessages messages = null;
// Make a local copy of the name attribute that we can modify.
String name = this.name;
if ((message != null) && "true".equalsIgnoreCase(message)) {
name = Globals.MESSAGE_KEY;
}
try {
messages = TagUtils.getInstance().getActionMessages(pageContext, name);
} catch (JspException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// Acquire the collection we are going to iterate over
this.iterator = (property == null) ? messages.get() : messages.get(property);
// Store the first value and evaluate, or skip the body if none
if (!this.iterator.hasNext()) {
return SKIP_BODY;
}
// process the first message
processMessage((ActionMessage) iterator.next());
if ((header != null) && (header.length() > 0)) {
String headerMessage = TagUtils.getInstance().message(pageContext, bundle, locale, header);
if (headerMessage != null) {
TagUtils.getInstance().write(pageContext, headerMessage);
}
}
// Set the processed variable to true so the
// doEndTag() knows processing took place
processed = true;
return (EVAL_BODY_TAG);
}
use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.
the class BaseHandlerTag method doErrorsExist.
/**
* Determine if there are errors for the component.
*
* @return Whether errors exist.
*/
protected boolean doErrorsExist() throws JspException {
boolean errorsExist = false;
if ((getErrorStyleId() != null) || (getErrorStyle() != null) || (getErrorStyleClass() != null)) {
String actualName = prepareName();
if (actualName != null) {
ActionMessages errors = TagUtils.getInstance().getActionMessages(pageContext, errorKey);
errorsExist = ((errors != null) && (errors.size(actualName) > 0));
}
}
return errorsExist;
}
use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.
the class ErrorsTag method doStartTag.
// ------------------------------------------------------- Public Methods
/**
* Render the specified error messages if there are any.
*
* @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Were any error messages specified?
ActionMessages errors = null;
try {
errors = TagUtils.getInstance().getActionMessages(pageContext, name);
} catch (JspException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
if ((errors == null) || errors.isEmpty()) {
return (EVAL_BODY_INCLUDE);
}
boolean headerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getHeader());
boolean footerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getFooter());
boolean prefixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getPrefix());
boolean suffixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getSuffix());
// Render the error messages appropriately
StringBuffer results = new StringBuffer();
boolean headerDone = false;
String message = null;
Iterator reports = (property == null) ? errors.get() : errors.get(property);
while (reports.hasNext()) {
ActionMessage report = (ActionMessage) reports.next();
if (!headerDone) {
if (headerPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getHeader());
results.append(message);
}
headerDone = true;
}
if (prefixPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getPrefix());
results.append(message);
}
if (report.isResource()) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, report.getKey(), report.getValues());
} else {
message = report.getKey();
}
if (message != null) {
results.append(message);
}
if (suffixPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getSuffix());
results.append(message);
}
}
if (headerDone && footerPresent) {
message = TagUtils.getInstance().message(pageContext, bundle, locale, getFooter());
results.append(message);
}
TagUtils.getInstance().write(pageContext, results.toString());
return (EVAL_BODY_INCLUDE);
}
use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.
the class TestTagUtils method testGetActionErrors1a.
// ------------------------------------------ getActionErrors()
// ActionErrors
public void testGetActionErrors1a() {
ActionMessages actionErrors = new ActionMessages();
actionErrors.add("prop", new ActionMessage("key.key"));
request.setAttribute("errors", actionErrors);
try {
ActionMessages errors = tagutils.getActionMessages(pageContext, "errors");
assertNotNull("errors should not be null", errors);
assertNotNull("errors prop should not be null", errors.get("prop"));
String val = null;
int i = 0;
for (Iterator iter = errors.get("prop"); iter.hasNext(); ) {
ActionMessage error = (ActionMessage) iter.next();
val = error.getKey();
i++;
}
assertEquals("only 1 error", i, 1);
assertEquals("errors prop should match", val, "key.key");
} catch (JspException e) {
fail(e.getMessage());
}
}
use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.
the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String4.
// -- using String Array
public void testActionMessages_getActionMessages_PageContext_String4() {
String[] vals = new String[] { "bar", "baz" };
request.setAttribute("foo", vals);
try {
ActionMessages messages = tagutils.getActionMessages(pageContext, "foo");
assertNotNull("messages should not be null", messages);
assertNotNull("messages prop should not be null", messages.get("prop"));
String key = null;
int i = 0;
for (Iterator iter = messages.get(ActionMessages.GLOBAL_MESSAGE); iter.hasNext(); ) {
ActionMessage message = (ActionMessage) iter.next();
key = message.getKey();
Object[] values = message.getValues();
assertNull((values));
assertEquals("1st key should match", key, vals[i]);
i++;
}
assertEquals("only 1 message", i, 2);
} catch (JspException e) {
fail(e.getMessage());
}
}
Aggregations