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);
}
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);
}
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?
}
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);
}
use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.
the class TestRequestUtils method testSelectApplication1b.
// Map to the second module -- direct
public void testSelectApplication1b() {
String[] prefixes = { "/1", "/2" };
context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
request.setPathElements("/myapp", "/2/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", "/2", moduleConfig.getPrefix());
// FIXME - check module resources?
}
Aggregations