You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/04/12 16:23:29 UTC
svn commit: r647454 - in
/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon:
blockdeployment/ spring/configurator/impl/
Author: reinhard
Date: Sat Apr 12 07:23:27 2008
New Revision: 647454
URL: http://svn.apache.org/viewvc?rev=647454&view=rev
Log:
. add a servlet context listener that installs the blocks - this makes sure that blocks are installed before Spring is initialized
. remove the old Spring based implementations (for now the support of Spring properties that point to the installation directory
of a block are not supported)
Added:
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java (with props)
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/DeploymentUtil.java
- copied, changed from r641638, cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/DeploymentUtil.java
Removed:
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/DefaultBlockResourcesHolder.java
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/DeploymentUtil.java
Modified:
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java
cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java
Added: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java?rev=647454&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java (added)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java Sat Apr 12 07:23:27 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.blockdeployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+
+public class BlockDeploymentServletContextListener implements ServletContextListener {
+
+ public static final String BLOCK_CONTEXT_MAP = BlockDeploymentServletContextListener.class.getName() + "/"
+ + "block-context-map";
+
+ public void contextInitialized(ServletContextEvent sce) {
+ try {
+ ServletContext servletContext = sce.getServletContext();
+
+ Map blocks = DeploymentUtil.deployBlockArtifacts(this.getWorkdir(servletContext).getAbsolutePath());
+ servletContext.setAttribute(BLOCK_CONTEXT_MAP, blocks);
+ } catch (IOException e) {
+ throw new RuntimeException("The available Cocoon blocks can't be deployed.", e);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent sce) {
+ sce.getServletContext().removeAttribute(BLOCK_CONTEXT_MAP);
+ }
+
+ private File getWorkdir(ServletContext servletContext) {
+ File workdir = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
+ if (workdir == null) {
+ workdir = new File("cocoon-files");
+ }
+
+ return workdir;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/BlockDeploymentServletContextListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/DeploymentUtil.java (from r641638, cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/DeploymentUtil.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/DeploymentUtil.java?p2=cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/DeploymentUtil.java&p1=cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/DeploymentUtil.java&r1=641638&r2=647454&rev=647454&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/DeploymentUtil.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/blockdeployment/DeploymentUtil.java Sat Apr 12 07:23:27 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.cocoon.spring.configurator.impl;
+package org.apache.cocoon.blockdeployment;
import java.io.File;
import java.io.FileOutputStream;
@@ -25,6 +25,7 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
@@ -46,23 +47,25 @@
protected static final String BLOCK_RESOURCES_PATH = "COB-INF";
/**
- * Deploy all files with a given prefix from a jar file to a directory
- * in the file system.
- * @param jarFile The jar file containing the resources.
- * @param prefix The common prefix for the files.
- * @param destination The destination directory.
+ * Deploy all files with a given prefix from a jar file to a directory in the file system.
+ *
+ * @param jarFile
+ * The jar file containing the resources.
+ * @param prefix
+ * The common prefix for the files.
+ * @param destination
+ * The destination directory.
* @throws IOException
*/
- public static void deploy(JarFile jarFile, String prefix, String destination)
- throws IOException {
- if ( logger.isDebugEnabled() ) {
+ public static void deploy(JarFile jarFile, String prefix, String destination) throws IOException {
+ if (logger.isDebugEnabled()) {
logger.debug("Deploying jar " + jarFile + " to " + destination);
}
- // FIXME - We should check if a deploy is required
+ // FIXME - We should check if a deployment is required
final Enumeration entries = jarFile.entries();
while (entries.hasMoreElements()) {
- final ZipEntry entry = (ZipEntry)entries.nextElement();
- if ( !entry.isDirectory() && entry.getName().startsWith(prefix) ) {
+ final ZipEntry entry = (ZipEntry) entries.nextElement();
+ if (!entry.isDirectory() && entry.getName().startsWith(prefix)) {
final String fileName = destination + entry.getName().substring(prefix.length());
final File out = new File(fileName);
// create directory
@@ -86,12 +89,10 @@
}
}
- protected static void deployBlockResources(String relativeDirectory,
- String destinationDirectory,
- Map blockContexts)
- throws IOException {
+ protected static void deployBlockResources(String relativeDirectory, String destinationDirectory, Map blockContexts)
+ throws IOException {
final Enumeration jarUrls = DeploymentUtil.class.getClassLoader().getResources(BLOCK_RESOURCES_PATH);
- while ( jarUrls.hasMoreElements() ) {
+ while (jarUrls.hasMoreElements()) {
final URL resourceUrl = (URL) jarUrls.nextElement();
String url = resourceUrl.toExternalForm();
@@ -113,7 +114,7 @@
int pos = url.indexOf('!');
url = url.substring(0, pos + 2); // +2 as we include "!/"
- //Included because of Weblogic 9.2 classloader behaviour
+ // Included because of Weblogic 9.2 classloader behaviour
if ("zip".equals(resourceUrl.getProtocol())) {
url = url.replaceAll("zip:", "jar:file:");
}
@@ -146,32 +147,35 @@
}
}
- public static Map deployBlockArtifacts(String destinationDirectory)
- throws IOException {
- if ( destinationDirectory == null ) {
- throw new IllegalArgumentException("Destination must not be null.");
+ public static Map deployBlockArtifacts(String destinationDirectory) throws IOException {
+ if (destinationDirectory == null) {
+ throw new IllegalArgumentException("Destination directory must not be null.");
}
final Map blockContexts = new HashMap();
// deploy all artifacts containing block resources
deployBlockResources("blocks", destinationDirectory, blockContexts);
+
+ for (Iterator it = blockContexts.keySet().iterator(); it.hasNext();) {
+ String name = (String) it.next();
+ }
+
return blockContexts;
}
- public static void deployJarResources(String pattern, String destinationDirectory)
- throws IOException {
+ public static void deployJarResources(String pattern, String destinationDirectory) throws IOException {
final Enumeration jarUrls = DeploymentUtil.class.getClassLoader().getResources(pattern);
- while ( jarUrls.hasMoreElements() ) {
- final URL resourceUrl = (URL)jarUrls.nextElement();
+ while (jarUrls.hasMoreElements()) {
+ final URL resourceUrl = (URL) jarUrls.nextElement();
String url = resourceUrl.toExternalForm();
// we only handle jars!
- if ( "jar".equals(resourceUrl.getProtocol()) ) {
+ if ("jar".equals(resourceUrl.getProtocol())) {
// if this is a jar url, it has this form: "jar:{url-to-jar}!/{resource-path}"
// to open the jar, we can simply remove everything after "!/"
int pos = url.indexOf('!');
- url = url.substring(0, pos+2); // +2 as we include "!/"
+ url = url.substring(0, pos + 2); // +2 as we include "!/"
final URL jarUrl = new URL(url);
- final JarURLConnection connection = (JarURLConnection)jarUrl.openConnection();
+ final JarURLConnection connection = (JarURLConnection) jarUrl.openConnection();
final JarFile jarFile = connection.getJarFile();
deploy(jarFile, pattern, destinationDirectory);
}
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java?rev=647454&r1=647453&r2=647454&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java Sat Apr 12 07:23:27 2008
@@ -53,7 +53,7 @@
implements Map, BeanFactoryAware {
/** The real map. */
- protected Map beanMap = new HashMap();
+ protected final Map beanMap = new HashMap();
/** Is the map initialized? */
protected boolean initialized = false;
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java?rev=647454&r1=647453&r2=647454&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java Sat Apr 12 07:23:27 2008
@@ -22,7 +22,6 @@
import javax.servlet.ServletContext;
import org.apache.cocoon.configuration.Settings;
-import org.apache.cocoon.spring.configurator.BlockResourcesHolder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
@@ -46,32 +45,31 @@
/** The name of the configuration attribute to specify if configurations are read from the global location. */
public static final String READ_FROM_GLOBAL_LOCATION_ATTR = "readFromGlobalLocation";
- /** The name of the configuration attribute to specify if block resources should be extracted. */
- public static final String EXTRACT_BLOCK_RESOURCES_ATTR = "extractBlockResources";
-
/**
* Create and register the settings bean factory post processor.
*/
- protected void createSettingsBeanFactoryPostProcessor(Element element,
- ParserContext parserContext,
- String runningMode) {
+ protected void createSettingsBeanFactoryPostProcessor(Element element, ParserContext parserContext,
+ String runningMode) {
// create bean definition for settings object
- final RootBeanDefinition beanDef = this.createBeanDefinition(SettingsBeanFactoryPostProcessor.class.getName(), "init", false);
+ final RootBeanDefinition beanDef = this.createBeanDefinition(SettingsBeanFactoryPostProcessor.class.getName(),
+ "init", false);
// add additional properties
final Properties additionalProps = this.getAdditionalProperties(element);
- if ( additionalProps != null ) {
+ if (additionalProps != null) {
beanDef.getPropertyValues().addPropertyValue("additionalProperties", additionalProps);
}
// add additional property directories
final List propertiesIncludes = this.getPropertyIncludes(element);
- if ( propertiesIncludes != null ) {
+ if (propertiesIncludes != null) {
beanDef.getPropertyValues().addPropertyValue("directories", propertiesIncludes);
}
// check for boolean settings
- final Boolean readFromClasspath = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_CLASSPATH_ATTR, "true"));
- final Boolean readFromGlobalLocation = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_GLOBAL_LOCATION_ATTR, "true"));
+ final Boolean readFromClasspath = Boolean.valueOf(this.getAttributeValue(element, READ_FROM_CLASSPATH_ATTR,
+ "true"));
+ final Boolean readFromGlobalLocation = Boolean.valueOf(this.getAttributeValue(element,
+ READ_FROM_GLOBAL_LOCATION_ATTR, "true"));
beanDef.getPropertyValues().addPropertyValue(READ_FROM_CLASSPATH_ATTR, readFromClasspath);
beanDef.getPropertyValues().addPropertyValue(READ_FROM_GLOBAL_LOCATION_ATTR, readFromGlobalLocation);
@@ -89,7 +87,7 @@
* @see org.apache.cocoon.spring.configurator.impl.AbstractSettingsElementParser#getRunningMode(org.w3c.dom.Element)
*/
protected String getRunningMode(Element e) {
- return RunningModeHelper.determineRunningMode( this.getAttributeValue(e, RUNNING_MODE_ATTR, null) );
+ return RunningModeHelper.determineRunningMode(this.getAttributeValue(e, RUNNING_MODE_ATTR, null));
}
/**
@@ -97,8 +95,9 @@
*/
protected List getBeanIncludes(Element settingsElement) {
final List includes = super.getBeanIncludes(settingsElement);
- final boolean readFromClasspath = Boolean.valueOf(this.getAttributeValue(settingsElement, READ_FROM_CLASSPATH_ATTR, "true")).booleanValue();
- if ( readFromClasspath ) {
+ final boolean readFromClasspath = Boolean.valueOf(
+ this.getAttributeValue(settingsElement, READ_FROM_CLASSPATH_ATTR, "true")).booleanValue();
+ if (readFromClasspath) {
includes.add(0, Constants.CLASSPATH_SPRING_CONFIGURATION_LOCATION);
}
return includes;
@@ -109,8 +108,10 @@
*/
protected List getBeanPropertyOverrideIncludes(Element settingsElement) {
final List includes = super.getBeanPropertyOverrideIncludes(settingsElement);
- final boolean readFromClasspath = Boolean.valueOf(this.getAttributeValue(settingsElement, READ_FROM_CLASSPATH_ATTR, "true")).booleanValue();
- final boolean readFromGlobalLocation = Boolean.valueOf(this.getAttributeValue(settingsElement, READ_FROM_GLOBAL_LOCATION_ATTR, "true")).booleanValue();
+ final boolean readFromClasspath = Boolean.valueOf(
+ this.getAttributeValue(settingsElement, READ_FROM_CLASSPATH_ATTR, "true")).booleanValue();
+ final boolean readFromGlobalLocation = Boolean.valueOf(
+ this.getAttributeValue(settingsElement, READ_FROM_GLOBAL_LOCATION_ATTR, "true")).booleanValue();
if (readFromGlobalLocation) {
int pos = (readFromClasspath ? 1 : 0);
includes.add(pos, Constants.GLOBAL_SPRING_CONFIGURATION_LOCATION);
@@ -119,20 +120,14 @@
}
/**
- * @see org.apache.cocoon.spring.configurator.impl.AbstractSettingsElementParser#registerComponents(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
+ * @see org.apache.cocoon.spring.configurator.impl.AbstractSettingsElementParser#registerComponents(org.w3c.dom.Element,
+ * org.springframework.beans.factory.xml.ParserContext)
*/
protected void registerComponents(Element settingsElement, ParserContext parserContext) {
super.registerComponents(settingsElement, parserContext);
// add the servlet context as a bean
- this.addComponent(ServletContextFactoryBean.class.getName(),
- ServletContext.class.getName(),
- null, false, parserContext.getRegistry());
-
- // deploy blocks and add a bean holding the information
- final Boolean extractBlockResources = Boolean.valueOf(this.getAttributeValue(settingsElement, EXTRACT_BLOCK_RESOURCES_ATTR, "true"));
- final RootBeanDefinition beanDef = this.createBeanDefinition(DefaultBlockResourcesHolder.class.getName(),
- "init", true);
- beanDef.getPropertyValues().addPropertyValue(EXTRACT_BLOCK_RESOURCES_ATTR, extractBlockResources);
- this.register(beanDef, BlockResourcesHolder.class.getName(), parserContext.getRegistry());
+ this.addComponent(ServletContextFactoryBean.class.getName(), ServletContext.class.getName(), null, false,
+ parserContext.getRegistry());
+
}
}