Index: magnolia-core/pom.xml
===================================================================
--- magnolia-core/pom.xml (revision Local version)
+++ magnolia-core/pom.xml (revision Shelved version)
@@ -141,6 +141,7 @@
javax.servlet
servlet-api
+ 2.5
provided
Index: magnolia-core/src/test/java/info/magnolia/cms/beans/config/PropertiesInitializerTest.java
===================================================================
--- magnolia-core/src/test/java/info/magnolia/cms/beans/config/PropertiesInitializerTest.java (revision Local version)
+++ magnolia-core/src/test/java/info/magnolia/cms/beans/config/PropertiesInitializerTest.java (revision Shelved version)
@@ -39,8 +39,9 @@
import java.io.File;
import java.net.URL;
-import com.mockrunner.mock.web.MockServletContext;
+import javax.servlet.ServletContext;
+import static org.easymock.EasyMock.*;
/**
* @author fgiust
@@ -89,27 +90,79 @@
}
public void testFileResolution() {
+ ServletContext ctx = createMock(ServletContext.class);
+ expect(ctx.getMajorVersion()).andReturn(2);
+ expect(ctx.getMinorVersion()).andReturn(4);
+ replay(ctx);
+ String replaced = PropertiesInitializer.processPropertyFilesString(
+ ctx,
+ "xserver",
+ "xwebapp",
+ PropertiesInitializer.DEFAULT_INITIALIZATION_PARAMETER);
- MockServletContext ctx = new MockServletContext();
+ assertEquals("WEB-INF/config/xserver/${contextPath}/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/xserver/xwebapp/magnolia.properties,"
+ + "WEB-INF/config/xserver/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/${contextPath}/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/xwebapp/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/default/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/magnolia.properties", replaced);
+ verify(ctx);
+ }
+
+ public void testFileResolutionWithServlet25() {
+ ServletContext ctx = createMock(ServletContext.class);
+ expect(ctx.getMajorVersion()).andReturn(2);
+ expect(ctx.getMinorVersion()).andReturn(5);
+ expect(ctx.getContextPath()).andReturn("myContextPath");
+ replay(ctx);
String replaced = PropertiesInitializer.processPropertyFilesString(
ctx,
"xserver",
"xwebapp",
PropertiesInitializer.DEFAULT_INITIALIZATION_PARAMETER);
- assertEquals("WEB-INF/config/xserver/xwebapp/magnolia.properties," //$NON-NLS-1$
+ assertEquals("WEB-INF/config/xserver/myContextPath/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/xserver/xwebapp/magnolia.properties,"
+ "WEB-INF/config/xserver/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/myContextPath/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/xwebapp/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/default/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/magnolia.properties", replaced);
+ verify(ctx);
}
- public void testFileResolutionCtxAttributes() {
+ public void testFileResolutionWithServlet25AndRootContextPath() {
+ ServletContext ctx = createMock(ServletContext.class);
+ expect(ctx.getMajorVersion()).andReturn(2);
+ expect(ctx.getMinorVersion()).andReturn(5);
+ expect(ctx.getContextPath()).andReturn("");
+ replay(ctx);
+ String replaced = PropertiesInitializer.processPropertyFilesString(
+ ctx,
+ "xserver",
+ "xwebapp",
+ PropertiesInitializer.DEFAULT_INITIALIZATION_PARAMETER);
- MockServletContext ctx = new MockServletContext();
- ctx.setAttribute("attribute", "attributevalue");
- ctx.setInitParameter("param", "paramvalue");
+ // TODO - this is ugly: double-slash
+ assertEquals("WEB-INF/config/xserver//magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/xserver/xwebapp/magnolia.properties,"
+ + "WEB-INF/config/xserver/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config//magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/xwebapp/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/default/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/magnolia.properties", replaced);
+ verify(ctx);
+ }
+ public void testFileResolutionCtxAttributes() {
+ ServletContext ctx = createMock(ServletContext.class);
+ expect(ctx.getInitParameter("param")).andReturn("paramvalue");
+ expect(ctx.getAttribute("attribute")).andReturn("attributevalue");
+ expect(ctx.getMajorVersion()).andReturn(2);
+ expect(ctx.getMinorVersion()).andReturn(4);
+ replay(ctx);
+
String replaced = PropertiesInitializer.processPropertyFilesString(
ctx,
"xserver",
@@ -117,5 +170,31 @@
"WEB-INF/${contextParam/param}/${contextAttribute/attribute}");
assertEquals("WEB-INF/paramvalue/attributevalue", replaced);
+ verify(ctx);
}
+
+ // TODO - test to ensure properties are indeed loaded in the correct order, i.e no accidental override
+
+ public void testAtLeast25() {
+ doTestAtLeast25(true, 3, 3);
+ doTestAtLeast25(true, 3, 0);
+ doTestAtLeast25(true, 2, 6);
+ doTestAtLeast25(true, 2, 5);
+ doTestAtLeast25(false, 2, 4);
+ doTestAtLeast25(false, 2, 2);
+ doTestAtLeast25(false, 2, 0);
+ doTestAtLeast25(false, 1, 7);
+ doTestAtLeast25(false, 1, 0);
+ doTestAtLeast25(false, 0, 1);
+ doTestAtLeast25(false, 0, 0);
-}
+ }
+
+ private void doTestAtLeast25(boolean expected, int major, int minor) {
+ final ServletContext sc = createMock(ServletContext.class);
+ expect(sc.getMajorVersion()).andReturn(major).anyTimes();
+ expect(sc.getMinorVersion()).andReturn(minor).anyTimes();
+ replay(sc);
+ assertEquals(expected, PropertiesInitializer.atLeastServlet25(sc));
+ verify(sc);
+ }
+}
Index: magnolia-core/src/main/java/info/magnolia/cms/beans/config/PropertiesInitializer.java
===================================================================
--- magnolia-core/src/main/java/info/magnolia/cms/beans/config/PropertiesInitializer.java (revision Local version)
+++ magnolia-core/src/main/java/info/magnolia/cms/beans/config/PropertiesInitializer.java (revision Shelved version)
@@ -106,8 +106,10 @@
* Default value for the MAGNOLIA_INITIALIZATION_FILE parameter.
*/
public static final String DEFAULT_INITIALIZATION_PARAMETER = //
- "WEB-INF/config/${servername}/${webapp}/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/${servername}/${contextPath}/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/${servername}/${webapp}/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/${servername}/magnolia.properties," //$NON-NLS-1$
+ + "WEB-INF/config/${contextPath}/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/${webapp}/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/default/magnolia.properties," //$NON-NLS-1$
+ "WEB-INF/config/magnolia.properties"; //$NON-NLS-1$
@@ -300,6 +302,10 @@
propertiesFilesString = StringUtils.replace(propertiesFilesString, "${servername}", servername); //$NON-NLS-1$
propertiesFilesString = StringUtils.replace(propertiesFilesString, "${webapp}", webapp); //$NON-NLS-1$
+ if (atLeastServlet25(context)) {
+ propertiesFilesString = StringUtils.replace(propertiesFilesString, "${contextPath}", context.getContextPath()); //$NON-NLS-1$
+ }
+
// Replacing servlet context attributes (${contextAttribute/something})
final String contextAttributePlaceHolder = PLACEHOLDER_PREFIX + CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX;
String[] contextAttributes = StringUtils.stripAll(StringUtils.substringsBetween(
@@ -404,4 +410,13 @@
return buf.toString();
}
+ public static boolean atLeastServlet25(ServletContext context) {
+ final int major = context.getMajorVersion();
+ if (major == 2) {
+ return context.getMinorVersion() >= 5;
+ } else {
+ return major > 2;
-}
+ }
+ }
+
+}
Index: magnolia-empty-webapp/src/main/webapp/WEB-INF/web.xml
===================================================================
--- magnolia-empty-webapp/src/main/webapp/WEB-INF/web.xml (revision Local version)
+++ magnolia-empty-webapp/src/main/webapp/WEB-INF/web.xml (revision Shelved version)
@@ -27,8 +27,12 @@
magnolia.initialization.file
- WEB-INF/config/${servername}/${webapp}/magnolia.properties, WEB-INF/config/${servername}/magnolia.properties,
- WEB-INF/config/${webapp}/magnolia.properties, WEB-INF/config/default/magnolia.properties,
+ WEB-INF/config/${servername}/${contextPath}/magnolia.properties,
+ WEB-INF/config/${servername}/${webapp}/magnolia.properties,
+ WEB-INF/config/${servername}/magnolia.properties,
+ WEB-INF/config/${contextPath}/magnolia.properties,
+ WEB-INF/config/${webapp}/magnolia.properties,
+ WEB-INF/config/default/magnolia.properties,
WEB-INF/config/magnolia.properties