CCM NG: KernelConfig now seems to work in a Java EE application container.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3519 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-07-04 08:16:49 +00:00
parent 5c2e18e51d
commit 5e1e1d1d77
3 changed files with 106 additions and 14 deletions

View File

@ -0,0 +1,87 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.web;
import com.arsdigita.runtime.CCMResourceManager;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
/**
* Listener used to initialise several parameters for legacy CCM classes. This
* class is not identical with the class with same name in old versions. It has
* been modified so that only those things are done which necessary to get the
* legacy classes, for instance the classes derived from
* {@link com.arsdigita.runtime.AbstractConfig} working. Also it is not longer
* necessary to include an entry in the {@code web.xml} for this class because
* this can be done using {@link @WebListener} annotation in the Servlet API
* 3.0.
*
* The following is the documentation from the original class which is provided
* here for reference. The information is outdated!
*
* Web application lifecycle listener, used to perform central initialisation
* tasks at CCM startup in a Servlet container / web application server,
* expecially setting the runtime context (file locations) and (in the future)
* the database connection.
*
* The methods of this classes are by definition only invoked by the Servlet
* container / web application server, not by any Servlet or java class of the
* application itself! Invocation is managed by the deployment descriptor.
*
* Note! Don't forget to configure it in web.xml deployment descriptor!
* <listener>
* <listener-class>
* com.arsdigita.runtime.CCMApplicationContextListener
* </listener-class>
* </listener>
* According to the 2.3 specification these tags must be placed after the filter
* tags and before the Servlet tags!
*
* @author pboy
* @author Jens Pelzetter <a href="mailto:jens.pelzetter@googlemail.com">Jens
* Pelzetter</a>
*/
@WebListener
public class CCMApplicationContextListener implements ServletContextListener {
public static final Logger logger = LogManager.getLogger(
CCMApplicationContextListener.class);
@Override
public void contextInitialized(final ServletContextEvent event) {
final ServletContext context = event.getServletContext();
final String appBase = context.getRealPath("/");
logger.info(String.format("Setting base directory to %s", appBase));
CCMResourceManager.setBaseDirectory(appBase);
}
@Override
public void contextDestroyed(final ServletContextEvent event) {
//Nothing yet
}
}

View File

@ -83,7 +83,7 @@ public class KernelConfigTest {
return ShrinkWrap return ShrinkWrap
.create(WebArchive.class, .create(WebArchive.class,
"LibreCCM-org.libreccm.core.KernelConfigTest.war") "LibreCCM-com.arsdigita.kernel.KernelConfigTest.war")
//.addPackage(CcmObject.class.getPackage()) //.addPackage(CcmObject.class.getPackage())
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage()) .addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.runtime.AbstractConfig.class.getPackage()) .addPackage(com.arsdigita.runtime.AbstractConfig.class.getPackage())
@ -91,10 +91,14 @@ public class KernelConfigTest {
getPackage()) getPackage())
.addPackage(com.arsdigita.util.JavaPropertyReader.class. .addPackage(com.arsdigita.util.JavaPropertyReader.class.
getPackage()) getPackage())
.addPackage(com.arsdigita.web.CCMApplicationContextListener.class
.getPackage())
.addPackage(com.arsdigita.xml.XML.class.getPackage())
.addPackage(com.arsdigita.xml.formatters.DateFormatter.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class .addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage()) .getPackage())
.addAsLibraries(libs) .addAsLibraries(libs)
.addAsWebInfResource( .addAsResource(
"configtests/com/arsdigita/kernel/KernelConfigTest/ccm-core.config", "configtests/com/arsdigita/kernel/KernelConfigTest/ccm-core.config",
"ccm-core.config") "ccm-core.config")
.addAsWebInfResource( .addAsWebInfResource(
@ -106,7 +110,7 @@ public class KernelConfigTest {
.addAsResource( .addAsResource(
"com/arsdigita/kernel/KernelConfig_parameter.properties", "com/arsdigita/kernel/KernelConfig_parameter.properties",
"com/arsdigita/kernel/KernelConfig_parameter.properties") "com/arsdigita/kernel/KernelConfig_parameter.properties")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
} }
@Test @Test