You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gk...@apache.org on 2008/02/06 19:24:06 UTC
svn commit: r619090 - in
/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon:
components/treeprocessor/sitemap/SitemapLanguage.java
core/container/spring/avalon/SitemapHelper.java
Author: gkossakowski
Date: Wed Feb 6 10:24:02 2008
New Revision: 619090
URL: http://svn.apache.org/viewvc?rev=619090&view=rev
Log:
Removed creation of child web application context (container). Inheritance of map:components when map:mount is used is dropped from now.
Modified:
cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=619090&r1=619089&r2=619090&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Wed Feb 6 10:24:02 2008
@@ -27,8 +27,6 @@
import java.util.Map;
import java.util.Set;
-import javax.servlet.ServletContext;
-
import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
@@ -42,7 +40,6 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.cocoon.Constants;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo;
import org.apache.cocoon.components.source.util.SourceUtil;
@@ -60,11 +57,11 @@
import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
import org.apache.cocoon.configuration.Settings;
import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
-import org.apache.cocoon.core.container.spring.avalon.SitemapHelper;
import org.apache.cocoon.generation.Generator;
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.sitemap.PatternException;
import org.apache.cocoon.sitemap.SitemapParameters;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.cocoon.util.location.Location;
import org.apache.cocoon.util.location.LocationImpl;
@@ -313,11 +310,7 @@
* Build a processing tree from a <code>Configuration</code>.
*/
public ProcessingNode build(Configuration tree, String location) throws Exception {
- this.itsContainer = SitemapHelper.createContainer(
- tree,
- location,
- null,
- (ServletContext)this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT));
+ this.itsContainer = WebAppContextUtils.getCurrentWebApplicationContext();
final Context itsContext = (Context)this.itsContainer.getBean(AvalonUtils.CONTEXT_ROLE);
// The namespace used in the whole sitemap is the one of the root
// element
Modified: cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java?rev=619090&r1=619089&r2=619090&view=diff
==============================================================================
--- cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java (original)
+++ cocoon/whiteboard/micro/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java Wed Feb 6 10:24:02 2008
@@ -52,175 +52,12 @@
private static final String DEFAULT_CONFIG_XCONF = "config/avalon";
/**
- * The default location of spring related child configuration files.
- */
- public static final String DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION = "config/spring";
- /**
- * The default location of spring related child configuration files.
- */
- public static final String DEFAULT_CHILD_PROPERTIES_LOCATION = "config/properties";
-
- protected static String createDefinition(String uriPrefix,
- String sitemapLocation,
- List beanIncludes,
- List propertyIncludes,
- Properties props) {
- final StringBuffer buffer = new StringBuffer();
- addHeader(buffer);
- // Child settings for sitemap
- buffer.append(" <configurator:child-settings");
- addAttribute(buffer, "name", sitemapLocation);
- buffer.append(">\n");
- if ( beanIncludes != null ) {
- final Iterator i = beanIncludes.iterator();
- while ( i.hasNext() ) {
- final String dir = (String)i.next();
- buffer.append(" <configurator:include-beans");
- addAttribute(buffer, "dir", dir);
- buffer.append("/>\n");
- }
- }
- if ( propertyIncludes != null ) {
- final Iterator i = propertyIncludes.iterator();
- while ( i.hasNext() ) {
- final String dir = (String)i.next();
- buffer.append(" <configurator:include-properties");
- addAttribute(buffer, "dir", dir);
- buffer.append("/>\n");
- }
- }
- if ( props != null ) {
- final Iterator kI = props.keySet().iterator();
- while ( kI.hasNext() ) {
- final String key = (String)kI.next();
- buffer.append(" <configurator:property");
- addAttribute(buffer, "name", key);
- addAttribute(buffer, "value", props.getProperty(key));
- buffer.append("/>\n");
- }
- }
- buffer.append(" </configurator:child-settings>\n");
- // Avalon
- buffer.append(" <avalon:sitemap");
- addAttribute(buffer, "location", sitemapLocation);
- addAttribute(buffer, "uriPrefix", uriPrefix);
- buffer.append("/>\n");
- addFooter(buffer);
-
- return buffer.toString();
- }
-
- /**
- * Add the header for the xml configuration file.
- */
- protected static void addHeader(StringBuffer buffer) {
- buffer.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"");
- buffer.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
- buffer.append(" xmlns:util=\"http://www.springframework.org/schema/util\"");
- buffer.append(" xmlns:configurator=\"http://cocoon.apache.org/schema/configurator\"");
- buffer.append(" xmlns:avalon=\"http://cocoon.apache.org/schema/avalon\"");
- buffer.append(" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd");
- buffer.append(" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd");
- buffer.append(" http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.xsd");
- buffer.append(" http://cocoon.apache.org/schema/avalon http://cocoon.apache.org/schema/avalon/cocoon-avalon-1.0.xsd\">\n");
- }
-
- /**
- * Add the footer for the xml configuration file.
- */
- protected static void addFooter(StringBuffer buffer) {
- buffer.append("</beans>\n");
- }
-
- /**
- * Append an attribute to the xml stream if it has a value.
- */
- protected static void addAttribute(StringBuffer buffer, String name, String value) {
- if ( value != null ) {
- buffer.append(' ');
- buffer.append(name);
- buffer.append("=\"");
- buffer.append(value);
- buffer.append("\"");
- }
- }
-
- /**
* Should the default includes be read for this sitemap?
*/
protected static boolean isUsingDefaultIncludes(Configuration config) {
return config.getChild("components").getAttributeAsBoolean("use-default-includes", true);
}
- /**
- * Get all includes for bean configurations from the sitemap.
- * @param sitemap
- * @return
- */
- protected static List getBeanIncludes(WebApplicationContext webAppContext,
- String contextUrl,
- Configuration sitemap)
- throws ConfigurationException {
- final List includes = new ArrayList();
- if ( isUsingDefaultIncludes(sitemap) ) {
- final Resource rsrc = webAppContext.getResource(contextUrl + DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION);
- if ( rsrc.exists() ) {
- includes.add(DEFAULT_CHILD_SPRING_CONFIGURATION_LOCATION);
- }
- }
- final Configuration[] includeConfigs = sitemap.getChild("components").getChildren("include-beans");
- for(int i = 0 ; i < includeConfigs.length; i++ ) {
- final String dir = includeConfigs[i].getAttribute("dir");
-
- includes.add(dir);
- }
- return includes;
- }
-
- /**
- * Get all includes for properties from the sitemap.
- * @param sitemap
- * @return
- */
- protected static List getPropertiesIncludes(WebApplicationContext webAppContext,
- String contextUrl,
- Configuration sitemap)
- throws ConfigurationException {
- final List includes = new ArrayList();
- if ( isUsingDefaultIncludes(sitemap) ) {
- final Resource rsrc = webAppContext.getResource(contextUrl + DEFAULT_CHILD_PROPERTIES_LOCATION);
- if ( rsrc.exists() ) {
- includes.add(DEFAULT_CHILD_PROPERTIES_LOCATION);
- }
- }
- final Configuration[] includeConfigs = sitemap.getChild("components").getChildren("include-properties");
- for(int i = 0 ; i < includeConfigs.length; i++ ) {
- final String dir = includeConfigs[i].getAttribute("dir");
-
- includes.add(dir);
- }
- return includes;
- }
-
- /**
- * compatibility with 2.1.x - check for global variables in sitemap
- * TODO - This will be removed in later versions!
- */
- protected static Properties getGlobalSitemapVariables(Configuration sitemap)
- throws ConfigurationException {
- Properties variables = null;
- final Configuration varConfig = sitemap.getChild("pipelines").getChild("component-configurations").getChild("global-variables", false);
- if ( varConfig != null ) {
- Deprecation.logger.warn("The 'component-configurations' section in the sitemap is deprecated. Please check for alternatives.");
- variables = new Properties();
- final Configuration[] variableElements = varConfig.getChildren();
- for(int v=0; v<variableElements.length; v++) {
- variables.setProperty(variableElements[v].getName(), variableElements[v].getValue());
- }
- }
- return variables;
- }
-
public static Configuration createSitemapConfiguration(Configuration config)
throws ConfigurationException {
Configuration componentConfig = config.getChild("components", false);
@@ -267,55 +104,6 @@
componentConfig = c;
}
return componentConfig;
- }
-
- /**
- * Create the per sitemap container.
- *
- * @param config The sitemap as a configuration object.
- * @param sitemapLocation The uri of the sitemap
- * @param fam
- * @param servletContext The servlet context
- * @return
- * @throws Exception
- */
- public static WebApplicationContext createContainer(Configuration config,
- String sitemapLocation,
- Monitor fam,
- ServletContext servletContext)
- throws Exception {
- // let's get the parent container first
- final WebApplicationContext parentContext = WebAppContextUtils.getCurrentWebApplicationContext();
- final ProcessInfoProvider infoProvider = (ProcessInfoProvider) parentContext.getBean(ProcessInfoProvider.ROLE);
- final Request request = ObjectModelHelper.getRequest(infoProvider.getObjectModel());
- // let's determine our context url
- int pos = sitemapLocation.lastIndexOf('/');
- if ( sitemapLocation.lastIndexOf(File.separatorChar) > pos ) {
- pos = sitemapLocation.lastIndexOf(File.separatorChar);
- }
- final String contextUrl = sitemapLocation.substring(0, pos + 1);
-
-
- // get classloader
-// TODO rcl
-// final ClassLoader classloader = createClassLoader(parentContext, config, fam, servletContext, sitemapResolver);
- final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
-
- // create root bean definition
- final String definition = createDefinition(request.getSitemapURIPrefix(),
- sitemapLocation.substring(pos+1),
- getBeanIncludes(parentContext, contextUrl, config),
- getPropertiesIncludes(parentContext, contextUrl, config),
- getGlobalSitemapVariables(config));
- final ChildXmlWebApplicationContext context = new ChildXmlWebApplicationContext(contextUrl,
- definition);
- context.setServletContext(servletContext);
- context.setParent(parentContext);
- if ( classloader != null ) {
- context.setClassLoader(classloader);
- }
- context.refresh();
- return context;
}
// TODO rcl