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