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