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