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);
}
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);
}
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?
}
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?
}
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);
}
Aggregations