1
22
23 package com.liferay.portal.util;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.util.KeyValuePair;
28
29 import java.io.InputStream;
30
31 import org.xml.sax.InputSource;
32
33
38 public class EntityResolver implements org.xml.sax.EntityResolver {
39
40 public InputSource resolveEntity(String publicId, String systemId) {
41 ClassLoader classLoader = getClass().getClassLoader();
42
43 if (_log.isDebugEnabled()) {
44 _log.debug("Resolving entity " + publicId + " " + systemId);
45 }
46
47 if (publicId != null) {
48 for (int i = 0; i < _PUBLIC_IDS.length; i++) {
49 KeyValuePair kvp = _PUBLIC_IDS[i];
50
51 if (publicId.equals(kvp.getKey())) {
52 InputStream is = classLoader.getResourceAsStream(
53 _DEFINITIONS_PATH + kvp.getValue());
54
55 if (_log.isDebugEnabled()) {
56 _log.debug("Entity found for public id " + systemId);
57 }
58
59 return new InputSource(is);
60 }
61 }
62 }
63 else if (systemId != null) {
64 for (int i = 0; i < _SYSTEM_IDS.length; i++) {
65 KeyValuePair kvp = _SYSTEM_IDS[i];
66
67 if (systemId.equals(kvp.getKey())) {
68 InputStream is = classLoader.getResourceAsStream(
69 _DEFINITIONS_PATH + kvp.getValue());
70
71 if (_log.isDebugEnabled()) {
72 _log.debug("Entity found for system id " + systemId);
73 }
74
75 return new InputSource(is);
76 }
77 }
78 }
79
80 if (_log.isDebugEnabled()) {
81 _log.debug("No entity found for " + publicId + " " + systemId);
82 }
83
84 return null;
85 }
86
87 private static String _DEFINITIONS_PATH = "com/liferay/portal/definitions/";
88
89 private static KeyValuePair[] _PUBLIC_IDS = {
90 new KeyValuePair(
91 "datatypes",
92 "datatypes.dtd"
93 ),
94
95 new KeyValuePair(
96 "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN",
97 "facelet-taglib_1_0.dtd"
98 ),
99
100 new KeyValuePair(
101 "-//Hibernate/Hibernate Mapping DTD 3.0//EN",
102 "hibernate-mapping-3.0.dtd"
103 ),
104
105 new KeyValuePair(
106 "-//Liferay//DTD Display 2.0.0//EN",
107 "liferay-display_2_0_0.dtd"
108 ),
109
110 new KeyValuePair(
111 "-//Liferay//DTD Display 3.5.0//EN",
112 "liferay-display_3_5_0.dtd"
113 ),
114
115 new KeyValuePair(
116 "-//Liferay//DTD Display 4.0.0//EN",
117 "liferay-display_4_0_0.dtd"
118 ),
119
120 new KeyValuePair(
121 "-//Liferay//DTD Display 5.0.0//EN",
122 "liferay-display_5_0_0.dtd"
123 ),
124
125 new KeyValuePair(
126 "-//Liferay//DTD Display 5.1.0//EN",
127 "liferay-display_5_1_0.dtd"
128 ),
129
130 new KeyValuePair(
131 "-//Liferay//DTD Hook 5.1.0//EN",
132 "liferay-hook_5_1_0.dtd"
133 ),
134
135 new KeyValuePair(
136 "-//Liferay//DTD Layout Templates 3.6.0//EN",
137 "liferay-layout-templates_3_6_0.dtd"
138 ),
139
140 new KeyValuePair(
141 "-//Liferay//DTD Layout Templates 4.0.0//EN",
142 "liferay-layout-templates_4_0_0.dtd"
143 ),
144
145 new KeyValuePair(
146 "-//Liferay//DTD Layout Templates 4.3.0//EN",
147 "liferay-layout-templates_4_3_0.dtd"
148 ),
149
150 new KeyValuePair(
151 "-//Liferay//DTD Layout Templates 5.0.0//EN",
152 "liferay-layout-templates_5_0_0.dtd"
153 ),
154
155 new KeyValuePair(
156 "-//Liferay//DTD Layout Templates 5.1.0//EN",
157 "liferay-layout-templates_5_1_0.dtd"
158 ),
159
160 new KeyValuePair(
161 "-//Liferay//DTD Look and Feel 3.5.0//EN",
162 "liferay-look-and-feel_3_5_0.dtd"
163 ),
164
165 new KeyValuePair(
166 "-//Liferay//DTD Look and Feel 4.0.0//EN",
167 "liferay-look-and-feel_4_0_0.dtd"
168 ),
169
170 new KeyValuePair(
171 "-//Liferay//DTD Look and Feel 4.3.0//EN",
172 "liferay-look-and-feel_4_3_0.dtd"
173 ),
174
175 new KeyValuePair(
176 "-//Liferay//DTD Look and Feel 5.0.0//EN",
177 "liferay-look-and-feel_5_0_0.dtd"
178 ),
179
180 new KeyValuePair(
181 "-//Liferay//DTD Look and Feel 5.1.0//EN",
182 "liferay-look-and-feel_5_1_0.dtd"
183 ),
184
185 new KeyValuePair(
186 "-//Liferay//DTD Plugin Package 4.3.0//EN",
187 "liferay-plugin-package_4_3_0.dtd"
188 ),
189
190 new KeyValuePair(
191 "-//Liferay//DTD Plugin Package 5.0.0//EN",
192 "liferay-plugin-package_5_0_0.dtd"
193 ),
194
195 new KeyValuePair(
196 "-//Liferay//DTD Plugin Package 5.1.0//EN",
197 "liferay-plugin-package_5_1_0.dtd"
198 ),
199
200 new KeyValuePair(
201 "-//Liferay//DTD Plugin Repository 4.3.0//EN",
202 "liferay-plugin-repository_4_3_0.dtd"
203 ),
204
205 new KeyValuePair(
206 "-//Liferay//DTD Plugin Repository 5.0.0//EN",
207 "liferay-plugin-repository_5_0_0.dtd"
208 ),
209
210 new KeyValuePair(
211 "-//Liferay//DTD Plugin Repository 5.1.0//EN",
212 "liferay-plugin-repository_5_1_0.dtd"
213 ),
214
215 new KeyValuePair(
216 "-//Liferay//DTD Portlet Application 3.5.0//EN",
217 "liferay-portlet-app_3_5_0.dtd"
218 ),
219
220 new KeyValuePair(
221 "-//Liferay//DTD Portlet Application 4.0.0//EN",
222 "liferay-portlet-app_4_0_0.dtd"
223 ),
224
225 new KeyValuePair(
226 "-//Liferay//DTD Portlet Application 4.1.0//EN",
227 "liferay-portlet-app_4_1_0.dtd"
228 ),
229
230 new KeyValuePair(
231 "-//Liferay//DTD Portlet Application 4.2.0//EN",
232 "liferay-portlet-app_4_2_0.dtd"
233 ),
234
235 new KeyValuePair(
236 "-//Liferay//DTD Portlet Application 4.3.0//EN",
237 "liferay-portlet-app_4_3_0.dtd"
238 ),
239
240 new KeyValuePair(
241 "-//Liferay//DTD Portlet Application 4.3.1//EN",
242 "liferay-portlet-app_4_3_1.dtd"
243 ),
244
245 new KeyValuePair(
246 "-//Liferay//DTD Portlet Application 4.3.2//EN",
247 "liferay-portlet-app_4_3_2.dtd"
248 ),
249
250 new KeyValuePair(
251 "-//Liferay//DTD Portlet Application 4.3.3//EN",
252 "liferay-portlet-app_4_3_3.dtd"
253 ),
254
255 new KeyValuePair(
256 "-//Liferay//DTD Portlet Application 4.3.6//EN",
257 "liferay-portlet-app_4_3_6.dtd"
258 ),
259
260 new KeyValuePair(
261 "-//Liferay//DTD Portlet Application 4.4.0//EN",
262 "liferay-portlet-app_4_4_0.dtd"
263 ),
264
265 new KeyValuePair(
266 "-//Liferay//DTD Portlet Application 5.0.0//EN",
267 "liferay-portlet-app_5_0_0.dtd"
268 ),
269
270 new KeyValuePair(
271 "-//Liferay//DTD Portlet Application 5.1.0//EN",
272 "liferay-portlet-app_5_1_0.dtd"
273 ),
274
275 new KeyValuePair(
276 "-//Liferay//DTD Service Builder 3.5.0//EN",
277 "liferay-service-builder_3_5_0.dtd"
278 ),
279
280 new KeyValuePair(
281 "-//Liferay//DTD Service Builder 3.6.1//EN",
282 "liferay-service-builder_3_6_1.dtd"
283 ),
284
285 new KeyValuePair(
286 "-//Liferay//DTD Service Builder 4.0.0//EN",
287 "liferay-service-builder_4_0_0.dtd"
288 ),
289
290 new KeyValuePair(
291 "-//Liferay//DTD Service Builder 4.2.0//EN",
292 "liferay-service-builder_4_2_0.dtd"
293 ),
294
295 new KeyValuePair(
296 "-//Liferay//DTD Service Builder 4.3.0//EN",
297 "liferay-service-builder_4_3_0.dtd"
298 ),
299
300 new KeyValuePair(
301 "-//Liferay//DTD Service Builder 4.3.3//EN",
302 "liferay-service-builder_4_3_3.dtd"
303 ),
304
305 new KeyValuePair(
306 "-//Liferay//DTD Service Builder 4.4.0//EN",
307 "liferay-service-builder_4_4_0.dtd"
308 ),
309
310 new KeyValuePair(
311 "-//Liferay//DTD Service Builder 5.0.0//EN",
312 "liferay-service-builder_5_0_0.dtd"
313 ),
314
315 new KeyValuePair(
316 "-//Liferay//DTD Service Builder 5.1.0//EN",
317 "liferay-service-builder_5_1_0.dtd"
318 ),
319
320 new KeyValuePair(
321 "-//Liferay//DTD Theme Loader 4.3.0//EN",
322 "liferay-theme-loader_4_3_0.dtd"
323 ),
324
325 new KeyValuePair(
326 "-//Liferay//DTD Theme Loader 5.0.0//EN",
327 "liferay-theme-loader_5_0_0.dtd"
328 ),
329
330 new KeyValuePair(
331 "-//Liferay//DTD Theme Loader 5.1.0//EN",
332 "liferay-theme-loader_5_1_0.dtd"
333 ),
334
335 new KeyValuePair(
336 "-//MuleSource //DTD mule-configuration XML V1.0//EN",
337 "mule-configuration.dtd"
338 ),
339
340 new KeyValuePair(
341 "-//SPRING//DTD BEAN//EN",
342 "spring-beans.dtd"
343 ),
344
345 new KeyValuePair(
346 "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN",
347 "struts-config_1_2.dtd"
348 ),
349
350 new KeyValuePair(
351 "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN",
352 "tiles-config_1_1.dtd"
353 ),
354
355 new KeyValuePair(
356 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
357 "web-app_2_3.dtd"
358 ),
359
360 new KeyValuePair(
361 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN",
362 "web-facesconfig_1_0.dtd"
363 ),
364
365 new KeyValuePair(
366 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
367 "web-facesconfig_1_1.dtd"
368 ),
369
370 new KeyValuePair(
371 "-//W3C//DTD XMLSCHEMA 200102//EN",
372 "XMLSchema.dtd"
373 )
374 };
375
376 private static KeyValuePair[] _SYSTEM_IDS = {
377 new KeyValuePair(
378 "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd",
379 "portlet-app_1_0.xsd"
380 ),
381
382 new KeyValuePair(
383 "http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd",
384 "portlet-app_2_0.xsd"
385 ),
386
387 new KeyValuePair(
388 "http://www.w3.org/2001/xml.xsd",
389 "xml.xsd"
390 )
391 };
392
393 private static Log _log = LogFactoryUtil.getLog(EntityResolver.class);
394
395 }