Search in sources :

Example 56 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java 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 57 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java 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 58 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java 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 59 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.

the class TestRequestUtils method testSelectApplication2b.

// Map to the second module -- include
public void testSelectApplication2b() {
    String[] prefixes = { "/1", "/2" };
    context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
    request.setPathElements("/myapp", "/noform.do", null, null);
    request.setAttribute(RequestProcessor.INCLUDE_SERVLET_PATH, "/2/noform.do");
    ModuleUtils.getInstance().selectModule(request, context);
    ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
    assertNotNull("Selected a module", moduleConfig);
    assertEquals("Selected correct module", "/2", moduleConfig.getPrefix());
// FIXME - check application resources?
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 60 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java 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)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)73 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 JspException (javax.servlet.jsp.JspException)10 Iterator (java.util.Iterator)8 ActionConfig (org.apache.struts.config.ActionConfig)8 ForwardConfig (org.apache.struts.config.ForwardConfig)8 MessageResources (org.apache.struts.util.MessageResources)8 ArrayList (java.util.ArrayList)6 ServletException (javax.servlet.ServletException)6 Enumeration (java.util.Enumeration)4 List (java.util.List)4 Locale (java.util.Locale)4 ActionServlet (org.apache.struts.action.ActionServlet)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)4 UnavailableException (javax.servlet.UnavailableException)3 Digester (org.apache.commons.digester.Digester)3 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)3 MultipartRequestHandler (org.apache.struts.upload.MultipartRequestHandler)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2