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