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.Http;
020 import com.liferay.portal.kernel.util.KeyValuePair;
021
022 import java.io.InputStream;
023
024 import org.apache.xerces.xni.XNIException;
025
026 import org.xml.sax.InputSource;
027
028
031 public class EntityResolver implements org.xml.sax.EntityResolver {
032
033 public InputSource resolveEntity(String publicId, String systemId) {
034 ClassLoader classLoader = getClass().getClassLoader();
035
036 if (_log.isDebugEnabled()) {
037 _log.debug("Resolving entity " + publicId + " " + systemId);
038 }
039
040 if (publicId != null) {
041 for (int i = 0; i < _PUBLIC_IDS.length; i++) {
042 KeyValuePair kvp = _PUBLIC_IDS[i];
043
044 if (publicId.equals(kvp.getKey())) {
045 InputStream is = classLoader.getResourceAsStream(
046 _DEFINITIONS_PATH + kvp.getValue());
047
048 if (_log.isDebugEnabled()) {
049 _log.debug("Entity found for public id " + systemId);
050 }
051
052 return new InputSource(is);
053 }
054 }
055 }
056 else if (systemId != null) {
057 for (int i = 0; i < _SYSTEM_IDS.length; i++) {
058 KeyValuePair kvp = _SYSTEM_IDS[i];
059
060 if (systemId.equals(kvp.getKey())) {
061 InputStream is = classLoader.getResourceAsStream(
062 _DEFINITIONS_PATH + kvp.getValue());
063
064 if (_log.isDebugEnabled()) {
065 _log.debug("Entity found for system id " + systemId);
066 }
067
068 InputSource inputSource = new InputSource(is);
069
070 inputSource.setSystemId(kvp.getKey());
071
072 return inputSource;
073 }
074 }
075
076 if (!systemId.endsWith(".dtd") && !systemId.endsWith(".xsd")) {
077 throw new XNIException("Invalid system id " + systemId);
078 }
079
080 if (!systemId.startsWith(Http.HTTP_WITH_SLASH) &&
081 !systemId.startsWith(Http.HTTPS_WITH_SLASH)) {
082
083 InputStream inputStream = classLoader.getResourceAsStream(
084 systemId);
085
086 if (inputStream != null) {
087 InputSource inputSource = new InputSource(inputStream);
088
089 inputSource.setSystemId(systemId);
090
091 return inputSource;
092 }
093 else {
094 throw new XNIException("Invalid system id " + systemId);
095 }
096 }
097 }
098
099 if (_log.isDebugEnabled()) {
100 _log.debug("No entity found for " + publicId + " " + systemId);
101 }
102
103 return null;
104 }
105
106 private static String _DEFINITIONS_PATH = "com/liferay/portal/definitions/";
107
108 private static KeyValuePair[] _PUBLIC_IDS = {
109 new KeyValuePair(
110 "datatypes",
111 "datatypes.dtd"
112 ),
113
114 new KeyValuePair(
115 "-
116 "facelet-taglib_1_0.dtd"
117 ),
118
119 new KeyValuePair(
120 "-
121 "hibernate-mapping-3.0.dtd"
122 ),
123
124 new KeyValuePair(
125 "-
126 "liferay-display_2_0_0.dtd"
127 ),
128
129 new KeyValuePair(
130 "-
131 "liferay-display_3_5_0.dtd"
132 ),
133
134 new KeyValuePair(
135 "-
136 "liferay-display_4_0_0.dtd"
137 ),
138
139 new KeyValuePair(
140 "-
141 "liferay-display_5_0_0.dtd"
142 ),
143
144 new KeyValuePair(
145 "-
146 "liferay-display_5_1_0.dtd"
147 ),
148
149 new KeyValuePair(
150 "-
151 "liferay-display_5_2_0.dtd"
152 ),
153
154 new KeyValuePair(
155 "-
156 "liferay-display_6_0_0.dtd"
157 ),
158
159 new KeyValuePair(
160 "-
161 "liferay-display_6_1_0.dtd"
162 ),
163
164 new KeyValuePair(
165 "-
166 "liferay-friendly-url-routes_6_0_0.dtd"
167 ),
168
169 new KeyValuePair(
170 "-
171 "liferay-friendly-url-routes_6_1_0.dtd"
172 ),
173
174 new KeyValuePair(
175 "-
176 "liferay-hook_5_1_0.dtd"
177 ),
178
179 new KeyValuePair(
180 "-
181 "liferay-hook_5_2_0.dtd"
182 ),
183
184 new KeyValuePair(
185 "-
186 "liferay-hook_6_0_0.dtd"
187 ),
188
189 new KeyValuePair(
190 "-
191 "liferay-hook_6_1_0.dtd"
192 ),
193
194 new KeyValuePair(
195 "-
196 "liferay-layout-templates_3_6_0.dtd"
197 ),
198
199 new KeyValuePair(
200 "-
201 "liferay-layout-templates_4_0_0.dtd"
202 ),
203
204 new KeyValuePair(
205 "-
206 "liferay-layout-templates_4_3_0.dtd"
207 ),
208
209 new KeyValuePair(
210 "-
211 "liferay-layout-templates_5_0_0.dtd"
212 ),
213
214 new KeyValuePair(
215 "-
216 "liferay-layout-templates_5_1_0.dtd"
217 ),
218
219 new KeyValuePair(
220 "-
221 "liferay-layout-templates_5_2_0.dtd"
222 ),
223
224 new KeyValuePair(
225 "-
226 "liferay-layout-templates_6_0_0.dtd"
227 ),
228
229 new KeyValuePair(
230 "-
231 "liferay-layout-templates_6_1_0.dtd"
232 ),
233
234 new KeyValuePair(
235 "-
236 "liferay-look-and-feel_3_5_0.dtd"
237 ),
238
239 new KeyValuePair(
240 "-
241 "liferay-look-and-feel_4_0_0.dtd"
242 ),
243
244 new KeyValuePair(
245 "-
246 "liferay-look-and-feel_4_3_0.dtd"
247 ),
248
249 new KeyValuePair(
250 "-
251 "liferay-look-and-feel_5_0_0.dtd"
252 ),
253
254 new KeyValuePair(
255 "-
256 "liferay-look-and-feel_5_1_0.dtd"
257 ),
258
259 new KeyValuePair(
260 "-
261 "liferay-look-and-feel_5_2_0.dtd"
262 ),
263
264 new KeyValuePair(
265 "-
266 "liferay-look-and-feel_6_0_0.dtd"
267 ),
268
269 new KeyValuePair(
270 "-
271 "liferay-look-and-feel_6_1_0.dtd"
272 ),
273
274 new KeyValuePair(
275 "-
276 "liferay-plugin-package_4_3_0.dtd"
277 ),
278
279 new KeyValuePair(
280 "-
281 "liferay-plugin-package_5_0_0.dtd"
282 ),
283
284 new KeyValuePair(
285 "-
286 "liferay-plugin-package_5_1_0.dtd"
287 ),
288
289 new KeyValuePair(
290 "-
291 "liferay-plugin-package_5_2_0.dtd"
292 ),
293
294 new KeyValuePair(
295 "-
296 "liferay-plugin-package_6_0_0.dtd"
297 ),
298
299 new KeyValuePair(
300 "-
301 "liferay-plugin-package_6_1_0.dtd"
302 ),
303
304 new KeyValuePair(
305 "-
306 "liferay-plugin-repository_4_3_0.dtd"
307 ),
308
309 new KeyValuePair(
310 "-
311 "liferay-plugin-repository_5_0_0.dtd"
312 ),
313
314 new KeyValuePair(
315 "-
316 "liferay-plugin-repository_5_1_0.dtd"
317 ),
318
319 new KeyValuePair(
320 "-
321 "liferay-plugin-repository_5_2_0.dtd"
322 ),
323
324 new KeyValuePair(
325 "-
326 "liferay-plugin-repository_6_0_0.dtd"
327 ),
328
329 new KeyValuePair(
330 "-
331 "liferay-plugin-repository_6_1_0.dtd"
332 ),
333
334 new KeyValuePair(
335 "-
336 "liferay-portlet-app_3_5_0.dtd"
337 ),
338
339 new KeyValuePair(
340 "-
341 "liferay-portlet-app_4_0_0.dtd"
342 ),
343
344 new KeyValuePair(
345 "-
346 "liferay-portlet-app_4_1_0.dtd"
347 ),
348
349 new KeyValuePair(
350 "-
351 "liferay-portlet-app_4_2_0.dtd"
352 ),
353
354 new KeyValuePair(
355 "-
356 "liferay-portlet-app_4_3_0.dtd"
357 ),
358
359 new KeyValuePair(
360 "-
361 "liferay-portlet-app_4_3_1.dtd"
362 ),
363
364 new KeyValuePair(
365 "-
366 "liferay-portlet-app_4_3_2.dtd"
367 ),
368
369 new KeyValuePair(
370 "-
371 "liferay-portlet-app_4_3_3.dtd"
372 ),
373
374 new KeyValuePair(
375 "-
376 "liferay-portlet-app_4_3_6.dtd"
377 ),
378
379 new KeyValuePair(
380 "-
381 "liferay-portlet-app_4_4_0.dtd"
382 ),
383
384 new KeyValuePair(
385 "-
386 "liferay-portlet-app_5_0_0.dtd"
387 ),
388
389 new KeyValuePair(
390 "-
391 "liferay-portlet-app_5_1_0.dtd"
392 ),
393
394 new KeyValuePair(
395 "-
396 "liferay-portlet-app_5_2_0.dtd"
397 ),
398
399 new KeyValuePair(
400 "-
401 "liferay-portlet-app_6_0_0.dtd"
402 ),
403
404 new KeyValuePair(
405 "-
406 "liferay-portlet-app_6_1_0.dtd"
407 ),
408
409 new KeyValuePair(
410 "-
411 "liferay-resource-action-mapping_6_0_0.dtd"
412 ),
413
414 new KeyValuePair(
415 "-
416 "liferay-resource-action-mapping_6_1_0.dtd"
417 ),
418
419 new KeyValuePair(
420 "-
421 "liferay-service-builder_3_5_0.dtd"
422 ),
423
424 new KeyValuePair(
425 "-
426 "liferay-service-builder_3_6_1.dtd"
427 ),
428
429 new KeyValuePair(
430 "-
431 "liferay-service-builder_4_0_0.dtd"
432 ),
433
434 new KeyValuePair(
435 "-
436 "liferay-service-builder_4_2_0.dtd"
437 ),
438
439 new KeyValuePair(
440 "-
441 "liferay-service-builder_4_3_0.dtd"
442 ),
443
444 new KeyValuePair(
445 "-
446 "liferay-service-builder_4_3_3.dtd"
447 ),
448
449 new KeyValuePair(
450 "-
451 "liferay-service-builder_4_4_0.dtd"
452 ),
453
454 new KeyValuePair(
455 "-
456 "liferay-service-builder_5_0_0.dtd"
457 ),
458
459 new KeyValuePair(
460 "-
461 "liferay-service-builder_5_1_0.dtd"
462 ),
463
464 new KeyValuePair(
465 "-
466 "liferay-service-builder_5_2_0.dtd"
467 ),
468
469 new KeyValuePair(
470 "-
471 "liferay-service-builder_6_0_0.dtd"
472 ),
473
474 new KeyValuePair(
475 "-
476 "liferay-service-builder_6_1_0.dtd"
477 ),
478
479 new KeyValuePair(
480 "-
481 "liferay-social_6_1_0.dtd"
482 ),
483
484 new KeyValuePair(
485 "-
486 "liferay-theme-loader_4_3_0.dtd"
487 ),
488
489 new KeyValuePair(
490 "-
491 "liferay-theme-loader_5_0_0.dtd"
492 ),
493
494 new KeyValuePair(
495 "-
496 "liferay-theme-loader_5_1_0.dtd"
497 ),
498
499 new KeyValuePair(
500 "-
501 "liferay-theme-loader_5_2_0.dtd"
502 ),
503
504 new KeyValuePair(
505 "-
506 "liferay-theme-loader_6_0_0.dtd"
507 ),
508
509 new KeyValuePair(
510 "-
511 "liferay-theme-loader_6_1_0.dtd"
512 ),
513
514 new KeyValuePair(
515 "-
516 "mule-configuration.dtd"
517 ),
518
519 new KeyValuePair(
520 "-
521 "spring-beans.dtd"
522 ),
523
524 new KeyValuePair(
525 "-
526 "struts-config_1_2.dtd"
527 ),
528
529 new KeyValuePair(
530 "-
531 "tiles-config_1_1.dtd"
532 ),
533
534 new KeyValuePair(
535 "-
536 "web-app_2_3.dtd"
537 ),
538
539 new KeyValuePair(
540 "-
541 "web-facesconfig_1_0.dtd"
542 ),
543
544 new KeyValuePair(
545 "-
546 "web-facesconfig_1_1.dtd"
547 ),
548
549 new KeyValuePair(
550 "-
551 "XMLSchema.dtd"
552 )
553 };
554
555 private static KeyValuePair[] _SYSTEM_IDS = {
556 new KeyValuePair(
557 "http:
558 "j2ee_1_4.xsd"
559 ),
560
561 new KeyValuePair(
562 "http:
563 "j2ee_web_services_client_1_1.xsd",
564 "j2ee_web_services_client_1_1.xsd"
565 ),
566
567 new KeyValuePair(
568 "http:
569 "javaee_5.xsd"
570 ),
571
572 new KeyValuePair(
573 "http:
574 "javaee_6.xsd"
575 ),
576
577 new KeyValuePair(
578 "http:
579 "javaee_web_services_client_1_2.xsd",
580 "javaee_web_services_client_1_2.xsd"
581 ),
582
583 new KeyValuePair(
584 "http:
585 "javaee_web_services_client_1_3.xsd",
586 "javaee_web_services_client_1_3.xsd"
587 ),
588
589 new KeyValuePair(
590 "http:
591 "jsp_2_0.xsd"
592 ),
593
594 new KeyValuePair(
595 "http:
596 "jsp_2_1.xsd"
597 ),
598
599 new KeyValuePair(
600 "http:
601 "jsp_2_2.xsd"
602 ),
603
604 new KeyValuePair(
605 "http:
606 "portlet-app_1_0.xsd"
607 ),
608
609 new KeyValuePair(
610 "http:
611 "portlet-app_2_0.xsd"
612 ),
613
614 new KeyValuePair(
615 "http:
616 "web-app_2_4.xsd"
617 ),
618
619 new KeyValuePair(
620 "http:
621 "web-app_2_5.xsd"
622 ),
623
624 new KeyValuePair(
625 "http:
626 "web-app_3_0.xsd"
627 ),
628
629 new KeyValuePair(
630 "http:
631 "web-common_3_0.xsd"
632 ),
633
634 new KeyValuePair(
635 "http:
636 "web-facesconfig_1_2.xsd"
637 ),
638
639 new KeyValuePair(
640 "http:
641 "web-facesconfig_2_0.xsd"
642 ),
643
644 new KeyValuePair(
645 "http:
646 "web-facesconfig_2_1.xsd"
647 ),
648
649 new KeyValuePair(
650 "http:
651 "liferay-workflow-definition_6_0_0.xsd"
652 ),
653
654 new KeyValuePair(
655 "http:
656 "liferay-workflow-definition_6_1_0.xsd"
657 ),
658
659 new KeyValuePair(
660 "http:
661 "xml.xsd"
662 )
663 };
664
665 private static Log _log = LogFactoryUtil.getLog(EntityResolver.class);
666
667 }