I've created a patch to include in the serverManager a properties file, which 
then is used to resolve variables inside the configuration.

Instead of 
  <bean id="serverManager" class="nl.hippo.servermanager.ServerManager" 
init-method="initialize">
    <property name="configurationLocation">
      %maven.cocoon.servermanager.configurationlocation%
    </property>
    <property name="workLocation">
      %maven.cocoon.servermanager.worklocation%
    </property>

    <property name="logger">
      <ref local="serverManagerLogger"/>
    </property>
  </bean>

You can add a property:

    <property 
name="propertyLocation">classpath://props/cms.properties</property>

Which listens to context://, classpath:// or an absolute path.

Is it possible to integrate this in the module?

With regards,

Nick Stolwijk

-----Original Message-----
From: [EMAIL PROTECTED] on behalf of [EMAIL PROTECTED]
Sent: Mon 1/14/2008 4:25 PM
To: Hippo CMS development public mailinglist
Subject: RE: [HippoCMS-dev] Reading domain name in 
sampleDomains.xmlfromproperty file
 
I guess I've found out why it isn't working.

This comment on [1]:

May be you are using BeanFactory, rather than ApplicationContext, which extends 
BeanFactory? ApplicationContext will detect automatically 
PropertyPlaceHolderConfigurer as one of it's beans, but BeanFactory will not.

And this part of ServerFactory.java [2]:

        Resource beansResource = 
m_factoryHelper.createBeansResource(SERVER_BEANS_TEMPLATE_LOCATION, context, 
serverStructure.getBeansWorkLocation());
        BeanFactory beanFactory = new XmlBeanFactory(beansResource, 
m_container);

Is there some other way to include properties in the ServerManager?

With regards,

Nick Stolwijk

[1] 
http://almaer.com/blog/spring-propertyplaceholderconfigurer-a-nice-clean-way-to-share
[2] 
https://svn.hippocms.org/repos/hippo/hippo-components/server-manager/trunk/src/java/nl/hippo/servermanager/ServerFactory.java


-----Original Message-----
From: [EMAIL PROTECTED] on behalf of [EMAIL PROTECTED]
Sent: Mon 1/14/2008 4:11 PM
To: [email protected]
Subject: [HippoCMS-dev] Reading domain name in sampleDomains.xml fromproperty 
file
 
Hi folks,

I'm trying to run the CMS on JBoss and now I'm having the requirement to keep 
properties outside of the jar file. Is it possible to read in the domain name 
in de sampleDomain.xml from a property file.

I already tried adding a PropertyPlaceholderConfigurer to sampleDomains.xml but 
it doesn't seem to work.

I've added:

        <bean id="placeholderConfig" 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="locations">
                        <list>
                                <value>
                                     classpath:props/cms.properties
                                </value>
                        </list>
                </property>
        </bean>

And changed the domain to ${cms.domain}

And my property file is in <server-instance>conf/props/cms.properties and 
contains:
cms.domain=cms-ontw-cocoon

Can someone help me?

With regards,

Nick Stolwijk
********************************************
Hippocms-dev: Hippo CMS development public mailinglist

********************************************
Hippocms-dev: Hippo CMS development public mailinglist


Index: src/java/nl/hippo/servermanager/ServerManager.java
===================================================================
--- src/java/nl/hippo/servermanager/ServerManager.java  (revision 9921)
+++ src/java/nl/hippo/servermanager/ServerManager.java  (working copy)
@@ -15,12 +15,16 @@
  */
 package nl.hippo.servermanager;
 
+import java.io.File;
+
 import org.apache.log4j.Logger;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.BeanFactoryAware;
 import org.springframework.beans.factory.xml.XmlBeanFactory;
 import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
 import org.springframework.context.ApplicationContext;
 import org.springframework.web.context.WebApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -34,6 +38,8 @@
     private String m_configurationLocation;
 
     private String m_workLocation;
+    
+    private String m_propertyLocation;
 
     private BeanFactory m_beanFactory;
 
@@ -58,7 +64,12 @@
         m_configurationLocation = configurationLocation;
     }
 
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException
+    public void setPropertyLocation(String location) 
+    {
+               m_propertyLocation = location;
+       }
+
+       public void setBeanFactory(BeanFactory beanFactory) throws 
BeansException
     {
         m_beanFactory = beanFactory;
     }
@@ -75,10 +86,11 @@
 
     public void initialize() throws Exception
     {
-       
if(m_configurationLocation.startsWith(PropertyResolverConfigurer.CONTEXT_SCHEME))
-           m_configurationLocation = m_servletContext.getRealPath( "/" ) + "/" 
+ 
m_configurationLocation.substring(PropertyResolverConfigurer.CONTEXT_SCHEME.length());
-       if(m_workLocation.startsWith(PropertyResolverConfigurer.CONTEXT_SCHEME))
-           m_workLocation = m_servletContext.getRealPath( "/" ) +  "/" + 
m_workLocation.substring(PropertyResolverConfigurer.CONTEXT_SCHEME.length());
+       
if(m_configurationLocation.startsWith(PropertyResolverConfigurer.CONTEXT_SCHEME))
+               m_configurationLocation = m_servletContext.getRealPath( "/" ) + 
"/" + 
m_configurationLocation.substring(PropertyResolverConfigurer.CONTEXT_SCHEME.length());
+       if(m_workLocation.startsWith(PropertyResolverConfigurer.CONTEXT_SCHEME))
+               m_workLocation = m_servletContext.getRealPath( "/" ) +  "/" + 
m_workLocation.substring(PropertyResolverConfigurer.CONTEXT_SCHEME.length());
+       Resource propertyFile = createResource(m_propertyLocation);
         m_logger.info("Creating server from '" + m_configurationLocation
                 + "' with work directory '" + m_workLocation + "'");
         ClassPathResource beansResource = new 
ClassPathResource("server-manager-beans.xml",
@@ -86,10 +98,25 @@
         BeanFactory beanFactory = new XmlBeanFactory(beansResource, 
m_beanFactory);
         ServerFactory serverFactory = (ServerFactory) 
beanFactory.getBean("serverFactory",
                 ServerFactory.class);
-        m_server = serverFactory.createServer(m_configurationLocation, 
m_workLocation);
+        m_server = serverFactory.createServer(m_configurationLocation, 
m_workLocation, propertyFile);
     }
 
-    public Server getServer() throws Exception
+    private Resource createResource(String location) {
+       Resource result = null;
+       if (location != null && !"".equals(location)) {
+                       
if(location.startsWith(PropertyResolverConfigurer.CONTEXT_SCHEME)) {
+                               String filepath = m_servletContext.getRealPath( 
"/" ) +  "/" + 
location.substring(PropertyResolverConfigurer.CONTEXT_SCHEME.length());
+                               result = new FileSystemResource(filepath);
+                       } else if 
(location.startsWith(PropertyResolverConfigurer.CLASSPATH_SCHEME)) {
+                               result = new 
ClassPathResource(location.substring(PropertyResolverConfigurer.CLASSPATH_SCHEME.length()));
+                       } else {
+                               result = new FileSystemResource(location);
+                       }
+               }
+       return result;
+       }
+
+       public Server getServer() throws Exception
     {
         return m_server;
     }
Index: src/java/nl/hippo/servermanager/PropertyResolverConfigurer.java
===================================================================
--- src/java/nl/hippo/servermanager/PropertyResolverConfigurer.java     
(revision 9921)
+++ src/java/nl/hippo/servermanager/PropertyResolverConfigurer.java     
(working copy)
@@ -39,6 +39,7 @@
 
     /** A field */
     public static final String CONTEXT_SCHEME = "context://";
+    public static final String CLASSPATH_SCHEME = "classpath://";
 
     /** A field */
     private ServletContext m_servletContext;
Index: src/java/nl/hippo/servermanager/ServerFactory.java
===================================================================
--- src/java/nl/hippo/servermanager/ServerFactory.java  (revision 9921)
+++ src/java/nl/hippo/servermanager/ServerFactory.java  (working copy)
@@ -23,6 +23,7 @@
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 import org.springframework.beans.factory.xml.XmlBeanFactory;
 import org.springframework.core.io.Resource;
 import org.w3c.dom.Document;
@@ -53,7 +54,7 @@
         m_factoryHelper = factoryHelper;
     }
 
-    public Server createServer(String configurationLocation, String 
workLocation) throws Exception
+    public Server createServer(String configurationLocation, String 
workLocation, Resource propertyLocation) throws Exception
     {
         Server result;
 
@@ -73,11 +74,21 @@
         context.put("serverSchedulerStore", schedulerStoreDefinitionWriter);
 
         Resource beansResource = 
m_factoryHelper.createBeansResource(SERVER_BEANS_TEMPLATE_LOCATION, context, 
serverStructure.getBeansWorkLocation());
-        BeanFactory beanFactory = new XmlBeanFactory(beansResource, 
m_container);
-
+        XmlBeanFactory beanFactory = new XmlBeanFactory(beansResource, 
m_container);
+        if(propertyLocation != null) {
+               PropertyPlaceholderConfigurer cfg = new 
PropertyPlaceholderConfigurer();
+               cfg.setLocation(propertyLocation);
+               // now actually do the replacement
+               cfg.postProcessBeanFactory(beanFactory);                
+        }
         result = (Server) beanFactory.getBean("server", Server.class);
         
         return result;
     }
+    
+    public Server createServer(String configurationLocation, String 
workLocation) throws Exception
+    {
+       return createServer(configurationLocation, workLocation);
+    }
 
 }
********************************************
Hippocms-dev: Hippo CMS development public mailinglist

Reply via email to