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.tiles.definition;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import jakarta.servlet.ServletContext;
28 import jakarta.servlet.ServletRequest;
29
30 import org.apache.struts.tiles.ComponentDefinition;
31 import org.apache.struts.tiles.DefinitionsFactory;
32 import org.apache.struts.tiles.DefinitionsFactoryConfig;
33 import org.apache.struts.tiles.DefinitionsFactoryException;
34 import org.apache.struts.tiles.NoSuchDefinitionException;
35 import org.apache.struts.util.RequestUtils;
36
37
38
39
40
41
42
43
44
45 @Deprecated
46 public class ComponentDefinitionsFactoryWrapper implements DefinitionsFactory {
47 private static final long serialVersionUID = -1996134499246652941L;
48
49
50
51
52 private org.apache.struts.tiles.ComponentDefinitionsFactory factory = null;
53
54
55
56
57 private DefinitionsFactoryConfig config = null;
58
59
60
61
62
63
64 public ComponentDefinitionsFactoryWrapper(org.apache.struts.tiles.ComponentDefinitionsFactory factory) {
65 this.factory = factory;
66 }
67
68
69
70
71
72
73
74 public ComponentDefinitionsFactoryWrapper() {
75 super();
76 }
77
78
79
80
81
82
83
84
85 public ComponentDefinition getDefinition(
86 String name,
87 ServletRequest request,
88 ServletContext servletContext)
89 throws NoSuchDefinitionException, DefinitionsFactoryException {
90
91 return factory.getDefinition(name, request, servletContext);
92 }
93
94
95
96
97
98
99 public void init(DefinitionsFactoryConfig config, ServletContext servletContext)
100 throws DefinitionsFactoryException {
101
102 this.config = config;
103
104
105 if (factory == null) {
106 factory = createFactoryInstance(config.getFactoryClassname());
107 }
108
109 factory.initFactory(servletContext, createConfigMap(config));
110 }
111
112
113
114
115 public void destroy() {
116 factory = null;
117 }
118
119
120
121
122
123
124
125 public void setConfig(
126 DefinitionsFactoryConfig config,
127 ServletContext servletContext)
128 throws DefinitionsFactoryException {
129
130 org.apache.struts.tiles.ComponentDefinitionsFactory newFactory =
131 createFactoryInstance(config.getFactoryClassname());
132
133 newFactory.initFactory(servletContext, createConfigMap(config));
134 factory = newFactory;
135 }
136
137
138
139
140
141 public DefinitionsFactoryConfig getConfig() {
142 return config;
143 }
144
145
146
147
148
149 public org.apache.struts.tiles.ComponentDefinitionsFactory getInternalFactory() {
150 return factory;
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164 protected org.apache.struts.tiles.ComponentDefinitionsFactory createFactoryInstance(String classname)
165 throws DefinitionsFactoryException {
166
167 try {
168 Class<?> factoryClass = RequestUtils.applicationClass(classname);
169 Object factory = factoryClass.newInstance();
170 return (org.apache.struts.tiles.ComponentDefinitionsFactory) factory;
171
172 } catch (ClassCastException ex) {
173 throw new DefinitionsFactoryException(
174 "Error - createDefinitionsFactory : Factory class '"
175 + classname
176 + " must implement 'DefinitionsFactory'.",
177 ex);
178
179 } catch (ClassNotFoundException ex) {
180 throw new DefinitionsFactoryException(
181 "Error - createDefinitionsFactory : Bad class name '"
182 + classname
183 + "'.",
184 ex);
185
186 } catch (InstantiationException ex) {
187 throw new DefinitionsFactoryException(ex);
188
189 } catch (IllegalAccessException ex) {
190 throw new DefinitionsFactoryException(ex);
191 }
192
193 }
194
195
196
197
198
199
200 public String toString() {
201 return getInternalFactory().toString();
202 }
203
204
205
206
207
208
209
210 public static Map<String, Object> createConfigMap(DefinitionsFactoryConfig config) {
211 Map<String, Object> map = new HashMap<>(config.getAttributes());
212
213 map.put(
214 DefinitionsFactoryConfig.DEFINITIONS_CONFIG_PARAMETER_NAME,
215 config.getDefinitionConfigFiles());
216
217 map.put(
218 DefinitionsFactoryConfig.PARSER_VALIDATE_PARAMETER_NAME,
219 (config.getParserValidate() ? Boolean.TRUE.toString() : Boolean.FALSE.toString()));
220
221 if (!"org.apache.struts.tiles.xmlDefinition.I18nFactorySet"
222 .equals(config.getFactoryClassname())) {
223
224 map.put(
225 DefinitionsFactoryConfig.FACTORY_CLASSNAME_PARAMETER_NAME,
226 config.getFactoryClassname());
227 }
228
229 return map;
230 }
231
232 }