1
14
15 package com.liferay.portal.util;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.KeyValuePair;
20
21 import java.io.InputStream;
22
23 import org.xml.sax.InputSource;
24
25
30 public class EntityResolver implements org.xml.sax.EntityResolver {
31
32 public InputSource resolveEntity(String publicId, String systemId) {
33 ClassLoader classLoader = getClass().getClassLoader();
34
35 if (_log.isDebugEnabled()) {
36 _log.debug("Resolving entity " + publicId + " " + systemId);
37 }
38
39 if (publicId != null) {
40 for (int i = 0; i < _PUBLIC_IDS.length; i++) {
41 KeyValuePair kvp = _PUBLIC_IDS[i];
42
43 if (publicId.equals(kvp.getKey())) {
44 InputStream is = classLoader.getResourceAsStream(
45 _DEFINITIONS_PATH + kvp.getValue());
46
47 if (_log.isDebugEnabled()) {
48 _log.debug("Entity found for public id " + systemId);
49 }
50
51 return new InputSource(is);
52 }
53 }
54 }
55 else if (systemId != null) {
56 for (int i = 0; i < _SYSTEM_IDS.length; i++) {
57 KeyValuePair kvp = _SYSTEM_IDS[i];
58
59 if (systemId.equals(kvp.getKey())) {
60 InputStream is = classLoader.getResourceAsStream(
61 _DEFINITIONS_PATH + kvp.getValue());
62
63 if (_log.isDebugEnabled()) {
64 _log.debug("Entity found for system id " + systemId);
65 }
66
67 return new InputSource(is);
68 }
69 }
70 }
71
72 if (_log.isDebugEnabled()) {
73 _log.debug("No entity found for " + publicId + " " + systemId);
74 }
75
76 return null;
77 }
78
79 private static String _DEFINITIONS_PATH = "com/liferay/portal/definitions/";
80
81 private static KeyValuePair[] _PUBLIC_IDS = {
82 new KeyValuePair(
83 "datatypes",
84 "datatypes.dtd"
85 ),
86
87 new KeyValuePair(
88 "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN",
89 "facelet-taglib_1_0.dtd"
90 ),
91
92 new KeyValuePair(
93 "-//Hibernate/Hibernate Mapping DTD 3.0//EN",
94 "hibernate-mapping-3.0.dtd"
95 ),
96
97 new KeyValuePair(
98 "-//Liferay//DTD Display 2.0.0//EN",
99 "liferay-display_2_0_0.dtd"
100 ),
101
102 new KeyValuePair(
103 "-//Liferay//DTD Display 3.5.0//EN",
104 "liferay-display_3_5_0.dtd"
105 ),
106
107 new KeyValuePair(
108 "-//Liferay//DTD Display 4.0.0//EN",
109 "liferay-display_4_0_0.dtd"
110 ),
111
112 new KeyValuePair(
113 "-//Liferay//DTD Display 5.0.0//EN",
114 "liferay-display_5_0_0.dtd"
115 ),
116
117 new KeyValuePair(
118 "-//Liferay//DTD Display 5.1.0//EN",
119 "liferay-display_5_1_0.dtd"
120 ),
121
122 new KeyValuePair(
123 "-//Liferay//DTD Display 5.2.0//EN",
124 "liferay-display_5_2_0.dtd"
125 ),
126
127 new KeyValuePair(
128 "-//Liferay//DTD Hook 5.1.0//EN",
129 "liferay-hook_5_1_0.dtd"
130 ),
131
132 new KeyValuePair(
133 "-//Liferay//DTD Hook 5.2.0//EN",
134 "liferay-hook_5_2_0.dtd"
135 ),
136
137 new KeyValuePair(
138 "-//Liferay//DTD Layout Templates 3.6.0//EN",
139 "liferay-layout-templates_3_6_0.dtd"
140 ),
141
142 new KeyValuePair(
143 "-//Liferay//DTD Layout Templates 4.0.0//EN",
144 "liferay-layout-templates_4_0_0.dtd"
145 ),
146
147 new KeyValuePair(
148 "-//Liferay//DTD Layout Templates 4.3.0//EN",
149 "liferay-layout-templates_4_3_0.dtd"
150 ),
151
152 new KeyValuePair(
153 "-//Liferay//DTD Layout Templates 5.0.0//EN",
154 "liferay-layout-templates_5_0_0.dtd"
155 ),
156
157 new KeyValuePair(
158 "-//Liferay//DTD Layout Templates 5.1.0//EN",
159 "liferay-layout-templates_5_1_0.dtd"
160 ),
161
162 new KeyValuePair(
163 "-//Liferay//DTD Layout Templates 5.2.0//EN",
164 "liferay-layout-templates_5_2_0.dtd"
165 ),
166
167 new KeyValuePair(
168 "-//Liferay//DTD Look and Feel 3.5.0//EN",
169 "liferay-look-and-feel_3_5_0.dtd"
170 ),
171
172 new KeyValuePair(
173 "-//Liferay//DTD Look and Feel 4.0.0//EN",
174 "liferay-look-and-feel_4_0_0.dtd"
175 ),
176
177 new KeyValuePair(
178 "-//Liferay//DTD Look and Feel 4.3.0//EN",
179 "liferay-look-and-feel_4_3_0.dtd"
180 ),
181
182 new KeyValuePair(
183 "-//Liferay//DTD Look and Feel 5.0.0//EN",
184 "liferay-look-and-feel_5_0_0.dtd"
185 ),
186
187 new KeyValuePair(
188 "-//Liferay//DTD Look and Feel 5.1.0//EN",
189 "liferay-look-and-feel_5_1_0.dtd"
190 ),
191
192 new KeyValuePair(
193 "-//Liferay//DTD Look and Feel 5.2.0//EN",
194 "liferay-look-and-feel_5_2_0.dtd"
195 ),
196
197 new KeyValuePair(
198 "-//Liferay//DTD Plugin Package 4.3.0//EN",
199 "liferay-plugin-package_4_3_0.dtd"
200 ),
201
202 new KeyValuePair(
203 "-//Liferay//DTD Plugin Package 5.0.0//EN",
204 "liferay-plugin-package_5_0_0.dtd"
205 ),
206
207 new KeyValuePair(
208 "-//Liferay//DTD Plugin Package 5.1.0//EN",
209 "liferay-plugin-package_5_1_0.dtd"
210 ),
211
212 new KeyValuePair(
213 "-//Liferay//DTD Plugin Package 5.2.0//EN",
214 "liferay-plugin-package_5_2_0.dtd"
215 ),
216
217 new KeyValuePair(
218 "-//Liferay//DTD Plugin Repository 4.3.0//EN",
219 "liferay-plugin-repository_4_3_0.dtd"
220 ),
221
222 new KeyValuePair(
223 "-//Liferay//DTD Plugin Repository 5.0.0//EN",
224 "liferay-plugin-repository_5_0_0.dtd"
225 ),
226
227 new KeyValuePair(
228 "-//Liferay//DTD Plugin Repository 5.1.0//EN",
229 "liferay-plugin-repository_5_1_0.dtd"
230 ),
231
232 new KeyValuePair(
233 "-//Liferay//DTD Plugin Repository 5.2.0//EN",
234 "liferay-plugin-repository_5_2_0.dtd"
235 ),
236
237 new KeyValuePair(
238 "-//Liferay//DTD Portlet Application 3.5.0//EN",
239 "liferay-portlet-app_3_5_0.dtd"
240 ),
241
242 new KeyValuePair(
243 "-//Liferay//DTD Portlet Application 4.0.0//EN",
244 "liferay-portlet-app_4_0_0.dtd"
245 ),
246
247 new KeyValuePair(
248 "-//Liferay//DTD Portlet Application 4.1.0//EN",
249 "liferay-portlet-app_4_1_0.dtd"
250 ),
251
252 new KeyValuePair(
253 "-//Liferay//DTD Portlet Application 4.2.0//EN",
254 "liferay-portlet-app_4_2_0.dtd"
255 ),
256
257 new KeyValuePair(
258 "-//Liferay//DTD Portlet Application 4.3.0//EN",
259 "liferay-portlet-app_4_3_0.dtd"
260 ),
261
262 new KeyValuePair(
263 "-//Liferay//DTD Portlet Application 4.3.1//EN",
264 "liferay-portlet-app_4_3_1.dtd"
265 ),
266
267 new KeyValuePair(
268 "-//Liferay//DTD Portlet Application 4.3.2//EN",
269 "liferay-portlet-app_4_3_2.dtd"
270 ),
271
272 new KeyValuePair(
273 "-//Liferay//DTD Portlet Application 4.3.3//EN",
274 "liferay-portlet-app_4_3_3.dtd"
275 ),
276
277 new KeyValuePair(
278 "-//Liferay//DTD Portlet Application 4.3.6//EN",
279 "liferay-portlet-app_4_3_6.dtd"
280 ),
281
282 new KeyValuePair(
283 "-//Liferay//DTD Portlet Application 4.4.0//EN",
284 "liferay-portlet-app_4_4_0.dtd"
285 ),
286
287 new KeyValuePair(
288 "-//Liferay//DTD Portlet Application 5.0.0//EN",
289 "liferay-portlet-app_5_0_0.dtd"
290 ),
291
292 new KeyValuePair(
293 "-//Liferay//DTD Portlet Application 5.1.0//EN",
294 "liferay-portlet-app_5_1_0.dtd"
295 ),
296
297 new KeyValuePair(
298 "-//Liferay//DTD Portlet Application 5.2.0//EN",
299 "liferay-portlet-app_5_2_0.dtd"
300 ),
301
302 new KeyValuePair(
303 "-//Liferay//DTD Service Builder 3.5.0//EN",
304 "liferay-service-builder_3_5_0.dtd"
305 ),
306
307 new KeyValuePair(
308 "-//Liferay//DTD Service Builder 3.6.1//EN",
309 "liferay-service-builder_3_6_1.dtd"
310 ),
311
312 new KeyValuePair(
313 "-//Liferay//DTD Service Builder 4.0.0//EN",
314 "liferay-service-builder_4_0_0.dtd"
315 ),
316
317 new KeyValuePair(
318 "-//Liferay//DTD Service Builder 4.2.0//EN",
319 "liferay-service-builder_4_2_0.dtd"
320 ),
321
322 new KeyValuePair(
323 "-//Liferay//DTD Service Builder 4.3.0//EN",
324 "liferay-service-builder_4_3_0.dtd"
325 ),
326
327 new KeyValuePair(
328 "-//Liferay//DTD Service Builder 4.3.3//EN",
329 "liferay-service-builder_4_3_3.dtd"
330 ),
331
332 new KeyValuePair(
333 "-//Liferay//DTD Service Builder 4.4.0//EN",
334 "liferay-service-builder_4_4_0.dtd"
335 ),
336
337 new KeyValuePair(
338 "-//Liferay//DTD Service Builder 5.0.0//EN",
339 "liferay-service-builder_5_0_0.dtd"
340 ),
341
342 new KeyValuePair(
343 "-//Liferay//DTD Service Builder 5.1.0//EN",
344 "liferay-service-builder_5_1_0.dtd"
345 ),
346
347 new KeyValuePair(
348 "-//Liferay//DTD Service Builder 5.2.0//EN",
349 "liferay-service-builder_5_2_0.dtd"
350 ),
351
352 new KeyValuePair(
353 "-//Liferay//DTD Theme Loader 4.3.0//EN",
354 "liferay-theme-loader_4_3_0.dtd"
355 ),
356
357 new KeyValuePair(
358 "-//Liferay//DTD Theme Loader 5.0.0//EN",
359 "liferay-theme-loader_5_0_0.dtd"
360 ),
361
362 new KeyValuePair(
363 "-//Liferay//DTD Theme Loader 5.1.0//EN",
364 "liferay-theme-loader_5_1_0.dtd"
365 ),
366
367 new KeyValuePair(
368 "-//Liferay//DTD Theme Loader 5.2.0//EN",
369 "liferay-theme-loader_5_2_0.dtd"
370 ),
371
372 new KeyValuePair(
373 "-//MuleSource //DTD mule-configuration XML V1.0//EN",
374 "mule-configuration.dtd"
375 ),
376
377 new KeyValuePair(
378 "-//SPRING//DTD BEAN//EN",
379 "spring-beans.dtd"
380 ),
381
382 new KeyValuePair(
383 "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN",
384 "struts-config_1_2.dtd"
385 ),
386
387 new KeyValuePair(
388 "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN",
389 "tiles-config_1_1.dtd"
390 ),
391
392 new KeyValuePair(
393 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
394 "web-app_2_3.dtd"
395 ),
396
397 new KeyValuePair(
398 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN",
399 "web-facesconfig_1_0.dtd"
400 ),
401
402 new KeyValuePair(
403 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
404 "web-facesconfig_1_1.dtd"
405 ),
406
407 new KeyValuePair(
408 "-//W3C//DTD XMLSCHEMA 200102//EN",
409 "XMLSchema.dtd"
410 )
411 };
412
413 private static KeyValuePair[] _SYSTEM_IDS = {
414 new KeyValuePair(
415 "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd",
416 "portlet-app_1_0.xsd"
417 ),
418
419 new KeyValuePair(
420 "http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd",
421 "portlet-app_2_0.xsd"
422 ),
423
424 new KeyValuePair(
425 "http://www.w3.org/2001/xml.xsd",
426 "xml.xsd"
427 )
428 };
429
430 private static Log _log = LogFactoryUtil.getLog(EntityResolver.class);
431
432 }