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