View Javadoc
1   /* ***************************************************************************
2    * Copyright (c) 2008 Brabenetz Harald, Austria.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * 
16   *****************************************************************************/
17  package org.settings4j.helper.spring;
18  
19  import org.springframework.web.context.ContextLoader;
20  import org.springframework.web.context.ContextLoaderListener;
21  
22  /**
23   * {@link javax.servlet.ServletContextListener} to initialize the {@link Settings4jContextLoader}.
24   * <p>
25   * This Implementation replaces the {@link ContextLoaderListener}
26   * <p>
27   * <h3>Usage - Make SpringContext configurable</h3> <br />
28   * Example Configuration could look like the following:
29   * 
30   * <pre>
31   * web.xml
32   * --------------------------------------
33   * &lt;context-param&gt;
34   *     &lt;param-name&gt;settings4jContextConfigLocation&lt;/param-name&gt;
35   *     &lt;param-value&gt;
36   *         ${com/myCompany/myApp/appContextSecurity},
37   *         /WEB-INF/applicationContext-otherBeans.xml
38   *     &lt;/param-value&gt;
39   * &lt;/context-param&gt;
40   * 
41   * &lt;listener&gt;
42   *     &lt;display-name&gt;&lt;/display-name&gt;
43   *     &lt;listener-class&gt;org.settings4j.helper.spring.Settings4jContextLoaderListener&lt;/listener-class&gt;
44   * &lt;/listener&gt;
45   * --------------------------------------
46   * </pre>
47   * 
48   * With this configuration you define with tehKey teh path to your Security configuration.
49   * <p>
50   * <h3>Server config Example</h3> <br />
51   * Example Configuration in TOMCAT:<br />
52   * Start tomcat with
53   * <code>-Dcom/myCompany/myApp/appContextSecurity=file:.../applicationContext-security-alwaysAdmin.xml</code><br />
54   * Or configured a JNDI Value:
55   * 
56   * <pre>
57   * TOMCAT context.xml
58   * --------------------------------------
59   * &lt;Environment name ="com/myCompany/myApp/appContextSecurity" 
60   *              value="/WEB-INF/applicationContext-security.xml" 
61   *              type="java.lang.String" /&gt;
62   * 
63   * --------------------------------------
64   * </pre>
65   * <p>
66   * <h3>Default Values</h3> <br />
67   * It is recommended to use this in combination with {@link org.settings4j.helper.web.DefaultPropertiesLoader}:
68   * 
69   * <pre>
70   * web.xml
71   * --------------------------------------
72   * &lt;context-param&gt;
73   *     &lt;param-name&gt;settings4jDefaultProperties&lt;/param-name&gt;
74   *     &lt;param-value&gt;
75   *         com/myCompany/myApp/appContextSecurity=/WEB-INF/applicationContext-security.xml
76   *     &lt;/param-value&gt;
77   * &lt;/context-param&gt;
78   * 
79   * &lt;context-param&gt;
80   *     &lt;param-name&gt;settings4jContextConfigLocation&lt;/param-name&gt;
81   *     &lt;param-value&gt;
82   *         ${com/myCompany/myApp/appContextSecurity},
83   *         /WEB-INF/applicationContext-otherBeans.xml
84   *     &lt;/param-value&gt;
85   * &lt;/context-param&gt;
86   * 
87   * &lt;listener&gt;
88   *     &lt;display-name&gt;&lt;/display-name&gt;
89   *     &lt;listener-class&gt;org.settings4j.helper.spring.Settings4jContextLoaderListener&lt;/listener-class&gt;
90   * &lt;/listener&gt;
91   * --------------------------------------
92   * </pre>
93   * 
94   * @author brabenetz
95   */
96  public class Settings4jContextLoaderListener extends ContextLoaderListener {
97  
98      /** {@inheritDoc} */
99      @Override
100     protected ContextLoader createContextLoader() {
101         return new Settings4jContextLoader();
102     }
103 
104 }