[Hippo-cms7-user] change suggestion for HstSiteConfigServlet

Jettro Coenradie jettro at jteam.nl
Wed Apr 29 18:48:10 CEST 2009


Glad we got that out of the way. I still think more options without specific XML would be good. 
-----Original Message-----
From: hippo-cms7-user-bounces at lists.onehippo.com on behalf of Woonsan Ko
Sent: Wed 4/29/2009 4:36 PM
To: j.reijn at onehippo.com; Hippo CMS7 user list
Subject: Re: [Hippo-cms7-user] change suggestion for HstSiteConfigServlet
 
In addition, the xml configuration file's location is
'/WEB-INF/hst-configuration.xml' by default.
If the file does not exist, the servlet will create a
PropertyConfiguration object to load /WEB-INF/hst-config.properties'.
Otherwise, of course, the servlet will create Configuration by using
commons-configuration's factory.
Anyway, you can use a commons-configuration's configuration xml file
for the purpose.
This configuration xml file's location is
'/WEB-INF/hst-configuration.xml' by default, but you can also
configure the path by setting init-param, 'hst-configuration'.

Kind regards,

Woonsan

On Wed, Apr 29, 2009 at 4:26 PM, Jeroen Reijn <j.reijn at onehippo.com> wrote:
> Hi Jettro,
>
> this is already possible, without changing the existing code. See [1]. You
> can use system properties in the XML configuration. For instance:
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <!-- A test configuration file for loading a file specified by a
>     system property.
> -->
> <configuration>
>  <properties fileName="${config.file}"/>
> </configuration>
>
>
> [1]http://commons.apache.org/configuration/userguide/howto_configurationfactory.html#Multiple_configuration_sources
>
> Jettro Coenradie wrote:
>>
>> Hi All,
>> I am looking at the configuration of a site created with the hippo hst. At
>> the moment you need to hard wire the path to the hst-config.properties in
>> the web.xml. I would like the web.xml to use an environment variable to find
>> the location of the config file. The following code can be a good start to
>> make this happen. It is a function out of the mentioned class that I
>> refactored a bit.
>>
>> Curious to what you think about it
>>
>> greetz Jettro
>>
>>    /**
>>     * <p>The goal of this method is to load the configuration using
>> parameters provided by servlet config parameters,
>>     * and/or system parameters. Some sane defaults are available as
>> well.</p>
>>     * <p>System parameters are placed in the configuration and can be
>> used</p>
>>     * <p>You can also specify the parameters in servlet init params. It is
>> possible to use placeholders in these paths</p>
>>     * <p/>
>>     *
>>     * <strong>Example</strong>
>>     * <code>-DConfig.dir=/usr/local/tomcat/config</code>
>>     *
>>     * <code>web.xml</code>
>>     * <init-param>
>>     *     <param-name>hst-config-properties>
>>     *     <param-value>file:${Config.dir}/site/hst-config.properties
>>     * </init-param>
>>     *
>>     * @param servletConfig <code>ServletConfig</code> that contains the
>> init params
>>     * @return <code>Configuration</code> containing all the params found
>> in the system, jndi and the config file found
>>     * @throws ServletException thrown if file's cannot be found or
>> configuration problems arise.
>>     */
>>    protected Configuration getConfiguration(ServletConfig servletConfig)
>> throws ServletException {
>>        CompositeConfiguration compConfig = new CompositeConfiguration();
>>        compConfig.addConfiguration(new SystemConfiguration());
>>
>>        ConfigurationFactory factory = new ConfigurationFactory();
>>
>>        // not sure what this is for (is this the commons-configuration
>> format??)
>>        String hstConfigurationFilePath =
>> servletConfig.getInitParameter(HST_CONFIGURATION_PARAM);
>>
>>        if (hstConfigurationFilePath == null) {
>>            hstConfigurationFilePath = "/WEB-INF/" + HST_CONFIGURATION_XML;
>>        }
>>                File hstConfigurationFile = new
>> File(servletConfig.getServletContext().getRealPath(hstConfigurationFilePath));
>>                try {
>>            if (hstConfigurationFile.isFile()) {
>>
>>  factory.setConfigurationFileName(hstConfigurationFile.toURI().toString());
>>                compConfig.addConfiguration(factory.getConfiguration());
>>            } else {
>>                String hstConfigPropFilePath =
>> servletConfig.getInitParameter(HST_CONFIG_PROPERTIES_PARAM);
>>
>>                if (hstConfigPropFilePath == null) {
>>                    hstConfigPropFilePath =
>> servletConfig.getServletContext().getRealPath("/WEB-INF/" +
>> HST_CONFIG_PROPERTIES);
>>                }
>>
>>                if (hstConfigPropFilePath.startsWith("file:")) {
>>                    // this is done for the placeholders
>>
>>  compConfig.addProperty(HST_CONFIG_PROPERTIES_PARAM,hstConfigPropFilePath);
>>                    compConfig.addConfiguration(new
>> PropertiesConfiguration(compConfig.getString(
>>                            HST_CONFIG_PROPERTIES_PARAM) + "/" +
>> HST_CONFIG_PROPERTIES ));
>>                } else {
>>                    compConfig.addConfiguration(new
>> PropertiesConfiguration(new File(hstConfigPropFilePath)));
>>                }
>>            }
>>        } catch (ConfigurationException e) {
>>            throw new ServletException(e);
>>        }
>>        return compConfig;
>>    }
>>
>> groeten Jettro
>> *
>> *
>> Jettro Coenradie* - jettro at jteam.nl <mailto:jettro at jteam.nl> -
>> http://www.jteam.nl - linkedin <http://www.linkedin.com/in/jettro>
>> *Phone*: +31(0)20 486 20 36 *Fax*: +31(0)20 475 08 28 *Mobile*: +31(0)6
>> 3473 9912 Frederiksplein 1 - 1017 XK - Amsterdam - The Netherlands
>> *
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/community.html
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/community.html
>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 5465 bytes
Desc: not available
URL: <http://lists.onehippo.org/pipermail/hippo-cms7-user/attachments/20090429/fb34d642/attachment.bin>


More information about the Hippo-cms7-user mailing list