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 Class<?> clazz = getClass();
036
037 ClassLoader classLoader = clazz.getClassLoader();
038
039 if (_log.isDebugEnabled()) {
040 _log.debug("Resolving entity " + publicId + " " + systemId);
041 }
042
043 if (publicId != null) {
044 for (int i = 0; i < _PUBLIC_IDS.length; i++) {
045 KeyValuePair kvp = _PUBLIC_IDS[i];
046
047 if (publicId.equals(kvp.getKey())) {
048 InputStream is = classLoader.getResourceAsStream(
049 _DEFINITIONS_PATH + kvp.getValue());
050
051 if (is == null) {
052 is = classLoader.getResourceAsStream(kvp.getValue());
053 }
054
055 if (_log.isDebugEnabled()) {
056 _log.debug("Entity found for public id " + publicId);
057 }
058
059 return new InputSource(is);
060 }
061 }
062 }
063 else if (systemId != null) {
064 for (int i = 0; i < _SYSTEM_IDS.length; i++) {
065 KeyValuePair kvp = _SYSTEM_IDS[i];
066
067 if (systemId.equals(kvp.getKey())) {
068 InputStream is = classLoader.getResourceAsStream(
069 _DEFINITIONS_PATH + kvp.getValue());
070
071 if (is == null) {
072 is = classLoader.getResourceAsStream(kvp.getValue());
073 }
074
075 if (_log.isDebugEnabled()) {
076 _log.debug("Entity found for system id " + systemId);
077 }
078
079 InputSource inputSource = new InputSource(is);
080
081 inputSource.setSystemId(kvp.getKey());
082
083 return inputSource;
084 }
085 }
086
087 if (!systemId.endsWith(".dtd") && !systemId.endsWith(".xsd")) {
088 throw new XNIException("Invalid system id " + systemId);
089 }
090
091 if (!systemId.startsWith(Http.HTTP_WITH_SLASH) &&
092 !systemId.startsWith(Http.HTTPS_WITH_SLASH)) {
093
094 InputStream inputStream = classLoader.getResourceAsStream(
095 systemId);
096
097 if (inputStream != null) {
098 InputSource inputSource = new InputSource(inputStream);
099
100 inputSource.setSystemId(systemId);
101
102 return inputSource;
103 }
104 else {
105 throw new XNIException("Invalid system id " + systemId);
106 }
107 }
108 }
109
110 if (_log.isDebugEnabled()) {
111 _log.debug("No entity found for " + publicId + " " + systemId);
112 }
113
114 return null;
115 }
116
117 private static final String _DEFINITIONS_PATH =
118 "com/liferay/portal/definitions/";
119
120 private static final KeyValuePair[] _PUBLIC_IDS = {
121 new KeyValuePair("datatypes", "datatypes.dtd"),
122 new KeyValuePair(
123 "-
124 "facelet-taglib_1_0.dtd"),
125 new KeyValuePair(
126 "-
127 "hibernate-mapping-3.0.dtd"),
128 new KeyValuePair(
129 "-
130 new KeyValuePair(
131 "-
132 new KeyValuePair(
133 "-
134 new KeyValuePair(
135 "-
136 new KeyValuePair(
137 "-
138 new KeyValuePair(
139 "-
140 new KeyValuePair(
141 "-
142 new KeyValuePair(
143 "-
144 new KeyValuePair(
145 "-
146 new KeyValuePair(
147 "-
148 new KeyValuePair(
149 "-
150 "liferay-friendly-url-routes_6_0_0.dtd"),
151 new KeyValuePair(
152 "-
153 "liferay-friendly-url-routes_6_1_0.dtd"),
154 new KeyValuePair(
155 "-
156 "liferay-friendly-url-routes_6_2_0.dtd"),
157 new KeyValuePair(
158 "-
159 "liferay-friendly-url-routes_7_0_0.dtd"),
160 new KeyValuePair(
161 "-
162 new KeyValuePair(
163 "-
164 new KeyValuePair(
165 "-
166 new KeyValuePair(
167 "-
168 new KeyValuePair(
169 "-
170 new KeyValuePair(
171 "-
172 new KeyValuePair(
173 "-
174 "liferay-layout-templates_3_6_0.dtd"),
175 new KeyValuePair(
176 "-
177 "liferay-layout-templates_4_0_0.dtd"),
178 new KeyValuePair(
179 "-
180 "liferay-layout-templates_4_3_0.dtd"),
181 new KeyValuePair(
182 "-
183 "liferay-layout-templates_5_0_0.dtd"),
184 new KeyValuePair(
185 "-
186 "liferay-layout-templates_5_1_0.dtd"),
187 new KeyValuePair(
188 "-
189 "liferay-layout-templates_5_2_0.dtd"),
190 new KeyValuePair(
191 "-
192 "liferay-layout-templates_6_0_0.dtd"),
193 new KeyValuePair(
194 "-
195 "liferay-layout-templates_6_1_0.dtd"),
196 new KeyValuePair(
197 "-
198 "liferay-layout-templates_6_2_0.dtd"),
199 new KeyValuePair(
200 "-
201 "liferay-layout-templates_7_0_0.dtd"),
202 new KeyValuePair(
203 "-
204 "liferay-look-and-feel_3_5_0.dtd"),
205 new KeyValuePair(
206 "-
207 "liferay-look-and-feel_4_0_0.dtd"),
208 new KeyValuePair(
209 "-
210 "liferay-look-and-feel_4_3_0.dtd"),
211 new KeyValuePair(
212 "-
213 "liferay-look-and-feel_5_0_0.dtd"),
214 new KeyValuePair(
215 "-
216 "liferay-look-and-feel_5_1_0.dtd"),
217 new KeyValuePair(
218 "-
219 "liferay-look-and-feel_5_2_0.dtd"),
220 new KeyValuePair(
221 "-
222 "liferay-look-and-feel_6_0_0.dtd"),
223 new KeyValuePair(
224 "-
225 "liferay-look-and-feel_6_1_0.dtd"),
226 new KeyValuePair(
227 "-
228 "liferay-look-and-feel_6_2_0.dtd"),
229 new KeyValuePair(
230 "-
231 "liferay-look-and-feel_7_0_0.dtd"),
232 new KeyValuePair(
233 "-
234 "liferay-plugin-package_4_3_0.dtd"),
235
236 new KeyValuePair(
237 "-
238 "liferay-plugin-package_5_0_0.dtd"),
239 new KeyValuePair(
240 "-
241 "liferay-plugin-package_5_1_0.dtd"),
242 new KeyValuePair(
243 "-
244 "liferay-plugin-package_5_2_0.dtd"),
245 new KeyValuePair(
246 "-
247 "liferay-plugin-package_6_0_0.dtd"),
248 new KeyValuePair(
249 "-
250 "liferay-plugin-package_6_1_0.dtd"),
251 new KeyValuePair(
252 "-
253 "liferay-plugin-package_6_2_0.dtd"),
254 new KeyValuePair(
255 "-
256 "liferay-plugin-package_7_0_0.dtd"),
257 new KeyValuePair(
258 "-
259 "liferay-plugin-repository_4_3_0.dtd"),
260 new KeyValuePair(
261 "-
262 "liferay-plugin-repository_5_0_0.dtd"),
263 new KeyValuePair(
264 "-
265 "liferay-plugin-repository_5_1_0.dtd"),
266 new KeyValuePair(
267 "-
268 "liferay-plugin-repository_5_2_0.dtd"),
269 new KeyValuePair(
270 "-
271 "liferay-plugin-repository_6_0_0.dtd"),
272 new KeyValuePair(
273 "-
274 "liferay-plugin-repository_6_1_0.dtd"),
275 new KeyValuePair(
276 "-
277 "liferay-plugin-repository_6_2_0.dtd"),
278 new KeyValuePair(
279 "-
280 "liferay-plugin-repository_7_0_0.dtd"),
281 new KeyValuePair(
282 "-
283 "liferay-portlet-app_3_5_0.dtd"),
284 new KeyValuePair(
285 "-
286 "liferay-portlet-app_4_0_0.dtd"),
287 new KeyValuePair(
288 "-
289 "liferay-portlet-app_4_1_0.dtd"),
290
291 new KeyValuePair(
292 "-
293 "liferay-portlet-app_4_2_0.dtd"),
294 new KeyValuePair(
295 "-
296 "liferay-portlet-app_4_3_0.dtd"),
297 new KeyValuePair(
298 "-
299 "liferay-portlet-app_4_3_1.dtd"),
300 new KeyValuePair(
301 "-
302 "liferay-portlet-app_4_3_2.dtd"),
303 new KeyValuePair(
304 "-
305 "liferay-portlet-app_4_3_3.dtd"),
306 new KeyValuePair(
307 "-
308 "liferay-portlet-app_4_3_6.dtd"),
309 new KeyValuePair(
310 "-
311 "liferay-portlet-app_4_4_0.dtd"),
312 new KeyValuePair(
313 "-
314 "liferay-portlet-app_5_0_0.dtd"),
315 new KeyValuePair(
316 "-
317 "liferay-portlet-app_5_1_0.dtd"),
318 new KeyValuePair(
319 "-
320 "liferay-portlet-app_5_2_0.dtd"),
321 new KeyValuePair(
322 "-
323 "liferay-portlet-app_6_0_0.dtd"),
324 new KeyValuePair(
325 "-
326 "liferay-portlet-app_6_1_0.dtd"),
327 new KeyValuePair(
328 "-
329 "liferay-portlet-app_6_2_0.dtd"),
330 new KeyValuePair(
331 "-
332 "liferay-portlet-app_7_0_0.dtd"),
333 new KeyValuePair(
334 "-
335 "liferay-resource-action-mapping_6_0_0.dtd"),
336 new KeyValuePair(
337 "-
338 "liferay-resource-action-mapping_6_1_0.dtd"),
339 new KeyValuePair(
340 "-
341 "liferay-resource-action-mapping_6_2_0.dtd"),
342 new KeyValuePair(
343 "-
344 "liferay-resource-action-mapping_7_0_0.dtd"),
345 new KeyValuePair(
346 "-
347 "liferay-service-builder_3_5_0.dtd"),
348 new KeyValuePair(
349 "-
350 "liferay-service-builder_3_6_1.dtd"),
351 new KeyValuePair(
352 "-
353 "liferay-service-builder_4_0_0.dtd"),
354 new KeyValuePair(
355 "-
356 "liferay-service-builder_4_2_0.dtd"),
357 new KeyValuePair(
358 "-
359 "liferay-service-builder_4_3_0.dtd"),
360 new KeyValuePair(
361 "-
362 "liferay-service-builder_4_3_3.dtd"),
363 new KeyValuePair(
364 "-
365 "liferay-service-builder_4_4_0.dtd"),
366 new KeyValuePair(
367 "-
368 "liferay-service-builder_5_0_0.dtd"),
369 new KeyValuePair(
370 "-
371 "liferay-service-builder_5_1_0.dtd"),
372 new KeyValuePair(
373 "-
374 "liferay-service-builder_5_2_0.dtd"),
375 new KeyValuePair(
376 "-
377 "liferay-service-builder_6_0_0.dtd"),
378 new KeyValuePair(
379 "-
380 "liferay-service-builder_6_1_0.dtd"),
381 new KeyValuePair(
382 "-
383 "liferay-service-builder_6_2_0.dtd"),
384 new KeyValuePair(
385 "-
386 "liferay-service-builder_7_0_0.dtd"),
387 new KeyValuePair(
388 "-
389 new KeyValuePair(
390 "-
391 new KeyValuePair(
392 "-
393 new KeyValuePair(
394 "-
395 "liferay-theme-loader_4_3_0.dtd"),
396 new KeyValuePair(
397 "-
398 "liferay-theme-loader_5_0_0.dtd"),
399 new KeyValuePair(
400 "-
401 "liferay-theme-loader_5_1_0.dtd"),
402 new KeyValuePair(
403 "-
404 "liferay-theme-loader_5_2_0.dtd"),
405 new KeyValuePair(
406 "-
407 "liferay-theme-loader_6_0_0.dtd"),
408 new KeyValuePair(
409 "-
410 "liferay-theme-loader_6_1_0.dtd"),
411 new KeyValuePair(
412 "-
413 "liferay-theme-loader_6_2_0.dtd"),
414 new KeyValuePair(
415 "-
416 "liferay-theme-loader_7_0_0.dtd"),
417 new KeyValuePair(
418 "-
419 "liferay-user-notification-definitions_6_2_0.dtd"),
420 new KeyValuePair(
421 "-
422 "liferay-user-notification-definitions_7_0_0.dtd"),
423 new KeyValuePair(
424 "-
425 "mule-configuration.dtd"),
426 new KeyValuePair("-
427 new KeyValuePair(
428 "-
429 "struts-config_1_2.dtd"),
430 new KeyValuePair(
431 "-
432 "tiles-config_1_1.dtd"),
433 new KeyValuePair(
434 "-
435 "web-app_2_3.dtd"),
436 new KeyValuePair(
437 "-
438 "web-facesconfig_1_0.dtd"),
439 new KeyValuePair(
440 "-
441 "web-facesconfig_1_1.dtd"),
442 new KeyValuePair(
443 "-
444 };
445
446 private static final KeyValuePair[] _SYSTEM_IDS = {
447 new KeyValuePair(
448 "http:
449 new KeyValuePair(
450 "http:
451 "j2ee_web_services_client_1_1.xsd",
452 "j2ee_web_services_client_1_1.xsd"),
453 new KeyValuePair(
454 "http:
455 new KeyValuePair(
456 "http:
457 new KeyValuePair(
458 "http:
459 "javaee_web_services_client_1_2.xsd",
460 "javaee_web_services_client_1_2.xsd"),
461 new KeyValuePair(
462 "http:
463 "javaee_web_services_client_1_3.xsd",
464 "javaee_web_services_client_1_3.xsd"),
465 new KeyValuePair(
466 "http:
467 new KeyValuePair(
468 "http:
469 new KeyValuePair(
470 "http:
471 new KeyValuePair(
472 "http:
473 "portlet-app_1_0.xsd"),
474 new KeyValuePair(
475 "http:
476 "portlet-app_2_0.xsd"),
477 new KeyValuePair(
478 "http:
479 "web-app_2_4.xsd"),
480 new KeyValuePair(
481 "http:
482 "web-app_2_5.xsd"),
483 new KeyValuePair(
484 "http:
485 "web-app_3_0.xsd"),
486 new KeyValuePair(
487 "http:
488 "web-common_3_0.xsd"),
489 new KeyValuePair(
490 "http:
491 "web-facesconfig_1_2.xsd"),
492 new KeyValuePair(
493 "http:
494 "web-facesconfig_2_0.xsd"),
495 new KeyValuePair(
496 "http:
497 "web-facesconfig_2_1.xsd"),
498 new KeyValuePair(
499 "http:
500 "liferay-ddm-structure_6_2_0.xsd"),
501 new KeyValuePair(
502 "http:
503 "liferay-ddm-structure_7_0_0.xsd"),
504 new KeyValuePair(
505 "http:
506 "liferay-workflow-definition_6_0_0.xsd"),
507 new KeyValuePair(
508 "http:
509 "liferay-workflow-definition_6_1_0.xsd"),
510 new KeyValuePair(
511 "http:
512 "liferay-workflow-definition_6_2_0.xsd"),
513 new KeyValuePair(
514 "http:
515 "liferay-workflow-definition_7_0_0.xsd"),
516 new KeyValuePair(
517 "http:
518 };
519
520 private static final Log _log = LogFactoryUtil.getLog(EntityResolver.class);
521
522 }