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