cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r648429 - in /cocoon/trunk/core/cocoon-core/src/main: java/org/apache/cocoon/spring/ java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
Date Tue, 15 Apr 2008 21:58:39 GMT
Author: reinhard
Date: Tue Apr 15 14:58:37 2008
New Revision: 648429

URL: http://svn.apache.org/viewvc?rev=648429&view=rev
Log:
. add a Spring bean that can resolve block path properties (don't know if the cocoon-core
module should become the final home for this bean but since I don't have a better idea at
the moment, I'm going to put it there)

Added:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java
  (with props)
    cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
  (with props)

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java?rev=648429&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java
Tue Apr 15 14:58:37 2008
@@ -0,0 +1,85 @@
+/*
+ * 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.spring;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.blockdeployment.BlockDeploymentServletContextListener;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionVisitor;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.web.context.ServletContextAware;
+
+public class BlockPathPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer
implements
+                BeanFactoryPostProcessor, ServletContextAware {
+
+    private ServletContext servletContext;
+
+    /**
+     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory,
+     *      java.util.Properties)
+     */
+    protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
Properties props)
+                    throws BeansException {
+        Map blockContexts = (Map) this.servletContext.getAttribute(BlockDeploymentServletContextListener.BLOCK_CONTEXT_MAP);
+        final BeanDefinitionVisitor visitor = new ResolvingBeanDefinitionVisitor(blockContexts);
+        String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
+        for (int i = 0; i < beanNames.length; i++) {
+            BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
+            try {
+                visitor.visitBeanDefinition(bd);
+            } catch (BeanDefinitionStoreException ex) {
+                throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i],
ex.getMessage());
+            }
+        }
+    }
+
+    protected class ResolvingBeanDefinitionVisitor extends BeanDefinitionVisitor {
+        protected final Properties props;
+
+        protected final Set visitedPlaceholders = new HashSet();
+
+        public ResolvingBeanDefinitionVisitor(Map blockContexts) {
+            this.props = new Properties();
+            final Iterator i = blockContexts.entrySet().iterator();
+            while (i.hasNext()) {
+                final Map.Entry current = (Map.Entry) i.next();
+                final String key = "org.apache.cocoon.blocks." + current.getKey() + ".resources";
+                this.props.put(key, current.getValue().toString());
+            }
+        }
+
+        protected String resolveStringValue(String strVal) {
+            return parseStringValue(strVal, this.props, visitedPlaceholders);
+        }
+    }
+
+    public void setServletContext(ServletContext servletContext) {
+        this.servletContext = servletContext;
+
+    }
+}

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

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

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/spring/BlockPathPropertyPlaceholderConfigurer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml?rev=648429&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
Tue Apr 15 14:58:37 2008
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- $Id$ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+  <bean name="org.apache.cocoon.spring.BlockPathPropertyPlaceholderConfigurer" class="org.apache.cocoon.spring.BlockPathPropertyPlaceholderConfigurer"
/>
+
+</beans>
\ No newline at end of file

Propchange: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/spring/cocoon-core-block-path-properties.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message