/*
 * Copyright 2009 Kantega AS
 *
 * 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 no.kantega.publishing.spring;

import no.kantega.commons.configuration.Configuration;
import no.kantega.commons.exception.ConfigurationException;
import no.kantega.publishing.common.Aksess;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.FileSystemResource;

import java.util.Properties;

/**
 *
 */
public class PropertyReplacer implements BeanFactoryPostProcessor{

    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

        try {
            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
            cfg.setProperties(Aksess.getConfiguration().getProperties());
            cfg.postProcessBeanFactory(configurableListableBeanFactory);
        } catch (ConfigurationException e) {
            System.out.println("Error getting configuration");
        }
    }

}

@@ -1123,16 +1123,113 @@
 source;%0A
+import org.springframework.web.context.ServletContextAware;%0A%0Aimport javax.servlet.ServletContext;
 %0Aimport 
@@ -1249,16 +1249,37 @@
 perties;
+%0Aimport java.io.File;
 %0A%0A/**%0A *
@@ -1348,17 +1348,82 @@
 rocessor
-%7B
+, ServletContextAware %7B%0A    private ServletContext servletContext;
 %0A%0A    pu
@@ -1660,15 +1660,36 @@
     
-cfg.set
+Properties properties = new 
 Prop
@@ -1738,16 +1738,252 @@
 ties());
+%0A%0A            File dataDir = (File) servletContext.getAttribute(OpenAksessContextLoaderListener.APPLICATION_DIRECTORY);%0A            properties.setProperty(%22appDir%22, dataDir.getAbsolutePath());%0A%0A            cfg.setProperties(properties);
 %0A       
@@ -2048,16 +2048,17 @@
 ctory);%0A
+%0A
         
@@ -2174,10 +2174,129 @@
 %0A    %7D%0A%0A
+    public void setServletContext(ServletContext servletContext) %7B%0A        this.servletContext = servletContext;%0A    %7D%0A
 %7D%0A

Replace ${appDir} with the application directory