001
014
015 package com.liferay.portal.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.KeyValuePair;
020
021 import java.io.InputStream;
022
023 import org.xml.sax.InputSource;
024
025
028 public class EntityResolver implements org.xml.sax.EntityResolver {
029
030 public InputSource resolveEntity(String publicId, String systemId) {
031 ClassLoader classLoader = getClass().getClassLoader();
032
033 if (_log.isDebugEnabled()) {
034 _log.debug("Resolving entity " + publicId + " " + systemId);
035 }
036
037 if (publicId != null) {
038 for (int i = 0; i < _PUBLIC_IDS.length; i++) {
039 KeyValuePair kvp = _PUBLIC_IDS[i];
040
041 if (publicId.equals(kvp.getKey())) {
042 InputStream is = classLoader.getResourceAsStream(
043 _DEFINITIONS_PATH + kvp.getValue());
044
045 if (_log.isDebugEnabled()) {
046 _log.debug("Entity found for public id " + systemId);
047 }
048
049 return new InputSource(is);
050 }
051 }
052 }
053 else if (systemId != null) {
054 for (int i = 0; i < _SYSTEM_IDS.length; i++) {
055 KeyValuePair kvp = _SYSTEM_IDS[i];
056
057 if (systemId.equals(kvp.getKey())) {
058 InputStream is = classLoader.getResourceAsStream(
059 _DEFINITIONS_PATH + kvp.getValue());
060
061 if (_log.isDebugEnabled()) {
062 _log.debug("Entity found for system id " + systemId);
063 }
064
065 return new InputSource(is);
066 }
067 }
068 }
069
070 if (_log.isDebugEnabled()) {
071 _log.debug("No entity found for " + publicId + " " + systemId);
072 }
073
074 return null;
075 }
076
077 private static String _DEFINITIONS_PATH = "com/liferay/portal/definitions/";
078
079 private static KeyValuePair[] _PUBLIC_IDS = {
080 new KeyValuePair(
081 "datatypes",
082 "datatypes.dtd"
083 ),
084
085 new KeyValuePair(
086 "-
087 "facelet-taglib_1_0.dtd"
088 ),
089
090 new KeyValuePair(
091 "-
092 "hibernate-mapping-3.0.dtd"
093 ),
094
095 new KeyValuePair(
096 "-
097 "liferay-display_2_0_0.dtd"
098 ),
099
100 new KeyValuePair(
101 "-
102 "liferay-display_3_5_0.dtd"
103 ),
104
105 new KeyValuePair(
106 "-
107 "liferay-display_4_0_0.dtd"
108 ),
109
110 new KeyValuePair(
111 "-
112 "liferay-display_5_0_0.dtd"
113 ),
114
115 new KeyValuePair(
116 "-
117 "liferay-display_5_1_0.dtd"
118 ),
119
120 new KeyValuePair(
121 "-
122 "liferay-display_5_2_0.dtd"
123 ),
124
125 new KeyValuePair(
126 "-
127 "liferay-display_6_0_0.dtd"
128 ),
129
130 new KeyValuePair(
131 "-
132 "liferay-friendly-url-routes_6_0_0.dtd"
133 ),
134
135 new KeyValuePair(
136 "-
137 "liferay-hook_5_1_0.dtd"
138 ),
139
140 new KeyValuePair(
141 "-
142 "liferay-hook_5_2_0.dtd"
143 ),
144
145 new KeyValuePair(
146 "-
147 "liferay-hook_6_0_0.dtd"
148 ),
149
150 new KeyValuePair(
151 "-
152 "liferay-layout-templates_3_6_0.dtd"
153 ),
154
155 new KeyValuePair(
156 "-
157 "liferay-layout-templates_4_0_0.dtd"
158 ),
159
160 new KeyValuePair(
161 "-
162 "liferay-layout-templates_4_3_0.dtd"
163 ),
164
165 new KeyValuePair(
166 "-
167 "liferay-layout-templates_5_0_0.dtd"
168 ),
169
170 new KeyValuePair(
171 "-
172 "liferay-layout-templates_5_1_0.dtd"
173 ),
174
175 new KeyValuePair(
176 "-
177 "liferay-layout-templates_5_2_0.dtd"
178 ),
179
180 new KeyValuePair(
181 "-
182 "liferay-layout-templates_6_0_0.dtd"
183 ),
184
185 new KeyValuePair(
186 "-
187 "liferay-look-and-feel_3_5_0.dtd"
188 ),
189
190 new KeyValuePair(
191 "-
192 "liferay-look-and-feel_4_0_0.dtd"
193 ),
194
195 new KeyValuePair(
196 "-
197 "liferay-look-and-feel_4_3_0.dtd"
198 ),
199
200 new KeyValuePair(
201 "-
202 "liferay-look-and-feel_5_0_0.dtd"
203 ),
204
205 new KeyValuePair(
206 "-
207 "liferay-look-and-feel_5_1_0.dtd"
208 ),
209
210 new KeyValuePair(
211 "-
212 "liferay-look-and-feel_5_2_0.dtd"
213 ),
214
215 new KeyValuePair(
216 "-
217 "liferay-look-and-feel_6_0_0.dtd"
218 ),
219
220 new KeyValuePair(
221 "-
222 "liferay-plugin-package_4_3_0.dtd"
223 ),
224
225 new KeyValuePair(
226 "-
227 "liferay-plugin-package_5_0_0.dtd"
228 ),
229
230 new KeyValuePair(
231 "-
232 "liferay-plugin-package_5_1_0.dtd"
233 ),
234
235 new KeyValuePair(
236 "-
237 "liferay-plugin-package_5_2_0.dtd"
238 ),
239
240 new KeyValuePair(
241 "-
242 "liferay-plugin-package_6_0_0.dtd"
243 ),
244
245 new KeyValuePair(
246 "-
247 "liferay-plugin-repository_4_3_0.dtd"
248 ),
249
250 new KeyValuePair(
251 "-
252 "liferay-plugin-repository_5_0_0.dtd"
253 ),
254
255 new KeyValuePair(
256 "-
257 "liferay-plugin-repository_5_1_0.dtd"
258 ),
259
260 new KeyValuePair(
261 "-
262 "liferay-plugin-repository_5_2_0.dtd"
263 ),
264
265 new KeyValuePair(
266 "-
267 "liferay-plugin-repository_6_0_0.dtd"
268 ),
269
270 new KeyValuePair(
271 "-
272 "liferay-portlet-app_3_5_0.dtd"
273 ),
274
275 new KeyValuePair(
276 "-
277 "liferay-portlet-app_4_0_0.dtd"
278 ),
279
280 new KeyValuePair(
281 "-
282 "liferay-portlet-app_4_1_0.dtd"
283 ),
284
285 new KeyValuePair(
286 "-
287 "liferay-portlet-app_4_2_0.dtd"
288 ),
289
290 new KeyValuePair(
291 "-
292 "liferay-portlet-app_4_3_0.dtd"
293 ),
294
295 new KeyValuePair(
296 "-
297 "liferay-portlet-app_4_3_1.dtd"
298 ),
299
300 new KeyValuePair(
301 "-
302 "liferay-portlet-app_4_3_2.dtd"
303 ),
304
305 new KeyValuePair(
306 "-
307 "liferay-portlet-app_4_3_3.dtd"
308 ),
309
310 new KeyValuePair(
311 "-
312 "liferay-portlet-app_4_3_6.dtd"
313 ),
314
315 new KeyValuePair(
316 "-
317 "liferay-portlet-app_4_4_0.dtd"
318 ),
319
320 new KeyValuePair(
321 "-
322 "liferay-portlet-app_5_0_0.dtd"
323 ),
324
325 new KeyValuePair(
326 "-
327 "liferay-portlet-app_5_1_0.dtd"
328 ),
329
330 new KeyValuePair(
331 "-
332 "liferay-portlet-app_5_2_0.dtd"
333 ),
334
335 new KeyValuePair(
336 "-
337 "liferay-portlet-app_6_0_0.dtd"
338 ),
339
340 new KeyValuePair(
341 "-
342 "liferay-service-builder_3_5_0.dtd"
343 ),
344
345 new KeyValuePair(
346 "-
347 "liferay-service-builder_3_6_1.dtd"
348 ),
349
350 new KeyValuePair(
351 "-
352 "liferay-service-builder_4_0_0.dtd"
353 ),
354
355 new KeyValuePair(
356 "-
357 "liferay-service-builder_4_2_0.dtd"
358 ),
359
360 new KeyValuePair(
361 "-
362 "liferay-service-builder_4_3_0.dtd"
363 ),
364
365 new KeyValuePair(
366 "-
367 "liferay-service-builder_4_3_3.dtd"
368 ),
369
370 new KeyValuePair(
371 "-
372 "liferay-service-builder_4_4_0.dtd"
373 ),
374
375 new KeyValuePair(
376 "-
377 "liferay-service-builder_5_0_0.dtd"
378 ),
379
380 new KeyValuePair(
381 "-
382 "liferay-service-builder_5_1_0.dtd"
383 ),
384
385 new KeyValuePair(
386 "-
387 "liferay-service-builder_5_2_0.dtd"
388 ),
389
390 new KeyValuePair(
391 "-
392 "liferay-service-builder_6_0_0.dtd"
393 ),
394
395 new KeyValuePair(
396 "-
397 "liferay-theme-loader_4_3_0.dtd"
398 ),
399
400 new KeyValuePair(
401 "-
402 "liferay-theme-loader_5_0_0.dtd"
403 ),
404
405 new KeyValuePair(
406 "-
407 "liferay-theme-loader_5_1_0.dtd"
408 ),
409
410 new KeyValuePair(
411 "-
412 "liferay-theme-loader_5_2_0.dtd"
413 ),
414
415 new KeyValuePair(
416 "-
417 "liferay-theme-loader_6_0_0.dtd"
418 ),
419
420 new KeyValuePair(
421 "-
422 "mule-configuration.dtd"
423 ),
424
425 new KeyValuePair(
426 "-
427 "spring-beans.dtd"
428 ),
429
430 new KeyValuePair(
431 "-
432 "struts-config_1_2.dtd"
433 ),
434
435 new KeyValuePair(
436 "-
437 "tiles-config_1_1.dtd"
438 ),
439
440 new KeyValuePair(
441 "-
442 "web-app_2_3.dtd"
443 ),
444
445 new KeyValuePair(
446 "-
447 "web-facesconfig_1_0.dtd"
448 ),
449
450 new KeyValuePair(
451 "-
452 "web-facesconfig_1_1.dtd"
453 ),
454
455 new KeyValuePair(
456 "-
457 "XMLSchema.dtd"
458 )
459 };
460
461 private static KeyValuePair[] _SYSTEM_IDS = {
462 new KeyValuePair(
463 "http:
464 "portlet-app_1_0.xsd"
465 ),
466
467 new KeyValuePair(
468 "http:
469 "portlet-app_2_0.xsd"
470 ),
471
472 new KeyValuePair(
473 "http:
474 "xml.xsd"
475 )
476 };
477
478 private static Log _log = LogFactoryUtil.getLog(EntityResolver.class);
479
480 }