5
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
6
* (the "License"); you may not use this file except in compliance with
7
7
* the License. You may obtain a copy of the License at
9
9
* http://www.apache.org/licenses/LICENSE-2.0
11
11
* Unless required by applicable law or agreed to in writing, software
12
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
49
import org.apache.catalina.core.StandardContext;
50
50
import org.apache.catalina.core.StandardHost;
51
51
import org.apache.catalina.util.StringManager;
52
import org.apache.tomcat.util.descriptor.DigesterFactory;
53
import org.apache.tomcat.util.descriptor.XmlErrorHandler;
52
54
import org.apache.tomcat.util.digester.Digester;
53
55
import org.xml.sax.InputSource;
91
93
noTldJars.add("ecj-3.7.2.jar");
92
94
noTldJars.add("ecj-4.2.1.jar");
93
95
noTldJars.add("ecj-4.2.2.jar");
96
noTldJars.add("ecj-4.3.1.jar");
94
97
noTldJars.add("jsp-api.jar");
95
98
noTldJars.add("servlet-api.jar");
96
99
noTldJars.add("tomcat-coyote.jar");
131
* The string resources for this package.
133
private static final StringManager sm =
134
StringManager.getManager(Constants.Package);
137
* The <code>Digester</code>s available to process tld files.
139
private static Digester[] tldDigesters = new Digester[2];
142
* Create (if necessary) and return a Digester configured to process the
145
private static Digester createTldDigester(boolean validation,
146
boolean blockExternal) {
148
Digester digester = null;
150
if (tldDigesters[0] == null) {
151
tldDigesters[0] = DigesterFactory.newDigester(validation,
152
true, new TldRuleSet(), blockExternal);
153
tldDigesters[0].getParser();
155
digester = tldDigesters[0];
157
if (tldDigesters[1] == null) {
158
tldDigesters[1] = DigesterFactory.newDigester(validation,
159
true, new TldRuleSet(), blockExternal);
160
tldDigesters[1].getParser();
162
digester = tldDigesters[1];
127
168
// ----------------------------------------------------- Instance Variables
136
* The string resources for this package.
138
private static final StringManager sm =
139
StringManager.getManager(Constants.Package);
142
177
* The <code>Digester</code> we will use to process tag library
143
178
* descriptor files.
145
private static Digester tldDigester = null;
149
* Attribute value used to turn on/off TLD validation
151
private static boolean tldValidation = false;
155
* Attribute value used to turn on/off TLD namespace awarenes.
157
private static boolean tldNamespaceAware = false;
180
private Digester tldDigester = null;
159
183
private boolean rescan=true;
166
190
* Sets the list of JARs that are known not to contain any TLDs.
168
* @param jarNames List of comma-separated names of JAR files that are
169
* known not to contain any TLDs
192
* @param jarNames List of comma-separated names of JAR files that are
193
* known not to contain any TLDs
171
195
public static void setNoTldJars(String jarNames) {
172
196
if (jarNames != null) {
182
* Set the validation feature of the XML parser used when
183
* parsing xml instances.
184
* @param tldValidation true to enable xml instance validation
206
* *.tld are parsed using the TLD validation setting of the associated
209
* @param tldValidation ignore
211
* @deprecated This option will be removed in 7.0.x.
186
214
public void setTldValidation(boolean tldValidation){
187
TldConfig.tldValidation = tldValidation;
191
* Get the server.xml <host> attribute's xmlValidation.
219
* *.tld are parsed using the TLD validation setting of the associated
192
222
* @return true if validation is enabled.
224
* @deprecated This option will be removed in 7.0.x.
195
227
public boolean getTldValidation(){
196
return tldValidation;
228
Context context = getContext();
229
if (context == null) {
232
return context.getTldValidation();
200
* Get the server.xml <host> attribute's xmlNamespaceAware.
201
* @return true if namespace awarenes is enabled.
236
* *.tld files are always parsed using a namespace aware parser.
238
* @return Always <code>true</code>
240
* @deprecated This option will be removed in 7.0.x.
204
243
public boolean getTldNamespaceAware(){
205
return tldNamespaceAware;
210
* Set the namespace aware feature of the XML parser used when
211
* parsing xml instances.
212
* @param tldNamespaceAware true to enable namespace awareness
249
* *.tld files are always parsed using a namespace aware parser.
251
* @param tldNamespaceAware ignored
253
* @deprecated This option will be removed in 7.0.x.
214
256
public void setTldNamespaceAware(boolean tldNamespaceAware){
215
TldConfig.tldNamespaceAware = tldNamespaceAware;
219
261
public boolean isRescan() {
362
404
log.trace(" Processing TLD at '" + name + "'");
365
tldScanStream(new InputSource(jarFile.getInputStream(entry)));
407
XmlErrorHandler handler = tldScanStream(
408
new InputSource(jarFile.getInputStream(entry)));
409
handler.logFindings(log, "[" + name + "] in [" +
410
file.getAbsolutePath() + "]");
366
411
} catch (Exception e) {
367
412
log.error(sm.getString("contextConfig.tldEntryException",
368
413
name, jarPath, context.getPath()),
395
440
* @exception Exception if an exception occurs while scanning this TLD
397
private void tldScanStream(InputSource resourceStream)
442
private XmlErrorHandler tldScanStream(InputSource resourceStream)
398
443
throws Exception {
445
XmlErrorHandler result = new XmlErrorHandler();
400
447
synchronized (tldDigester) {
449
tldDigester.setErrorHandler(result);
402
450
tldDigester.push(this);
403
451
tldDigester.parse(resourceStream);
405
453
tldDigester.reset();
437
485
(sm.getString("contextConfig.tldResourcePath",
440
tldScanStream(inputSource);
488
XmlErrorHandler handler = tldScanStream(inputSource);
489
handler.logFindings(log, resourcePath);
441
490
} catch (Exception e) {
442
491
throw new ServletException
443
492
(sm.getString("contextConfig.tldFileException", resourcePath,
444
493
context.getPath()),
551
600
* The latter constitutes a Tomcat-specific extension to the TLD search
552
601
* order defined in the JSP spec. It allows tag libraries packaged as JAR
553
* files to be shared by web applications by simply dropping them in a
602
* files to be shared by web applications by simply dropping them in a
554
603
* location that all web applications have access to (e.g.,
555
604
* <CATALINA_HOME>/common/lib).
575
624
// This is definitely not as clean as using JAR URLs either
576
625
// over file or the custom jndi handler, but a lot less
579
628
// Check that the URL is using file protocol, else ignore it
580
629
if (!"file".equals(urls[i].getProtocol())) {
584
633
File file = null;
586
635
file = new File(urls[i].toURI());
644
693
listeners.clear();
648
697
private void init() {
649
698
if (tldDigester == null){
650
699
// (1) check if the attribute has been defined
651
700
// on the context element.
652
setTldValidation(context.getTldValidation());
653
setTldNamespaceAware(context.getTldNamespaceAware());
701
boolean tldValidation = context.getTldValidation();
655
703
// (2) if the attribute wasn't defined on the context
657
705
if (!tldValidation) {
659
((StandardHost) context.getParent()).getXmlValidation());
662
if (!tldNamespaceAware) {
663
setTldNamespaceAware(
664
((StandardHost) context.getParent()).getXmlNamespaceAware());
707
((StandardHost) context.getParent()).getXmlValidation();
667
tldDigester = DigesterFactory.newDigester(tldValidation,
670
tldDigester.getParser();
710
tldDigester = createTldDigester(context.getTldValidation(),
711
context.getXmlBlockExternal());