cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r441590 - in /cocoon/trunk/core/cocoon-core/src/main: java/org/apache/cocoon/core/container/spring/ java/org/apache/cocoon/core/container/spring/avalon/ resources/org/apache/cocoon/core/container/spring/
Date Fri, 08 Sep 2006 17:47:26 GMT
Author: cziegeler
Date: Fri Sep  8 10:47:25 2006
New Revision: 441590

URL: http://svn.apache.org/viewvc?view=rev&rev=441590
Log:
Add new interface to separate sitemap from Spring creation stuff

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
  (with props)
Modified:
    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/SitemapHelper.java
    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/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=441590&r1=441589&r2=441590
==============================================================================
--- 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 10:47:25 2006
@@ -21,6 +21,7 @@
 
 import javax.servlet.ServletContext;
 
+import org.apache.cocoon.configuration.Settings;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 import org.springframework.core.io.ByteArrayResource;
@@ -39,9 +40,12 @@
  * @since 2.2
  * @version $Id$
  */
-public class CocoonWebApplicationContext extends XmlWebApplicationContext {
+public class CocoonWebApplicationContext extends XmlWebApplicationContext implements Container
{
 
-    private static final String BEAN_FACTORY_STACK_REQUEST_ATTRIBUTE = CocoonWebApplicationContext.class.getName()
+ "/Stack";
+    /** The name of the request attribute containing the current bean factory. */
+    public static final String WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE = CocoonWebApplicationContext.class.getName();
+
+    private static final String WEB_APPLICATION_CONTEXT_STACK_REQUEST_ATTRIBUTE = CocoonWebApplicationContext.class.getName()
+ "/Stack";
 
     /** The base url (already postfixed with a '/'). */
     protected final String baseUrl;
@@ -106,16 +110,16 @@
      */
     public Object enteringContext(RequestAttributes attributes) {
         final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-        final Object oldContext = attributes.getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
+        final Object oldContext = attributes.getAttribute(WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
         if ( oldContext != null ) {
-            Stack stack = (Stack)attributes.getAttribute(BEAN_FACTORY_STACK_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
+            Stack stack = (Stack)attributes.getAttribute(WEB_APPLICATION_CONTEXT_STACK_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
             if ( stack == null ) {
                 stack = new Stack();
-                attributes.setAttribute(BEAN_FACTORY_STACK_REQUEST_ATTRIBUTE, stack, RequestAttributes.SCOPE_REQUEST);
+                attributes.setAttribute(WEB_APPLICATION_CONTEXT_STACK_REQUEST_ATTRIBUTE,
stack, RequestAttributes.SCOPE_REQUEST);
             }
             stack.push(oldContext);
         }
-        attributes.setAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, this, RequestAttributes.SCOPE_REQUEST);
+        attributes.setAttribute(WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, this, RequestAttributes.SCOPE_REQUEST);
         Thread.currentThread().setContextClassLoader(this.classLoader);
         return oldClassLoader;
     }
@@ -127,14 +131,14 @@
      */
     public void leavingContext(RequestAttributes attributes, Object handle) {
         Thread.currentThread().setContextClassLoader((ClassLoader)handle);
-        final Stack stack = (Stack)attributes.getAttribute(BEAN_FACTORY_STACK_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
+        final Stack stack = (Stack)attributes.getAttribute(WEB_APPLICATION_CONTEXT_STACK_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
         if ( stack == null ) {
-            attributes.removeAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
+            attributes.removeAttribute(WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
         } else {
             final Object oldContext = stack.pop();
-            attributes.setAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, oldContext,
RequestAttributes.SCOPE_REQUEST);
+            attributes.setAttribute(WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, oldContext,
RequestAttributes.SCOPE_REQUEST);
             if ( stack.size() == 0 ) {
-                attributes.removeAttribute(BEAN_FACTORY_STACK_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+                attributes.removeAttribute(WEB_APPLICATION_CONTEXT_STACK_REQUEST_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
             }
         }
     }
@@ -148,10 +152,17 @@
     public static WebApplicationContext getCurrentContext(ServletContext servletContext,
                                                           RequestAttributes attributes) {
         WebApplicationContext parentContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
-        if (attributes.getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)
!= null) {
+        if (attributes.getAttribute(WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)
!= null) {
             parentContext = (CocoonWebApplicationContext) attributes
-                    .getAttribute(CocoonBeanFactory.BEAN_FACTORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+                    .getAttribute(WEB_APPLICATION_CONTEXT_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
         }
         return parentContext;
+    }
+
+    /**
+     * @see org.apache.cocoon.core.container.spring.Container#getSettings()
+     */
+    public Settings getSettings() {
+        return (Settings)this.getBean(Settings.ROLE);
     }
 }

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java?view=auto&rev=441590
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/Container.java
Fri Sep  8 10:47:25 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.web.context.scope.RequestAttributes;
+
+/**
+ * 
+ * @version $Id$
+ */
+public interface Container {
+
+    /**
+     * Notify about entering this context.
+     * @param attributes The request attributes.
+     * @return A handle which should be passed to {@link #leavingContext(RequestAttributes,
Object)}.
+     */
+    Object enteringContext(RequestAttributes attributes);
+
+    /**
+     * Notify about leaving this context.
+     * @param attributes The request attributes.
+     * @param handle     The returned handle from {@link #enteringContext(RequestAttributes)}.
+     */
+    void leavingContext(RequestAttributes attributes, Object handle);
+
+    ClassLoader getClassLoader();
+
+    Settings getSettings();
+}

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

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

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=441590&r1=441589&r2=441590
==============================================================================
--- 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 10:47:25 2006
@@ -17,7 +17,10 @@
 package org.apache.cocoon.core.container.spring.avalon;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 
 import javax.servlet.ServletContext;
 
@@ -29,6 +32,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.cocoon.util.Deprecation;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
 import org.springframework.beans.factory.BeanFactory;
@@ -50,33 +54,58 @@
 
     private static final String DEFAULT_CONFIG_SPRING = "config/spring";
 
-    public static String createDefinition(String uriPrefix) {
+    protected static String createDefinition(String     uriPrefix,
+                                             boolean    useDefaultIncludes,
+                                             List       includes,
+                                             Properties globalVariables) {
         final StringBuffer buffer = new StringBuffer();
         addHeader(buffer);
         // Settings
-        // TODO: use default includes, global variables and directories
-        buffer.append("<cocoon:properties/>");
+        buffer.append("  <cocoon:properties useDefaultIncludes=\"");
+        buffer.append(useDefaultIncludes);
+        buffer.append("\">\n");
+        if ( includes != null && includes.size() > 0 ) {
+            buffer.append("    <property name=\"directories\">\n      <list>\n");
+            final Iterator i = includes.iterator();
+            while ( i.hasNext() ) {
+                final String current = (String)i.next();
+                buffer.append("        <value>");
+                buffer.append(current);
+                buffer.append("</value>\n");
+            }
+            buffer.append("      </list>\n    </property>");            
+        }
+        if ( globalVariables != null && globalVariables.size() > 0 ) {
+            buffer.append("    <property name=\"globalSitemapVariables\">\n      <props>\n");
+            final Iterator i = globalVariables.entrySet().iterator();
+            while ( i.hasNext() ) {
+                final Map.Entry current = (Map.Entry)i.next();
+                buffer.append("        <prop key=\"");
+                buffer.append(current.getKey().toString());
+                buffer.append("\">");
+                buffer.append(current.getValue().toString());
+                buffer.append("</prop>\n");
+            }
+            buffer.append("      </props>\n    </property>\n");
+        }
+        buffer.append("  </cocoon:properties>\n");
         // Avalon
-        buffer.append("<avalon:sitemap location=\"sitemap.xmap\" uriPrefix=\"");
+        buffer.append("  <avalon:sitemap location=\"sitemap.xmap\" uriPrefix=\"");
         buffer.append(uriPrefix);
-        buffer.append("\"/>");
+        buffer.append("\"/>\n");
         addFooter(buffer);
+        System.out.println("NEW CONFIG: " + buffer.toString());
         return buffer.toString();
     }
 
-    public static Configuration createSitemapConfiguration(Configuration config)
-    throws ConfigurationException {
-        Configuration componentConfig = config.getChild("components", false);
-        Configuration classPathConfig = null;
-
-        // by default we include configuration files and properties from
-        // predefined locations
-        boolean useDefaultIncludes = true;
-        if ( componentConfig != null ) {
-            useDefaultIncludes = componentConfig.getAttributeAsBoolean("use-default-includes",
true);
-        }
+    protected static boolean isUsingDefaultIncludes(Configuration config) {
+        return config.getChild("components").getAttributeAsBoolean("use-default-includes",
true);
+    }
 
+    protected static List getPropertyIncludes(Configuration config)
+    throws ConfigurationException {
         List propertyDirs = null;
+        final Configuration componentConfig = config.getChild("components", false);
         if ( componentConfig != null ) {
             Configuration[] propertyDirConfigs = componentConfig.getChildren("include-properties");
             if ( propertyDirConfigs.length > 0 ) {
@@ -86,6 +115,17 @@
                 }
             }
         }
+        return propertyDirs;        
+    }
+
+    public static Configuration createSitemapConfiguration(Configuration config)
+    throws ConfigurationException {
+        Configuration componentConfig = config.getChild("components", false);
+        Configuration classPathConfig = null;
+
+        // by default we include configuration files and properties from
+        // predefined locations
+        final boolean useDefaultIncludes = isUsingDefaultIncludes(config);
 
         // if we want to add the default includes and have no component section
         // we have to create one!
@@ -144,11 +184,39 @@
         buffer.append(" xsi:schemaLocation=\"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd");
         buffer.append(" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd");
         buffer.append(" http://org.apache.cocoon/core http://org.apache.cocoon/core.xsd");
-        buffer.append(" http://org.apache.cocoon/avalon http://org.apache.cocoon/avalon.xsd\">");
+        buffer.append(" http://org.apache.cocoon/avalon http://org.apache.cocoon/avalon.xsd\">\n");
     }
 
     protected static void addFooter(StringBuffer buffer) {
-        buffer.append("</beans>");
+        buffer.append("</beans>\n");
+    }
+
+    /**
+     * compatibility with 2.1.x - check for global variables in sitemap
+     * TODO - This will be removed in later versions!
+     */
+    protected static Properties getGlobalSitemapVariables(Configuration tree)
+    throws ConfigurationException {
+        // compatibility with 2.1.x - check for global variables in sitemap
+        // TODO - This will be removed in later versions!
+        Properties globalSitemapVariables = null;
+        if ( tree.getChild("pipelines").getChild("component-configurations", false) != null
) {
+            Deprecation.logger.warn("The 'component-configurations' section in the sitemap
is deprecated. Please check for alternatives.");
+            globalSitemapVariables = new Properties();
+            // now check for global variables - if any other element occurs: throw exception
+            Configuration[] children = tree.getChild("pipelines").getChild("component-configurations").getChildren();
+            for(int i=0; i<children.length; i++) {
+                if ( "global-variables".equals(children[i].getName()) ) {
+                    Configuration[] variables = children[i].getChildren();
+                    for(int v=0; v<variables.length; v++) {
+                        globalSitemapVariables.setProperty(variables[v].getName(), variables[v].getValue());
+                    }
+               } else {
+                    throw new ConfigurationException("Component configurations in the sitemap
are not allowed for component: " + children[i].getName());
+                }
+            }
+        }
+        return globalSitemapVariables;
     }
 
     public static CocoonWebApplicationContext createApplicationContext(String         uriPrefix,
@@ -169,7 +237,12 @@
         // get classloader
         final ClassLoader classloader = createClassLoader(parentContext, config, servletContext,
sitemapResolver);
         // create root bean definition
-        final String definition = createDefinition(uriPrefix);
+        final boolean useDefaultIncludes = isUsingDefaultIncludes(config);
+        final List propIncludes = getPropertyIncludes(config);
+        final String definition = createDefinition(uriPrefix,
+                                                   useDefaultIncludes,
+                                                   propIncludes,
+                                                   getGlobalSitemapVariables(config));
         PARENT_CONTEXT.set(parentContext);
         try {
             final CocoonWebApplicationContext context = new CocoonWebApplicationContext(classloader,

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=441590&r1=441589&r2=441590
==============================================================================
--- 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 10:47:25 2006
@@ -15,9 +15,9 @@
   limitations under the License.
 -->
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-        targetNamespace="http://org.apache.cocoon/core"
-        xmlns:tns="http://org.apache.cocoon/core">
-
+            targetNamespace="http://org.apache.cocoon/core"
+            xmlns:tns="http://org.apache.cocoon/core">
+
     <xsd:element name="settings" type="tns:settingsType"/>
 
     <xsd:complexType name="settingsType">
@@ -26,6 +26,10 @@
 
     <xsd:element name="properties" type="tns:propertiesType"/>
     <xsd:complexType name="propertiesType">
-      <xsd:attribute name="useDefaultIncludes" type="xsd:string" use="optional"></xsd:attribute>
+     <xsd:complexContent>
+       <xsd:extension base="xsd:anyType">
+         <xsd:attribute name="useDefaultIncludes" type="xsd:string" use="optional"></xsd:attribute>
+       </xsd:extension>
+      </xsd:complexContent>
     </xsd:complexType>
 </xsd:schema>



Mime
View raw message