From: <fg...@us...> - 2010-03-19 22:24:35
|
Revision: 2163 http://openutils.svn.sourceforge.net/openutils/?rev=2163&view=rev Author: fgiust Date: 2010-03-19 22:24:28 +0000 (Fri, 19 Mar 2010) Log Message: ----------- [maven-release-plugin] copy for tag openutils-deployment-2.2 Added Paths: ----------- tags/openutils-deployment-2.2/ tags/openutils-deployment-2.2/pom.xml tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/Property.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/PropertyAnnotationsUtils.java tags/openutils-deployment-2.2/src/test/java/it/openutils/deployment/spring/PropertyInjectBeanPostProcessorTest.java tags/openutils-deployment-2.2/src/test/java/it/openutils/deployment/spring/SampleBean.java Removed Paths: ------------- tags/openutils-deployment-2.2/pom.xml tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/Property.java tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/PropertyAnnotationsUtils.java tags/openutils-deployment-2.2/src/test/java/it/openutils/deployment/spring/PropertyInjectBeanPostProcessorTest.java tags/openutils-deployment-2.2/src/test/java/it/openutils/deployment/spring/SampleBean.java Deleted: tags/openutils-deployment-2.2/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-deployment-2.2/pom.xml 2010-03-19 22:24:28 UTC (rev 2163) @@ -1,117 +0,0 @@ -<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> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils-parent</artifactId> - <version>1.2</version> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>2.1.4-SNAPSHOT</version> - <description>Openutils deployment tools</description> - <licenses> - <license> - <name>The Apache Software License, Version 2.0</name> - <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> - </license> - </licenses> - <url>http://www.openmindlab.com/lab/products/deployment.html</url> - <issueManagement> - <system>jira</system> - <url>http://jira.openmindlab.com/browse/DEPLOY</url> - </issueManagement> - <build> - <plugins> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <id>bundle</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - <configuration> - <descriptors> - <descriptor>${basedir}/src/main/assembly/assembly-bundle.xml</descriptor> - </descriptors> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>${spring.version}</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <version>${spring.version}</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - <exclusion> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.7</version> - <scope>test</scope> - </dependency> - </dependencies> - <properties> - <spring.version>3.0.0.RELEASE</spring.version> - </properties> -</project> Copied: tags/openutils-deployment-2.2/pom.xml (from rev 2162, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-2.2/pom.xml (rev 0) +++ tags/openutils-deployment-2.2/pom.xml 2010-03-19 22:24:28 UTC (rev 2163) @@ -0,0 +1,103 @@ +<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> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-parent</artifactId> + <version>1.2</version> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>2.2</version> + <description>Openutils deployment tools</description> + <inceptionYear>2007</inceptionYear> + <licenses> + <license> + <name>The Apache Software License, Version 2.0</name> + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> + </license> + </licenses> + <url>http://www.openmindlab.com/lab/products/deployment.html</url> + <issueManagement> + <system>jira</system> + <url>http://jira.openmindlab.com/browse/DEPLOY</url> + </issueManagement> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>${spring.version}</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${spring.version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.7</version> + <scope>test</scope> + </dependency> + </dependencies> + <properties> + <spring.version>3.0.0.RELEASE</spring.version> + </properties> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-2.2</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-2.2</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-2.2</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -1,110 +0,0 @@ -/** - * - * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) - * Copyright(C) null-2010, Openmind S.r.l. http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.deployment.log4j; - -import java.io.File; -import java.io.FileNotFoundException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.MessageFormat; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DeploymentResolver -{ - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(DeploymentResolver.class); - - public static File resolveServerRelativeLocation(ServletContext context, String commaSeparatedListOfPaths) - throws FileNotFoundException - { - String[] propertiesLocation = StringUtils.split(commaSeparatedListOfPaths, ','); - - String servername = resolveServerName(); - - String rootPath = StringUtils.stripEnd(StringUtils.replace(context.getRealPath("/"), "\\", "/"), "/"); //$NON-NLS-1$ //$NON-NLS-2$ - String webapp = StringUtils.substringAfterLast(rootPath, "/"); //$NON-NLS-1$ - - log.info("Resolving log configuration using servername={} and webapp={}", servername, webapp); - - for (int j = 0; j < propertiesLocation.length; j++) - { - String location = StringUtils.trim(propertiesLocation[j]); - location = StringUtils.replace(location, "${servername}", servername); //$NON-NLS-1$ - location = StringUtils.replace(location, "${webapp}", webapp); //$NON-NLS-1$ - - File initFile = new File(rootPath, location); - - if (!initFile.exists() || initFile.isDirectory()) - { - log.debug("Log4j config not found at {}", initFile.getAbsolutePath()); - continue; - } - - log.debug("Log4j config FOUND at {}", initFile.getAbsolutePath()); - - return initFile; - - } - - throw new FileNotFoundException( - MessageFormat - .format( - "No configuration found using location list {0}. [servername] is [{1}], [webapp] is [{2}] and base path is [{3}]", //$NON-NLS-1$ - new Object[]{ArrayUtils.toString(propertiesLocation), servername, webapp, rootPath })); - - } - - /** - * Resolve the current server name. - * @return server name, all lowercase, without domain - */ - public static String resolveServerName() - { - String servername = null; - - try - { - servername = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); - if (StringUtils.contains(servername, ".")) - { - servername = StringUtils.substringBefore(servername, "."); - } - - } - catch (UnknownHostException e) - { - System.err.println(e.getMessage()); - } - return servername; - } -} Copied: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java (from rev 2161, trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java) =================================================================== --- tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java (rev 0) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/DeploymentResolver.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -0,0 +1,110 @@ +/** + * + * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) + * Copyright(C) 2007-2010, Openmind S.r.l. http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.deployment.log4j; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.MessageFormat; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DeploymentResolver +{ + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(DeploymentResolver.class); + + public static File resolveServerRelativeLocation(ServletContext context, String commaSeparatedListOfPaths) + throws FileNotFoundException + { + String[] propertiesLocation = StringUtils.split(commaSeparatedListOfPaths, ','); + + String servername = resolveServerName(); + + String rootPath = StringUtils.stripEnd(StringUtils.replace(context.getRealPath("/"), "\\", "/"), "/"); //$NON-NLS-1$ //$NON-NLS-2$ + String webapp = StringUtils.substringAfterLast(rootPath, "/"); //$NON-NLS-1$ + + log.info("Resolving log configuration using servername={} and webapp={}", servername, webapp); + + for (int j = 0; j < propertiesLocation.length; j++) + { + String location = StringUtils.trim(propertiesLocation[j]); + location = StringUtils.replace(location, "${servername}", servername); //$NON-NLS-1$ + location = StringUtils.replace(location, "${webapp}", webapp); //$NON-NLS-1$ + + File initFile = new File(rootPath, location); + + if (!initFile.exists() || initFile.isDirectory()) + { + log.debug("Log4j config not found at {}", initFile.getAbsolutePath()); + continue; + } + + log.debug("Log4j config FOUND at {}", initFile.getAbsolutePath()); + + return initFile; + + } + + throw new FileNotFoundException( + MessageFormat + .format( + "No configuration found using location list {0}. [servername] is [{1}], [webapp] is [{2}] and base path is [{3}]", //$NON-NLS-1$ + new Object[]{ArrayUtils.toString(propertiesLocation), servername, webapp, rootPath })); + + } + + /** + * Resolve the current server name. + * @return server name, all lowercase, without domain + */ + public static String resolveServerName() + { + String servername = null; + + try + { + servername = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + if (StringUtils.contains(servername, ".")) + { + servername = StringUtils.substringBefore(servername, "."); + } + + } + catch (UnknownHostException e) + { + System.err.println(e.getMessage()); + } + return servername; + } +} Deleted: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -1,126 +0,0 @@ -/** - * - * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) - * Copyright(C) null-2010, Openmind S.r.l. http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.deployment.log4j; - -import java.io.FileNotFoundException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.springframework.util.Log4jConfigurer; -import org.springframework.web.util.Log4jConfigListener; -import org.springframework.web.util.WebUtils; - - -/** - * @author Fabrizio Giustina - * @version $Id$ - */ -public class EnvironmentLog4jConfigListener extends Log4jConfigListener -{ - - /** - * Default value for the DEFAULT_INITIALIZATION_PARAMETER parameter. - */ - public static final String DEFAULT_INITIALIZATION_PARAMETER = // - "WEB-INF/config/${servername}/${webapp}/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/${servername}/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/${webapp}/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/default/log4j.xml," //$NON-NLS-1$ - + "WEB-INF/config/log4j.xml"; //$NON-NLS-1$ - - /** - * {@inheritDoc} - */ - @Override - public void contextInitialized(ServletContextEvent event) - { - initLogging(event.getServletContext()); - } - - public static void initLogging(ServletContext servletContext) - { - if (exposeWebAppRoot(servletContext)) - { - WebUtils.setWebAppRootSystemProperty(servletContext); - } - - String servername = DeploymentResolver.resolveServerName(); - if (servername != null) - { - System.setProperty("server.name", servername); - System.setProperty("server", servername); - } - - String locationList = servletContext.getInitParameter("log4jConfigLocation"); - - if (locationList == null) - { - locationList = DEFAULT_INITIALIZATION_PARAMETER; - } - - String location; - - try - { - location = DeploymentResolver.resolveServerRelativeLocation(servletContext, locationList).getAbsolutePath(); - } - catch (FileNotFoundException ex) - { - throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); - } - if (location != null) - { - servletContext.log("Initializing Log4J from [" + location + "]"); - try - { - - String intervalString = servletContext.getInitParameter("log4jRefreshInterval"); - if (intervalString != null) - { - try - { - long refreshInterval = Long.parseLong(intervalString); - Log4jConfigurer.initLogging(location, refreshInterval); - } - catch (NumberFormatException ex) - { - throw new IllegalArgumentException("Invalid 'log4jRefreshInterval' parameter: " - + ex.getMessage()); - } - } - else - { - Log4jConfigurer.initLogging(location); - } - } - catch (FileNotFoundException ex) - { - throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); - } - } - } - - private static boolean exposeWebAppRoot(ServletContext servletContext) - { - String exposeWebAppRootParam = servletContext.getInitParameter("log4jExposeWebAppRoot"); - return exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam).booleanValue(); - } - -} Copied: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java (from rev 2161, trunk/openutils-deployment/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java) =================================================================== --- tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java (rev 0) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/log4j/EnvironmentLog4jConfigListener.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -0,0 +1,126 @@ +/** + * + * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) + * Copyright(C) 2007-2010, Openmind S.r.l. http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.deployment.log4j; + +import java.io.FileNotFoundException; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.springframework.util.Log4jConfigurer; +import org.springframework.web.util.Log4jConfigListener; +import org.springframework.web.util.WebUtils; + + +/** + * @author Fabrizio Giustina + * @version $Id$ + */ +public class EnvironmentLog4jConfigListener extends Log4jConfigListener +{ + + /** + * Default value for the DEFAULT_INITIALIZATION_PARAMETER parameter. + */ + public static final String DEFAULT_INITIALIZATION_PARAMETER = // + "WEB-INF/config/${servername}/${webapp}/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/${servername}/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/${webapp}/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/default/log4j.xml," //$NON-NLS-1$ + + "WEB-INF/config/log4j.xml"; //$NON-NLS-1$ + + /** + * {@inheritDoc} + */ + @Override + public void contextInitialized(ServletContextEvent event) + { + initLogging(event.getServletContext()); + } + + public static void initLogging(ServletContext servletContext) + { + if (exposeWebAppRoot(servletContext)) + { + WebUtils.setWebAppRootSystemProperty(servletContext); + } + + String servername = DeploymentResolver.resolveServerName(); + if (servername != null) + { + System.setProperty("server.name", servername); + System.setProperty("server", servername); + } + + String locationList = servletContext.getInitParameter("log4jConfigLocation"); + + if (locationList == null) + { + locationList = DEFAULT_INITIALIZATION_PARAMETER; + } + + String location; + + try + { + location = DeploymentResolver.resolveServerRelativeLocation(servletContext, locationList).getAbsolutePath(); + } + catch (FileNotFoundException ex) + { + throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); + } + if (location != null) + { + servletContext.log("Initializing Log4J from [" + location + "]"); + try + { + + String intervalString = servletContext.getInitParameter("log4jRefreshInterval"); + if (intervalString != null) + { + try + { + long refreshInterval = Long.parseLong(intervalString); + Log4jConfigurer.initLogging(location, refreshInterval); + } + catch (NumberFormatException ex) + { + throw new IllegalArgumentException("Invalid 'log4jRefreshInterval' parameter: " + + ex.getMessage()); + } + } + else + { + Log4jConfigurer.initLogging(location); + } + } + catch (FileNotFoundException ex) + { + throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); + } + } + } + + private static boolean exposeWebAppRoot(ServletContext servletContext) + { + String exposeWebAppRootParam = servletContext.getInitParameter("log4jExposeWebAppRoot"); + return exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam).booleanValue(); + } + +} Deleted: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -1,194 +0,0 @@ -/** - * - * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) - * Copyright(C) null-2010, Openmind S.r.l. http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.deployment.spring; - -import java.io.IOException; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Properties; - -import javax.sql.DataSource; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowCallbackHandler; - - -/** - * @author fgiust - * @version $Id$ - */ -public class DatabaseEnvironmentPropertyConfigurer extends EnvironmentPropertyConfigurer - implements - ApplicationContextAware, - ApplicationListener -{ - - private static Logger log = LoggerFactory.getLogger(DatabaseEnvironmentPropertyConfigurer.class); - - private String sqlQuery; - - private String dataSourceName; - - private DataSource dataSource; - - private ApplicationContext applicationContext; - - public void setSqlQuery(String sqlQuery) - { - this.sqlQuery = sqlQuery; - } - - public void setDataSourceName(String dataSourceName) - { - this.dataSourceName = dataSourceName; - } - - /** - * {@inheritDoc} - */ - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException - { - this.applicationContext = applicationContext; - } - - /** - * Get Spring Context proprieties. - * @return A properties object containing all spring properties. - */ - @Override - public Properties getProperties() - { - // loadAndRefresh(); @todo is this needed anymore? - return properties; - } - - /** - * @throws IOException - */ - private void loadAndRefresh() throws IOException - { - properties = mergeProperties(); - refresh(); - } - - /** - * used to reload configuration code from db - */ - public void refresh() - { - manuallyLoadDatasource(); - - /** - * inner utility class to create properties from rows extracted by the query - * @author diego - * @version $Id$ - */ - class RowHandler implements RowCallbackHandler - { - - /** - * {@inheritDoc} - */ - public void processRow(final ResultSet rs) throws SQLException - { - String parmName = rs.getString(1); - String parmValue = rs.getString(2); - - log.debug("Configuring property {}={}", parmName, parmValue); - properties.put(parmName, parmValue); - - } - } - - JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); - try - { - jdbcTemplate.query(sqlQuery, new RowHandler()); - } - catch (DataAccessException e) - { - log.error(e.getMessage()); - } - } - - /** - * {@inheritDoc} - */ - public void onApplicationEvent(ApplicationEvent event) - { - manuallyLoadDatasource(); - } - - /** - * - */ - private void manuallyLoadDatasource() - { - if (dataSource == null) - { - dataSource = (DataSource) applicationContext.getBean(dataSourceName); - try - { - properties = mergeProperties(); - } - catch (IOException e) - { - log.debug("Exception while loading environment properties from file."); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - - super.postProcessBeanFactory(beanFactory); - - try - { - loadAndRefresh(); - Properties mergedProps = properties; - - // Convert the merged properties, if necessary. - convertProperties(mergedProps); - - // Let the subclass process the properties. - processProperties(beanFactory, mergedProps); - } - catch (IOException ex) - { - throw new BeanInitializationException("Could not load properties", ex); - } - - } -} Copied: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java (from rev 2161, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/DatabaseEnvironmentPropertyConfigurer.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -0,0 +1,194 @@ +/** + * + * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) + * Copyright(C) 2007-2010, Openmind S.r.l. http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.deployment.spring; + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import javax.sql.DataSource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanInitializationException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; + + +/** + * @author fgiust + * @version $Id$ + */ +public class DatabaseEnvironmentPropertyConfigurer extends EnvironmentPropertyConfigurer + implements + ApplicationContextAware, + ApplicationListener +{ + + private static Logger log = LoggerFactory.getLogger(DatabaseEnvironmentPropertyConfigurer.class); + + private String sqlQuery; + + private String dataSourceName; + + private DataSource dataSource; + + private ApplicationContext applicationContext; + + public void setSqlQuery(String sqlQuery) + { + this.sqlQuery = sqlQuery; + } + + public void setDataSourceName(String dataSourceName) + { + this.dataSourceName = dataSourceName; + } + + /** + * {@inheritDoc} + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.applicationContext = applicationContext; + } + + /** + * Get Spring Context proprieties. + * @return A properties object containing all spring properties. + */ + @Override + public Properties getProperties() + { + // loadAndRefresh(); @todo is this needed anymore? + return properties; + } + + /** + * @throws IOException + */ + private void loadAndRefresh() throws IOException + { + properties = mergeProperties(); + refresh(); + } + + /** + * used to reload configuration code from db + */ + public void refresh() + { + manuallyLoadDatasource(); + + /** + * inner utility class to create properties from rows extracted by the query + * @author diego + * @version $Id$ + */ + class RowHandler implements RowCallbackHandler + { + + /** + * {@inheritDoc} + */ + public void processRow(final ResultSet rs) throws SQLException + { + String parmName = rs.getString(1); + String parmValue = rs.getString(2); + + log.debug("Configuring property {}={}", parmName, parmValue); + properties.put(parmName, parmValue); + + } + } + + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + try + { + jdbcTemplate.query(sqlQuery, new RowHandler()); + } + catch (DataAccessException e) + { + log.error(e.getMessage()); + } + } + + /** + * {@inheritDoc} + */ + public void onApplicationEvent(ApplicationEvent event) + { + manuallyLoadDatasource(); + } + + /** + * + */ + private void manuallyLoadDatasource() + { + if (dataSource == null) + { + dataSource = (DataSource) applicationContext.getBean(dataSourceName); + try + { + properties = mergeProperties(); + } + catch (IOException e) + { + log.debug("Exception while loading environment properties from file."); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + + super.postProcessBeanFactory(beanFactory); + + try + { + loadAndRefresh(); + Properties mergedProps = properties; + + // Convert the merged properties, if necessary. + convertProperties(mergedProps); + + // Let the subclass process the properties. + processProperties(beanFactory, mergedProps); + } + catch (IOException ex) + { + throw new BeanInitializationException("Could not load properties", ex); + } + + } +} Deleted: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2010-03-19 09:34:10 UTC (rev 2159) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -1,451 +0,0 @@ -/** - * - * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) - * Copyright(C) null-2010, Openmind S.r.l. http://www.openmindonline.it - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package it.openutils.deployment.spring; - -import java.beans.PropertyDescriptor; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.PropertyValues; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.util.ResourceUtils; -import org.springframework.util.StringValueResolver; -import org.springframework.web.context.WebApplicationContext; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer - implements - ApplicationContextAware, - SmartInstantiationAwareBeanPostProcessor -{ - - /** - * Application name (webapp name) variable. - */ - private static final String PROPERTY_APPL = "${appl}"; - - /** - * Environment (server name) variable. - */ - private static final String PROPERTY_ENV = "${env}"; - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); - - /** - * @deprecated use defaultLocation - */ - @Deprecated - private String defaultEnvironment; - - private ServletContext servletContext; - - private String fileLocation; - - /** - * Cached properties (super field is private). - */ - protected Properties properties; - - /** - * Are properties inherited from default configuration? default is true, - */ - private boolean inherit = true; - - /** - * Set all the properties configured as system properties. - */ - private boolean exposeSystemProperties; - - private String nullValue; - - /** - * Setter for <code>fileLocation</code>. - * @param fileLocation The fileLocation to set. - */ - public void setFileLocation(String fileLocation) - { - this.fileLocation = fileLocation; - } - - /** - * Sets the inherit. - * @param inherit the inherit to set - */ - public void setInherit(boolean inherit) - { - this.inherit = inherit; - } - - /** - * Setter for <code>defaultEnvironment</code>. - * @param defaultEnvironment The defaultEnvironment to set. - * @deprecated use defaultLocation - */ - @Deprecated - public void setDefaultEnvironment(String defaultEnvironment) - { - this.defaultEnvironment = defaultEnvironment; - } - - /** - * Set all the properties configured as system properties. - * @param exposeSystemProperties <code>true</code> if you want to set configured properties as system properties. - */ - public void setExposeSystemProperties(boolean exposeSystemProperties) - { - this.exposeSystemProperties = exposeSystemProperties; - } - - @Override - public void setNullValue(String nullValue) - { - this.nullValue = nullValue; - super.setNullValue(nullValue); - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - if (fileLocation != null) - { - - String hostname = null; - try - { - hostname = StringUtils.substringBefore( - StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()), - "."); - } - catch (UnknownHostException e) - { - log.error(e.getMessage()); // should not happen - } - - if (hostname != null) - { - System.setProperty("env", hostname); - } - - String applName = getApplicationName(); - if (applName != null) - { - System.setProperty("appl", applName); - } - - URL propertyUrl = null; - - String fileLocationFull = fileLocation; - - if (defaultEnvironment != null) - { - log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " - + "as the last comma separated value in \"fileLocation\""); - fileLocationFull = fileLocationFull - + "," - + StringUtils.replace(fileLocationFull, PROPERTY_ENV, this.defaultEnvironment); - } - - String replacedLocations = StringUtils.replace(fileLocationFull, PROPERTY_ENV, hostname); - replacedLocations = StringUtils.replace(replacedLocations, PROPERTY_APPL, applName); - - String[] locations = StringUtils.split(replacedLocations, ","); - - if (inherit) - { - ArrayUtils.reverse(locations); - } - - Properties props = new Properties(); - boolean found = false; - - for (String loc : locations) - { - propertyUrl = getResource(StringUtils.strip(loc)); - if (propertyUrl != null) - { - found = true; - log.debug("Loading property file at {}", loc); - - Resource resource = new UrlResource(propertyUrl); - InputStream is = null; - - try - { - is = resource.getInputStream(); - props.load(is); - } - catch (IOException e) - { - log.error("Error loading " + propertyUrl.toString(), e); - } - finally - { - if (is != null) - { - try - { - is.close(); - } - catch (IOException e) - { - // ignore - } - } - } - - if (!inherit) - { - break; - } - } - log.debug("Property file not found at {}", loc); - - } - - if (!found) - { - log.error("No properties found at {}", replacedLocations); - } - - this.properties = props; - super.setProperties(props); - - if (exposeSystemProperties) - { - Iterator<Object> i = props.keySet().iterator(); - while (i.hasNext()) - { - String key = (String) i.next(); - String value = (String) props.get(key); - System.setProperty(key, value); - } - - } - - } - - super.postProcessBeanFactory(beanFactory); - } - - private URL getResource(String resource) - { - URL url = null; - - if (servletContext != null && !StringUtils.contains(resource, "classpath:")) - { - try - { - if (resource != null && !resource.startsWith("/")) - { - url = servletContext.getResource("/" + resource); - } - else - { - url = servletContext.getResource(resource); - } - - if (url != null) - { - // check needed for servletUnit - // we need to check for a connection because getResource always returns a URL, also if the resource - // doesn't exists - url.openConnection().connect(); - } - - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - catch (IOException e) - { - // ignore, URL is not a valid resource - url = null; - } - } - if (url == null) - { - try - { - url = ResourceUtils.getURL(resource); - url.openStream().close(); // test if the resource actually exists - } - catch (IOException e) - { - // ignore, can be normal - url = null; - } - } - return url; - } - - private String getApplicationName() - { - if (servletContext != null) - { - String url = servletContext.getRealPath("/"); - url = StringUtils.replace(url, "\\", "/"); - if (url.endsWith("/")) - { - url = StringUtils.substringBeforeLast(url, "/"); - } - - return StringUtils.substringAfterLast(url, "/"); - } - return StringUtils.EMPTY; - } - - /** - * Returns the Properties loaded by this configurer. - * @return Properties - */ - public Properties getProperties() - { - return properties; - } - - /** - * Returns a single property. - * @param key Property key - * @return property value or <code>null</code> if not found. - */ - public String getProperty(String key) - { - // better be safe, it doesn't hurt - if (properties == null) - { - return null; - } - return properties.getProperty(key); - } - - /** - * {@inheritDoc} - */ - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException - { - // don't implement ServletContextAware or it will fail if javax.servlet dependency is not available - try - { - if (applicationContext instanceof WebApplicationContext) - { - this.servletContext = ((WebApplicationContext) applicationContext).getServletContext(); - } - } - catch (NoClassDefFoundError e) - { - // ignore, we are not in a web project or spring web is not available - } - } - - public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException - { - PropertyAnnotationsUtils.autowireProperties(bean, new PlaceholderResolvingStringValueResolver(properties)); - return true; - } - - public Class predictBeanType(Class beanClass, String beanName) - { - return null; - } - - public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException - { - return null; - } - - public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException - { - return bean; - } - - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException - { - return null; - } - - public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, - String beanName) throws BeansException - { - - return pvs; - } - - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException - { - return bean; - } - - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException - { - return bean; - } - - /** - * BeanDefinitionVisitor that resolves placeholders in String values, delegating to the - * <code>parseStringValue</code> method of the containing class. - */ - protected class PlaceholderResolvingStringValueResolver implements StringValueResolver - { - - private final Properties props; - - public PlaceholderResolvingStringValueResolver(Properties props) - { - this.props = props; - } - - public String resolveStringValue(String strVal) throws BeansException - { - String value = parseStringValue(strVal, this.props, new HashSet()); - return (value.equals(nullValue) ? null : value); - } - } -} Copied: tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 2161, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-2.2/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2010-03-19 22:24:28 UTC (rev 2163) @@ -0,0 +1,498 @@ +/** + * + * openutils deployment tools (http://www.openmindlab.com/lab/products/deployment.html) + * Copyright(C) 2007-2010, Openmind S.r.l. http://www.openmindonline.it + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.openutils.deployment.spring; + +import java.beans.PropertyDescriptor; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.PropertyValues; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.util.ResourceUtils; +import org.springframework.util.StringValueResolver; +import org.springframework.web.context.WebApplicationContext; + + +/** + * <p> + * A propertyconfigurer that can be used to dynamically select a list of property files based on the current + * environment. + * </p> + * <p> + * You can configure the <code>fileLocation</code> parameter with a list of file location, using variables for: + * </p> + * <ul> + * <li>the server name: ${env}</li> + * <li>the web application root folder name (only for web contexts): ${appl}</li> + * <li>any web context init parameter (only for web contexts): ${contextParam/paramname}</li> + * </ul> + * <p> + * <p> + * A sample value for the <code>fileLocation</code> parameter would be: <code>WEB-INF/config/${env}/my.properties, + * WEB-INF/config/${appl}/my.properties, + * WEB-INF/config/${contextParam/instance}/my.properties, + * classpath:my-${env}.properties,classpath:default.properties</code>. + * </p> + * <p> + * After replacing all the known variables the resulting list is parsed and any existing file is merged in a single + * property list, used to configure the remaining spring context + * </p> + * @author fgiust + * @version $Id: EnvironmentPropertyConfigurer.java 592 2010-03-19 13:24:12Z christian.strappazzon $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer + implements + ApplicationContextAware, + SmartInstantiationAwareBeanPostProcessor +{ + + private String serverPropertyName = "env"; + + private String applicationPropertyName = "appl"; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + private ServletContext servletContext; + + private String fileLocation; + + /** + * Cached properties (super field is private). + */ + protected Properties properties; + + /** + * Are properties inherited from default configuration? default is true, + */ + private boolean inherit = true; + + /** + * Set all the properties configured as system properties. + */ + private boolean exposeSystemProperties; + + private String nullValue; + + /** + * Setter for <code>fileLocation</code>. + * @param fileLocation The fileLocation to set. + */ + public void setFileLocation(String fileLocation) + { + this.fileLocation = fileLocation; + } + + /** + * Sets the inherit. + * @param inherit the inherit to set + */ + public void setInherit(boolean inherit) + { + this.inherit = inherit; + } + + /** + * Sets the serverPropertyName. + * @param serverPropertyName the serverPropertyName to set + */ + public void setServerPropertyName(String serverPropertyName) + { + this.serverPropertyName = serverPropertyName; + } + + /** + * Sets the applicationPropertyName. + * @param applicationPropertyName the applicationPropertyName to set + */ + public void setApplicationPropertyName(String applicationPropertyName) + { + this.applicationPropertyName = applicationPropertyName; + } + + /** + * Set all the proper... [truncated message content] |