RequestContextListener.class.getName() + ".REQUEST_ATTRIBUTES";
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
StringBuilder configLocation = new StringBuilder();
configLocation.append("classpath:org/geomajas/spring/geomajasContext.xml");
String additionalLocations = servletContext.getInitParameter(CONFIG_LOCATION_PARAMETER);
if (null != additionalLocations) {
for (String onePart : additionalLocations.split("\\s")) {
String part = onePart.trim();
if (part.length() > 0) {
configLocation.append(',');
int pos = part.indexOf(':');
if (pos < 0) {
// no protocol specified, use "classpath:"
configLocation.append("classpath:");
} else if (0 == pos) {
// location starts with colon, use default application context
part = part.substring(1);
}
configLocation.append(part);
}
}
}
ConfigurableWebApplicationContext applicationContext = new XmlWebApplicationContext();
// Assign the best possible id value.
String id;
try {
String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(servletContext);
id = ObjectUtils.getDisplayString(contextPath);
} catch (Exception ex) {
// Servlet <= 2.4: resort to name specified in web.xml, if any.
String servletContextName = servletContext.getServletContextName();
id = ObjectUtils.getDisplayString(servletContextName);
}
applicationContext.setId("Geomajas:" + id);
applicationContext.setServletContext(servletContext);
applicationContext.setConfigLocation(configLocation.toString());
applicationContext.refresh();
ApplicationContextUtil.setApplicationContext(servletContext, applicationContext);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
}