~ubuntu-branches/ubuntu/vivid/tomcat6/vivid

« back to all changes in this revision

Viewing changes to java/org/apache/catalina/startup/TldConfig.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2014-02-17 00:02:00 UTC
  • mfrom: (1.2.10)
  • Revision ID: package-import@ubuntu.com-20140217000200-qs6ki7bhqnfhkas7
Tags: 6.0.39-1
* Team upload.
* New upstream release.
  - Refreshed the patches
* Standards-Version updated to 3.9.5 (no changes)
* Switch to debhelper level 9
* Use XZ compression for the upstream tarball
* Use canonical URL for the Vcs-Git field

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
8
 
 * 
 
8
 *
9
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 
 * 
 
10
 *
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;
54
56
 
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");
124
127
    }
125
128
 
126
129
 
 
130
    /**
 
131
     * The string resources for this package.
 
132
     */
 
133
    private static final StringManager sm =
 
134
        StringManager.getManager(Constants.Package);
 
135
 
 
136
    /**
 
137
     * The <code>Digester</code>s available to process tld files.
 
138
     */
 
139
    private static Digester[] tldDigesters = new Digester[2];
 
140
 
 
141
    /**
 
142
     * Create (if necessary) and return a Digester configured to process the
 
143
     * tld.
 
144
     */
 
145
    private static Digester createTldDigester(boolean validation,
 
146
            boolean blockExternal) {
 
147
 
 
148
        Digester digester = null;
 
149
        if (!validation) {
 
150
            if (tldDigesters[0] == null) {
 
151
                tldDigesters[0] = DigesterFactory.newDigester(validation,
 
152
                        true, new TldRuleSet(), blockExternal);
 
153
                tldDigesters[0].getParser();
 
154
            }
 
155
            digester = tldDigesters[0];
 
156
        } else {
 
157
            if (tldDigesters[1] == null) {
 
158
                tldDigesters[1] = DigesterFactory.newDigester(validation,
 
159
                        true, new TldRuleSet(), blockExternal);
 
160
                tldDigesters[1].getParser();
 
161
            }
 
162
            digester = tldDigesters[1];
 
163
        }
 
164
        return digester;
 
165
    }
 
166
 
 
167
 
127
168
    // ----------------------------------------------------- Instance Variables
128
169
 
129
170
    /**
133
174
 
134
175
 
135
176
    /**
136
 
     * The string resources for this package.
137
 
     */
138
 
    private static final StringManager sm =
139
 
        StringManager.getManager(Constants.Package);
140
 
 
141
 
    /**
142
177
     * The <code>Digester</code> we will use to process tag library
143
178
     * descriptor files.
144
179
     */
145
 
    private static Digester tldDigester = null;
146
 
 
147
 
 
148
 
    /**
149
 
     * Attribute value used to turn on/off TLD validation
150
 
     */
151
 
     private static boolean tldValidation = false;
152
 
 
153
 
 
154
 
    /**
155
 
     * Attribute value used to turn on/off TLD  namespace awarenes.
156
 
     */
157
 
    private static boolean tldNamespaceAware = false;
 
180
    private Digester tldDigester = null;
 
181
 
158
182
 
159
183
    private boolean rescan=true;
160
184
 
165
189
    /**
166
190
     * Sets the list of JARs that are known not to contain any TLDs.
167
191
     *
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
170
194
     */
171
195
    public static void setNoTldJars(String jarNames) {
172
196
        if (jarNames != null) {
179
203
    }
180
204
 
181
205
    /**
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
 
207
     * context.
 
208
     *
 
209
     * @param tldValidation ignore
 
210
     *
 
211
     * @deprecated This option will be removed in 7.0.x.
185
212
     */
 
213
    @Deprecated
186
214
    public void setTldValidation(boolean tldValidation){
187
 
        TldConfig.tldValidation = tldValidation;
 
215
        // NO-OP
188
216
    }
189
217
 
190
218
    /**
191
 
     * Get the server.xml &lt;host&gt; attribute's xmlValidation.
 
219
     * *.tld are parsed using the TLD validation setting of the associated
 
220
     * context.
 
221
     *
192
222
     * @return true if validation is enabled.
193
223
     *
 
224
     * @deprecated This option will be removed in 7.0.x.
194
225
     */
 
226
    @Deprecated
195
227
    public boolean getTldValidation(){
196
 
        return tldValidation;
 
228
        Context context = getContext();
 
229
        if (context == null) {
 
230
            return false;
 
231
        }
 
232
        return context.getTldValidation();
197
233
    }
198
234
 
199
235
    /**
200
 
     * Get the server.xml &lt;host&gt; attribute's xmlNamespaceAware.
201
 
     * @return true if namespace awarenes is enabled.
202
 
     *
 
236
     * *.tld files are always parsed using a namespace aware parser.
 
237
     *
 
238
     * @return Always <code>true</code>
 
239
     *
 
240
     * @deprecated This option will be removed in 7.0.x.
203
241
     */
 
242
    @Deprecated
204
243
    public boolean getTldNamespaceAware(){
205
 
        return tldNamespaceAware;
 
244
        return true;
206
245
    }
207
246
 
208
247
 
209
248
    /**
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.
 
250
     *
 
251
     * @param tldNamespaceAware ignored
 
252
     *
 
253
     * @deprecated This option will be removed in 7.0.x.
213
254
     */
 
255
    @Deprecated
214
256
    public void setTldNamespaceAware(boolean tldNamespaceAware){
215
 
        TldConfig.tldNamespaceAware = tldNamespaceAware;
216
 
    }    
 
257
        // NO-OP
 
258
    }
217
259
 
218
260
 
219
261
    public boolean isRescan() {
362
404
                    log.trace("  Processing TLD at '" + name + "'");
363
405
                }
364
406
                try {
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()),
394
439
     *
395
440
     * @exception Exception if an exception occurs while scanning this TLD
396
441
     */
397
 
    private void tldScanStream(InputSource resourceStream)
 
442
    private XmlErrorHandler tldScanStream(InputSource resourceStream)
398
443
        throws Exception {
399
444
 
 
445
        XmlErrorHandler result = new XmlErrorHandler();
 
446
 
400
447
        synchronized (tldDigester) {
401
448
            try {
 
449
                tldDigester.setErrorHandler(result);
402
450
                tldDigester.push(this);
403
451
                tldDigester.parse(resourceStream);
404
452
            } finally {
405
453
                tldDigester.reset();
406
454
            }
407
455
        }
408
 
 
 
456
        return result;
409
457
    }
410
458
 
411
459
    /**
437
485
                    (sm.getString("contextConfig.tldResourcePath",
438
486
                                  resourcePath));
439
487
            }
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()),
445
494
                  e);
446
 
        } 
 
495
        }
447
496
 
448
497
    }
449
498
 
508
557
     */
509
558
    private void tldScanResourcePathsWebInf(DirContext resources,
510
559
                                            String rootPath,
511
 
                                            Set tldPaths) 
 
560
                                            Set tldPaths)
512
561
            throws IOException {
513
562
 
514
563
        if (log.isTraceEnabled()) {
550
599
     *
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).
556
605
     *
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
577
626
                    // buggy overall
578
 
                    
 
627
 
579
628
                    // Check that the URL is using file protocol, else ignore it
580
629
                    if (!"file".equals(urls[i].getProtocol())) {
581
630
                        continue;
582
631
                    }
583
 
                    
 
632
 
584
633
                    File file = null;
585
634
                    try {
586
635
                        file = new File(urls[i].toURI());
630
679
            log.error(sm.getString("tldConfig.cce", event.getLifecycle()), e);
631
680
            return;
632
681
        }
633
 
        
 
682
 
634
683
        if (event.getType().equals(Lifecycle.INIT_EVENT)) {
635
684
            init();
636
685
        } else if (event.getType().equals(Lifecycle.START_EVENT)) {
644
693
            listeners.clear();
645
694
        }
646
695
    }
647
 
    
 
696
 
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());
654
 
    
 
701
            boolean tldValidation = context.getTldValidation();
 
702
 
655
703
            // (2) if the attribute wasn't defined on the context
656
704
            //     try the host.
657
705
            if (!tldValidation) {
658
 
              setTldValidation(
659
 
                      ((StandardHost) context.getParent()).getXmlValidation());
660
 
            }
661
 
    
662
 
            if (!tldNamespaceAware) {
663
 
              setTldNamespaceAware(
664
 
                      ((StandardHost) context.getParent()).getXmlNamespaceAware());
 
706
                tldValidation =
 
707
                        ((StandardHost) context.getParent()).getXmlValidation();
665
708
            }
666
709
 
667
 
            tldDigester = DigesterFactory.newDigester(tldValidation, 
668
 
                    tldNamespaceAware, 
669
 
                    new TldRuleSet());
670
 
            tldDigester.getParser();
 
710
            tldDigester = createTldDigester(context.getTldValidation(),
 
711
                    context.getXmlBlockExternal());
671
712
        }
672
713
    }
673
714
}