Search in sources :

Example 16 with JspException

use of javax.servlet.jsp.JspException 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);
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages)

Example 17 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class MultiboxTag method prepareValue.

/**
     * Render the value element
     *
     * @param results The StringBuffer that output will be appended to.
     */
protected String prepareValue(StringBuffer results) throws JspException {
    String value = (this.value == null) ? this.constant : this.value;
    if (value == null) {
        JspException e = new JspException(messages.getMessage("multiboxTag.value"));
        pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
        throw e;
    }
    prepareAttribute(results, "value", TagUtils.getInstance().filter(value));
    return value;
}
Also used : JspException(javax.servlet.jsp.JspException)

Example 18 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class BaseHandlerTag method message.

// ------------------------------------------------------ Protected Methods
/**
     * Return the text specified by the literal value or the message resources
     * key, if any; otherwise return <code>null</code>.
     *
     * @param literal Literal text value or <code>null</code>
     * @param key     Message resources key or <code>null</code>
     * @throws JspException if both arguments are non-null
     */
protected String message(String literal, String key) throws JspException {
    if (literal != null) {
        if (key != null) {
            JspException e = new JspException(messages.getMessage("common.both"));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        } else {
            return (literal);
        }
    } else {
        if (key != null) {
            return TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), key);
        } else {
            return null;
        }
    }
}
Also used : JspException(javax.servlet.jsp.JspException)

Example 19 with JspException

use of javax.servlet.jsp.JspException 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);
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Example 20 with JspException

use of javax.servlet.jsp.JspException in project sonarqube by SonarSource.

the class FormTag method doEndTag.

/**
     * Render the end of this form.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doEndTag() throws JspException {
    // Remove the page scope attributes we created
    pageContext.removeAttribute(Constants.BEAN_KEY, PageContext.REQUEST_SCOPE);
    pageContext.removeAttribute(Constants.FORM_KEY, PageContext.REQUEST_SCOPE);
    // Render a tag representing the end of our current form
    StringBuffer results = new StringBuffer("</form>");
    // Render JavaScript to set the input focus if required
    if (this.focus != null) {
        results.append(this.renderFocusJavascript());
    }
    // Print this value to our output writer
    JspWriter writer = pageContext.getOut();
    try {
        writer.print(results.toString());
    } catch (IOException e) {
        throw new JspException(messages.getMessage("common.io", e.toString()));
    }
    postbackAction = null;
    // Continue processing this page
    return (EVAL_PAGE);
}
Also used : JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

JspException (javax.servlet.jsp.JspException)151 IOException (java.io.IOException)34 Map (java.util.Map)30 HashMap (java.util.HashMap)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)21 Iterator (java.util.Iterator)20 JspWriter (javax.servlet.jsp.JspWriter)20 ActionMessages (org.apache.struts.action.ActionMessages)15 MockFormBean (org.apache.struts.mock.MockFormBean)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)11 ActionMessage (org.apache.struts.action.ActionMessage)11 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 List (java.util.List)7 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 MalformedURLException (java.net.MalformedURLException)5 Locale (java.util.Locale)5 ModuleConfig (org.apache.struts.config.ModuleConfig)5 UserContext (org.mifos.security.util.UserContext)5 JspTag (javax.servlet.jsp.tagext.JspTag)4