cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r441481 - in /cocoon/trunk/core/cocoon-core/src/main: java/org/apache/cocoon/components/treeprocessor/sitemap/ java/org/apache/cocoon/core/container/spring/ java/org/apache/cocoon/core/container/spring/avalon/ resources/org/apache/cocoon/co...
Date Fri, 08 Sep 2006 11:54:18 GMT
Author: cziegeler
Date: Fri Sep  8 04:54:17 2006
New Revision: 441481

URL: http://svn.apache.org/viewvc?view=rev&rev=441481
Log:
Fix some bugs in the per sitemap context handling

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
    cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/avalon/avalon.xsd
    cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Fri Sep  8 04:54:17 2006
@@ -27,6 +27,8 @@
 import java.util.Properties;
 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;
@@ -45,6 +47,7 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.ProcessingUtil;
+import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.components.LifecycleHelper;
 import org.apache.cocoon.components.source.SourceUtil;
 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
@@ -67,7 +70,9 @@
 import org.apache.cocoon.configuration.impl.SettingsHelper;
 import org.apache.cocoon.core.container.spring.BeanFactoryFactoryImpl;
 import org.apache.cocoon.core.container.spring.avalon.AvalonUtils;
+import org.apache.cocoon.core.container.spring.avalon.SitemapHelper;
 import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 import org.apache.cocoon.generation.Generator;
 import org.apache.cocoon.serialization.Serializer;
@@ -397,6 +402,16 @@
      * Build a processing tree from a <code>Configuration</code>.
      */
     public ProcessingNode build(Configuration tree) throws Exception {
+        /*
+        // get the request
+        final Request request = ContextHelper.getRequest(this.context);
+        final String prefix = request.getSitemapURIPrefix();
+        SitemapHelper.createApplicationContext(prefix,
+                                               tree, 
+                                               (ServletContext)this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT),

+                                               this.processor.getSourceResolver(), 
+                                               request);
+        */
         // The namespace used in the whole sitemap is the one of the root
         // element
         this.itsNamespace = tree.getNamespace();

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonNamespaceHandler.java
Fri Sep  8 04:54:17 2006
@@ -37,5 +37,6 @@
      */
     public void init() {
         registerBeanDefinitionParser("settings", new SettingsElementParser());
+        registerBeanDefinitionParser("properties", new PropertiesElementParser());
     }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonWebApplicationContext.java
Fri Sep  8 04:54:17 2006
@@ -16,7 +16,6 @@
  */
 package org.apache.cocoon.core.container.spring;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.Stack;
 
@@ -24,7 +23,7 @@
 
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.core.io.InputStreamResource;
+import org.springframework.core.io.ByteArrayResource;
 import org.springframework.core.io.Resource;
 import org.springframework.util.ClassUtils;
 import org.springframework.util.ResourceUtils;
@@ -58,6 +57,8 @@
                                        String                url,
                                        String                rootDefinition) {
         this.setParent(parent);
+        this.setClassLoader(classloader);
+        this.setServletContext(parent.getServletContext());
         if ( url.endsWith("/") ) {
             this.baseUrl = url;
         } else {
@@ -65,6 +66,7 @@
         }
         this.classLoader = (classloader != null ? classloader : ClassUtils.getDefaultClassLoader());
         this.beanDefinition = rootDefinition;
+        this.refresh();
     }
 
     /**
@@ -72,7 +74,7 @@
      */
     protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException,
IOException {
         if ( this.beanDefinition != null ) {
-            reader.loadBeanDefinitions(new InputStreamResource(new ByteArrayInputStream(this.beanDefinition.getBytes("utf-8"))));
+            reader.loadBeanDefinitions(new ByteArrayResource(this.beanDefinition.getBytes("utf-8")));
         }
         super.loadBeanDefinitions(reader);
     }
@@ -94,7 +96,7 @@
      * @see org.springframework.web.context.support.XmlWebApplicationContext#getDefaultConfigLocations()
      */
     protected String[] getDefaultConfigLocations() {
-        return null;
+        return new String[0];
     }
 
     /**

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java?view=auto&rev=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java
Fri Sep  8 04:54:17 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ * Licensed  under the  Apache License,  Version 2.0  (the "License");
+ * you may not use  this file  except in  compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed  under the  License is distributed on an "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.core.container.spring;
+
+import org.apache.cocoon.configuration.Settings;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Element;
+
+/**
+ * Add a bean definition for the settings object of a child context to the bean factory.
+ *
+ * @see CocoonNamespaceHandler
+ * @see SubSettingsBeanFactoryPostProcessor
+ * @version $Id$
+ * @since 2.2
+ */
+public class PropertiesElementParser extends AbstractElementParser {
+
+    /**
+     * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
org.springframework.beans.factory.xml.ParserContext)
+     */
+    public BeanDefinition parse(Element element, ParserContext parserContext) {
+        this.addComponent(SubSettingsBeanFactoryPostProcessor.class.getName(),
+                          Settings.ROLE,
+                          "init",
+                          false,
+                          parserContext.getRegistry());
+
+        return null;
+    }
+}

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/PropertiesElementParser.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/ConfigurationReader.java
Fri Sep  8 04:54:17 2006
@@ -89,6 +89,9 @@
                                                 String            source,
                                                 ResourceLoader    resourceLoader)
     throws Exception {
+        if ( source == null || source.trim().length() == 0 ) {
+            source = "sitemap.xmap";
+        }
         final ConfigurationReader converter = new ConfigurationReader(parentInfo, resourceLoader);
         converter.convertSitemap(source);
         return converter.configInfo;
@@ -208,7 +211,7 @@
         if ( this.logger.isDebugEnabled() ) {
             this.logger.debug("Reading sitemap from " + sitemapLocation);
         }
-        Resource root = this.resolver.getResource(this.convertUrl(sitemapLocation));
+        final Resource root = this.resolver.getResource(this.convertUrl(sitemapLocation));
         final DefaultConfigurationBuilder b = new DefaultConfigurationBuilder(true);
         
         final Configuration config = b.build(this.getInputSource(root));
@@ -219,7 +222,7 @@
         }
         final Configuration completeConfig = SitemapHelper.createSitemapConfiguration(config);
         if ( completeConfig != null ) {
-            this.convert(config, null, root.getURL().toExternalForm());
+            this.convert(completeConfig, null, root.getURL().toExternalForm());
         }
     }
 

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapElementParser.java
Fri Sep  8 04:54:17 2006
@@ -20,6 +20,7 @@
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.core.io.ResourceLoader;
+import org.springframework.web.context.WebApplicationContext;
 import org.w3c.dom.Element;
 
 /**
@@ -62,7 +63,8 @@
      */
     protected ConfigurationInfo readConfiguration(String location, ResourceLoader resourceLoader)
     throws Exception {
-        return ConfigurationReader.readSitemap(null, location, resourceLoader);
+        WebApplicationContext parentContext = (WebApplicationContext)SitemapHelper.PARENT_CONTEXT.get();
+        return ConfigurationReader.readSitemap((ConfigurationInfo)parentContext.getBean(ConfigurationInfo.class.getName()),
location, resourceLoader);
     }
 
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/SitemapHelper.java
Fri Sep  8 04:54:17 2006
@@ -29,6 +29,7 @@
 import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
 import org.apache.cocoon.core.container.spring.CocoonWebApplicationContext;
 import org.apache.cocoon.environment.Request;
+import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.web.context.WebApplicationContext;
@@ -41,6 +42,8 @@
  */
 public class SitemapHelper {
 
+    public static final ThreadLocal PARENT_CONTEXT = new ThreadLocal();
+
     private static final String CLASSLOADER_CONFIG_NAME = "classloader";
 
     private static final String DEFAULT_CONFIG_XCONF  = "config/xconf";
@@ -51,9 +54,10 @@
         final StringBuffer buffer = new StringBuffer();
         addHeader(buffer);
         // Settings
+        // TODO: use default includes, global variables and directories
         buffer.append("<cocoon:properties/>");
         // Avalon
-        buffer.append("<avalon:sitemap uriPrefix=\"");
+        buffer.append("<avalon:sitemap location=\"sitemap.xmap\" uriPrefix=\"");
         buffer.append(uriPrefix);
         buffer.append("\"/>");
         addFooter(buffer);
@@ -147,13 +151,18 @@
         buffer.append("</beans>");
     }
 
-    public static CocoonWebApplicationContext createApplicationContext(String         contextUrl,
-                                                                       String         uriPrefix,
+    public static CocoonWebApplicationContext createApplicationContext(String         uriPrefix,
                                                                        Configuration  config,
                                                                        ServletContext servletContext,
                                                                        SourceResolver sitemapResolver,
                                                                        Request        request)
     throws Exception {
+        // let's determine our context url
+        Source s = sitemapResolver.resolveURI("a");
+        String contextUrl = s.getURI();
+        sitemapResolver.release(s);
+        contextUrl = contextUrl.substring(0, contextUrl.length() - 1);
+
         final RequestAttributes attr = new CocoonRequestAttributes(request);
         final WebApplicationContext parentContext = CocoonWebApplicationContext.getCurrentContext(servletContext,
attr);
 
@@ -161,20 +170,25 @@
         final ClassLoader classloader = createClassLoader(parentContext, config, servletContext,
sitemapResolver);
         // create root bean definition
         final String definition = createDefinition(uriPrefix);
-        final CocoonWebApplicationContext context = new CocoonWebApplicationContext(classloader,
-                                                                                    parentContext,
-                                                                                    contextUrl,
-                                                                                    definition);
-        return context;
+        PARENT_CONTEXT.set(parentContext);
+        try {
+            final CocoonWebApplicationContext context = new CocoonWebApplicationContext(classloader,
+                                                                                        parentContext,
+                                                                                        contextUrl,
+                                                                                        definition);
+            return context;
+        } finally {
+            PARENT_CONTEXT.set(null);
+        }
     }
 
     /**
      * Build a processing tree from a <code>Configuration</code>.
      */
-    public static ClassLoader createClassLoader(BeanFactory    parentFactory,
-                                                Configuration  config,
-                                                ServletContext servletContext,
-                                                SourceResolver sitemapResolver)
+    protected static ClassLoader createClassLoader(BeanFactory    parentFactory,
+                                                   Configuration  config,
+                                                   ServletContext servletContext,
+                                                   SourceResolver sitemapResolver)
     throws Exception {
         final Configuration componentConfig = config.getChild("components", false);
         Configuration classPathConfig = null;

Modified: cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/avalon/avalon.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/avalon/avalon.xsd?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/avalon/avalon.xsd
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/avalon/avalon.xsd
Fri Sep  8 04:54:17 2006
@@ -27,6 +27,7 @@
     </xsd:complexType>
 
     <xsd:complexType name="sitemapType">
+        <xsd:attribute name="location" type="xsd:string"></xsd:attribute>
     	<xsd:attribute name="uriPrefix" type="xsd:string"></xsd:attribute>
     </xsd:complexType>
 </xsd:schema>

Modified: cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd?view=diff&rev=441481&r1=441480&r2=441481
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/core/container/spring/cocoon.xsd
Fri Sep  8 04:54:17 2006
@@ -23,4 +23,9 @@
     <xsd:complexType name="settingsType">
     	<xsd:attribute name="processorClassName" type="xsd:string" use="optional"></xsd:attribute>
     </xsd:complexType>
+
+    <xsd:element name="properties" type="tns:propertiesType"/>
+    <xsd:complexType name="propertiesType">
+      <xsd:attribute name="useDefaultIncludes" type="xsd:string" use="optional"></xsd:attribute>
+    </xsd:complexType>
 </xsd:schema>



Mime
View raw message