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 "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 ),
177
178 new KeyValuePair(
179 "-
180 ),
181
182 new KeyValuePair(
183 "-
184 ),
185
186 new KeyValuePair(
187 "-
188 ),
189
190 new KeyValuePair(
191 "-
192 "liferay-layout-templates_3_6_0.dtd"
193 ),
194
195 new KeyValuePair(
196 "-
197 "liferay-layout-templates_4_0_0.dtd"
198 ),
199
200 new KeyValuePair(
201 "-
202 "liferay-layout-templates_4_3_0.dtd"
203 ),
204
205 new KeyValuePair(
206 "-
207 "liferay-layout-templates_5_0_0.dtd"
208 ),
209
210 new KeyValuePair(
211 "-
212 "liferay-layout-templates_5_1_0.dtd"
213 ),
214
215 new KeyValuePair(
216 "-
217 "liferay-layout-templates_5_2_0.dtd"
218 ),
219
220 new KeyValuePair(
221 "-
222 "liferay-layout-templates_6_0_0.dtd"
223 ),
224
225 new KeyValuePair(
226 "-
227 "liferay-layout-templates_6_1_0.dtd"
228 ),
229
230 new KeyValuePair(
231 "-
232 "liferay-look-and-feel_3_5_0.dtd"
233 ),
234
235 new KeyValuePair(
236 "-
237 "liferay-look-and-feel_4_0_0.dtd"
238 ),
239
240 new KeyValuePair(
241 "-
242 "liferay-look-and-feel_4_3_0.dtd"
243 ),
244
245 new KeyValuePair(
246 "-
247 "liferay-look-and-feel_5_0_0.dtd"
248 ),
249
250 new KeyValuePair(
251 "-
252 "liferay-look-and-feel_5_1_0.dtd"
253 ),
254
255 new KeyValuePair(
256 "-
257 "liferay-look-and-feel_5_2_0.dtd"
258 ),
259
260 new KeyValuePair(
261 "-
262 "liferay-look-and-feel_6_0_0.dtd"
263 ),
264
265 new KeyValuePair(
266 "-
267 "liferay-look-and-feel_6_1_0.dtd"
268 ),
269
270 new KeyValuePair(
271 "-
272 "liferay-plugin-package_4_3_0.dtd"
273 ),
274
275 new KeyValuePair(
276 "-
277 "liferay-plugin-package_5_0_0.dtd"
278 ),
279
280 new KeyValuePair(
281 "-
282 "liferay-plugin-package_5_1_0.dtd"
283 ),
284
285 new KeyValuePair(
286 "-
287 "liferay-plugin-package_5_2_0.dtd"
288 ),
289
290 new KeyValuePair(
291 "-
292 "liferay-plugin-package_6_0_0.dtd"
293 ),
294
295 new KeyValuePair(
296 "-
297 "liferay-plugin-package_6_1_0.dtd"
298 ),
299
300 new KeyValuePair(
301 "-
302 "liferay-plugin-repository_4_3_0.dtd"
303 ),
304
305 new KeyValuePair(
306 "-
307 "liferay-plugin-repository_5_0_0.dtd"
308 ),
309
310 new KeyValuePair(
311 "-
312 "liferay-plugin-repository_5_1_0.dtd"
313 ),
314
315 new KeyValuePair(
316 "-
317 "liferay-plugin-repository_5_2_0.dtd"
318 ),
319
320 new KeyValuePair(
321 "-
322 "liferay-plugin-repository_6_0_0.dtd"
323 ),
324
325 new KeyValuePair(
326 "-
327 "liferay-plugin-repository_6_1_0.dtd"
328 ),
329
330 new KeyValuePair(
331 "-
332 "liferay-portlet-app_3_5_0.dtd"
333 ),
334
335 new KeyValuePair(
336 "-
337 "liferay-portlet-app_4_0_0.dtd"
338 ),
339
340 new KeyValuePair(
341 "-
342 "liferay-portlet-app_4_1_0.dtd"
343 ),
344
345 new KeyValuePair(
346 "-
347 "liferay-portlet-app_4_2_0.dtd"
348 ),
349
350 new KeyValuePair(
351 "-
352 "liferay-portlet-app_4_3_0.dtd"
353 ),
354
355 new KeyValuePair(
356 "-
357 "liferay-portlet-app_4_3_1.dtd"
358 ),
359
360 new KeyValuePair(
361 "-
362 "liferay-portlet-app_4_3_2.dtd"
363 ),
364
365 new KeyValuePair(
366 "-
367 "liferay-portlet-app_4_3_3.dtd"
368 ),
369
370 new KeyValuePair(
371 "-
372 "liferay-portlet-app_4_3_6.dtd"
373 ),
374
375 new KeyValuePair(
376 "-
377 "liferay-portlet-app_4_4_0.dtd"
378 ),
379
380 new KeyValuePair(
381 "-
382 "liferay-portlet-app_5_0_0.dtd"
383 ),
384
385 new KeyValuePair(
386 "-
387 "liferay-portlet-app_5_1_0.dtd"
388 ),
389
390 new KeyValuePair(
391 "-
392 "liferay-portlet-app_5_2_0.dtd"
393 ),
394
395 new KeyValuePair(
396 "-
397 "liferay-portlet-app_6_0_0.dtd"
398 ),
399
400 new KeyValuePair(
401 "-
402 "liferay-portlet-app_6_1_0.dtd"
403 ),
404
405 new KeyValuePair(
406 "-
407 "liferay-resource-action-mapping_6_0_0.dtd"
408 ),
409
410 new KeyValuePair(
411 "-
412 "liferay-resource-action-mapping_6_1_0.dtd"
413 ),
414
415 new KeyValuePair(
416 "-
417 "liferay-service-builder_3_5_0.dtd"
418 ),
419
420 new KeyValuePair(
421 "-
422 "liferay-service-builder_3_6_1.dtd"
423 ),
424
425 new KeyValuePair(
426 "-
427 "liferay-service-builder_4_0_0.dtd"
428 ),
429
430 new KeyValuePair(
431 "-
432 "liferay-service-builder_4_2_0.dtd"
433 ),
434
435 new KeyValuePair(
436 "-
437 "liferay-service-builder_4_3_0.dtd"
438 ),
439
440 new KeyValuePair(
441 "-
442 "liferay-service-builder_4_3_3.dtd"
443 ),
444
445 new KeyValuePair(
446 "-
447 "liferay-service-builder_4_4_0.dtd"
448 ),
449
450 new KeyValuePair(
451 "-
452 "liferay-service-builder_5_0_0.dtd"
453 ),
454
455 new KeyValuePair(
456 "-
457 "liferay-service-builder_5_1_0.dtd"
458 ),
459
460 new KeyValuePair(
461 "-
462 "liferay-service-builder_5_2_0.dtd"
463 ),
464
465 new KeyValuePair(
466 "-
467 "liferay-service-builder_6_0_0.dtd"
468 ),
469
470 new KeyValuePair(
471 "-
472 "liferay-service-builder_6_1_0.dtd"
473 ),
474
475 new KeyValuePair(
476 "-
477 ),
478
479 new KeyValuePair(
480 "-
481 "liferay-theme-loader_4_3_0.dtd"
482 ),
483
484 new KeyValuePair(
485 "-
486 "liferay-theme-loader_5_0_0.dtd"
487 ),
488
489 new KeyValuePair(
490 "-
491 "liferay-theme-loader_5_1_0.dtd"
492 ),
493
494 new KeyValuePair(
495 "-
496 "liferay-theme-loader_5_2_0.dtd"
497 ),
498
499 new KeyValuePair(
500 "-
501 "liferay-theme-loader_6_0_0.dtd"
502 ),
503
504 new KeyValuePair(
505 "-
506 "liferay-theme-loader_6_1_0.dtd"
507 ),
508
509 new KeyValuePair(
510 "-
511 "mule-configuration.dtd"
512 ),
513
514 new KeyValuePair(
515 "-
516 ),
517
518 new KeyValuePair(
519 "-
520 "struts-config_1_2.dtd"
521 ),
522
523 new KeyValuePair(
524 "-
525 "tiles-config_1_1.dtd"
526 ),
527
528 new KeyValuePair(
529 "-
530 "web-app_2_3.dtd"
531 ),
532
533 new KeyValuePair(
534 "-
535 "web-facesconfig_1_0.dtd"
536 ),
537
538 new KeyValuePair(
539 "-
540 "web-facesconfig_1_1.dtd"
541 ),
542
543 new KeyValuePair(
544 "-
545 )
546 };
547
548 private static final KeyValuePair[] _SYSTEM_IDS = {
549 new KeyValuePair(
550 "http:
551 ),
552
553 new KeyValuePair(
554 "http:
555 "j2ee_web_services_client_1_1.xsd",
556 "j2ee_web_services_client_1_1.xsd"
557 ),
558
559 new KeyValuePair(
560 "http:
561 ),
562
563 new KeyValuePair(
564 "http:
565 ),
566
567 new KeyValuePair(
568 "http:
569 "javaee_web_services_client_1_2.xsd",
570 "javaee_web_services_client_1_2.xsd"
571 ),
572
573 new KeyValuePair(
574 "http:
575 "javaee_web_services_client_1_3.xsd",
576 "javaee_web_services_client_1_3.xsd"
577 ),
578
579 new KeyValuePair(
580 "http:
581 ),
582
583 new KeyValuePair(
584 "http:
585 ),
586
587 new KeyValuePair(
588 "http:
589 ),
590
591 new KeyValuePair(
592 "http:
593 "portlet-app_1_0.xsd"
594 ),
595
596 new KeyValuePair(
597 "http:
598 "portlet-app_2_0.xsd"
599 ),
600
601 new KeyValuePair(
602 "http:
603 ),
604
605 new KeyValuePair(
606 "http:
607 "web-app_2_5.xsd"
608 ),
609
610 new KeyValuePair(
611 "http:
612 "web-app_3_0.xsd"
613 ),
614
615 new KeyValuePair(
616 "http:
617 "web-common_3_0.xsd"
618 ),
619
620 new KeyValuePair(
621 "http:
622 "web-facesconfig_1_2.xsd"
623 ),
624
625 new KeyValuePair(
626 "http:
627 "web-facesconfig_2_0.xsd"
628 ),
629
630 new KeyValuePair(
631 "http:
632 "web-facesconfig_2_1.xsd"
633 ),
634
635 new KeyValuePair(
636 "http:
637 "liferay-workflow-definition_6_0_0.xsd"
638 ),
639
640 new KeyValuePair(
641 "http:
642 "liferay-workflow-definition_6_1_0.xsd"
643 ),
644
645 new KeyValuePair(
646 "http:
647 )
648 };
649
650 private static Log _log = LogFactoryUtil.getLog(EntityResolver.class);
651
652 }