Search in sources :

Example 21 with JspException

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

the class FormTag method lookup.

// ------------------------------------------------------ Protected Methods
/**
     * Look up values for the <code>name</code>, <code>scope</code>, and
     * <code>type</code> properties if necessary.
     *
     * @throws JspException if a required value cannot be looked up
     */
protected void lookup() throws JspException {
    // Look up the module configuration information we need
    moduleConfig = TagUtils.getInstance().getModuleConfig(pageContext);
    if (moduleConfig == null) {
        JspException e = new JspException(messages.getMessage("formTag.collections"));
        pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
        throw e;
    }
    String calcAction = this.action;
    // If the action is not specified, use the original request uri
    if (this.action == null) {
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        postbackAction = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
        String prefix = moduleConfig.getPrefix();
        if (postbackAction != null && prefix.length() > 0 && postbackAction.startsWith(prefix)) {
            postbackAction = postbackAction.substring(prefix.length());
        }
        calcAction = postbackAction;
    } else {
        // Translate the action if it is an actionId
        ActionConfig actionConfig = moduleConfig.findActionConfigId(this.action);
        if (actionConfig != null) {
            this.action = actionConfig.getPath();
            calcAction = this.action;
        }
    }
    servlet = (ActionServlet) pageContext.getServletContext().getAttribute(Globals.ACTION_SERVLET_KEY);
    // Look up the action mapping we will be submitting to
    String mappingName = TagUtils.getInstance().getActionMappingName(calcAction);
    mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName);
    if (mapping == null) {
        JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
        pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
        throw e;
    }
    // Look up the form bean definition
    FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig(mapping.getName());
    if (formBeanConfig == null) {
        JspException e = null;
        if (mapping.getName() == null) {
            e = new JspException(messages.getMessage("formTag.name", calcAction));
        } else {
            e = new JspException(messages.getMessage("formTag.formBean", mapping.getName(), calcAction));
        }
        pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
        throw e;
    }
    // Calculate the required values
    beanName = mapping.getAttribute();
    beanScope = mapping.getScope();
    beanType = formBeanConfig.getType();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) ActionConfig(org.apache.struts.config.ActionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig)

Example 22 with JspException

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

the class ImageTag method src.

// ------------------------------------------------------ Protected Methods
/**
     * Return the base source URL that will be rendered in the
     * <code>src</code> property for this generated element, or
     * <code>null</code> if there is no such URL.
     *
     * @throws JspException if an error occurs
     */
protected String src() throws JspException {
    // Deal with a direct context-relative page that has been specified
    if (this.page != null) {
        if ((this.src != null) || (this.srcKey != null) || (this.pageKey != null)) {
            JspException e = new JspException(messages.getMessage("imgTag.src"));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        }
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(this.module, request, pageContext.getServletContext());
        String pageValue = this.page;
        if (config != null) {
            pageValue = TagUtils.getInstance().pageURL(request, this.page, config);
        }
        return (request.getContextPath() + pageValue);
    }
    // Deal with an indirect context-relative page that has been specified
    if (this.pageKey != null) {
        if ((this.src != null) || (this.srcKey != null)) {
            JspException e = new JspException(messages.getMessage("imgTag.src"));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        }
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(this.module, request, pageContext.getServletContext());
        String pageValue = TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), this.pageKey);
        if (config != null) {
            pageValue = TagUtils.getInstance().pageURL(request, pageValue, config);
        }
        return (request.getContextPath() + pageValue);
    }
    // Deal with an absolute source that has been specified
    if (this.src != null) {
        if (this.srcKey != null) {
            JspException e = new JspException(messages.getMessage("imgTag.src"));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        }
        return (this.src);
    }
    // Deal with an indirect source that has been specified
    if (this.srcKey == null) {
        JspException e = new JspException(messages.getMessage("imgTag.src"));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    return TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), this.srcKey);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 23 with JspException

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

the class HeaderTag method handleMultipleHeaders.

/**
     * Expose an array of header values.
     *
     * @throws JspException
     * @since Struts 1.2
     */
protected void handleMultipleHeaders() throws JspException {
    ArrayList values = new ArrayList();
    Enumeration items = ((HttpServletRequest) pageContext.getRequest()).getHeaders(name);
    while (items.hasMoreElements()) {
        values.add(items.nextElement());
    }
    if (values.isEmpty() && (this.value != null)) {
        values.add(this.value);
    }
    String[] headers = new String[values.size()];
    if (headers.length == 0) {
        JspException e = new JspException(messages.getMessage("header.get", name));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    pageContext.setAttribute(id, values.toArray(headers));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspException(javax.servlet.jsp.JspException) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList)

Example 24 with JspException

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

the class MessageTag method doStartTag.

// --------------------------------------------------------- Public Methods
/**
     * Process the start tag.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doStartTag() throws JspException {
    String key = this.key;
    if (key == null) {
        // Look up the requested property value
        Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
        if ((value != null) && !(value instanceof String)) {
            JspException e = new JspException(messages.getMessage("message.property", key));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        }
        key = (String) value;
    }
    // Construct the optional arguments array we will be using
    Object[] args = new Object[] { arg0, arg1, arg2, arg3, arg4 };
    // Retrieve the message string we are looking for
    String message = TagUtils.getInstance().message(pageContext, this.bundle, this.localeKey, key, args);
    if (message == null) {
        Locale locale = TagUtils.getInstance().getUserLocale(pageContext, this.localeKey);
        String localeVal = (locale == null) ? "default locale" : locale.toString();
        JspException e = new JspException(messages.getMessage("message.message", "\"" + key + "\"", "\"" + ((bundle == null) ? "(default bundle)" : bundle) + "\"", localeVal));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    TagUtils.getInstance().write(pageContext, message);
    return (SKIP_BODY);
}
Also used : Locale(java.util.Locale) JspException(javax.servlet.jsp.JspException)

Example 25 with JspException

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

the class ParameterTag method doStartTag.

// --------------------------------------------------------- Public Methods
/**
     * Retrieve the required property and expose it as a scripting variable.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doStartTag() throws JspException {
    // Deal with a single parameter value
    if (multiple == null) {
        String value = pageContext.getRequest().getParameter(name);
        if ((value == null) && (this.value != null)) {
            value = this.value;
        }
        if (value == null) {
            JspException e = new JspException(messages.getMessage("parameter.get", name));
            TagUtils.getInstance().saveException(pageContext, e);
            throw e;
        }
        pageContext.setAttribute(id, value);
        return (SKIP_BODY);
    }
    // Deal with multiple parameter values
    String[] values = pageContext.getRequest().getParameterValues(name);
    if ((values == null) || (values.length == 0)) {
        if (this.value != null) {
            values = new String[] { this.value };
        }
    }
    if ((values == null) || (values.length == 0)) {
        JspException e = new JspException(messages.getMessage("parameter.get", name));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    pageContext.setAttribute(id, values);
    return (SKIP_BODY);
}
Also used : JspException(javax.servlet.jsp.JspException)

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