2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.tomcat.util.descriptor;
20
import java.util.Collections;
21
import java.util.HashMap;
24
import javax.servlet.ServletContext;
26
import org.apache.tomcat.util.digester.Digester;
27
import org.apache.tomcat.util.digester.RuleSet;
28
import org.xml.sax.ext.EntityResolver2;
31
* Wrapper class around the Digester that hide Digester's initialization
34
public class DigesterFactory {
37
* Mapping of well-known public IDs used by the Servlet API to the matching
40
public static final Map<String,String> SERVLET_API_PUBLIC_IDS;
43
* Mapping of well-known system IDs used by the Servlet API to the matching
46
public static final Map<String,String> SERVLET_API_SYSTEM_IDS;
49
Map<String, String> publicIds = new HashMap<String, String>();
50
Map<String, String> systemIds = new HashMap<String, String>();
53
publicIds.put(XmlIdentifiers.XSD_10_PUBLIC, idFor("XMLSchema.dtd"));
54
publicIds.put(XmlIdentifiers.DATATYPES_PUBLIC, idFor("datatypes.dtd"));
55
systemIds.put(XmlIdentifiers.XML_2001_XSD, idFor("xml.xsd"));
58
publicIds.put(XmlIdentifiers.WEB_22_PUBLIC, idFor("web-app_2_2.dtd"));
59
publicIds.put(XmlIdentifiers.TLD_11_PUBLIC, idFor("web-jsptaglibrary_1_1.dtd"));
62
publicIds.put(XmlIdentifiers.WEB_23_PUBLIC, idFor("web-app_2_3.dtd"));
63
publicIds.put(XmlIdentifiers.TLD_12_PUBLIC, idFor("web-jsptaglibrary_1_2.dtd"));
66
systemIds.put("http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd",
67
idFor("j2ee_web_services_1_1.xsd"));
68
systemIds.put("http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd",
69
idFor("j2ee_web_services_client_1_1.xsd"));
70
systemIds.put(XmlIdentifiers.WEB_24_XSD, idFor("web-app_2_4.xsd"));
71
systemIds.put(XmlIdentifiers.TLD_20_XSD, idFor("web-jsptaglibrary_2_0.xsd"));
72
addSelf(systemIds, "j2ee_1_4.xsd");
73
addSelf(systemIds, "jsp_2_0.xsd");
76
systemIds.put(XmlIdentifiers.WEB_25_XSD, idFor("web-app_2_5.xsd"));
77
systemIds.put(XmlIdentifiers.TLD_21_XSD, idFor("web-jsptaglibrary_2_1.xsd"));
78
addSelf(systemIds, "javaee_5.xsd");
79
addSelf(systemIds, "jsp_2_1.xsd");
80
addSelf(systemIds, "javaee_web_services_1_2.xsd");
81
addSelf(systemIds, "javaee_web_services_client_1_2.xsd");
83
SERVLET_API_PUBLIC_IDS = Collections.unmodifiableMap(publicIds);
84
SERVLET_API_SYSTEM_IDS = Collections.unmodifiableMap(systemIds);
87
private static void addSelf(Map<String, String> ids, String id) {
88
String systemId = idFor(id);
89
ids.put(systemId, systemId);
90
ids.put(id, systemId);
93
private static String idFor(String url) {
94
URL id = ServletContext.class.getResource("resources/" + url);
96
id = ServletContext.class.getResource("jsp/resources/" + url);
98
return id.toExternalForm();
103
* Create a <code>Digester</code> parser.
104
* @param xmlValidation turn on/off xml validation
105
* @param xmlNamespaceAware turn on/off namespace validation
106
* @param rule an instance of <code>RuleSet</code> used for parsing the xml.
107
* @param blockExternal turn on/off the blocking of external resources
109
public static Digester newDigester(boolean xmlValidation,
110
boolean xmlNamespaceAware,
112
boolean blockExternal) {
113
Digester digester = new Digester();
114
digester.setNamespaceAware(xmlNamespaceAware);
115
digester.setValidating(xmlValidation);
116
digester.setUseContextClassLoader(true);
117
EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS,
118
SERVLET_API_SYSTEM_IDS, blockExternal);
119
digester.setEntityResolver(resolver);
121
digester.addRuleSet(rule);