You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/02/20 09:53:43 UTC
svn commit: r379061 - in
/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon:
components/treeprocessor/sitemap/SitemapLanguage.java
core/SpringCoreUtil.java core/container/spring/ConfigReader.java
Author: cziegeler
Date: Mon Feb 20 00:53:41 2006
New Revision: 379061
URL: http://svn.apache.org/viewcvs?rev=379061&view=rev
Log:
Add support for user-roles, config version check and reloading
Modified:
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/SpringCoreUtil.java
cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=379061&r1=379060&r2=379061&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Mon Feb 20 00:53:41 2006
@@ -29,24 +29,20 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.Constants;
import org.apache.cocoon.components.LifecycleHelper;
-import org.apache.cocoon.components.container.CocoonServiceManager;
import org.apache.cocoon.components.treeprocessor.CategoryNode;
import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder;
import org.apache.cocoon.components.treeprocessor.DefaultTreeBuilder;
-import org.apache.cocoon.components.treeprocessor.ProcessorComponentInfo;
import org.apache.cocoon.components.treeprocessor.TreeBuilder;
import org.apache.cocoon.core.Core;
import org.apache.cocoon.core.container.spring.ApplicationContextFactory;
import org.apache.cocoon.core.container.spring.AvalonEnvironment;
import org.apache.cocoon.core.container.spring.CocoonXmlWebApplicationContext;
-import org.apache.cocoon.core.container.spring.ComponentInfo;
import org.apache.cocoon.core.container.spring.ConfigReader;
import org.apache.cocoon.core.container.spring.ConfigurationInfo;
import org.apache.cocoon.environment.Environment;
@@ -127,33 +123,20 @@
c.removeChild(config.getChild("classpath"));
c.removeChild(config.getChild("listeners"));
- Logger sitemapLogger;
// setup spring container
- if ( this.applicationContext != null ) {
- final AvalonEnvironment ae = new AvalonEnvironment();
- ae.context = context;
- ae.core = (Core)applicationContext.getBean(Core.ROLE);
- ae.logger = this.getLogger();
- ae.servletContext = ((ServletConfig)context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG)).getServletContext();
- ae.settings = ae.core.getSettings();
- final ConfigurationInfo ci = ConfigReader.readConfiguration(c, this.applicationContext.getConfigurationInfo(), ae);
-
- System.out.println("Setting up spring based tree processor.");
- final CocoonXmlWebApplicationContext sitemapContext =
- ApplicationContextFactory.createApplicationContext(ae, ci, this.applicationContext, false);
- System.out.println("Looked up core: " + sitemapContext.getBean(Core.ROLE));
- newManager = (ServiceManager) sitemapContext.getBean(ServiceManager.class.getName());
- sitemapLogger = (Logger)sitemapContext.getBean(Logger.class.getName());
- } else {
- newManager = new CocoonServiceManager(this.parentProcessorManager, classloader);
-
- // Go through the component lifecycle
- ContainerUtil.enableLogging(newManager, this.getLogger());
- ContainerUtil.contextualize(newManager, context);
- ContainerUtil.configure(newManager, c);
- ContainerUtil.initialize(newManager);
- sitemapLogger = ((CocoonServiceManager)newManager).getServiceManagerLogger();
- }
+ final AvalonEnvironment ae = new AvalonEnvironment();
+ ae.context = context;
+ ae.core = (Core)applicationContext.getBean(Core.ROLE);
+ ae.logger = this.getLogger();
+ ae.servletContext = ((ServletConfig)context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG)).getServletContext();
+ ae.settings = ae.core.getSettings();
+ final ConfigurationInfo ci = ConfigReader.readConfiguration(c, this.applicationContext.getConfigurationInfo(), ae);
+
+ final CocoonXmlWebApplicationContext sitemapContext =
+ ApplicationContextFactory.createApplicationContext(ae, ci, this.applicationContext, false);
+ newManager = (ServiceManager) sitemapContext.getBean(ServiceManager.class.getName());
+ Logger sitemapLogger = sitemapLogger = (Logger)sitemapContext.getBean(Logger.class.getName());
+
// check for an application specific container
final Configuration appContainer = config.getChild("application-container", false);
if ( appContainer != null ) {
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/SpringCoreUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/SpringCoreUtil.java?rev=379061&r1=379060&r2=379061&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/SpringCoreUtil.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/SpringCoreUtil.java Mon Feb 20 00:53:41 2006
@@ -41,10 +41,12 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.cocoon.Cocoon;
import org.apache.cocoon.Constants;
-import org.apache.cocoon.Modifiable;
import org.apache.cocoon.Processor;
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.components.container.ComponentContext;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.components.source.impl.DelayedRefreshSourceWrapper;
+import org.apache.cocoon.configuration.ConfigurationBuilder;
import org.apache.cocoon.core.container.spring.ApplicationContextFactory;
import org.apache.cocoon.core.container.spring.AvalonEnvironment;
import org.apache.cocoon.core.container.spring.ConfigReader;
@@ -58,7 +60,9 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.TraversableSource;
+import org.apache.excalibur.source.impl.URLSource;
import org.springframework.context.ApplicationContext;
+import org.xml.sax.InputSource;
/**
* This is an utility class to create a new Cocoon instance.
@@ -97,6 +101,9 @@
/** The container. */
protected ApplicationContext container;
+ /** The configuration file */
+ protected Source configurationFile;
+
// Register the location finder for Avalon configuration objects and exceptions
// and keep a strong reference to it.
private static final LocationUtils.LocationFinder confLocFinder = new LocationUtils.LocationFinder() {
@@ -154,10 +161,15 @@
public SpringCoreUtil(BootstrapEnvironment environment,
ServletContext context)
throws Exception {
+ try {
this.servletContext = context;
this.env = environment;
this.init();
- this.createClassloader();
+ this.createClassloader();
+ } catch (Exception ignore) {
+ ignore.printStackTrace();
+ throw ignore;
+ }
}
protected void init()
@@ -638,7 +650,7 @@
boolean reload = false;
if (this.processor != null) {
- if (this.processor instanceof Modifiable && ((Modifiable)this.processor).modifiedSince(this.settings.getCreationTime())) {
+ if (this.settings.getCreationTime() < this.configurationFile.getLastModified()) {
if (this.log.isInfoEnabled()) {
this.log.info("Configuration changed reload attempt");
}
@@ -668,7 +680,32 @@
}
protected ApplicationContext setupSpringContainer() throws Exception {
- System.out.println("Setting up test Spring container...");
+ if (this.log.isInfoEnabled()) {
+ this.log.info("Reading root configuration: " + this.settings.getConfiguration());
+ }
+
+ URLSource urlSource = new URLSource();
+ urlSource.init(new URL(this.settings.getConfiguration()), null);
+ this.configurationFile = new DelayedRefreshSourceWrapper(urlSource,
+ this.settings.getReloadDelay("config"));
+ final InputSource is = SourceUtil.getInputSource(this.configurationFile);
+
+ final ConfigurationBuilder builder = new ConfigurationBuilder(settings);
+ final Configuration rootConfig = builder.build(is);
+
+ if (!"cocoon".equals(rootConfig.getName())) {
+ throw new ConfigurationException("Invalid configuration file\n" + rootConfig.toString());
+ }
+ if (this.log.isDebugEnabled()) {
+ this.log.debug("Configuration version: " + rootConfig.getAttribute("version"));
+ }
+ if (!Constants.CONF_VERSION.equals(rootConfig.getAttribute("version"))) {
+ throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
+ }
+
+ if (this.log.isInfoEnabled()) {
+ this.log.info("Setting up root Spring container.");
+ }
AvalonEnvironment env = new AvalonEnvironment();
env.context = this.appContext;
env.core = this.core;
@@ -678,7 +715,7 @@
ApplicationContext rootContext = ApplicationContextFactory.createRootApplicationContext(env);
ConfigurationInfo result = ConfigReader.readConfiguration(settings.getConfiguration(), env);
ApplicationContext mainContext = ApplicationContextFactory.createApplicationContext(env, result, rootContext, true);
- System.out.println("Getting core cocoon processor context: " + mainContext.getBean(Core.ROLE));
+
return mainContext;
}
Modified: cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java?rev=379061&r1=379060&r2=379061&view=diff
==============================================================================
--- cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java (original)
+++ cocoon/trunk/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/ConfigReader.java Mon Feb 20 00:53:41 2006
@@ -27,6 +27,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
+import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.configuration.ConfigurationBuilder;
import org.apache.cocoon.core.source.SimpleSourceResolver;
import org.apache.cocoon.matching.helpers.WildcardHelper;
@@ -38,6 +39,8 @@
* This component reads in Avalon style configuration files and returns all
* contained components and their configurations.
*
+ * FIXME - Add logging statements
+ *
* @since 2.2
* @version $Id$
*/
@@ -118,14 +121,26 @@
final Source root = this.resolver.resolveURI(relativePath);
try {
ConfigurationBuilder b = new ConfigurationBuilder(this.environment.settings);
- Configuration config = b.build(root.getInputStream());
+ Configuration config = b.build(SourceUtil.getInputSource(root));
// It's possible to define a logger on a per sitemap/service manager base.
// This is the default logger for all components defined with this sitemap/manager.
this.configInfo.setRootLogger(config.getAttribute("logger", null));
// and load configuration with a empty list of loaded configurations
- this.parseConfiguration(config, root.getURI(), new HashSet());
+ final Set loadedConfigs = new HashSet();
+ this.parseConfiguration(config, root.getURI(),loadedConfigs);
+ // test for optional user-roles attribute
+ final String userRoles = config.getAttribute("user-roles", null);
+ if (userRoles != null) {
+ final Source userRolesSource = this.resolver.resolveURI(userRoles, root.getURI(), null);
+ try {
+ Configuration userRolesConfig = b.build(SourceUtil.getInputSource(userRolesSource));
+ this.parseConfiguration(userRolesConfig, userRolesSource.getURI(), loadedConfigs);
+ } finally {
+ this.resolver.release(userRolesSource);
+ }
+ }
} finally {
this.resolver.release(root);
}