1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.tiles;
22
23 import org.apache.tiles.listener.TilesListener;
24 import org.apache.tiles.TilesContainer;
25 import org.apache.tiles.TilesException;
26 import org.apache.tiles.factory.TilesContainerFactory;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 import javax.servlet.ServletContext;
31 import java.util.Map;
32 import java.util.HashMap;
33
34 /***
35 * Listener used to automatically inject ServletContext
36 * init parameters so that they don't need to be configured
37 * explicitly for tiles integration. This is provided
38 * mainly for backwards compatibility with Struts 2.0.1
39 * configuration.
40 *
41 * @since Struts 2.0.2
42 * @version $Rev: 478625 $
43 *
44 */
45 public class StrutsTilesListener extends TilesListener {
46
47 private static final Log LOG =
48 LogFactory.getLog(StrutsTilesListener.class);
49
50 private static final Map<String, String> INIT;
51
52 static {
53 INIT = new HashMap<String, String>();
54 INIT.put(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM,
55 StrutsTilesContainerFactory.class.getName());
56 }
57
58 protected TilesContainer createContainer(ServletContext context)
59 throws TilesException {
60 if(context.getInitParameter(TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM) == null) {
61 context = decorate(context);
62 }
63 else {
64 LOG.warn("Tiles container factory is explicitly set. Not injecting struts configuration.");
65 }
66 return super.createContainer(context);
67 }
68
69 protected ServletContext decorate(ServletContext context) {
70 return new ConfiguredServletContext(context, INIT);
71 }
72
73 }