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