use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.
the class SelectAction method getPath.
// ------------------------------------------------------- Protected Methods
protected String getPath(ActionContext context) {
ServletActionContext saContext = (ServletActionContext) context;
HttpServletRequest request = saContext.getRequest();
String path = null;
boolean extension = false;
// For prefix matching, match on the path info
path = (String) request.getAttribute(Constants.INCLUDE_PATH_INFO);
if ((path == null) || (path.length() == 0)) {
path = request.getPathInfo();
}
// For extension matching, match on the servlet path
if ((path == null) || (path.length() == 0)) {
path = (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
if ((path == null) || (path.length() == 0)) {
path = request.getServletPath();
}
if ((path == null) || (path.length() == 0)) {
throw new IllegalArgumentException("No path information in request");
}
extension = true;
}
// Strip the module prefix and extension (if any)
ModuleConfig moduleConfig = saContext.getModuleConfig();
String prefix = moduleConfig.getPrefix();
if (!path.startsWith(prefix)) {
throw new IllegalArgumentException("Path does not start with '" + prefix + "'");
}
path = path.substring(prefix.length());
if (extension) {
int slash = path.lastIndexOf("/");
int period = path.lastIndexOf(".");
if ((period >= 0) && (period > slash)) {
path = path.substring(0, period);
}
}
return (path);
}
use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.
the class SelectLocale method getLocale.
// ------------------------------------------------------- Protected Methods
/**
* <p>Return the <code>Locale</code> to be used for this request.</p>
*
* @param context The <code>Context</code> for this request
*/
protected Locale getLocale(ActionContext context) {
ServletActionContext saContext = (ServletActionContext) context;
// Has a Locale already been selected?
HttpSession session = saContext.getRequest().getSession();
Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
if (locale != null) {
return (locale);
}
// Select and cache the Locale to be used
locale = saContext.getRequest().getLocale();
if (locale == null) {
locale = Locale.getDefault();
}
session.setAttribute(Globals.LOCALE_KEY, locale);
return (locale);
}
use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.
the class SelectModule method getPrefix.
// ------------------------------------------------------- Protected Methods
protected String getPrefix(ActionContext context) {
// Identify the URI from which we will match a module prefix
ServletActionContext sacontext = (ServletActionContext) context;
HttpServletRequest request = sacontext.getRequest();
String uri = (String) request.getAttribute(Constants.INCLUDE_SERVLET_PATH);
if (uri == null) {
uri = request.getServletPath();
}
if (uri == null) {
throw new IllegalArgumentException("No path information in request");
}
// Identify the module prefix for the current module
// Initialize to default prefix
String prefix = "";
String[] prefixes = (String[]) sacontext.getApplicationScope().get(Globals.MODULE_PREFIXES_KEY);
int lastSlash = 0;
while (prefix.equals("") && ((lastSlash = uri.lastIndexOf("/")) > 0)) {
uri = uri.substring(0, lastSlash);
for (int i = 0; i < prefixes.length; i++) {
if (uri.equals(prefixes[i])) {
prefix = prefixes[i];
break;
}
}
}
return (prefix);
}
use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.
the class TestWrappingLookupCommand method testWrapContextSubclass.
public void testWrapContextSubclass() throws Exception {
WrappingLookupCommand command = new WrappingLookupCommand();
command.setWrapperClassName(ServletActionContext.class.getName());
Context testContext = new ServletWebContext();
Context wrapped = command.getContext(testContext);
assertNotNull(wrapped);
assertTrue(wrapped instanceof ServletActionContext);
}
use of org.apache.struts.chain.contexts.ServletActionContext in project sonarqube by SonarSource.
the class TestAuthorizeAction method setUp.
/* setUp method for test case */
protected void setUp() throws Exception {
this.request = new MockHttpServletRequest();
this.principal = new MockPrincipal("Mr. Macri", new String[] { "administrator" });
this.request.setUserPrincipal(principal);
MockServletConfig servletConfig = new MockServletConfig();
MockServletContext servletContext = new MockServletContext();
MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig);
servlet.initInternal();
this.saContext = new ServletActionContext(servletContext, request, new MockHttpServletResponse());
this.saContext.setActionServlet(servlet);
this.command = new AuthorizeAction();
}
Aggregations