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