Search in sources :

Example 26 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class JavascriptValidatorTag method renderJavascript.

/**
     * Returns fully rendered JavaScript.
     *
     * @since Struts 1.2
     */
protected String renderJavascript() throws JspException {
    StringBuffer results = new StringBuffer();
    ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
    ValidatorResources resources = (ValidatorResources) pageContext.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), PageContext.APPLICATION_SCOPE);
    if (resources == null) {
        throw new JspException("ValidatorResources not found in application scope under key \"" + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix() + "\"");
    }
    Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);
    Form form = null;
    if ("true".equalsIgnoreCase(dynamicJavascript)) {
        form = resources.getForm(locale, formName);
        if (form == null) {
            throw new JspException("No form found under '" + formName + "' in locale '" + locale + "'.  A form must be defined in the " + "Commons Validator configuration when " + "dynamicJavascript=\"true\" is set.");
        }
    }
    if (form != null) {
        if ("true".equalsIgnoreCase(dynamicJavascript)) {
            results.append(this.createDynamicJavascript(config, resources, locale, form));
        } else if ("true".equalsIgnoreCase(staticJavascript)) {
            results.append(this.renderStartElement());
            if ("true".equalsIgnoreCase(htmlComment)) {
                results.append(HTML_BEGIN_COMMENT);
            }
        }
    }
    if ("true".equalsIgnoreCase(staticJavascript)) {
        results.append(getJavascriptStaticMethods(resources));
    }
    if ((form != null) && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) {
        results.append(getJavascriptEnd());
    }
    return results.toString();
}
Also used : Locale(java.util.Locale) JspException(javax.servlet.jsp.JspException) Form(org.apache.commons.validator.Form) ValidatorResources(org.apache.commons.validator.ValidatorResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 27 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class StrutsTag method doStartTag.

// --------------------------------------------------------- Public Methods
/**
     * Retrieve the required configuration object and expose it as a scripting
     * variable.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doStartTag() throws JspException {
    // Validate the selector arguments
    int n = 0;
    if (formBean != null) {
        n++;
    }
    if (forward != null) {
        n++;
    }
    if (mapping != null) {
        n++;
    }
    if (n != 1) {
        JspException e = new JspException(messages.getMessage("struts.selector"));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    // Retrieve our module configuration information
    ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
    // Retrieve the requested object to be exposed
    Object object = null;
    String selector = null;
    if (formBean != null) {
        selector = formBean;
        object = config.findFormBeanConfig(formBean);
    } else if (forward != null) {
        selector = forward;
        object = config.findForwardConfig(forward);
    } else if (mapping != null) {
        selector = mapping;
        object = config.findActionConfig(mapping);
    }
    if (object == null) {
        JspException e = new JspException(messages.getMessage("struts.missing", selector));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    // Expose this value as a scripting variable
    pageContext.setAttribute(id, object);
    return (SKIP_BODY);
}
Also used : JspException(javax.servlet.jsp.JspException) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 28 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class ImgTag method src.

/**
     * 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)) {
            throwImgTagSrcException();
        }
        ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(this.module, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext());
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        String pageValue = this.page;
        if (!srcDefaultReference(config)) {
            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)) {
            throwImgTagSrcException();
        }
        ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(this.module, (HttpServletRequest) pageContext.getRequest(), pageContext.getServletContext());
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        String pageValue = TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), this.pageKey);
        if (!srcDefaultReference(config)) {
            pageValue = TagUtils.getInstance().pageURL(request, pageValue, config);
        }
        return (request.getContextPath() + pageValue);
    }
    if (this.action != null) {
        if ((this.src != null) || (this.srcKey != null)) {
            throwImgTagSrcException();
        }
        return TagUtils.getInstance().getActionMappingURL(action, module, pageContext, false);
    }
    // Deal with an absolute source that has been specified
    if (this.src != null) {
        if (this.srcKey != null) {
            throwImgTagSrcException();
        }
        return (this.src);
    }
    // Deal with an indirect source that has been specified
    if (this.srcKey == null) {
        throwImgTagSrcException();
    }
    return TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), this.srcKey);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 29 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class TestRequestUtils method testSelectApplication1a.

// ---------------------------------------------------- selectApplication()
// Map to the default module -- direct
public void testSelectApplication1a() {
    request.setPathElements("/myapp", "/noform.do", null, null);
    ModuleUtils.getInstance().selectModule(request, context);
    ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
    assertNotNull("Selected a module", moduleConfig);
    assertEquals("Selected correct module", "", moduleConfig.getPrefix());
// FIXME - check module resources?
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 30 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class ForwardTag method doEndTag.

/**
     * Look up the ActionForward associated with the specified name, and
     * perform a forward or redirect to that path as indicated.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doEndTag() throws JspException {
    // Look up the desired ActionForward entry
    ActionForward forward = null;
    ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
    if (config != null) {
        forward = (ActionForward) config.findForwardConfig(name);
    }
    if (forward == null) {
        JspException e = new JspException(messages.getMessage("forward.lookup", name));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    // Forward or redirect to the corresponding actual path
    String path = forward.getPath();
    path = config.getPrefix() + path;
    if (forward.getRedirect()) {
        this.doRedirect(path);
    } else {
        this.doForward(path);
    }
    // Skip the remainder of this page
    return (SKIP_PAGE);
}
Also used : JspException(javax.servlet.jsp.JspException) ModuleConfig(org.apache.struts.config.ModuleConfig) ActionForward(org.apache.struts.action.ActionForward)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JspException (javax.servlet.jsp.JspException)5 Iterator (java.util.Iterator)4 ActionConfig (org.apache.struts.config.ActionConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 MessageResources (org.apache.struts.util.MessageResources)4 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Locale (java.util.Locale)2 ServletException (javax.servlet.ServletException)2 ActionServlet (org.apache.struts.action.ActionServlet)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1