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.struts.tiles2;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.struts.config.ModuleConfig;
28 import org.apache.struts.util.ModuleUtils;
29 import org.apache.tiles.Definition;
30 import org.apache.tiles.definition.DefinitionsFactory;
31 import org.apache.tiles.impl.BasicTilesContainer;
32 import org.apache.tiles.locale.LocaleResolver;
33 import org.apache.tiles.request.Request;
34 import org.apache.tiles.request.jakarta.servlet.ServletRequest;
35
36 import jakarta.servlet.http.HttpServletRequest;
37
38 public class TilesPluginContainer extends BasicTilesContainer {
39
40
41
42
43 private final Map<String, DefinitionsFactory> key2definitionsFactory =
44 new HashMap<>();
45
46
47
48
49 private LocaleResolver localeResolver;
50
51
52
53
54
55
56
57
58 void setLocaleResolver(LocaleResolver localeResolver) {
59 this.localeResolver = localeResolver;
60 }
61
62
63
64
65
66
67
68
69 LocaleResolver getLocaleResolverIntern() {
70 return localeResolver;
71 }
72
73
74
75
76
77
78
79
80
81 public DefinitionsFactory getProperDefinitionsFactory(String key) {
82 DefinitionsFactory retValue = null;
83
84 if (key != null) {
85 retValue = key2definitionsFactory.get(key);
86 }
87
88 return retValue;
89 }
90
91
92
93
94
95
96
97
98
99 public void setDefinitionsFactory(String key,
100 DefinitionsFactory definitionsFactory) {
101 if (key != null) {
102 key2definitionsFactory.put(key, definitionsFactory);
103 } else {
104 setDefinitionsFactory(definitionsFactory);
105 }
106 }
107
108 @Override
109 public Definition getDefinition(String definitionName,
110 Request request) {
111 Definition retValue = null;
112 String key = getDefinitionsFactoryKey(request);
113 if (key != null) {
114 DefinitionsFactory definitionsFactory =
115 key2definitionsFactory.get(key);
116 if (definitionsFactory != null) {
117 retValue = definitionsFactory.getDefinition(definitionName,
118 request);
119 }
120 }
121 if (retValue == null) {
122 retValue = super.getDefinition(definitionName, request);
123 }
124 return retValue;
125 }
126
127
128
129
130
131
132
133 protected String getDefinitionsFactoryKey(Request request) {
134 String retValue = null;
135
136 if (request instanceof ServletRequest) {
137 HttpServletRequest servletRequest =
138 ((ServletRequest) request).getRequest();
139 ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(
140 servletRequest);
141
142 if (config == null) {
143
144 ModuleUtils.getInstance().selectModule(servletRequest,
145 servletRequest.getSession().getServletContext());
146 config = ModuleUtils.getInstance().getModuleConfig(servletRequest);
147 }
148
149 if (config != null) {
150 retValue = config.getPrefix();
151 }
152 }
153 return retValue;
154 }
155 }