Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[maven-release-plugin] copy for tag cocoon-spring-configurator-2.1.0

git-svn-id: https://svn.apache.org/repos/asf/cocoon/tags/cocoon-configuration@761910 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 598e8881266a2e3fd3814b03742f527b64a85241 1 parent 1a0ef14
@reinhard reinhard authored
Showing with 3,919 additions and 0 deletions.
  1. +201 −0 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/LICENSE.txt
  2. +5 −0 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/NOTICE.txt
  3. +146 −0 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/pom.xml
  4. +107 −0 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/src/changes/changes.xml
  5. +47 −0 ...or/cocoon-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/ResourceFilter.java
  6. +242 −0 ...tor/cocoon-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/ResourceUtils.java
  7. +123 −0 ...ocoon-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/WebAppContextUtils.java
  8. +226 −0 ...ring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java
  9. +365 −0 ....1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java
  10. +247 −0 ...figurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java
  11. +335 −0 ...ator/cocoon-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java
  12. +59 −0 ...pring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java
  13. +61 −0 ...r-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsBeanFactoryPostProcessor.java
  14. +75 −0 ...configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java
  15. +119 −0 ...figurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/ChildXmlWebApplicationContext.java
  16. +48 −0 ...nfigurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/ConfiguratorNamespaceHandler.java
  17. +51 −0 ...or/cocoon-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/Constants.java
  18. +138 −0 ...ator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/ExtendedPropertyOverrideConfigurer.java
  19. +86 −0 ...n-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/RunningModeHelper.java
  20. +69 −0 ...-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/ServletContextFactoryBean.java
  21. +358 −0 ...urator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsBeanFactoryPostProcessor.java
  22. +140 −0 ...ring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsElementParser.java
  23. +59 −0 ...-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/SettingsProperties.java
  24. +69 −0 ...oon-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/WildcardBeanMap.java
  25. +56 −0 ...nfigurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/WildcardBeanMapElementParser.java
  26. +77 −0 ...-spring-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/log4j/Log4JConfigurator.java
  27. +16 −0 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/src/main/resources/META-INF/spring.handlers
  28. +19 −0 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/src/main/resources/META-INF/spring.schemas
  29. +93 −0 ...gurator-2.1.0/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.1.xsd
  30. +71 −0 ...figurator-2.1.0/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-1.0.xsd
  31. +95 −0 ...gurator-2.1.0/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-2.0.0.xsd
  32. +116 −0 ...gurator-2.1.0/src/main/resources/org/apache/cocoon/spring/configurator/schema/cocoon-configurator-2.1.0.xsd
View
201 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
View
5 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/NOTICE.txt
@@ -0,0 +1,5 @@
+Apache Cocoon
+Copyright 1999-2008 The Apache Software Foundation.
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
View
146 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/pom.xml
@@ -0,0 +1,146 @@
+<?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$ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+
+ <parent>
+ <artifactId>cocoon</artifactId>
+ <groupId>org.apache.cocoon</groupId>
+ <version>8</version>
+ <relativePath>../../../parent</relativePath>
+ </parent>
+ <artifactId>cocoon-spring-configurator</artifactId>
+ <version>2.1.0</version>
+ <name>Cocoon Spring Configurator</name>
+ <description>
+ The Cocoon Spring Configurator is an extension for the Spring framework.
+ It provides a standardized way of handling various configuration issues when using Spring.
+ The feature list includes automatic property handling and inclusion of configuration files.
+ </description>
+
+ <distributionManagement>
+ <site>
+ <id>website</id>
+ <url>${docs.deploymentBaseUrl}/${docs.m.spring-configurator.relPath}/</url>
+ </site>
+ </distributionManagement>
+
+ <properties>
+ <docs.name>Cocoon Spring Configurator</docs.name>
+ <docs.version>${docs.m.spring-configurator.version}</docs.version>
+ <docs.urlRelativizer>../../../../../</docs.urlRelativizer>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <tagBase>https://svn.apache.org/repos/asf/cocoon/tags/cocoon-configuration/${project.artifactId}</tagBase>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.cocoon</groupId>
+ <artifactId>cocoon-configuration-api</artifactId>
+ <version>1.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <exclusions>
+ <exclusion>
+ <artifactId>logkit</artifactId>
+ <groupId>logkit</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>avalon-framework</artifactId>
+ <groupId>avalon-framework</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:https://svn.apache.org/repos/asf/cocoon/tags/cocoon-configuration/cocoon-spring-configurator/cocoon-spring-configurator-2.1.0</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/cocoon/tags/cocoon-configuration/cocoon-spring-configurator/cocoon-spring-configurator-2.1.0</developerConnection>
+ <url>https://svn.apache.org/repos/asf/cocoon/tags/cocoon-configuration/cocoon-spring-configurator/cocoon-spring-configurator-2.1.0</url>
+ </scm>
+
+ <profiles>
+ <profile>
+ <id>daisy</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.daisycms</groupId>
+ <artifactId>daisy-maven-plugin</artifactId>
+ <configuration>
+ <navDocId>1305</navDocId>
+ <collection>cdocs-spring-configurator</collection>
+ <skipFirstNavigationDocumentLevel>false</skipFirstNavigationDocumentLevel>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
View
107 cocoon-spring-configurator/cocoon-spring-configurator-2.1.0/src/changes/changes.xml
@@ -0,0 +1,107 @@
+<?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.
+-->
+
+<!--
+ - @see http://maven.apache.org/plugins/maven-changes-plugin/usage.html
+ - @version $Id$
+ -->
+<document>
+ <body>
+ <release version="2.1.0" date="2009-??-??" description="unreleased">
+ <action dev="reinhard" type="add">
+ Add a WildcardBeanMap that extends BeanMap but checks for a wildcard expression
+ instead of the bean type.
+ </action>
+ <action dev="reinhard" type="add">
+ Support the definition of a user properties file as servlet context init parameter
+ (org.apache.cocoon.settings).
+ </action>
+ </release>
+ <release version="2.0.0" date="2008-08-09" description="released">
+ <action dev="gkossakowski" type="update">
+ Java 5 as minimum requirement.
+ </action>
+ <action dev="reinhard" type="fix">
+ Remove Block-Deployment functionality into a separate module.
+ </action>
+ <action dev="gkossakowski" type="add">
+ Introduced resource filter feature as explained here: http://article.gmane.org/gmane.text.xml.cocoon.devel/78158
+ The resource filtering is used for *all* resources being processed by
+ Spring Configurator including beans definitions and property files.
+
+ The resource filter itself is a simple class implementing one method of
+ ResourceFilter interface.
+ </action>
+ <action dev="lgawron" type="fix">
+ Fix configurator:bean-map throwing ClassCastException when
+ key-property="propertyName" did not resolve to a String property.
+ </action>
+ </release>
+
+ <release version="1.0.2" date="2008-04-07" description="released">
+ <action dev="reinhard" type="fix" issue="COCOON-2172" due-to="Juan Jose Vazquez Delgado" due-to-email="jvazquez@apache.org">
+ Fix block deployment for Weblogic 9.2.
+ </action>
+ <action dev="vgritsenko" type="fix">
+ SettingsBeanFactoryPostProcessor creates work and cache directories only
+ after properties are loaded and settings object is populated, and
+ not before that.
+ </action>
+ </release>
+
+ <release version="1.0.1" date="2007-09-20" description="released">
+ <action dev="giacomo" type="add">
+ Added ability to the bean-map handler to specify what properties a bean must have
+ to be considered as a candidate for the constructed Map as well as keying the Map
+ with a property value from the bean itself instead of its bean-id.
+ </action>
+ <action dev="cziegeler" type="fix">
+ SettingsBeanFactoryPostProcessor can be used outside of a servlet context.
+ </action>
+ </release>
+
+ <release version="1.0.0" date="2007-02-22" description="released">
+ <action dev="reinhard" type="fix">
+ WebAppContextUtils stored a Spring parent application context in a static field. This
+ made it impossible to reload the context. The static field was removed and a request
+ for the parent context results in
+ WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext)
+ which returns the parent Spring application context stored in the servlet context.
+ </action>
+ <action dev="cziegeler" type="add">
+ Each property reference can have an optional default value, like
+ ${my.property.net:THE DEFAULT}. If no other definition for this
+ property is found, the default is used.
+ </action>
+ <action dev="cziegeler" type="add">
+ Add a bean map that collects all beans from the Spring context
+ conforming to a specified type.
+ </action>
+ <action dev="cziegeler" type="add">
+ Improved the DefaultBlockResourcesHolder to act like a PropertyPlaceholderConfigurer.
+ This allows access to the path of the deployed blocks in the configuration files
+ through properties like ${org.apache.cocoon.blocks.[BLOCK_NAME].resources}.
+ </action>
+ <action dev="cziegeler" type="add">
+ Initial creation.
+ </action>
+ </release>
+ </body>
+</document>
View
47 ...onfigurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/ResourceFilter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.configurator;
+
+import java.util.Set;
+
+import org.springframework.core.io.Resource;
+
+/**
+ * <p>This is an interface for custom implementations of filtering of resources being
+ * processed by Spring Configurator.</p>
+ *
+ * <p>If you want to make some decisions on which resources you want to include at the runtime
+ * then you should implement this interface and configure it following way:</p>
+ * <pre>
+ * <configurator:settings>
+ * ..
+ * <configurator:filter class="org.package.SomeClass"/>
+ * </configurator:settings>
+ * </pre>
+ *
+ * <p>The implementations of this interface should be stateless</p>
+ *
+ */
+public interface ResourceFilter {
+
+ /**
+ * @param resources The set of {@link Resource Spring resources}
+ * @return
+ */
+ Set filter(Set resources);
+
+}
View
242 ...configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/ResourceUtils.java
@@ -0,0 +1,242 @@
+/*
+ * 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.configurator;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
+
+/**
+ * Utility class for Spring resource handling.
+ *
+ * @since 1.0
+ * @version $Id$
+ */
+public abstract class ResourceUtils {
+
+ /**
+ * Get the uri of a resource. This method corrects the uri in the case of
+ * the file protocol on windows.
+ *
+ * @param resource The resource.
+ * @return The uri.
+ * @throws IOException
+ */
+ public static String getUri(Resource resource) throws IOException {
+ if (resource == null) {
+ return null;
+ }
+ return correctUri(resource.getURL().toExternalForm());
+ }
+
+ protected static String correctUri(String uri) {
+ // if it is a file we have to recreate the url,
+ // otherwise we get problems under windows with some file
+ // references starting with "/DRIVELETTER" and some
+ // just with "DRIVELETTER"
+ if (uri.startsWith("file:")) {
+ final File f = new File(uri.substring(5));
+ return "file://" + f.getAbsolutePath();
+ }
+
+ return uri;
+ }
+
+ public static boolean isClasspathUri(String uri) {
+ return uri.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX) ||
+ uri.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX);
+ }
+
+ /**
+ * Read all property files from the given directory and apply them to the
+ * supplied properties.
+ * @param propertiesPath The directory path.
+ * @param properties The properties object where all the read properties are applied to.
+ * @param resourceLoader The resource loader to load the property files.
+ * @param resourceFilter The resource filter used to filter read property files, if null no filtering is being applied.
+ * @param logger Optional logger for debugging.
+ */
+ public static void readProperties(String propertiesPath,
+ Properties properties,
+ ResourceLoader resourceLoader,
+ ResourceFilter resourceFilter,
+ Log logger) {
+ if (logger != null && logger.isDebugEnabled()) {
+ logger.debug("Reading properties from directory: " + propertiesPath);
+ }
+
+ ResourcePatternResolver resolver;
+ if (resourceLoader instanceof ResourcePatternResolver) {
+ resolver = (ResourcePatternResolver) resourceLoader;
+ } else {
+ resolver = new PathMatchingResourcePatternResolver(resourceLoader);
+ }
+
+ Resource[] resources = null;
+
+ // check if directory exists
+ boolean load = true;
+ if (!ResourceUtils.isClasspathUri(propertiesPath)) {
+ final Resource resource = resolver.getResource(propertiesPath);
+ if (!resource.exists()) {
+ load = false;
+ }
+ }
+ if (load) {
+ try {
+ resources = resolver.getResources(propertiesPath + "/*.properties");
+ resources = filterResources(resources, resourceFilter);
+ if (logger != null && logger.isDebugEnabled())
+ logger.debug("Found " + resources.length + " matching resources in " +
+ propertiesPath + "/*.properties");
+ } catch (IOException ignore) {
+ if (logger != null && logger.isDebugEnabled()) {
+ logger.debug("Unable to read properties from directory '" +
+ propertiesPath + "' - Continuing initialization.", ignore);
+ }
+ }
+ }
+
+ if (resources != null) {
+ // we process the resources in alphabetical order, so we put
+ // them first into a list, sort them and then read the properties.
+ Arrays.sort(resources, getResourceComparator());
+
+ // now process
+ for (int i = 0; i < resources.length; i++) {
+ final Resource src = resources[i];
+ try {
+ if (logger != null && logger.isDebugEnabled()) {
+ logger.debug("Reading settings from '" + src.getURL() + "'.");
+ }
+ final InputStream propsIS = src.getInputStream();
+ properties.load(propsIS);
+ propsIS.close();
+ } catch (IOException ignore) {
+ if (logger != null && logger.isDebugEnabled()) {
+ logger.info("Unable to read properties from file '" + src.getDescription() +
+ "' - Continuing initialization.", ignore);
+ }
+ }
+ }
+ } else {
+ if (logger != null && logger.isDebugEnabled()) {
+ logger.debug("Directory '" + propertiesPath + "' does not exist - Continuing initialization.");
+ }
+ }
+ }
+
+ /**
+ * Return a resource comparator.
+ * This comparator compares the file name of two resources.
+ * In addition all resources contained in a directory named
+ * WEB-INF/classes/cocoon are sorted (in alphabetical) order
+ * after all other files.
+ *
+ * @return A new comparator for resources.
+ */
+ public static Comparator getResourceComparator() {
+ return new ResourceComparator();
+ }
+
+ /**
+ * Class implementing a simple resource comparator as described
+ * here: {@link ResourceUtils#getResourceComparator}.
+ */
+ protected final static class ResourceComparator implements Comparator {
+
+ protected static final String WEB_INF_CLASSES_META_INF_COCOON = "/WEB-INF/classes/META-INF/cocoon/";
+
+ /**
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object o1, Object o2) {
+ if (!(o1 instanceof Resource) || !(o2 instanceof Resource)) {
+ return 0;
+ }
+
+ try {
+ String name1 = ((Resource) o1).getURL().toExternalForm();
+ String name2 = ((Resource) o2).getURL().toExternalForm();
+ // replace '\' with '/'
+ name1 = name1.replace('\\', '/');
+ name2 = name2.replace('\\', '/');
+
+ boolean webInfClasses1 = name1.indexOf(ResourceComparator.WEB_INF_CLASSES_META_INF_COCOON) != -1;
+ boolean webInfClasses2 = name2.indexOf(ResourceComparator.WEB_INF_CLASSES_META_INF_COCOON) != -1;
+ if (!webInfClasses1 && webInfClasses2) {
+ return -1;
+ }
+ if (webInfClasses1 && !webInfClasses2) {
+ return +1;
+ }
+ } catch (IOException io) {
+ // ignore
+ }
+
+ // default behaviour:
+ return ((Resource) o1).getFilename().compareTo(((Resource) o2).getFilename());
+ }
+ }
+
+ /**
+ * Return the properties added by Maven.
+ *
+ * @param groupId The group identifier of the artifact.
+ * @param artifactId The artifact identifier.
+ * @return Returns a properties object or null if the properties can't be found/read.
+ */
+ public static Properties getPOMProperties(String groupId, String artifactId) {
+ final String resourceName = "META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties";
+ try {
+ final Properties p = new Properties();
+ final InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
+ if (resourceAsStream == null)
+ return null;
+ p.load(resourceAsStream);
+ return p;
+ } catch (IOException ignore) {
+ return null;
+ }
+ }
+
+ /**
+ * @param resources The array of resources need to be filtered
+ * @param filter The instance of the filter itself
+ * @return the array of resources that has been filtered
+ */
+ public static Resource[] filterResources(Resource[] resources, ResourceFilter filter) {
+ if (filter == null)
+ return resources;
+
+ Set resourcesSet = new HashSet(Arrays.asList(resources));
+ Set filteredResources = filter.filter(resourcesSet);
+ return (Resource[])(new ArrayList(filteredResources)).toArray(new Resource[0]);
+ }
+}
View
123 ...gurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/WebAppContextUtils.java
@@ -0,0 +1,123 @@
+/*
+ * 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.configurator;
+
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import org.apache.cocoon.spring.configurator.impl.ServletContextFactoryBean;
+
+/**
+ * Utility class to manage hierarchical application contexts.
+ *
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class WebAppContextUtils {
+
+ /** The name of the request attribute containing the current bean factory. */
+ public static final String CONTAINER_REQUEST_ATTRIBUTE = WebAppContextUtils.class.getName();
+
+ /**
+ * Get the current web application context.
+ *
+ * @throws IllegalStateException if no WebApplicationContext could not be found
+ * @return The current web application context.
+ */
+ public static WebApplicationContext getCurrentWebApplicationContext() {
+ final RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
+ return getCurrentWebApplicationContext(attributes);
+ }
+
+ /**
+ * Return the current web application context or if the attributes are null, the parent context.
+ *
+ * @param attributes The request attributes.
+ * @throws IllegalStateException if no WebApplicationContext could not be found
+ * @return The web application context.
+ */
+ protected static WebApplicationContext getCurrentWebApplicationContext(RequestAttributes attributes) {
+ if (attributes != null) {
+ Object obj = attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+ if (obj != null) {
+ return (WebApplicationContext) obj;
+ }
+ }
+
+ // return the root context
+ return WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContextFactoryBean.getServletContext());
+ }
+
+ /**
+ * Notify about entering this context.
+ *
+ * @param webAppContext The current web application context.
+ * @return A handle which should be passed to {@link #leavingContext(WebApplicationContext, Object)}.
+ */
+ public static Object enteringContext(WebApplicationContext webAppContext) {
+ // get request attributes
+ final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
+
+ // save current class loader and web application context
+ final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ final WebApplicationContext oldContext = (WebApplicationContext) attributes.getAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+
+ // set new class loader and context
+ attributes.setAttribute(CONTAINER_REQUEST_ATTRIBUTE, webAppContext, RequestAttributes.SCOPE_REQUEST);
+ Thread.currentThread().setContextClassLoader(webAppContext.getClassLoader());
+
+ return new ContextInfo(oldContext, oldClassLoader);
+ }
+
+ /**
+ * Notify about leaving this context.
+ * @param webAppContext The current web application context.
+ * @param handle The returned handle from {@link #enteringContext(WebApplicationContext)}.
+ */
+ public static void leavingContext(WebApplicationContext webAppContext, Object handle) {
+ if (!(handle instanceof ContextInfo)) {
+ throw new IllegalArgumentException("Handle must be an instance of ContextInfo and not " + handle);
+ }
+ final ContextInfo info = (ContextInfo) handle;
+
+ // get request attributes
+ final RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
+
+ // restore class loader and previous web application context
+ Thread.currentThread().setContextClassLoader(info.classLoader);
+ if (info.webAppContext == null) {
+ attributes.removeAttribute(CONTAINER_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
+ } else {
+ attributes.setAttribute(CONTAINER_REQUEST_ATTRIBUTE, info.webAppContext, RequestAttributes.SCOPE_REQUEST);
+ }
+ }
+
+ /**
+ * Private bean keeping track of the class loader and web application context.
+ */
+ protected static final class ContextInfo {
+ public final ClassLoader classLoader;
+ public final WebApplicationContext webAppContext;
+
+ public ContextInfo(WebApplicationContext w, ClassLoader c) {
+ this.classLoader = c;
+ this.webAppContext = w;
+ }
+ }
+}
View
226 ...2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractElementParser.java
@@ -0,0 +1,226 @@
+/*
+ * 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.configurator.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.BeanDefinitionParser;
+import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
+import org.springframework.util.StringUtils;
+
+import org.apache.cocoon.configuration.Settings;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * This is a base class for all bean definition parsers used in Cocoon. It
+ * provides some utility methods.
+ *
+ * @since 1.0
+ * @version $Id$
+ */
+public abstract class AbstractElementParser implements BeanDefinitionParser {
+
+ /** Logger (we use the same logging mechanism as Spring!) */
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ /**
+ * Get the value of an attribute or if the attribute is not present return
+ * the default value. As Element#getAttribute(String) returns an empty string
+ * and not null, we have to check this.
+ */
+ protected String getAttributeValue(Element element, String attributeName, String defaultValue) {
+ String value = element.getAttribute(attributeName);
+ if (value == null || value.trim().length() == 0) {
+ value = defaultValue;
+ }
+
+ return value;
+ }
+
+ /**
+ * Returns all Element children of an Element that have the given local name.
+ */
+ protected Element[] getChildElements(Element element, String localName) {
+ final ArrayList elements = new ArrayList();
+ final NodeList nodeList = element.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ final Node node = nodeList.item(i);
+ if (node instanceof Element && localName.equals(node.getLocalName())) {
+ elements.add(node);
+ }
+ }
+
+ return (Element[]) elements.toArray(new Element[elements.size()]);
+ }
+
+ /**
+ * Register a bean definition.
+ *
+ * @param beanDef The bean definition.
+ * @param beanName The name of the bean.
+ * @param registry The registry.
+ */
+ protected void register(BeanDefinition beanDef, String beanName, BeanDefinitionRegistry registry) {
+ register(beanDef, beanName, null, registry);
+ }
+
+ /**
+ * Register a bean definition.
+ *
+ * @param beanDef The bean definition.
+ * @param beanName The name of the bean.
+ * @param alias Optional alias.
+ * @param registry The registry.
+ */
+ protected void register(BeanDefinition beanDef, String beanName, String alias, BeanDefinitionRegistry registry) {
+ if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Registering bean with name " + beanName +
+ (alias != null ? " (alias=" + alias + ") " : " ") + beanDef);
+ }
+ final BeanDefinitionHolder holder;
+ if (alias != null) {
+ holder = new BeanDefinitionHolder(beanDef, beanName, new String[] { alias });
+ } else {
+ holder = new BeanDefinitionHolder(beanDef, beanName);
+ }
+
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+ }
+
+ /**
+ * Register a global bean definition.
+ * The provided xml element is searched for an id and/or name attribute to register
+ * the bean. This implementation works the same as the default spring implementation.
+ *
+ * @param beanDef The bean definition.
+ * @param element The xml element defining the bean.
+ * @param registry The registry.
+ * @since 1.0.1
+ */
+ protected void register(BeanDefinition beanDef, Element element, BeanDefinitionRegistry registry) {
+ String id = element.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
+ String nameAttr = element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
+
+ final List aliases = new ArrayList();
+ if (StringUtils.hasLength(nameAttr)) {
+ String[] nameArr = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
+ aliases.addAll(Arrays.asList(nameArr));
+ }
+
+ String beanName = id;
+ if (!StringUtils.hasText(beanName) && !aliases.isEmpty()) {
+ beanName = (String) aliases.remove(0);
+ if (this.logger.isDebugEnabled()) {
+ this.logger.debug("No XML 'id' specified - using '" + beanName +
+ "' as bean name and " + aliases + " as aliases");
+ }
+ }
+
+ final BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, beanName, StringUtils.toStringArray(aliases));
+ BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
+ }
+
+ /**
+ * Helper method to create a new bean definition.
+ *
+ * @param componentClass The class of the implementation.
+ * @param initMethod Optional initialization method.
+ * @param requiresSettings If set to true, this bean has a property "settings" for the
+ * settings object.
+ * @return A new root bean definition.
+ */
+ protected RootBeanDefinition createBeanDefinition(Class componentClass, String initMethod, boolean requiresSettings) {
+ final RootBeanDefinition beanDef = new RootBeanDefinition();
+ beanDef.setBeanClass(componentClass);
+ fillBeanDefinition(beanDef, initMethod, requiresSettings);
+ return beanDef;
+ }
+
+ /**
+ * Helper method to create a new bean definition.
+ *
+ * @param componentClass The class of the implementation.
+ * @param initMethod Optional initialization method.
+ * @param requiresSettings If set to true, this bean has a property "settings" for the
+ * settings object.
+ * @return A new root bean definition.
+ */
+ protected RootBeanDefinition createBeanDefinition(String componentClass, String initMethod, boolean requiresSettings) {
+ final RootBeanDefinition beanDef = new RootBeanDefinition();
+ beanDef.setBeanClassName(componentClass);
+ fillBeanDefinition(beanDef, initMethod, requiresSettings);
+ return beanDef;
+ }
+
+ private void fillBeanDefinition(RootBeanDefinition beanDef, String initMethod, boolean requiresSettings) {
+ beanDef.setScope(BeanDefinition.SCOPE_SINGLETON);
+ beanDef.setLazyInit(false);
+ if (initMethod != null) {
+ beanDef.setInitMethodName(initMethod);
+ }
+ if (requiresSettings) {
+ beanDef.getPropertyValues().addPropertyValue("settings", new RuntimeBeanReference(Settings.ROLE));
+ }
+ }
+
+ /**
+ * Add a new bean definition to the registry.
+ *
+ * @param componentClass The class of the implementation.
+ * @param beanName The name of the bean.
+ * @param initMethod Optional initialization method.
+ * @param requiresSettings If set to true, this bean has a property "settings" for the
+ * settings object.
+ * @param registry The bean registry.
+ */
+ protected void addComponent(Class componentClass, String beanName,
+ String initMethod, boolean requiresSettings,
+ BeanDefinitionRegistry registry) {
+ final RootBeanDefinition beanDef = createBeanDefinition(componentClass, initMethod, requiresSettings);
+ register(beanDef, beanName, registry);
+ }
+
+ /**
+ * Add a new bean definition to the registry.
+ *
+ * @param componentClass The class of the implementation.
+ * @param beanName The name of the bean.
+ * @param initMethod Optional initialization method.
+ * @param requiresSettings If set to true, this bean has a property "settings" for the
+ * settings object.
+ * @param registry The bean registry.
+ */
+ protected void addComponent(String componentClass, String beanName,
+ String initMethod, boolean requiresSettings,
+ BeanDefinitionRegistry registry) {
+ final RootBeanDefinition beanDef = createBeanDefinition(componentClass, initMethod, requiresSettings);
+ register(beanDef, beanName, registry);
+ }
+}
View
365 .../org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java
@@ -0,0 +1,365 @@
+/*
+ * 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.configurator.impl;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+
+import org.apache.cocoon.configuration.MutableSettings;
+import org.apache.cocoon.configuration.PropertyHelper;
+import org.apache.cocoon.configuration.PropertyProvider;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.spring.configurator.ResourceFilter;
+import org.apache.cocoon.spring.configurator.ResourceUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.beans.factory.HierarchicalBeanFactory;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionVisitor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.FileSystemResourceLoader;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.web.context.ServletContextAware;
+import org.springframework.web.context.support.ServletContextResourceLoader;
+
+/**
+ * This is a bean factory post processor which handles all the settings stuff
+ * for Cocoon. It reads in all properties files and replaces references to
+ * them in the spring configuration files.
+ * In addition this bean acts as a factory bean providing the settings object.
+ *
+ * @see SettingsBeanFactoryPostProcessor
+ * @see ChildSettingsBeanFactoryPostProcessor
+ * @since 1.0
+ * @version $Id$
+ */
+public abstract class AbstractSettingsBeanFactoryPostProcessor
+ extends PropertyPlaceholderConfigurer
+ implements ServletContextAware, ResourceLoaderAware, FactoryBean {
+
+ /** Logger (we use the same logging mechanism as Spring!) */
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ protected ServletContext servletContext;
+
+ protected MutableSettings settings;
+
+ protected BeanFactory beanFactory;
+
+ protected ResourceLoader resourceLoader;
+
+ protected ResourceFilter resourceFilter;
+
+ /**
+ * Additional properties.
+ */
+ protected Properties additionalProperties;
+
+ /**
+ * List of additional property directories.
+ */
+ protected List directories;
+
+ /**
+ * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+ */
+ public void setBeanFactory(BeanFactory factory) {
+ super.setBeanFactory(factory);
+ this.beanFactory = factory;
+ }
+
+ /**
+ * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
+ */
+ public void setServletContext(ServletContext sContext) {
+ this.servletContext = sContext;
+ }
+
+ /**
+ * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
+ */
+ public void setResourceLoader(ResourceLoader loader) {
+ this.resourceLoader = loader;
+ }
+
+ public void setResourceFilter(ResourceFilter resourceFilter) {
+ this.resourceFilter = resourceFilter;
+ }
+
+ public void setDirectories(List directories) {
+ this.directories = directories;
+ }
+
+ public void setAdditionalProperties(Properties props) {
+ this.additionalProperties = props;
+ }
+
+ /**
+ * Initialize this processor.
+ * Setup the settings object.
+ *
+ * @throws Exception
+ */
+ public void init()
+ throws Exception {
+ settings = createSettings();
+ dumpSettings();
+ }
+
+ /**
+ * Get the running mode.
+ * This method should be implemented by subclasses.
+ */
+ protected abstract String getRunningMode();
+
+ /**
+ * Return a parent settings object if available.
+ */
+ protected Settings getParentSettings() {
+ final BeanFactory parentBeanFactory = ((HierarchicalBeanFactory) this.beanFactory).getParentBeanFactory();
+ if (parentBeanFactory != null) {
+ return (Settings) parentBeanFactory.getBean(Settings.ROLE);
+ }
+
+ return null;
+ }
+
+ /**
+ * Create a new settings object.
+ * If a parent settings object is available a new child settings object is created.
+ * Otherwise a new root settings object with the running mode is instantiated.
+ */
+ protected MutableSettings createMutableSettingsInstance() {
+ final Settings parentSettings = getParentSettings();
+ if (parentSettings == null) {
+ return new MutableSettings(getRunningMode());
+ }
+
+ return new MutableSettings(parentSettings);
+ }
+
+ /**
+ * This method can be used by subclasses to initialize the settings and/or
+ * the properties before {@link #createSettings()} does it's work.
+ */
+ protected void preInit(final MutableSettings s, final Properties properties) {
+ // default implementation does nothing
+ }
+
+ /**
+ * This method can be used by subclasses to initialize the settings and/or
+ * the properties after {@link #createSettings()} did it's work.
+ */
+ protected void postInit(final MutableSettings s, final Properties properties) {
+ // default implementation does nothing
+ }
+
+ protected String getNameForPropertyProvider() {
+ return null;
+ }
+
+ /**
+ * Create a settings object.
+ * This method creates the settings by executing the following task:
+ * <ol>
+ * <li>Create a new mutable settings object invoking {@link #createMutableSettingsInstance()}.
+ * <li>Configure the properties and settings object by calling {@link #preInit(MutableSettings, Properties)}.
+ * <li>Invoke a {@link PropertyProvider} if configured in the same application context (or its parent)
+ * <li>Add properties from configured directories {@link #directories}.
+ * <li>Add additional properties configured at {@link #additionalProperties}
+ * <li>Apply system properties
+ * <li>Configure the properties and settings object by calling {@link #postInit(MutableSettings, Properties)}.
+ * <li>Replace references in properties
+ * <li>Configure the settings object with the properties
+ * <li>Make the settings object read-only.
+ * </ol>
+ *
+ * @return A new Settings object
+ */
+ protected MutableSettings createSettings() {
+ final String mode = getRunningMode();
+ // create an empty settings objects
+ final MutableSettings s = createMutableSettingsInstance();
+ // create the initial properties
+ final Properties properties = new Properties();
+
+ // invoke pre initialization hook
+ preInit(s, properties);
+
+ // check for property providers
+ if (this.beanFactory != null && this.beanFactory.containsBean(PropertyProvider.ROLE) ) {
+ try {
+ final PropertyProvider provider = (PropertyProvider) this.beanFactory.getBean(PropertyProvider.ROLE);
+ final Properties providedProperties = provider.getProperties(s, mode, this.getNameForPropertyProvider());
+ if (providedProperties != null) {
+ properties.putAll(providedProperties);
+ }
+ } catch (Exception ignore) {
+ this.logger.warn("Unable to get properties from provider.", ignore);
+ this.logger.warn("Continuing initialization.");
+ }
+ }
+
+ // add aditional directories
+ if (this.directories != null) {
+ final Iterator i = directories.iterator();
+ while (i.hasNext()) {
+ final String directory = (String) i.next();
+ // now read all properties from the properties directory
+ ResourceUtils.readProperties(directory, properties, getResourceLoader(), this.resourceFilter, this.logger);
+ // read all properties from the mode dependent directory
+ ResourceUtils.readProperties(directory + '/' + mode, properties, getResourceLoader(), this.resourceFilter, this.logger);
+ }
+ }
+
+ // add additional properties
+ if (this.additionalProperties != null) {
+ PropertyHelper.replaceAll(this.additionalProperties, s);
+ properties.putAll(this.additionalProperties);
+ }
+
+ // now overwrite with system properties
+ try {
+ properties.putAll(System.getProperties());
+ } catch (SecurityException se) {
+ // we ignore this
+ }
+
+ // invoke post initialization hook
+ postInit(s, properties);
+
+ PropertyHelper.replaceAll(properties, getParentSettings());
+ // configure settings
+ s.configure(properties);
+ s.makeReadOnly();
+
+ return s;
+ }
+
+ protected ResourceLoader getResourceLoader() {
+ if (this.resourceLoader != null) {
+ return this.resourceLoader;
+ }
+ if (this.servletContext != null) {
+ return new ServletContextResourceLoader(this.servletContext);
+ } else {
+ return new FileSystemResourceLoader();
+ }
+ }
+
+ protected String getSystemProperty(String key) {
+ return getSystemProperty(key, null);
+ }
+
+ protected String getSystemProperty(String key, String defaultValue) {
+ try {
+ return System.getProperty(key, defaultValue);
+ } catch (SecurityException se) {
+ // we ignore this
+ return defaultValue;
+ }
+ }
+
+ /**
+ * @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 {
+ final BeanDefinitionVisitor visitor = new CocoonSettingsResolvingBeanDefinitionVisitor(this.settings);
+ String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
+ for (int i = 0; i < beanNames.length; i++) {
+ BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(beanNames[i]);
+ try {
+ visitor.visitBeanDefinition(bd);
+ } catch (BeanDefinitionStoreException e) {
+ throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanNames[i], e);
+ }
+ }
+ }
+
+ /**
+ * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#resolvePlaceholder(java.lang.String, java.util.Properties)
+ */
+ protected String resolvePlaceholder(String placeholder, Properties props) {
+ return PropertyHelper.getProperty(placeholder, props, null);
+ }
+
+ protected class CocoonSettingsResolvingBeanDefinitionVisitor
+ extends BeanDefinitionVisitor {
+
+ protected final Properties props;
+ protected final Set visitedPlaceholders = new HashSet();
+
+ public CocoonSettingsResolvingBeanDefinitionVisitor(Settings settings) {
+ this.props = new SettingsProperties(settings);
+ }
+
+ protected String resolveStringValue(String strVal) {
+ return parseStringValue(strVal, this.props, visitedPlaceholders);
+ }
+ }
+
+ /**
+ * Dump the settings object
+ */
+ protected void dumpSettings() {
+ if (this.logger.isDebugEnabled()) {
+ this.logger.debug("===== Settings Start =====");
+ this.logger.debug(this.settings.toString());
+ final List names = this.settings.getPropertyNames();
+ final Iterator i = names.iterator();
+ while (i.hasNext()) {
+ final String name = (String) i.next();
+ this.logger.debug("Property: " + name + "=" + this.settings.getProperty(name));
+ }
+ this.logger.debug("===== Settings End =====");
+ }
+ }
+
+ /**
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject() throws Exception {
+ return this.settings;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+ */
+ public Class getObjectType() {
+ return Settings.class;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+}
View
247 ...c/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsElementParser.java
@@ -0,0 +1,247 @@
+/*
+ * 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.configurator.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.cocoon.spring.configurator.ResourceFilter;
+import org.apache.cocoon.spring.configurator.ResourceUtils;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.w3c.dom.Element;
+
+/**
+ * Abstract class for the settings element parsers.
+ *
+ * @see ChildSettingsElementParser
+ * @see SettingsElementParser
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractSettingsElementParser extends AbstractElementParser {
+
+ /**
+ * Get the current running mode
+ */
+ protected abstract String getRunningMode(Element e);
+
+ /**
+ * Create and register the settings bean factory post processor.
+ */
+ protected abstract void createSettingsBeanFactoryPostProcessor(Element element,
+ ParserContext parserContext,
+ String runningMode);
+
+ private ResourceFilter resourceFilter;
+
+ /**
+ * Get additional includes of property directories.
+ */
+ protected List getPropertyIncludes(Element childSettingsElement) {
+ List propertyDirs = null;
+ if ( childSettingsElement != null ) {
+ final Element[] propertyDirConfigs = this.getChildElements(childSettingsElement, "include-properties");
+ if ( propertyDirConfigs != null && propertyDirConfigs.length > 0 ) {
+ propertyDirs = new ArrayList();
+ for(int i=0; i < propertyDirConfigs.length; i++) {
+ propertyDirs.add(this.getAttributeValue(propertyDirConfigs[i], "dir", null));
+ }
+ }
+ }
+ return propertyDirs;
+ }
+
+ /**
+ * Get additional properties.
+ */
+ protected Properties getAdditionalProperties(Element childSettingsElement) {
+ Properties variables = null;
+ final Element[] properties = this.getChildElements(childSettingsElement, "property");
+ if ( properties != null && properties.length > 0 ) {
+ variables = new Properties();
+ for(int i=0; i<properties.length; i++) {
+ variables.setProperty(this.getAttributeValue(properties[i], "name", null),
+ this.getAttributeValue(properties[i], "value", null));
+ }
+ }
+ return variables;
+ }
+
+ /**
+ * Get additional includes of bean configurations.
+ */
+ protected List getBeanIncludes(Element childSettingsElement) {
+ final List includes = new ArrayList();
+ // search for includes
+ if ( childSettingsElement.hasChildNodes() ) {
+ final Element[] includeElements = this.getChildElements(childSettingsElement, "include-beans");
+ if ( includeElements != null ) {
+ for(int i = 0 ; i < includeElements.length; i++ ) {
+ final String dir = this.getAttributeValue(includeElements[i], "dir", null);
+
+ includes.add(dir);
+ }
+ }
+ }
+ return includes;
+ }
+
+ /**
+ * Return the includes for the property override configuration
+ */
+ protected List getBeanPropertyOverrideIncludes(Element settingsElement) {
+ return this.getBeanIncludes(settingsElement);
+ }
+
+ /**
+ * @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) {
+ final String runningMode = this.getRunningMode(element);
+
+ try {
+ this.resourceFilter = getResourceFilter(element);
+ } catch (Exception e) {
+ throw new BeanDefinitionStoreException("Unable to read filter configuration", e);
+ }
+
+ // create factory for settings object
+ this.createSettingsBeanFactoryPostProcessor(element, parserContext, runningMode);
+
+ // Get bean includes for property overrides
+ final List overridePropertyIncludes = this.getBeanPropertyOverrideIncludes(element);
+
+ // If there are bean includes for a directory, we register a property placeholder configurer
+ if ( overridePropertyIncludes.size() > 0 ) {
+ this.registerPropertyOverrideConfigurer(parserContext, overridePropertyIncludes);
+ }
+
+ // register additonal components
+ this.registerComponents(element, parserContext);
+
+ // Get bean includes
+ final List beanIncludes = this.getBeanIncludes(element);
+ // process bean includes!
+ final Iterator beanIncludeIterator = beanIncludes.iterator();
+ while ( beanIncludeIterator.hasNext() ) {
+ final String dir = (String)beanIncludeIterator.next();
+
+ try {
+ this.handleBeanInclude(parserContext, dir, false);
+ this.handleBeanInclude(parserContext, dir + "/" + runningMode, true);
+ } catch (Exception e) {
+ throw new BeanDefinitionStoreException("Unable to read spring configurations from " + dir, e);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * This method can be used for subclasses to register additional components.
+ */
+ protected void registerComponents(Element settingsElement, ParserContext parserContext) {
+ // nothing to do here
+ }
+
+ /**
+ * Handle include for spring bean configurations.
+ */
+ protected void handleBeanInclude(final ParserContext parserContext,
+ final String path,
+ final boolean optional)
+ throws Exception {
+ final ResourcePatternResolver resolver =
+ (ResourcePatternResolver) parserContext.getReaderContext().getReader().getResourceLoader();
+
+ // check if the directory to read from exists
+ // we only check if optional is set to true
+ boolean load = true;
+ if ( optional
+ && !ResourceUtils.isClasspathUri(path) ) {
+ final Resource rsrc = resolver.getResource(path);
+ if ( !rsrc.exists()) {
+ load = false;
+ }
+ }
+ if ( load ) {
+ try {
+ Resource[] resources = resolver.getResources(path + "/*.xml");
+ resources = ResourceUtils.filterResources(resources, getResourceFilter());
+ Arrays.sort(resources, ResourceUtils.getResourceComparator());
+ for (int i = 0; i < resources.length; i++) {
+ this.handleImport(parserContext, resources[i].getURL().toExternalForm());
+ }
+ } catch (IOException ioe) {
+ throw new Exception("Unable to read configurations from " + path, ioe);
+ }
+ }
+ }
+
+ protected void handleImport(ParserContext parserContext, String uri) {
+ final ResourceLoader resourceLoader = parserContext.getReaderContext().getReader().getResourceLoader();
+ parserContext.getDelegate().getReaderContext().getReader().loadBeanDefinitions(resourceLoader.getResource(uri));
+ }
+
+ /**
+ * Register a property placeholder configurer. The configurer will read all
+ * *.properties files from the specified locations.
+ *
+ * @param parserContext
+ * @param locations
+ */
+ protected void registerPropertyOverrideConfigurer(final ParserContext parserContext,
+ final List locations) {
+ final RootBeanDefinition beanDef = this.createBeanDefinition(ExtendedPropertyOverrideConfigurer.class.getName(),
+ null, true);
+ beanDef.getPropertyValues().addPropertyValue("locations", locations);
+ beanDef.getPropertyValues().addPropertyValue("resourceLoader",
+ parserContext.getReaderContext().getReader().getResourceLoader());
+ beanDef.getPropertyValues().addPropertyValue("resourceFilter", getResourceFilter());
+ beanDef.getPropertyValues().addPropertyValue("beanNameSeparator", "/");
+ this.register(beanDef, ExtendedPropertyOverrideConfigurer.class.getName(), parserContext.getRegistry());
+ }
+
+
+ protected ResourceFilter getResourceFilter(Element e) throws Exception {
+ Element[] filters = this.getChildElements(e, "filter");
+
+ if (filters.length == 0)
+ return null;
+ else if (filters.length > 1)
+ throw new RuntimeException("Only one filter definition is allowed and you configured " + filters.length + " filters.");
+
+ String filterClassName = filters[0].getAttribute("class");
+ if (filterClassName.length() == 0)
+ throw new RuntimeException("Missing 'class' attribute.");
+ return (ResourceFilter)java.lang.Class.forName(filterClassName).newInstance();
+ }
+
+ protected final ResourceFilter getResourceFilter() {
+ return this.resourceFilter;
+ }
+}
View
335 ...-configurator-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMap.java
@@ -0,0 +1,335 @@
+/*
+ * 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.configurator.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.springframework.beans.BeanWrapperImpl;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.HierarchicalBeanFactory;
+import org.springframework.beans.factory.ListableBeanFactory;
+
+/**
+ * This is a map implementation collecting all beans of a specific type (class)
+ * from a spring bean factory. The beans are available through their configured
+ * bean id.
+ *
+ * The map has a lazy implementation: the beans are not searched on
+ * instantiation but the first time the map is accessed. This avoids any startup
+ * ordering problems.
+ *
+ * By default the map searches in the bean factory it is used in and in all the
+ * parent bean factories (if there are any). This behaviour can be changed by
+ * calling the {@link #setCheckParent(boolean)} method.
+ *
+ * @version $Id$
+ * @since 1.0.1
+ */
+public class BeanMap implements Map<Object, Object>, BeanFactoryAware {
+
+ /** The real map. */
+ protected final Map<Object, Object> beanMap = new HashMap<Object, Object>();
+
+ /** Is the map initialized? */
+ protected boolean initialized = false;
+
+ /** The bean factory. */
+ protected ListableBeanFactory beanFactory;
+
+ /** The class for all beans in this map. */
+ protected Class<?> beanClass;
+
+ /** Do we strip the prefix from the bean name? */
+ protected boolean stripPrefix = true;
+
+ /** Do we check the parent factories? */
+ protected boolean checkParent = true;
+
+ /** Do we check for properties? */
+ protected List<String> hasProperties = new ArrayList<String>();
+
+ /** Which property should we use to key the map? */
+ protected String keyProperty;
+
+ /**
+ * Get all the beans from the bean factory and put them into a map using their id.
+ *
+ * @param beanNames The bean names to load.
+ */
+ protected void load(Set<String> beanNames) {
+ for (String beanName : beanNames) {
+ Object key = this.stripPrefix(beanName);
+ if (this.hasProperties.size() > 0) {
+ final Object bean = this.beanFactory.getBean(beanName);
+ final BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
+ boolean isOk = true;
+ for (String propName : this.hasProperties) {
+ if (!wrapper.isReadableProperty(propName)) {
+ isOk = false;
+ }
+ }
+ if (isOk) {
+ if (this.keyProperty != null && this.keyProperty.length() > 0
+ && wrapper.isReadableProperty(this.keyProperty)) {
+ key = wrapper.getPropertyValue(this.keyProperty);
+ }
+ this.beanMap.put(key, bean);
+ }
+ } else {
+ final Object bean = this.beanFactory.getBean(beanName);
+ final BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
+ if (this.keyProperty != null && this.keyProperty.length() > 0
+ && wrapper.isReadableProperty(this.keyProperty)) {
+ key = wrapper.getPropertyValue(this.keyProperty);
+ }
+ this.beanMap.put(key, bean);
+ }
+ }
+ }
+
+ protected Object stripPrefix(final String beanName) {
+ final String prefix1 = this.beanClass.getName() + '.';
+ final String prefix2 = this.beanClass.getName() + '/';
+
+ Object key = beanName;
+ if (this.stripPrefix && (beanName.startsWith(prefix1) || beanName.startsWith(prefix2))) {
+ key = beanName.substring(prefix1.length());
+ }
+
+ return key;
+ }
+
+ /**
+ * Check if the bean is already initialized. If not, the bean's are searched
+ * in the bean factory.
+ */
+ protected void checkInit() {
+ if (!this.initialized) {
+ synchronized (this) {
+ if (!this.initialized) {
+ // although it is unlikely, but if this bean is used outside
+ // spring
+ // it will just contain an empty map
+ if (this.beanFactory != null) {
+ final Set<String> beanNames = new HashSet<String>();
+ this.getBeanNames(this.beanFactory, beanNames);
+ this.load(beanNames);
+ }
+ this.initialized = true;
+ }
+ }
+ }
+ }
+
+ /**
+ * Get all bean names for the given type.
+ *
+ * @param factory
+ * The bean factory.
+ * @param beanNames
+ * The set containing the resulting bean names.
+ */
+ protected void getBeanNames(ListableBeanFactory factory, Set<String> beanNames) {
+ // check parent first
+ if (this.checkParent) {
+ if (factory instanceof HierarchicalBeanFactory) {
+ if (((HierarchicalBeanFactory) factory).getParentBeanFactory() != null) {
+ this.getBeanNames((ListableBeanFactory) ((HierarchicalBeanFactory) factory).getParentBeanFactory(),
+ beanNames);
+ }
+ }
+ }
+ // get all bean names for our class
+ final String[] names = this.lookupBeans(factory);
+ for (int i = 0; i < names.length; i++) {
+ beanNames.add(names[i]);
+ }
+ }
+
+ protected String[] lookupBeans(ListableBeanFactory factory) {
+ return factory.getBeanNamesForType(this.beanClass);
+ }
+
+ /**
+ * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+ */
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ if (!(factory instanceof ListableBeanFactory)) {
+ throw new BeanDefinitionStoreException("BeanFactory must be listable.");
+ }
+ this.beanFactory = (ListableBeanFactory) factory;
+ }
+
+ public void setStripPrefix(boolean stripPrefix) {
+ this.stripPrefix = stripPrefix;
+ }
+
+ public void setCheckParent(boolean checkParent) {
+ this.checkParent = checkParent;
+ }
+
+ public void setHasProperties(String pHasProperties) {
+ final StringTokenizer tokenizer = new StringTokenizer(pHasProperties, " \t\n\r\f,");
+ final List<String> propNames = new ArrayList<String>();
+ while (tokenizer.hasMoreTokens()) {
+ propNames.add(tokenizer.nextToken());
+ }
+ this.hasProperties = propNames;
+ }
+
+ public void setKeyProperty(String pKeyProperty) {
+ this.keyProperty = pKeyProperty;
+ }
+
+ public void setType(Class<?> typeClass) {
+ this.beanClass = typeClass;
+ }
+
+ /**
+ * @see java.util.Map#clear()
+ */
+ public void clear() {
+ // no need to call checkInit as we clear the map!
+ this.initialized = true;
+ this.beanMap.clear();
+ }
+
+ /**
+ * @see java.util.Map#containsKey(java.lang.Object)
+ */
+ public boolean containsKey(Object key) {
+ this.checkInit();
+ return this.beanMap.containsKey(key);
+ }
+
+ /**
+ * @see java.util.Map#containsValue(java.lang.Object)
+ */
+ public boolean containsValue(Object value) {
+ this.checkInit();
+ return this.beanMap.containsValue(value);
+ }
+
+ /**
+ * @see java.util.Map#entrySet()
+ */
+ public Set<Entry<Object, Object>> entrySet() {
+ this.checkInit();
+ return this.beanMap.entrySet();
+ }
+
+ /**
+ * @see java.util.Map#get(java.lang.Object)
+ */
+ public Object get(Object key) {
+ this.checkInit();
+ return this.beanMap.get(key);
+ }
+
+ /**
+ * @see java.util.Map#isEmpty()
+ */
+ public boolean isEmpty() {
+ this.checkInit();
+ return this.beanMap.isEmpty();
+ }
+
+ /**
+ * @see java.util.Map#keySet()
+ */
+ public Set<Object> keySet() {
+ this.checkInit();
+ return this.beanMap.keySet();
+ }
+
+ /**
+ * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+ */
+ public Object put(Object key, Object value) {
+ this.checkInit();
+ return this.beanMap.put(key, value);
+ }
+
+ /**
+ * @see java.util.Map#putAll(java.util.Map)
+ */
+ public void putAll(Map<?, ?> t) {
+ this.checkInit();
+ this.beanMap.putAll(t);
+ }
+
+ /**
+ * @see java.util.Map#remove(java.lang.Object)
+ */
+ public Object remove(Object key) {
+ this.checkInit();
+ return this.beanMap.remove(key);
+ }
+
+ /**
+ * @see java.util.Map#size()
+ */
+ public int size() {
+ this.checkInit();
+ return this.beanMap.size();
+ }
+
+ /**
+ * @see java.util.Map#values()
+ */
+ public Collection<Object> values() {
+ this.checkInit();
+ return this.beanMap.values();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ this.checkInit();
+ return this.beanMap.equals(obj);
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ this.checkInit();
+ return this.beanMap.hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ this.checkInit();
+ return this.beanMap.toString();
+ }
+}
View
59 ...-2.1.0/src/main/java/org/apache/cocoon/spring/configurator/impl/BeanMapElementParser.java
@@ -0,0 +1,59 @@
+/*
+ * 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.configurator.impl;
+
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.ClassUtils;
+import org.w3c.dom.Element;
+
+/**
+ * The parser for the bean-map element.
+ *
+ * @version $Id$
+ * @since 1.0.1
+ */
+public class BeanMapElementParser 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) {
+ // create a new bean definition for the aspect chain
+ RootBeanDefinition beanDef = this.createBeanDefinition(BeanMap.class, null, false);
+ final String type = this.getAttributeValue(element, "type", null);
+ final Class typeClass;
+ try {
+ typeClass = ClassUtils.forName(type);
+ } catch (ClassNotFoundException e) {
+ throw new BeanDefinitionStoreException("Unable to load aspect class: " + type, e);
+ }
+ beanDef.getPropertyValues().addPropertyValue("type", typeClass);
+ beanDef.getPropertyValues().addPropertyValue("checkParent", this.getAttributeValue(element, "check-parent", "true"));
+ beanDef.getPropertyValues().addPropertyValue("stripPrefix", this.getAttributeValue(element, "strip-prefix", "true"));
+ beanDef.getPropertyValues().addPropertyValue("hasProperties", this.getAttributeValue(element, "has-properties", ""));
+ beanDef.getPropertyValues().addPropertyValue("keyProperty", this.getAttributeValue(element, "key-property", ""));
+
+ // register bean if it's a global definition
+ if ( !parserContext.isNested() ) {
+ this.register(beanDef, element, parserContext.getRegistry());
+ }
+ return beanDef;
+ }
+}
View
61 ...ava/org/apache/cocoon/spring/configurator/impl/ChildSettingsBeanFactoryPostProcessor.java
@@ -0,0 +1,61 @@
+/*
+ * 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.configurator.impl;
+
+
+/**
+ * This is a bean factory post processor which sets up a child settings object.
+ *
+ * The settings object is created by reading several property files and merging of
+ * the values. If there is more than one definition for a property, the last one wins.
+ * The property files are read in the following order:
+ * 1) Property provider (if configured in the bean factory)
+ * 2) Add properties from configured directories {@link #directories}.
+ * 3) Add additional properties configured at {@link #additionalProperties}
+ * 4) System properties
+ *
+ * @since 1.0
+ * @version $Id$
+ */
+public class ChildSettingsBeanFactoryPostProcessor
+ extends AbstractSettingsBeanFactoryPostProcessor {
+
+ /** Unique name for this child settings context. */
+ protected String name;
+
+ /**
+ * Set the unique name for this settings context.
+ * @param newName The new name.
+ */
+ public void setName(String newName) {
+ this.name = newName;
+ }
+
+ /**
+ * @see org.apache.cocoon.spring.configurator.impl.AbstractSettingsBeanFactoryPostProcessor#getRunningMode()
+ */
+ protected String getRunningMode() {
+ return this.getParentSettings().getRunningMode();
+ }
+
+ /**
+ * @see org.apache.cocoon.spring.configurator.impl.AbstractSettingsBeanFactoryPostProcessor#getNameForPropertyProvider()
+ */
+ protected String getNameForPropertyProvider() {
+ return this.name;
+ }
+}
View
75 .../src/main/java/org/apache/cocoon/spring/configurator/impl/ChildSettingsElementParser.java
@@ -0,0 +1,75 @@
+/*
+ * 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.configurator.impl;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.web.context.WebApplicationContext;
+import org.w3c.dom.Element;
+
+/**
+ * Add a bean definition for the settings object of a child context to the bean factory
+ * and process all includes of spring configurations.
+ *
+ * @see ConfiguratorNamespaceHandler
+ * @see ChildSettingsBeanFactoryPostProcessor
+ * @version $Id$
+ * @since 1.0
+ */
+public class ChildSettingsElementParser extends AbstractSettingsElementParser {
+
+ /**
+ * @see org.apache.cocoon.spring.configurator.impl.AbstractSettingsElementParser#getRunningMode(org.w3c.dom.Element)
+ */
+ protected String getRunningMode(Element e) {
+ // get root application context
+ final WebApplicationContext rootAppContext = WebAppContextUtils.getCurrentWebApplicationContext();
+ // get running mode from root settings
+ return ((Settings)rootAppContext.getBean(Settings.ROLE)).getRunningMode();
+ }
+
+ /**
+ * Create and register the settings bean factory post processor.
+ */
+ protected void createSettingsBeanFactoryPostProcessor(Element element,
+ ParserContext parserContext,
+ String runningMode) {
+ // Create definition for child settings
+ RootBeanDefinition def = this.createBeanDefinition(ChildSettingsBeanFactoryPostProcessor.class.getName(),
+ "init",
+ false);
+ def.getPropertyValues().addPropertyValue("name", element.getAttribute("name"));
+
+ final Properties additionalProps = this.getAdditionalProperties(element);
+ if ( additionalProps != null ) {
+ def.getPropertyValues().addPropertyValue("additionalProperties", additionalProps);
+ }
+
+ final List propertiesIncludes = this.getPropertyIncludes(element);
+ if ( propertiesIncludes != null ) {
+ def.getPropertyValues().addPropertyValue("directories", propertiesIncludes);
+ }
+
+ // and now we register the child settings
+ this.register(def, Settings.ROLE, parserContext.getRegistry());
+ }
+}
View
119 ...c/main/java/org/apache/cocoon/spring/configurator/impl/ChildXmlWebApplicationContext.java
@@ -0,0 +1,119 @@
+/*
+ * 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.configurator.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.UrlResource;
+import org.springframework.util.ResourceUtils;
+import org.springframework.web.context.support.XmlWebApplicationContext;
+
+/**
+ * Own implementation of a {@link XmlWebApplicationContext} which is configured with
+ * a base url specifying the root directory for this web application context.
+ *
+ * @since 1.0
+ * @version $Id$
+ */
+public class ChildXmlWebApplicationContext extends XmlWebApplicationContext {
+
+ /** The base url (already postfixed with a '/'). */
+ protected String baseUrl;
+
+ /** The bean definition for this context. */
+ protected String beanDefinition;
+
+ public ChildXmlWebApplicationContext() {
+ // nothing to do here
+ }
+
+ public ChildXmlWebApplicationContext(String url,
+ String rootDefinition) {
+ this.setBaseUrl(url);
+ this.setBeanDefinition(rootDefinition);
+ }
+
+ public String getBaseUrl() {
+ return this.baseUrl;
+ }
+
+ public void setBaseUrl(String url) {
+ if ( url.endsWith("/") ) {
+ this.baseUrl = url;
+ } else {
+ this.baseUrl = url + '/';
+ }
+ }
+
+ public String getBeanDefinition() {
+ return beanDefinition;
+ }
+
+ public void setBeanDefinition(String beanDefinition) {
+ this.beanDefinition = beanDefinition;
+ }
+
+ /**
+ * @see org.springframework.web.context.support.XmlWebApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
+ */
+ protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException {
+ if ( this.beanDefinition != null ) {
+ reader.loadBeanDefinitions(new ByteArrayResource(th