View | Details | Raw Unified | Return to bug 48689
Collapse All | Expand All

(-)java/org/apache/jasper/JspCompilationContext.java (-18 / +20 lines)
Lines 30-39 Link Here
30
import javax.servlet.jsp.tagext.TagInfo;
30
import javax.servlet.jsp.tagext.TagInfo;
31
31
32
import org.apache.jasper.compiler.Compiler;
32
import org.apache.jasper.compiler.Compiler;
33
import org.apache.jasper.compiler.JarResource;
33
import org.apache.jasper.compiler.JspRuntimeContext;
34
import org.apache.jasper.compiler.JspRuntimeContext;
34
import org.apache.jasper.compiler.JspUtil;
35
import org.apache.jasper.compiler.JspUtil;
35
import org.apache.jasper.compiler.Localizer;
36
import org.apache.jasper.compiler.Localizer;
36
import org.apache.jasper.compiler.ServletWriter;
37
import org.apache.jasper.compiler.ServletWriter;
38
import org.apache.jasper.compiler.TldLocation;
37
import org.apache.jasper.servlet.JasperLoader;
39
import org.apache.jasper.servlet.JasperLoader;
38
import org.apache.jasper.servlet.JspServletWrapper;
40
import org.apache.jasper.servlet.JspServletWrapper;
39
import org.apache.juli.logging.Log;
41
import org.apache.juli.logging.Log;
Lines 57-63 Link Here
57
59
58
    private final Log log = LogFactory.getLog(JspCompilationContext.class); // must not be static
60
    private final Log log = LogFactory.getLog(JspCompilationContext.class); // must not be static
59
61
60
    protected Map<String, URL> tagFileJarUrls;
62
    protected Map<String, JarResource> tagFileJarUrls;
61
    protected boolean isPackagedTagFile;
63
    protected boolean isPackagedTagFile;
62
64
63
    protected String className;
65
    protected String className;
Lines 91-97 Link Here
91
    protected boolean isTagFile;
93
    protected boolean isTagFile;
92
    protected boolean protoTypeMode;
94
    protected boolean protoTypeMode;
93
    protected TagInfo tagInfo;
95
    protected TagInfo tagInfo;
94
    protected URL tagFileJarUrl;
96
    protected JarResource tagJarResource;
95
97
96
    // jspURI _must_ be relative to the context
98
    // jspURI _must_ be relative to the context
97
    public JspCompilationContext(String jspUri,
99
    public JspCompilationContext(String jspUri,
Lines 121-127 Link Here
121
        }
123
        }
122
124
123
        this.rctxt = rctxt;
125
        this.rctxt = rctxt;
124
        this.tagFileJarUrls = new HashMap<String, URL>();
126
        this.tagFileJarUrls = new HashMap<String, JarResource>();
125
        this.basePackageName = Constants.JSP_PACKAGE_NAME;
127
        this.basePackageName = Constants.JSP_PACKAGE_NAME;
126
    }
128
    }
127
129
Lines 131-142 Link Here
131
                                 ServletContext context,
133
                                 ServletContext context,
132
                                 JspServletWrapper jsw,
134
                                 JspServletWrapper jsw,
133
                                 JspRuntimeContext rctxt,
135
                                 JspRuntimeContext rctxt,
134
                                 URL tagFileJarUrl) {
136
                                 JarResource tagJarResource) {
135
        this(tagfile, false, options, context, jsw, rctxt);
137
        this(tagfile, false, options, context, jsw, rctxt);
136
        this.isTagFile = true;
138
        this.isTagFile = true;
137
        this.tagInfo = tagInfo;
139
        this.tagInfo = tagInfo;
138
        this.tagFileJarUrl = tagFileJarUrl;
140
        this.tagJarResource = tagJarResource;
139
        if (tagFileJarUrl != null) {
141
        if (tagJarResource != null) {
140
            isPackagedTagFile = true;
142
            isPackagedTagFile = true;
141
        }
143
        }
142
    }
144
    }
Lines 288-299 Link Here
288
290
289
        if (res.startsWith("/META-INF/")) {
291
        if (res.startsWith("/META-INF/")) {
290
            // This is a tag file packaged in a jar that is being compiled
292
            // This is a tag file packaged in a jar that is being compiled
291
            URL jarUrl = tagFileJarUrls.get(res);
293
            JarResource jarResource = tagFileJarUrls.get(res);
292
            if (jarUrl == null) {
294
            if (jarResource == null) {
293
                jarUrl = tagFileJarUrl;
295
                jarResource = tagJarResource;
294
            }
296
            }
295
            if (jarUrl != null) {
297
            if (jarResource != null) {
296
                result = new URL(jarUrl.toExternalForm() + res.substring(1));
298
                result = jarResource.getEntry(res.substring(1));
297
            }
299
            }
298
        } else if (res.startsWith("jar:file:")) {
300
        } else if (res.startsWith("jar:file:")) {
299
                // This is a tag file packaged in a jar that is being checked
301
                // This is a tag file packaged in a jar that is being checked
Lines 330-341 Link Here
330
     * The map is populated when parsing the tag-file elements of the TLDs
332
     * The map is populated when parsing the tag-file elements of the TLDs
331
     * of any imported taglibs. 
333
     * of any imported taglibs. 
332
     */
334
     */
333
    public URL getTagFileJarUrl(String tagFile) {
335
    public JarResource getTagFileJarResource(String tagFile) {
334
        return this.tagFileJarUrls.get(tagFile);
336
        return this.tagFileJarUrls.get(tagFile);
335
    }
337
    }
336
338
337
    public void setTagFileJarUrl(String tagFile, URL tagFileURL) {
339
    public void setTagFileJarResource(String tagFile, JarResource jarResource) {
338
        this.tagFileJarUrls.put(tagFile, tagFileURL);
340
        this.tagFileJarUrls.put(tagFile, jarResource);
339
    }
341
    }
340
342
341
    /**
343
    /**
Lines 344-351 Link Here
344
     * JspCompilationContext does not correspond to a tag file, or if the
346
     * JspCompilationContext does not correspond to a tag file, or if the
345
     * corresponding tag file is not packaged in a JAR.
347
     * corresponding tag file is not packaged in a JAR.
346
     */
348
     */
347
    public URL getTagFileJarUrl() {
349
    public JarResource getTagFileJarResource() {
348
        return this.tagFileJarUrl;
350
        return this.tagJarResource;
349
    }
351
    }
350
352
351
    /* ==================== Common implementation ==================== */
353
    /* ==================== Common implementation ==================== */
Lines 546-553 Link Here
546
     * Returns null if the given uri is not associated with any tag library
548
     * Returns null if the given uri is not associated with any tag library
547
     * 'exposed' in the web application.
549
     * 'exposed' in the web application.
548
     */
550
     */
549
    public String[] getTldLocation(String uri) throws JasperException {
551
    public TldLocation getTldLocation(String uri) throws JasperException {
550
        String[] location = 
552
        TldLocation location = 
551
            getOptions().getTldLocationsCache().getLocation(uri);
553
            getOptions().getTldLocationsCache().getLocation(uri);
552
        return location;
554
        return location;
553
    }
555
    }
(-)java/org/apache/jasper/servlet/JspServletWrapper.java (-2 / +3 lines)
Lines 35-40 Link Here
35
import org.apache.jasper.JspCompilationContext;
35
import org.apache.jasper.JspCompilationContext;
36
import org.apache.jasper.Options;
36
import org.apache.jasper.Options;
37
import org.apache.jasper.compiler.ErrorDispatcher;
37
import org.apache.jasper.compiler.ErrorDispatcher;
38
import org.apache.jasper.compiler.JarResource;
38
import org.apache.jasper.compiler.JavacErrorDetail;
39
import org.apache.jasper.compiler.JavacErrorDetail;
39
import org.apache.jasper.compiler.JspRuntimeContext;
40
import org.apache.jasper.compiler.JspRuntimeContext;
40
import org.apache.jasper.compiler.Localizer;
41
import org.apache.jasper.compiler.Localizer;
Lines 105-111 Link Here
105
                             String tagFilePath,
106
                             String tagFilePath,
106
                             TagInfo tagInfo,
107
                             TagInfo tagInfo,
107
                             JspRuntimeContext rctxt,
108
                             JspRuntimeContext rctxt,
108
                             URL tagFileJarUrl) {
109
                             JarResource tagJarResource) {
109
110
110
        this.isTagFile = true;
111
        this.isTagFile = true;
111
        this.config = null;        // not used
112
        this.config = null;        // not used
Lines 114-120 Link Here
114
        this.tripCount = 0;
115
        this.tripCount = 0;
115
        ctxt = new JspCompilationContext(jspUri, tagInfo, options,
116
        ctxt = new JspCompilationContext(jspUri, tagInfo, options,
116
                                         servletContext, this, rctxt,
117
                                         servletContext, this, rctxt,
117
                                         tagFileJarUrl);
118
                                         tagJarResource);
118
    }
119
    }
119
120
120
    public JspCompilationContext getJspEngineContext() {
121
    public JspCompilationContext getJspEngineContext() {
(-)java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java (-1 / +1 lines)
Lines 195-201 Link Here
195
                tagInfo = TagFileProcessor.parseTagFileDirectives(pc,
195
                tagInfo = TagFileProcessor.parseTagFileDirectives(pc,
196
                        shortName,
196
                        shortName,
197
                        path,
197
                        path,
198
                        pc.getJspCompilationContext().getTagFileJarUrl(path),
198
                        pc.getJspCompilationContext().getTagFileJarResource(path),
199
                        this);
199
                        this);
200
            } catch (JasperException je) {
200
            } catch (JasperException je) {
201
                throw new RuntimeException(je.toString(), je);
201
                throw new RuntimeException(je.toString(), je);
(-)java/org/apache/jasper/compiler/JarURLResource.java (+57 lines)
Line 0 Link Here
1
/*
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
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
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.
16
 */
17
18
package org.apache.jasper.compiler;
19
20
import java.io.IOException;
21
import java.net.JarURLConnection;
22
import java.net.MalformedURLException;
23
import java.net.URL;
24
import java.util.jar.JarFile;
25
26
public class JarURLResource implements JarResource {
27
    
28
    private String jarUrl;
29
    
30
    public JarURLResource(URL jarURL) {
31
        this(jarURL.toExternalForm());
32
    }
33
    
34
    public JarURLResource(String jarUrl) {
35
        this.jarUrl = jarUrl;
36
    }
37
    
38
    public JarFile getJarFile() throws IOException {
39
        URL jarFileUrl = new URL("jar:" + jarUrl + "!/");
40
        JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
41
        conn.setUseCaches(false);
42
        conn.connect();
43
        return conn.getJarFile();
44
    }
45
       
46
    public String getUrl() {
47
        return jarUrl;
48
    }
49
    
50
    public URL getEntry(String name) {
51
        try {
52
            return new URL("jar:" + jarUrl + "!/" + name);
53
        } catch (MalformedURLException e) {
54
            throw new RuntimeException("", e);
55
        }
56
    }
57
}
0
  + text/plain
58
  + text/plain
1
  + Date Revision
59
  + Date Revision
2
  + native
60
  + native
(-)java/org/apache/jasper/compiler/JspDocumentParser.java (-1 / +1 lines)
Lines 1267-1273 Link Here
1267
                isPlainUri = true;
1267
                isPlainUri = true;
1268
            }
1268
            }
1269
1269
1270
            String[] location = ctxt.getTldLocation(uri);
1270
            TldLocation location = ctxt.getTldLocation(uri);
1271
            if (location != null || !isPlainUri) {
1271
            if (location != null || !isPlainUri) {
1272
                if (ctxt.getOptions().isCaching()) {
1272
                if (ctxt.getOptions().isCaching()) {
1273
                    result = ctxt.getOptions().getCache().get(uri);
1273
                    result = ctxt.getOptions().getCache().get(uri);
(-)java/org/apache/jasper/compiler/TldLocation.java (+60 lines)
Line 0 Link Here
1
/*
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
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
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.
16
 */
17
18
package org.apache.jasper.compiler;
19
20
public class TldLocation {
21
    
22
    private String entryName;
23
    private JarResource jar;
24
    
25
    public TldLocation(String entryName) {
26
        this(entryName, (JarResource)null);
27
    }
28
    
29
    public TldLocation(String entryName, String resourceUrl) {
30
        this(entryName, getJarResource(resourceUrl));
31
    }
32
    
33
    public TldLocation(String entryName, JarResource jarResource) {
34
        if (entryName == null) {
35
            throw new IllegalArgumentException("Tld name is required");
36
        }
37
        this.entryName = entryName;
38
        this.jar = jarResource;
39
    }
40
        
41
    private static JarResource getJarResource(String resourceUrl) {
42
        return (resourceUrl != null) ? new JarURLResource(resourceUrl) : null;
43
    }
44
    
45
    /**
46
     * @return The name of the tag library.
47
     */
48
    public String getName() {
49
        return entryName;
50
    }
51
    
52
    /**
53
     * 
54
     * @return The jar resource the tag library is contained in. 
55
     *         Might return null if the tag library is not contained in jar resource.
56
     */
57
    public JarResource getJarResource() {
58
        return jar;
59
    }
60
}
0
  + text/plain
61
  + text/plain
1
  + Date Revision
62
  + Date Revision
2
  + native
63
  + native
(-)java/org/apache/jasper/compiler/JarResource.java (+45 lines)
Line 0 Link Here
1
/*
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
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
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.
16
 */
17
18
package org.apache.jasper.compiler;
19
20
import java.io.IOException;
21
import java.net.URL;
22
import java.util.jar.JarFile;
23
24
public interface JarResource {
25
       
26
    /**     
27
     * @return The JarFile for this resource. A new instance of JarFile
28
     *         should be returned on each call.
29
     * @throws IOException
30
     */
31
    JarFile getJarFile() throws IOException;
32
       
33
    /**     
34
     * @return The URL of this resource. May or may not point 
35
     *         to the actual Jar file.    
36
     */
37
    String getUrl();
38
    
39
    /**     
40
     * @param name
41
     * @return The URL for the entry within this resource.
42
     */
43
    URL getEntry(String name);
44
45
}
0
  + text/plain
46
  + text/plain
1
  + Date Revision
47
  + Date Revision
2
  + native
48
  + native
(-)java/org/apache/jasper/compiler/ParserController.java (-10 / +11 lines)
Lines 100-106 Link Here
100
        // respectively.
100
        // respectively.
101
        isTagFile = ctxt.isTagFile();
101
        isTagFile = ctxt.isTagFile();
102
        directiveOnly = false;
102
        directiveOnly = false;
103
        return doParse(inFileName, null, ctxt.getTagFileJarUrl());
103
        return doParse(inFileName, null, ctxt.getTagFileJarResource());
104
    }
104
    }
105
105
106
    /**
106
    /**
Lines 117-123 Link Here
117
        // respectively.
117
        // respectively.
118
        isTagFile = ctxt.isTagFile();
118
        isTagFile = ctxt.isTagFile();
119
        directiveOnly = true;
119
        directiveOnly = true;
120
        return doParse(inFileName, null, ctxt.getTagFileJarUrl());
120
        return doParse(inFileName, null, ctxt.getTagFileJarResource());
121
    }
121
    }
122
122
123
123
Lines 130-140 Link Here
130
     * or null of the included resource is to be read from the filesystem
130
     * or null of the included resource is to be read from the filesystem
131
     */
131
     */
132
    public Node.Nodes parse(String inFileName, Node parent,
132
    public Node.Nodes parse(String inFileName, Node parent,
133
            URL jarFileUrl)
133
            JarResource jarResource)
134
    throws FileNotFoundException, JasperException, IOException {
134
    throws FileNotFoundException, JasperException, IOException {
135
        // For files that are statically included, isTagfile and directiveOnly
135
        // For files that are statically included, isTagfile and directiveOnly
136
        // remain unchanged.
136
        // remain unchanged.
137
        return doParse(inFileName, parent, jarFileUrl);
137
        return doParse(inFileName, parent, jarResource);
138
    }
138
    }
139
139
140
    /**
140
    /**
Lines 146-158 Link Here
146
     * @param tagFileJarUrl The location of the tag file.
146
     * @param tagFileJarUrl The location of the tag file.
147
     */
147
     */
148
    public Node.Nodes parseTagFileDirectives(String inFileName,
148
    public Node.Nodes parseTagFileDirectives(String inFileName,
149
            URL tagFileJarUrl)
149
            JarResource jarResource)
150
            throws FileNotFoundException, JasperException, IOException {
150
            throws FileNotFoundException, JasperException, IOException {
151
        boolean isTagFileSave = isTagFile;
151
        boolean isTagFileSave = isTagFile;
152
        boolean directiveOnlySave = directiveOnly;
152
        boolean directiveOnlySave = directiveOnly;
153
        isTagFile = true;
153
        isTagFile = true;
154
        directiveOnly = true;
154
        directiveOnly = true;
155
        Node.Nodes page = doParse(inFileName, null, tagFileJarUrl);
155
        Node.Nodes page = doParse(inFileName, null, jarResource);
156
        directiveOnly = directiveOnlySave;
156
        directiveOnly = directiveOnlySave;
157
        isTagFile = isTagFileSave;
157
        isTagFile = isTagFileSave;
158
        return page;
158
        return page;
Lines 174-180 Link Here
174
     */
174
     */
175
    private Node.Nodes doParse(String inFileName,
175
    private Node.Nodes doParse(String inFileName,
176
            Node parent,
176
            Node parent,
177
            URL jarFileUrl)
177
            JarResource jarResource)
178
    throws FileNotFoundException, JasperException, IOException {
178
    throws FileNotFoundException, JasperException, IOException {
179
179
180
        Node.Nodes parsedPage = null;
180
        Node.Nodes parsedPage = null;
Lines 182-188 Link Here
182
        isBomPresent = false;
182
        isBomPresent = false;
183
        isDefaultPageEncoding = false;
183
        isDefaultPageEncoding = false;
184
184
185
        JarFile jarFile = getJarFile(jarFileUrl);
185
        JarFile jarFile = (jarResource == null) ? null : jarResource.getJarFile();
186
        String absFileName = resolveFileName(inFileName);
186
        String absFileName = resolveFileName(inFileName);
187
        String jspConfigPageEnc = getJspConfigPageEncoding(absFileName);
187
        String jspConfigPageEnc = getJspConfigPageEncoding(absFileName);
188
188
Lines 196-202 Link Here
196
                compiler.getPageInfo().addDependant(absFileName);
196
                compiler.getPageInfo().addDependant(absFileName);
197
            } else {
197
            } else {
198
                compiler.getPageInfo().addDependant(
198
                compiler.getPageInfo().addDependant(
199
                        jarFileUrl.toExternalForm() + absFileName.substring(1));
199
                        jarResource.getEntry(absFileName.substring(1)).toString());
200
                        
200
            }
201
            }
201
        }
202
        }
202
203
Lines 237-243 Link Here
237
                        sourceEnc, inStreamReader,
238
                        sourceEnc, inStreamReader,
238
                        err);
239
                        err);
239
                parsedPage = Parser.parse(this, jspReader, parent, isTagFile,
240
                parsedPage = Parser.parse(this, jspReader, parent, isTagFile,
240
                        directiveOnly, jarFileUrl,
241
                        directiveOnly, jarResource,
241
                        sourceEnc, jspConfigPageEnc,
242
                        sourceEnc, jspConfigPageEnc,
242
                        isDefaultPageEncoding, isBomPresent);
243
                        isDefaultPageEncoding, isBomPresent);
243
            } finally {
244
            } finally {
(-)java/org/apache/jasper/compiler/TagFileProcessor.java (-22 / +16 lines)
Lines 489-495 Link Here
489
     * @return a TagInfo object assembled from the directives in the tag file.
489
     * @return a TagInfo object assembled from the directives in the tag file.
490
     */
490
     */
491
    public static TagInfo parseTagFileDirectives(ParserController pc,
491
    public static TagInfo parseTagFileDirectives(ParserController pc,
492
            String name, String path, URL tagFileJarUrl, TagLibraryInfo tagLibInfo)
492
            String name, String path, JarResource jarResource, TagLibraryInfo tagLibInfo)
493
            throws JasperException {
493
            throws JasperException {
494
494
495
495
Lines 497-503 Link Here
497
497
498
        Node.Nodes page = null;
498
        Node.Nodes page = null;
499
        try {
499
        try {
500
            page = pc.parseTagFileDirectives(path, tagFileJarUrl);
500
            page = pc.parseTagFileDirectives(path, jarResource);
501
        } catch (FileNotFoundException e) {
501
        } catch (FileNotFoundException e) {
502
            err.jspError("jsp.error.file.not.found", path);
502
            err.jspError("jsp.error.file.not.found", path);
503
        } catch (IOException e) {
503
        } catch (IOException e) {
Lines 518-550 Link Here
518
    private Class<?> loadTagFile(Compiler compiler, String tagFilePath,
518
    private Class<?> loadTagFile(Compiler compiler, String tagFilePath,
519
            TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException {
519
            TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException {
520
520
521
        URL tagFileJarUrl = null;
521
        JarResource tagJarResouce = null;
522
        if (tagFilePath.startsWith("/META-INF/")) {
522
        if (tagFilePath.startsWith("/META-INF/")) {
523
            try { 
523
            tagJarResouce = 
524
                tagFileJarUrl = new URL("jar:" +
524
                compiler.getCompilationContext().getTldLocation(
525
                        compiler.getCompilationContext().getTldLocation(
525
                        tagInfo.getTagLibrary().getURI()).getJarResource();
526
                        tagInfo.getTagLibrary().getURI())[0] + "!/");
527
            } catch (MalformedURLException e) {
528
                // Ignore - tagFileJarUrl will be null
529
            }
530
        }
526
        }
531
        String tagFileJarPath;
527
        String wrapperUri;
532
        if (tagFileJarUrl == null) {
528
        if (tagJarResouce == null) {
533
            tagFileJarPath = "";
529
            wrapperUri = tagFilePath;
534
        } else {
530
        } else {
535
            tagFileJarPath = tagFileJarUrl.toString();
531
            wrapperUri = tagJarResouce.getEntry(tagFilePath).toString();
536
        }
532
        }
537
533
538
        JspCompilationContext ctxt = compiler.getCompilationContext();
534
        JspCompilationContext ctxt = compiler.getCompilationContext();
539
        JspRuntimeContext rctxt = ctxt.getRuntimeContext();
535
        JspRuntimeContext rctxt = ctxt.getRuntimeContext();
540
        String wrapperUri = tagFileJarPath + tagFilePath;
541
        JspServletWrapper wrapper = rctxt.getWrapper(wrapperUri);
536
        JspServletWrapper wrapper = rctxt.getWrapper(wrapperUri);
542
537
543
        synchronized (rctxt) {
538
        synchronized (rctxt) {
544
            if (wrapper == null) {
539
            if (wrapper == null) {
545
                wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt
540
                wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt
546
                        .getOptions(), tagFilePath, tagInfo, ctxt
541
                        .getOptions(), tagFilePath, tagInfo, ctxt
547
                        .getRuntimeContext(), tagFileJarUrl);
542
                        .getRuntimeContext(), tagJarResouce);
548
                rctxt.addWrapper(wrapperUri, wrapper);
543
                rctxt.addWrapper(wrapperUri, wrapper);
549
544
550
                // Use same classloader and classpath for compiling tag files
545
                // Use same classloader and classpath for compiling tag files
Lines 571-577 Link Here
571
                    JspServletWrapper tempWrapper = new JspServletWrapper(ctxt
566
                    JspServletWrapper tempWrapper = new JspServletWrapper(ctxt
572
                            .getServletContext(), ctxt.getOptions(),
567
                            .getServletContext(), ctxt.getOptions(),
573
                            tagFilePath, tagInfo, ctxt.getRuntimeContext(),
568
                            tagFilePath, tagInfo, ctxt.getRuntimeContext(),
574
                            ctxt.getTagFileJarUrl(tagFilePath));
569
                            ctxt.getTagFileJarResource(tagFilePath));
575
                    tagClazz = tempWrapper.loadTagFilePrototype();
570
                    tagClazz = tempWrapper.loadTagFilePrototype();
576
                    tempVector.add(tempWrapper.getJspEngineContext()
571
                    tempVector.add(tempWrapper.getJspEngineContext()
577
                            .getCompiler());
572
                            .getCompiler());
Lines 625-639 Link Here
625
                String tagFilePath = tagFileInfo.getPath();
620
                String tagFilePath = tagFileInfo.getPath();
626
                if (tagFilePath.startsWith("/META-INF/")) {
621
                if (tagFilePath.startsWith("/META-INF/")) {
627
                    // For tags in JARs, add the TLD and the tag as a dependency
622
                    // For tags in JARs, add the TLD and the tag as a dependency
628
                    String[] location =
623
                    TldLocation location =
629
                        compiler.getCompilationContext().getTldLocation(
624
                        compiler.getCompilationContext().getTldLocation(
630
                            tagFileInfo.getTagInfo().getTagLibrary().getURI());
625
                            tagFileInfo.getTagInfo().getTagLibrary().getURI());
626
                    JarResource jarResource = location.getJarResource();
631
                    // Add TLD
627
                    // Add TLD
632
                    pageInfo.addDependant("jar:" + location[0] + "!/" +
628
                    pageInfo.addDependant(jarResource.getEntry(location.getName()).toString());
633
                            location[1]);
634
                    // Add Tag
629
                    // Add Tag
635
                    pageInfo.addDependant("jar:" + location[0] + "!" +
630
                    pageInfo.addDependant(jarResource.getEntry(tagFilePath.substring(1)).toString());
636
                            tagFilePath);
637
                } else {
631
                } else {
638
                    pageInfo.addDependant(tagFilePath);
632
                    pageInfo.addDependant(tagFilePath);
639
                }
633
                }
(-)java/org/apache/jasper/compiler/TldLocationsCache.java (-8 / +15 lines)
Lines 96-102 Link Here
96
     *    [0] The location
96
     *    [0] The location
97
     *    [1] If the location is a jar file, this is the location of the tld.
97
     *    [1] If the location is a jar file, this is the location of the tld.
98
     */
98
     */
99
    private Hashtable<String, String[]> mappings;
99
    private Hashtable<String, TldLocation> mappings;
100
100
101
    private boolean initialized;
101
    private boolean initialized;
102
    private ServletContext ctxt;
102
    private ServletContext ctxt;
Lines 108-114 Link Here
108
     */
108
     */
109
    public TldLocationsCache(ServletContext ctxt) {
109
    public TldLocationsCache(ServletContext ctxt) {
110
        this.ctxt = ctxt;
110
        this.ctxt = ctxt;
111
        mappings = new Hashtable<String, String[]>();
111
        mappings = new Hashtable<String, TldLocation>();
112
        initialized = false;
112
        initialized = false;
113
    }
113
    }
114
114
Lines 150-156 Link Here
150
     * Returns null if the uri is not associated with any tag library 'exposed'
150
     * Returns null if the uri is not associated with any tag library 'exposed'
151
     * in the web application.
151
     * in the web application.
152
     */
152
     */
153
    public String[] getLocation(String uri) throws JasperException {
153
    public TldLocation getLocation(String uri) throws JasperException {
154
        if (!initialized) {
154
        if (!initialized) {
155
            init();
155
            init();
156
        }
156
        }
Lines 262-273 Link Here
262
                    continue;
262
                    continue;
263
                if (uriType(tagLoc) == NOROOT_REL_URI)
263
                if (uriType(tagLoc) == NOROOT_REL_URI)
264
                    tagLoc = "/WEB-INF/" + tagLoc;
264
                    tagLoc = "/WEB-INF/" + tagLoc;
265
                String tagLoc2 = null;
265
                TldLocation location;
266
                if (tagLoc.endsWith(JAR_EXT)) {
266
                if (tagLoc.endsWith(JAR_EXT)) {
267
                    tagLoc = ctxt.getResource(tagLoc).toString();
267
                    location = new TldLocation("META-INF/taglib.tld", ctxt.getResource(tagLoc).toString());
268
                    tagLoc2 = "META-INF/taglib.tld";
268
                } else {
269
                    location = new TldLocation(tagLoc);
269
                }
270
                }
270
                mappings.put(tagUri, new String[] { tagLoc, tagLoc2 });
271
                mappings.put(tagUri, location);
271
            }
272
            }
272
        } finally {
273
        } finally {
273
            if (webXml != null) {
274
            if (webXml != null) {
Lines 422-428 Link Here
422
            // Add implicit map entry only if its uri is not already
423
            // Add implicit map entry only if its uri is not already
423
            // present in the map
424
            // present in the map
424
            if (uri != null && mappings.get(uri) == null) {
425
            if (uri != null && mappings.get(uri) == null) {
425
                mappings.put(uri, new String[]{ resourcePath, entryName });
426
                TldLocation location;
427
                if (entryName == null) {
428
                    location = new TldLocation(resourcePath);
429
                } else {
430
                    location = new TldLocation(entryName, resourcePath);
431
                }
432
                mappings.put(uri, location);
426
            }
433
            }
427
        } catch (JasperException e) {
434
        } catch (JasperException e) {
428
            // Hack - makes exception handling simpler
435
            // Hack - makes exception handling simpler
(-)java/org/apache/jasper/compiler/Parser.java (-9 / +9 lines)
Lines 60-66 Link Here
60
60
61
    private boolean directivesOnly;
61
    private boolean directivesOnly;
62
62
63
    private URL jarFileUrl;
63
    private JarResource jarResource;
64
64
65
    private PageInfo pageInfo;
65
    private PageInfo pageInfo;
66
66
Lines 79-85 Link Here
79
     * The constructor
79
     * The constructor
80
     */
80
     */
81
    private Parser(ParserController pc, JspReader reader, boolean isTagFile,
81
    private Parser(ParserController pc, JspReader reader, boolean isTagFile,
82
            boolean directivesOnly, URL jarFileUrl) {
82
            boolean directivesOnly, JarResource jarResource) {
83
        this.parserController = pc;
83
        this.parserController = pc;
84
        this.ctxt = pc.getJspCompilationContext();
84
        this.ctxt = pc.getJspCompilationContext();
85
        this.pageInfo = pc.getCompiler().getPageInfo();
85
        this.pageInfo = pc.getCompiler().getPageInfo();
Lines 88-94 Link Here
88
        this.scriptlessCount = 0;
88
        this.scriptlessCount = 0;
89
        this.isTagFile = isTagFile;
89
        this.isTagFile = isTagFile;
90
        this.directivesOnly = directivesOnly;
90
        this.directivesOnly = directivesOnly;
91
        this.jarFileUrl = jarFileUrl;
91
        this.jarResource = jarResource;
92
        start = reader.mark();
92
        start = reader.mark();
93
    }
93
    }
94
94
Lines 106-117 Link Here
106
     */
106
     */
107
    public static Node.Nodes parse(ParserController pc, JspReader reader,
107
    public static Node.Nodes parse(ParserController pc, JspReader reader,
108
            Node parent, boolean isTagFile, boolean directivesOnly,
108
            Node parent, boolean isTagFile, boolean directivesOnly,
109
            URL jarFileUrl, String pageEnc, String jspConfigPageEnc,
109
            JarResource jarResource, String pageEnc, String jspConfigPageEnc,
110
            boolean isDefaultPageEncoding, boolean isBomPresent)
110
            boolean isDefaultPageEncoding, boolean isBomPresent)
111
            throws JasperException {
111
            throws JasperException {
112
112
113
        Parser parser = new Parser(pc, reader, isTagFile, directivesOnly,
113
        Parser parser = new Parser(pc, reader, isTagFile, directivesOnly,
114
                jarFileUrl);
114
                jarResource);
115
115
116
        Node.Root root = new Node.Root(reader.mark(), parent, false);
116
        Node.Root root = new Node.Root(reader.mark(), parent, false);
117
        root.setPageEncoding(pageEnc);
117
        root.setPageEncoding(pageEnc);
Lines 292-298 Link Here
292
        }
292
        }
293
293
294
        try {
294
        try {
295
            parserController.parse(file, parent, jarFileUrl);
295
            parserController.parse(file, parent, jarResource);
296
        } catch (FileNotFoundException ex) {
296
        } catch (FileNotFoundException ex) {
297
            err.jspError(start, "jsp.error.file.not.found", file);
297
            err.jspError(start, "jsp.error.file.not.found", file);
298
        } catch (Exception ex) {
298
        } catch (Exception ex) {
Lines 381-387 Link Here
381
                                .getCache().get(uri);
381
                                .getCache().get(uri);
382
                    }
382
                    }
383
                    if (impl == null) {
383
                    if (impl == null) {
384
                        String[] location = ctxt.getTldLocation(uri);
384
                        TldLocation location = ctxt.getTldLocation(uri);
385
                        impl = new TagLibraryInfoImpl(ctxt, parserController,
385
                        impl = new TagLibraryInfoImpl(ctxt, parserController,
386
                                pageInfo, prefix, uri, location, err);
386
                                pageInfo, prefix, uri, location, err);
387
                        if (ctxt.getOptions().isCaching()) {
387
                        if (ctxt.getOptions().isCaching()) {
Lines 391-398 Link Here
391
                        // Current compilation context needs location of cached
391
                        // Current compilation context needs location of cached
392
                        // tag files
392
                        // tag files
393
                        for (TagFileInfo info : impl.getTagFiles()) {
393
                        for (TagFileInfo info : impl.getTagFiles()) {
394
                            ctxt.setTagFileJarUrl(info.getPath(),
394
                            ctxt.setTagFileJarResource(info.getPath(),
395
                                    ctxt.getTagFileJarUrl());
395
                                    ctxt.getTagFileJarResource());
396
                        }
396
                        }
397
                    }
397
                    }
398
                    pageInfo.addTaglib(uri, impl);
398
                    pageInfo.addTaglib(uri, impl);
(-)java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (-41 / +26 lines)
Lines 137-143 Link Here
137
     * Constructor.
137
     * Constructor.
138
     */
138
     */
139
    public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc, PageInfo pi,
139
    public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc, PageInfo pi,
140
            String prefix, String uriIn, String[] location, ErrorDispatcher err)
140
            String prefix, String uriIn, TldLocation location, ErrorDispatcher err)
141
            throws JasperException {
141
            throws JasperException {
142
        super(prefix, uriIn);
142
        super(prefix, uriIn);
143
143
Lines 146-152 Link Here
146
        this.pi = pi;
146
        this.pi = pi;
147
        this.err = err;
147
        this.err = err;
148
        InputStream in = null;
148
        InputStream in = null;
149
        JarFile jarFile = null;
150
149
151
        if (location == null) {
150
        if (location == null) {
152
            // The URI points to the TLD itself or to a JAR file in which the
151
            // The URI points to the TLD itself or to a JAR file in which the
Lines 154-192 Link Here
154
            location = generateTLDLocation(uri, ctxt);
153
            location = generateTLDLocation(uri, ctxt);
155
        }
154
        }
156
155
156
        String tldName = location.getName();
157
        JarResource jarResource = location.getJarResource();
157
        try {
158
        try {
158
            if (location[1] == null) {
159
            if (jarResource == null) {
159
                // Location points directly to TLD file
160
                // Location points directly to TLD file
160
                try {
161
                try {
161
                    in = getResourceAsStream(location[0]);
162
                    in = getResourceAsStream(tldName);
162
                    if (in == null) {
163
                    if (in == null) {
163
                        throw new FileNotFoundException(location[0]);
164
                        throw new FileNotFoundException(tldName);
164
                    }
165
                    }
165
                } catch (FileNotFoundException ex) {
166
                } catch (FileNotFoundException ex) {
166
                    err.jspError("jsp.error.file.not.found", location[0]);
167
                    err.jspError("jsp.error.file.not.found", tldName);
167
                }
168
                }
168
169
169
                parseTLD(location[0], in, null);
170
                parseTLD(tldName, in, null);
170
                // Add TLD to dependency list
171
                // Add TLD to dependency list
171
                PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
172
                PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
172
                if (pageInfo != null) {
173
                if (pageInfo != null) {
173
                    pageInfo.addDependant(location[0]);
174
                    pageInfo.addDependant(tldName);
174
                }
175
                }
175
            } else {
176
            } else {
176
                // Tag library is packaged in JAR file
177
                // Tag library is packaged in JAR file
177
                try {
178
                try {
178
                    URL jarFileUrl = new URL("jar:" + location[0] + "!/");
179
                    in = jarResource.getEntry(tldName).openStream();
179
                    JarURLConnection conn = (JarURLConnection) jarFileUrl
180
                    parseTLD(jarResource.getUrl(), in, jarResource);
180
                            .openConnection();
181
                    conn.setUseCaches(false);
182
                    conn.connect();
183
                    jarFile = conn.getJarFile();
184
                    ZipEntry jarEntry = jarFile.getEntry(location[1]);
185
                    in = jarFile.getInputStream(jarEntry);
186
                    parseTLD(location[0], in, jarFileUrl);
187
                } catch (Exception ex) {
181
                } catch (Exception ex) {
188
                    err.jspError("jsp.error.tld.unable_to_read", location[0],
182
                    err.jspError("jsp.error.tld.unable_to_read", jarResource.getUrl(),
189
                            location[1], ex.toString());
183
                            jarResource.getUrl(), ex.toString());
190
                }
184
                }
191
            }
185
            }
192
        } finally {
186
        } finally {
Lines 196-207 Link Here
196
                } catch (Throwable t) {
190
                } catch (Throwable t) {
197
                }
191
                }
198
            }
192
            }
199
            if (jarFile != null) {
200
                try {
201
                    jarFile.close();
202
                } catch (Throwable t) {
203
                }
204
            }
205
        }
193
        }
206
194
207
    }
195
    }
Lines 217-223 Link Here
217
     * in The TLD's input stream @param jarFileUrl The JAR file containing the
205
     * in The TLD's input stream @param jarFileUrl The JAR file containing the
218
     * TLD, or null if the tag library is not packaged in a JAR
206
     * TLD, or null if the tag library is not packaged in a JAR
219
     */
207
     */
220
    private void parseTLD(String uri, InputStream in, URL jarFileUrl)
208
    private void parseTLD(String uri, InputStream in, JarResource jarResource)
221
            throws JasperException {
209
            throws JasperException {
222
        Vector<TagInfo> tagVector = new Vector<TagInfo>();
210
        Vector<TagInfo> tagVector = new Vector<TagInfo>();
223
        Vector<TagFileInfo> tagFileVector = new Vector<TagFileInfo>();
211
        Vector<TagFileInfo> tagFileVector = new Vector<TagFileInfo>();
Lines 257-263 Link Here
257
                tagVector.addElement(createTagInfo(element, jspversion));
245
                tagVector.addElement(createTagInfo(element, jspversion));
258
            else if ("tag-file".equals(tname)) {
246
            else if ("tag-file".equals(tname)) {
259
                TagFileInfo tagFileInfo = createTagFileInfo(element,
247
                TagFileInfo tagFileInfo = createTagFileInfo(element,
260
                        jarFileUrl);
248
                        jarResource);
261
                tagFileVector.addElement(tagFileInfo);
249
                tagFileVector.addElement(tagFileInfo);
262
            } else if ("function".equals(tname)) { // JSP2.0
250
            } else if ("function".equals(tname)) { // JSP2.0
263
                FunctionInfo funcInfo = createFunctionInfo(element);
251
                FunctionInfo funcInfo = createFunctionInfo(element);
Lines 314-320 Link Here
314
     * the name of the TLD entry in the jar file, which is hardcoded to
302
     * the name of the TLD entry in the jar file, which is hardcoded to
315
     * META-INF/taglib.tld.
303
     * META-INF/taglib.tld.
316
     */
304
     */
317
    private String[] generateTLDLocation(String uri, JspCompilationContext ctxt)
305
    private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt)
318
            throws JasperException {
306
            throws JasperException {
319
307
320
        int uriType = TldLocationsCache.uriType(uri);
308
        int uriType = TldLocationsCache.uriType(uri);
Lines 325-348 Link Here
325
            uri = ctxt.resolveRelativeUri(uri);
313
            uri = ctxt.resolveRelativeUri(uri);
326
        }
314
        }
327
315
328
        String[] location = new String[2];
316
        if (uri.endsWith(".jar")) {
329
        location[0] = uri;
330
        if (location[0].endsWith(".jar")) {
331
            URL url = null;
317
            URL url = null;
332
            try {
318
            try {
333
                url = ctxt.getResource(location[0]);
319
                url = ctxt.getResource(uri);
334
            } catch (Exception ex) {
320
            } catch (Exception ex) {
335
                err.jspError("jsp.error.tld.unable_to_get_jar", location[0], ex
321
                err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex
336
                        .toString());
322
                        .toString());
337
            }
323
            }
338
            if (url == null) {
324
            if (url == null) {
339
                err.jspError("jsp.error.tld.missing_jar", location[0]);
325
                err.jspError("jsp.error.tld.missing_jar", uri);
340
            }
326
            }
341
            location[0] = url.toString();
327
            return new TldLocation("META-INF/taglib.tld", url.toString());
342
            location[1] = "META-INF/taglib.tld";
328
        } else {
329
            return new TldLocation(uri);
343
        }
330
        }
344
345
        return location;
346
    }
331
    }
347
332
348
    private TagInfo createTagInfo(TreeNode elem, String jspVersion)
333
    private TagInfo createTagInfo(TreeNode elem, String jspVersion)
Lines 453-459 Link Here
453
     * 
438
     * 
454
     * @return TagInfo corresponding to tag file directives
439
     * @return TagInfo corresponding to tag file directives
455
     */
440
     */
456
    private TagFileInfo createTagFileInfo(TreeNode elem, URL jarFileUrl)
441
    private TagFileInfo createTagFileInfo(TreeNode elem, JarResource jarResource)
457
            throws JasperException {
442
            throws JasperException {
458
443
459
        String name = null;
444
        String name = null;
Lines 488-500 Link Here
488
            // See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471
473
            // See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471
489
            // This needs to be removed once all the broken code that depends on
474
            // This needs to be removed once all the broken code that depends on
490
            // it has been removed
475
            // it has been removed
491
            ctxt.setTagFileJarUrl(path, jarFileUrl);
476
            ctxt.setTagFileJarResource(path, jarResource);
492
        } else if (!path.startsWith("/WEB-INF/tags")) {
477
        } else if (!path.startsWith("/WEB-INF/tags")) {
493
            err.jspError("jsp.error.tagfile.illegalPath", path);
478
            err.jspError("jsp.error.tagfile.illegalPath", path);
494
        }
479
        }
495
480
496
        TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(
481
        TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(
497
                parserController, name, path, jarFileUrl, this);
482
                parserController, name, path, jarResource, this);
498
        return new TagFileInfo(name, path, tagInfo);
483
        return new TagFileInfo(name, path, tagInfo);
499
    }
484
    }
500
485

Return to bug 48689