001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.util;
022:
023: import com.liferay.portal.kernel.util.KeyValuePair;
024:
025: import java.io.InputStream;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: import org.xml.sax.InputSource;
031:
032: /**
033: * <a href="EntityResolver.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Brian Wing Shun Chan
036: *
037: */
038: public class EntityResolver implements org.xml.sax.EntityResolver {
039:
040: public InputSource resolveEntity(String publicId, String systemId) {
041: ClassLoader classLoader = getClass().getClassLoader();
042:
043: if (_log.isInfoEnabled()) {
044: _log.info("Resolving entity " + publicId + " " + systemId);
045: }
046:
047: if (publicId != null) {
048: for (int i = 0; i < _PUBLIC_IDS.length; i++) {
049: KeyValuePair kvp = _PUBLIC_IDS[i];
050:
051: if (publicId.equals(kvp.getKey())) {
052: InputStream is = classLoader
053: .getResourceAsStream(_DEFINITIONS_PATH
054: + kvp.getValue());
055:
056: if (_log.isInfoEnabled()) {
057: _log.info("Entity found for public id "
058: + systemId);
059: }
060:
061: return new InputSource(is);
062: }
063: }
064: } else if (systemId != null) {
065: for (int i = 0; i < _SYSTEM_IDS.length; i++) {
066: KeyValuePair kvp = _SYSTEM_IDS[i];
067:
068: if (systemId.equals(kvp.getKey())) {
069: InputStream is = classLoader
070: .getResourceAsStream(_DEFINITIONS_PATH
071: + kvp.getValue());
072:
073: if (_log.isInfoEnabled()) {
074: _log.info("Entity found for system id "
075: + systemId);
076: }
077:
078: return new InputSource(is);
079: }
080: }
081: }
082:
083: if (_log.isInfoEnabled()) {
084: _log.info("No entity found for " + publicId + " "
085: + systemId);
086: }
087:
088: return null;
089: }
090:
091: private static String _DEFINITIONS_PATH = "com/liferay/portal/definitions/";
092:
093: private static KeyValuePair[] _PUBLIC_IDS = {
094: new KeyValuePair("datatypes", "datatypes.dtd"),
095:
096: new KeyValuePair(
097: "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN",
098: "facelet-taglib_1_0.dtd"),
099:
100: new KeyValuePair("-//Liferay//DTD Display 2.0.0//EN",
101: "liferay-display_2_0_0.dtd"),
102:
103: new KeyValuePair("-//Liferay//DTD Display 3.5.0//EN",
104: "liferay-display_3_5_0.dtd"),
105:
106: new KeyValuePair("-//Liferay//DTD Display 4.0.0//EN",
107: "liferay-display_4_0_0.dtd"),
108:
109: new KeyValuePair(
110: "-//Liferay//DTD Layout Templates 3.6.0//EN",
111: "liferay-layout-templates_3_6_0.dtd"),
112:
113: new KeyValuePair(
114: "-//Liferay//DTD Layout Templates 4.0.0//EN",
115: "liferay-layout-templates_4_0_0.dtd"),
116:
117: new KeyValuePair(
118: "-//Liferay//DTD Layout Templates 4.3.0//EN",
119: "liferay-layout-templates_4_3_0.dtd"),
120:
121: new KeyValuePair("-//Liferay//DTD Look and Feel 3.5.0//EN",
122: "liferay-look-and-feel_3_5_0.dtd"),
123:
124: new KeyValuePair("-//Liferay//DTD Look and Feel 4.0.0//EN",
125: "liferay-look-and-feel_4_0_0.dtd"),
126:
127: new KeyValuePair("-//Liferay//DTD Look and Feel 4.3.0//EN",
128: "liferay-look-and-feel_4_3_0.dtd"),
129:
130: new KeyValuePair(
131: "-//Liferay//DTD Plugin Package 4.3.0//EN",
132: "liferay-plugin-package_4_3_0.dtd"),
133:
134: new KeyValuePair(
135: "-//Liferay//DTD Plugin Repository 4.3.0//EN",
136: "liferay-plugin-repository_4_3_0.dtd"),
137:
138: new KeyValuePair(
139: "-//Liferay//DTD Portlet Application 3.5.0//EN",
140: "liferay-portlet-app_3_5_0.dtd"),
141:
142: new KeyValuePair(
143: "-//Liferay//DTD Portlet Application 4.0.0//EN",
144: "liferay-portlet-app_4_0_0.dtd"),
145:
146: new KeyValuePair(
147: "-//Liferay//DTD Portlet Application 4.1.0//EN",
148: "liferay-portlet-app_4_1_0.dtd"),
149:
150: new KeyValuePair(
151: "-//Liferay//DTD Portlet Application 4.2.0//EN",
152: "liferay-portlet-app_4_2_0.dtd"),
153:
154: new KeyValuePair(
155: "-//Liferay//DTD Portlet Application 4.3.0//EN",
156: "liferay-portlet-app_4_3_0.dtd"),
157:
158: new KeyValuePair(
159: "-//Liferay//DTD Portlet Application 4.3.1//EN",
160: "liferay-portlet-app_4_3_1.dtd"),
161:
162: new KeyValuePair(
163: "-//Liferay//DTD Portlet Application 4.3.2//EN",
164: "liferay-portlet-app_4_3_2.dtd"),
165:
166: new KeyValuePair(
167: "-//Liferay//DTD Portlet Application 4.3.3//EN",
168: "liferay-portlet-app_4_3_3.dtd"),
169:
170: new KeyValuePair(
171: "-//Liferay//DTD Portlet Application 4.3.6//EN",
172: "liferay-portlet-app_4_3_6.dtd"),
173:
174: new KeyValuePair(
175: "-//Liferay//DTD Portlet Application 4.4.0//EN",
176: "liferay-portlet-app_4_4_0.dtd"),
177:
178: new KeyValuePair(
179: "-//Liferay//DTD Service Builder 3.5.0//EN",
180: "liferay-service-builder_3_5_0.dtd"),
181:
182: new KeyValuePair(
183: "-//Liferay//DTD Service Builder 3.6.1//EN",
184: "liferay-service-builder_3_6_1.dtd"),
185:
186: new KeyValuePair(
187: "-//Liferay//DTD Service Builder 4.0.0//EN",
188: "liferay-service-builder_4_0_0.dtd"),
189:
190: new KeyValuePair(
191: "-//Liferay//DTD Service Builder 4.2.0//EN",
192: "liferay-service-builder_4_2_0.dtd"),
193:
194: new KeyValuePair(
195: "-//Liferay//DTD Service Builder 4.3.0//EN",
196: "liferay-service-builder_4_3_0.dtd"),
197:
198: new KeyValuePair(
199: "-//Liferay//DTD Service Builder 4.3.3//EN",
200: "liferay-service-builder_4_3_3.dtd"),
201:
202: new KeyValuePair(
203: "-//Liferay//DTD Service Builder 4.4.0//EN",
204: "liferay-service-builder_4_4_0.dtd"),
205:
206: new KeyValuePair("-//Liferay//DTD Theme Loader 4.3.0//EN",
207: "liferay-theme-loader_4_3_0.dtd"),
208:
209: new KeyValuePair(
210: "-//MuleSource //DTD mule-configuration XML V1.0//EN",
211: "mule-configuration.dtd"),
212:
213: new KeyValuePair("-//SPRING//DTD BEAN//EN",
214: "spring-beans.dtd"),
215:
216: new KeyValuePair(
217: "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN",
218: "struts-config_1_2.dtd"),
219:
220: new KeyValuePair(
221: "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN",
222: "tiles-config_1_1.dtd"),
223:
224: new KeyValuePair(
225: "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
226: "web-app_2_3.dtd"),
227:
228: new KeyValuePair(
229: "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN",
230: "web-facesconfig_1_0.dtd"),
231:
232: new KeyValuePair(
233: "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN",
234: "web-facesconfig_1_1.dtd"),
235:
236: new KeyValuePair("-//W3C//DTD XMLSCHEMA 200102//EN",
237: "XMLSchema.dtd") };
238:
239: private static KeyValuePair[] _SYSTEM_IDS = {
240: new KeyValuePair(
241: "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd",
242: "portlet-app_1_0.xsd"),
243:
244: new KeyValuePair("http://www.w3.org/2001/xml.xsd",
245: "xml.xsd") };
246:
247: private static Log _log = LogFactory.getLog(EntityResolver.class);
248:
249: }
|