org.hippoecm.hst.site.container
Class HstSiteConfigServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.hippoecm.hst.site.container.HstSiteConfigServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class HstSiteConfigServlet
extends javax.servlet.http.HttpServlet

HST Site Container Servlet This servlet should initialize all the components that can be accessed via HstServices from the each HST-based applications. Under portal environment, this servlet may not be used because the portal itself can initialize all the necessary component for each HST-based portlet application.

The configuration could be set by a properties file or an xml file. If you would set the configuration by a properties file, you can set an init parameter named 'hst-config-properties' for the servlet config or for the servlet context.

The parameter value for the properties file or the xml file is regarded as a web application context relative path or file system relative path if the path does not start with 'file:'. So, you should use a 'file:' prefixed URI for the path parameter value if you want to set an absolute path. When the path starts with a leading slash ('/'), the path is regarded as a servlet context relative path. If the path does not start with 'file:' nor with a leading slash ('/'), it is regarded as a relative path of the file system.

For example, you can add an init parameter named 'hst-config-properties' for this servlet config like the following:


   <servlet>
    <servlet-name>HstSiteConfigServlet</servlet-name>
    <servlet-class>org.hippoecm.hst.site.container.HstSiteConfigServlet</servlet-class>
    <init-param>
      <param-name>hst-config-properties</param-name>
      <param-value>/WEB-INF/hst-config.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
 

Also, you can set context init parameter instead of the config init parameter like the following:

  <context-param>
    <param-name>hst-config-properties</param-name>
    <param-value>/WEB-INF/hst-config.properties</param-value>
  </context-param>
  <!-- SNIP -->
  <servlet>
    <servlet-name>HstSiteConfigServlet</servlet-name>
    <servlet-class>org.hippoecm.hst.site.container.HstSiteConfigServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 
The servlet will retrieve the config init parameter first and it will retrieve the context init parameter when the config init parameter is not set.
If you don't provide the init parameter named 'hst-config-properties' at all, the value is set to '/WEB-INF/hst-config.properties' by default.

Also, the configuration can be set by an XML file which is of the XML configuration format of Apache Commons Configuration. If you want to set the configuration by the Apache Commons Configuration XML file, you should provide an init parameter named 'hst-configuration' for servlet config or servlet context. For example,


   <servlet>
    <servlet-name>HstSiteConfigServlet</servlet-name>
    <servlet-class>org.hippoecm.hst.site.container.HstSiteConfigServlet</servlet-class>
    <init-param>
      <param-name>hst-configuration</param-name>
      <param-value>/WEB-INF/hst-configuration.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
 
Also, you can set context init parameter instead of the config init parameter like the following:

  <context-param>
    <param-name>hst-configuration</param-name>
    <param-value>/WEB-INF/hst-configuration.xml</param-value>
  </context-param>
  <!-- SNIP -->
  <servlet>
    <servlet-name>HstSiteConfigServlet</servlet-name>
    <servlet-class>org.hippoecm.hst.site.container.HstSiteConfigServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
 

For your information, you can configure the /WEB-INF/hst-configuration.xml file like the following example. In this example, you can see that system properties can be aggregated, multiple properties files can be added and system property values can be used to configure other properties file paths as well:

 <?xml version='1.0'?>
 <configuration>
   <system/>
   <properties fileName='${catalina.home}/conf/hst-config-1.properties'/>
   <properties fileName='${catalina.home}/conf/hst-config-2.properties'/>
 </configuration>
 
Please refer to the documentation of Apache Commons Configuration for details.
The servlet will retrieve the config init parameter first and it will retrieve the context init parameter when the config init parameter is not set.
If you don't provide the init parameter named 'hst-config-properties' at all, the value is set to '/WEB-INF/hst-configuration.xml' by default.
The parameter value for the properties file or the xml file is regarded as a web application context relative path or file system relative path if the path does not start with 'file:'. So, you should use a 'file:' prefixed URI for the path parameter value if you want to set an absolute path. When the path starts with a leading slash ('/'), the path is regarded as a servlet context relative path. If the path does not start with 'file:' nor with a leading slash ('/'), it is regarded as a relative path of the file system.

Version:
$Id: HstSiteConfigServlet.java 34738 2012-06-19 16:08:30Z wko $
See Also:
Serialized Form

Field Summary
protected  boolean allRepositoriesAvailable
           
protected  String[] assemblyOverridesConfigurations
           
protected  boolean checkRepositoriesRunning
           
protected  org.apache.commons.configuration.Configuration configuration
           
protected  boolean forecefulReinitialization
           
static String HST_CONFIG_PROPERTIES_PARAM
           
static String HST_CONFIGURATION_PARAM
           
protected  boolean initialized
           
protected  Map<String[],Boolean> repositoryCheckingStatus
           
 
Constructor Summary
HstSiteConfigServlet()
           
 
Method Summary
protected  boolean checkAllRepositoriesRunning()
           
 void destroy()
           
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          In this application doGet and doPost are the same thing.
protected  String getConfigOrContextInitParameter(String paramName, String defaultValue)
           
protected  org.apache.commons.configuration.Configuration getConfiguration(javax.servlet.ServletConfig servletConfig)
          The goal of this method is to load the configuration using parameters provided by servlet config parameters, and/or system parameters.
protected  File getResourceFile(String resourcePath)
          Returns the physical resource file object.
 void init(javax.servlet.ServletConfig config)
          Intialize Servlet.
protected  void initializeComponentManager(javax.servlet.ServletConfig config)
           
protected  boolean isInitialized()
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HST_CONFIGURATION_PARAM

public static final String HST_CONFIGURATION_PARAM
See Also:
Constant Field Values

HST_CONFIG_PROPERTIES_PARAM

public static final String HST_CONFIG_PROPERTIES_PARAM
See Also:
Constant Field Values

assemblyOverridesConfigurations

protected String[] assemblyOverridesConfigurations

initialized

protected boolean initialized

forecefulReinitialization

protected boolean forecefulReinitialization

checkRepositoriesRunning

protected boolean checkRepositoriesRunning

allRepositoriesAvailable

protected boolean allRepositoriesAvailable

configuration

protected org.apache.commons.configuration.Configuration configuration

repositoryCheckingStatus

protected Map<String[],Boolean> repositoryCheckingStatus
Constructor Detail

HstSiteConfigServlet

public HstSiteConfigServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Intialize Servlet.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

isInitialized

protected boolean isInitialized()

initializeComponentManager

protected void initializeComponentManager(javax.servlet.ServletConfig config)

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws IOException,
                  javax.servlet.ServletException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
IOException
javax.servlet.ServletException

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws IOException,
                   javax.servlet.ServletException
In this application doGet and doPost are the same thing.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req - Servlet request.
res - Servlet response.
Throws:
IOException - a servlet exception.
javax.servlet.ServletException - a servlet exception.

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

checkAllRepositoriesRunning

protected boolean checkAllRepositoriesRunning()

getConfiguration

protected org.apache.commons.configuration.Configuration getConfiguration(javax.servlet.ServletConfig servletConfig)
                                                                   throws javax.servlet.ServletException

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.

You can use the commons configuration xml config, which by default should be in the WEB-INF folder. You can also configure the location of this file in init-params of the servlet. Check the example

Another way to configure commons configuration is to use a properties file. Again the location by default is in the WEB-INF folder, but you can change location and name of the file using init-params of the servlet

Example - using xml configuration and a system parameter

-DConfig.dir=/usr/local/tomcat/config

hst-configuration.xml
(in the WEB-INF folder)
 <configuration>
     <properties fileName="${Config.dir}/site/hst-config.properties"/>
 </configuration>
 
Example - using servlet init param for hst.properties
web.xml
 <init-param>
     <param-name>hst-config-properties</param-name>
 <param-value>/usr/local/tomcat/config/site/hst-config.properties</param-value>
 </init-param>
 

Parameters:
servletConfig - ServletConfig that contains the init params
Returns:
Configuration containing all the params found in the system, jndi and the config file found
Throws:
javax.servlet.ServletException - thrown if file's cannot be found or configuration problems arise.

getConfigOrContextInitParameter

protected String getConfigOrContextInitParameter(String paramName,
                                                 String defaultValue)

getResourceFile

protected File getResourceFile(String resourcePath)
Returns the physical resource file object.

Parameters:
resourcePath -
Returns:


Copyright © 2008-2012 Hippo. All Rights Reserved.