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.TilesApplicationContext;
24 import org.apache.tiles.TilesException;
25 import org.apache.tiles.context.TilesContextFactory;
26 import org.apache.tiles.context.TilesRequestContext;
27 import org.apache.tiles.definition.DefinitionsFactory;
28 import org.apache.tiles.factory.TilesContainerFactory;
29 import org.apache.tiles.impl.BasicTilesContainer;
30 import org.apache.tiles.preparer.PreparerFactory;
31
32 import java.util.Map;
33
34
35 public class StrutsTilesContainerFactory extends TilesContainerFactory {
36
37
38 @Override
39 protected void storeContainerDependencies(Object context, Map<String, String> initParameters, Map<String, String> configuration, BasicTilesContainer container) throws TilesException {
40 TilesContextFactory contextFactory =
41 (TilesContextFactory) createFactory(configuration,
42 CONTEXT_FACTORY_INIT_PARAM);
43
44 contextFactory = new StrutsTilesContextFactory(contextFactory);
45
46 DefinitionsFactory defsFactory =
47 (DefinitionsFactory) createFactory(configuration,
48 DEFINITIONS_FACTORY_INIT_PARAM);
49
50 PreparerFactory prepFactory =
51 (PreparerFactory) createFactory(configuration,
52 PREPARER_FACTORY_INIT_PARAM);
53
54 contextFactory.init(configuration);
55 TilesApplicationContext tilesContext =
56 contextFactory.createApplicationContext(context);
57
58 container.setDefinitionsFactory(defsFactory);
59 container.setContextFactory(contextFactory);
60 container.setPreparerFactory(prepFactory);
61 container.setApplicationContext(tilesContext);
62 }
63
64 /***
65 * Wrapper factory, used to decorate the TilesRequestContext with a
66 * FreemarkerResult aware version.
67 *
68 */
69 class StrutsTilesContextFactory implements TilesContextFactory {
70
71 private TilesContextFactory factory;
72
73 public StrutsTilesContextFactory(TilesContextFactory factory) {
74 this.factory = factory;
75 }
76
77 public void init(Map<String, String> map) {
78 factory.init(map);
79 }
80
81 public TilesApplicationContext createApplicationContext(Object context) {
82 return factory.createApplicationContext(context);
83 }
84
85 public TilesRequestContext createRequestContext(
86 TilesApplicationContext tilesApplicationContext,
87 Object... requestItems) {
88 TilesRequestContext context = factory.createRequestContext(tilesApplicationContext, requestItems);
89 return new StrutsTilesRequestContext(context);
90 }
91 }
92 }