ASF Bugzilla – Attachment 24933 Details for
Bug 48689
Jar abstraction for Jasper
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch for this issue.
Tomcat-48689.patch (text/plain), 34.80 KB, created by
Jarek Gawor
on 2010-02-05 12:38:53 UTC
(
hide
)
Description:
Proposed patch for this issue.
Filename:
MIME Type:
Creator:
Jarek Gawor
Created:
2010-02-05 12:38:53 UTC
Size:
34.80 KB
patch
obsolete
>Index: java/org/apache/jasper/JspCompilationContext.java >=================================================================== >--- java/org/apache/jasper/JspCompilationContext.java (revision 907055) >+++ java/org/apache/jasper/JspCompilationContext.java (working copy) >@@ -30,10 +30,12 @@ > import javax.servlet.jsp.tagext.TagInfo; > > import org.apache.jasper.compiler.Compiler; >+import org.apache.jasper.compiler.JarResource; > import org.apache.jasper.compiler.JspRuntimeContext; > import org.apache.jasper.compiler.JspUtil; > import org.apache.jasper.compiler.Localizer; > import org.apache.jasper.compiler.ServletWriter; >+import org.apache.jasper.compiler.TldLocation; > import org.apache.jasper.servlet.JasperLoader; > import org.apache.jasper.servlet.JspServletWrapper; > import org.apache.juli.logging.Log; >@@ -57,7 +59,7 @@ > > private final Log log = LogFactory.getLog(JspCompilationContext.class); // must not be static > >- protected Map<String, URL> tagFileJarUrls; >+ protected Map<String, JarResource> tagFileJarUrls; > protected boolean isPackagedTagFile; > > protected String className; >@@ -91,7 +93,7 @@ > protected boolean isTagFile; > protected boolean protoTypeMode; > protected TagInfo tagInfo; >- protected URL tagFileJarUrl; >+ protected JarResource tagJarResource; > > // jspURI _must_ be relative to the context > public JspCompilationContext(String jspUri, >@@ -121,7 +123,7 @@ > } > > this.rctxt = rctxt; >- this.tagFileJarUrls = new HashMap<String, URL>(); >+ this.tagFileJarUrls = new HashMap<String, JarResource>(); > this.basePackageName = Constants.JSP_PACKAGE_NAME; > } > >@@ -131,12 +133,12 @@ > ServletContext context, > JspServletWrapper jsw, > JspRuntimeContext rctxt, >- URL tagFileJarUrl) { >+ JarResource tagJarResource) { > this(tagfile, false, options, context, jsw, rctxt); > this.isTagFile = true; > this.tagInfo = tagInfo; >- this.tagFileJarUrl = tagFileJarUrl; >- if (tagFileJarUrl != null) { >+ this.tagJarResource = tagJarResource; >+ if (tagJarResource != null) { > isPackagedTagFile = true; > } > } >@@ -288,12 +290,12 @@ > > if (res.startsWith("/META-INF/")) { > // This is a tag file packaged in a jar that is being compiled >- URL jarUrl = tagFileJarUrls.get(res); >- if (jarUrl == null) { >- jarUrl = tagFileJarUrl; >+ JarResource jarResource = tagFileJarUrls.get(res); >+ if (jarResource == null) { >+ jarResource = tagJarResource; > } >- if (jarUrl != null) { >- result = new URL(jarUrl.toExternalForm() + res.substring(1)); >+ if (jarResource != null) { >+ result = jarResource.getEntry(res.substring(1)); > } > } else if (res.startsWith("jar:file:")) { > // This is a tag file packaged in a jar that is being checked >@@ -330,12 +332,12 @@ > * The map is populated when parsing the tag-file elements of the TLDs > * of any imported taglibs. > */ >- public URL getTagFileJarUrl(String tagFile) { >+ public JarResource getTagFileJarResource(String tagFile) { > return this.tagFileJarUrls.get(tagFile); > } > >- public void setTagFileJarUrl(String tagFile, URL tagFileURL) { >- this.tagFileJarUrls.put(tagFile, tagFileURL); >+ public void setTagFileJarResource(String tagFile, JarResource jarResource) { >+ this.tagFileJarUrls.put(tagFile, jarResource); > } > > /** >@@ -344,8 +346,8 @@ > * JspCompilationContext does not correspond to a tag file, or if the > * corresponding tag file is not packaged in a JAR. > */ >- public URL getTagFileJarUrl() { >- return this.tagFileJarUrl; >+ public JarResource getTagFileJarResource() { >+ return this.tagJarResource; > } > > /* ==================== Common implementation ==================== */ >@@ -546,8 +548,8 @@ > * Returns null if the given uri is not associated with any tag library > * 'exposed' in the web application. > */ >- public String[] getTldLocation(String uri) throws JasperException { >- String[] location = >+ public TldLocation getTldLocation(String uri) throws JasperException { >+ TldLocation location = > getOptions().getTldLocationsCache().getLocation(uri); > return location; > } >Index: java/org/apache/jasper/servlet/JspServletWrapper.java >=================================================================== >--- java/org/apache/jasper/servlet/JspServletWrapper.java (revision 907055) >+++ java/org/apache/jasper/servlet/JspServletWrapper.java (working copy) >@@ -35,6 +35,7 @@ > import org.apache.jasper.JspCompilationContext; > import org.apache.jasper.Options; > import org.apache.jasper.compiler.ErrorDispatcher; >+import org.apache.jasper.compiler.JarResource; > import org.apache.jasper.compiler.JavacErrorDetail; > import org.apache.jasper.compiler.JspRuntimeContext; > import org.apache.jasper.compiler.Localizer; >@@ -105,7 +106,7 @@ > String tagFilePath, > TagInfo tagInfo, > JspRuntimeContext rctxt, >- URL tagFileJarUrl) { >+ JarResource tagJarResource) { > > this.isTagFile = true; > this.config = null; // not used >@@ -114,7 +115,7 @@ > this.tripCount = 0; > ctxt = new JspCompilationContext(jspUri, tagInfo, options, > servletContext, this, rctxt, >- tagFileJarUrl); >+ tagJarResource); > } > > public JspCompilationContext getJspEngineContext() { >Index: java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java >=================================================================== >--- java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java (revision 907055) >+++ java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java (working copy) >@@ -195,7 +195,7 @@ > tagInfo = TagFileProcessor.parseTagFileDirectives(pc, > shortName, > path, >- pc.getJspCompilationContext().getTagFileJarUrl(path), >+ pc.getJspCompilationContext().getTagFileJarResource(path), > this); > } catch (JasperException je) { > throw new RuntimeException(je.toString(), je); >Index: java/org/apache/jasper/compiler/JarURLResource.java >=================================================================== >--- java/org/apache/jasper/compiler/JarURLResource.java (revision 0) >+++ java/org/apache/jasper/compiler/JarURLResource.java (revision 0) >@@ -0,0 +1,57 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+ >+package org.apache.jasper.compiler; >+ >+import java.io.IOException; >+import java.net.JarURLConnection; >+import java.net.MalformedURLException; >+import java.net.URL; >+import java.util.jar.JarFile; >+ >+public class JarURLResource implements JarResource { >+ >+ private String jarUrl; >+ >+ public JarURLResource(URL jarURL) { >+ this(jarURL.toExternalForm()); >+ } >+ >+ public JarURLResource(String jarUrl) { >+ this.jarUrl = jarUrl; >+ } >+ >+ public JarFile getJarFile() throws IOException { >+ URL jarFileUrl = new URL("jar:" + jarUrl + "!/"); >+ JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection(); >+ conn.setUseCaches(false); >+ conn.connect(); >+ return conn.getJarFile(); >+ } >+ >+ public String getUrl() { >+ return jarUrl; >+ } >+ >+ public URL getEntry(String name) { >+ try { >+ return new URL("jar:" + jarUrl + "!/" + name); >+ } catch (MalformedURLException e) { >+ throw new RuntimeException("", e); >+ } >+ } >+} > >Property changes on: java/org/apache/jasper/compiler/JarURLResource.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain >Added: svn:keywords > + Date Revision >Added: svn:eol-style > + native > >Index: java/org/apache/jasper/compiler/JspDocumentParser.java >=================================================================== >--- java/org/apache/jasper/compiler/JspDocumentParser.java (revision 907055) >+++ java/org/apache/jasper/compiler/JspDocumentParser.java (working copy) >@@ -1267,7 +1267,7 @@ > isPlainUri = true; > } > >- String[] location = ctxt.getTldLocation(uri); >+ TldLocation location = ctxt.getTldLocation(uri); > if (location != null || !isPlainUri) { > if (ctxt.getOptions().isCaching()) { > result = ctxt.getOptions().getCache().get(uri); >Index: java/org/apache/jasper/compiler/TldLocation.java >=================================================================== >--- java/org/apache/jasper/compiler/TldLocation.java (revision 0) >+++ java/org/apache/jasper/compiler/TldLocation.java (revision 0) >@@ -0,0 +1,60 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+ >+package org.apache.jasper.compiler; >+ >+public class TldLocation { >+ >+ private String entryName; >+ private JarResource jar; >+ >+ public TldLocation(String entryName) { >+ this(entryName, (JarResource)null); >+ } >+ >+ public TldLocation(String entryName, String resourceUrl) { >+ this(entryName, getJarResource(resourceUrl)); >+ } >+ >+ public TldLocation(String entryName, JarResource jarResource) { >+ if (entryName == null) { >+ throw new IllegalArgumentException("Tld name is required"); >+ } >+ this.entryName = entryName; >+ this.jar = jarResource; >+ } >+ >+ private static JarResource getJarResource(String resourceUrl) { >+ return (resourceUrl != null) ? new JarURLResource(resourceUrl) : null; >+ } >+ >+ /** >+ * @return The name of the tag library. >+ */ >+ public String getName() { >+ return entryName; >+ } >+ >+ /** >+ * >+ * @return The jar resource the tag library is contained in. >+ * Might return null if the tag library is not contained in jar resource. >+ */ >+ public JarResource getJarResource() { >+ return jar; >+ } >+} > >Property changes on: java/org/apache/jasper/compiler/TldLocation.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain >Added: svn:keywords > + Date Revision >Added: svn:eol-style > + native > >Index: java/org/apache/jasper/compiler/JarResource.java >=================================================================== >--- java/org/apache/jasper/compiler/JarResource.java (revision 0) >+++ java/org/apache/jasper/compiler/JarResource.java (revision 0) >@@ -0,0 +1,45 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+ >+package org.apache.jasper.compiler; >+ >+import java.io.IOException; >+import java.net.URL; >+import java.util.jar.JarFile; >+ >+public interface JarResource { >+ >+ /** >+ * @return The JarFile for this resource. A new instance of JarFile >+ * should be returned on each call. >+ * @throws IOException >+ */ >+ JarFile getJarFile() throws IOException; >+ >+ /** >+ * @return The URL of this resource. May or may not point >+ * to the actual Jar file. >+ */ >+ String getUrl(); >+ >+ /** >+ * @param name >+ * @return The URL for the entry within this resource. >+ */ >+ URL getEntry(String name); >+ >+} > >Property changes on: java/org/apache/jasper/compiler/JarResource.java >___________________________________________________________________ >Added: svn:mime-type > + text/plain >Added: svn:keywords > + Date Revision >Added: svn:eol-style > + native > >Index: java/org/apache/jasper/compiler/ParserController.java >=================================================================== >--- java/org/apache/jasper/compiler/ParserController.java (revision 907055) >+++ java/org/apache/jasper/compiler/ParserController.java (working copy) >@@ -100,7 +100,7 @@ > // respectively. > isTagFile = ctxt.isTagFile(); > directiveOnly = false; >- return doParse(inFileName, null, ctxt.getTagFileJarUrl()); >+ return doParse(inFileName, null, ctxt.getTagFileJarResource()); > } > > /** >@@ -117,7 +117,7 @@ > // respectively. > isTagFile = ctxt.isTagFile(); > directiveOnly = true; >- return doParse(inFileName, null, ctxt.getTagFileJarUrl()); >+ return doParse(inFileName, null, ctxt.getTagFileJarResource()); > } > > >@@ -130,11 +130,11 @@ > * or null of the included resource is to be read from the filesystem > */ > public Node.Nodes parse(String inFileName, Node parent, >- URL jarFileUrl) >+ JarResource jarResource) > throws FileNotFoundException, JasperException, IOException { > // For files that are statically included, isTagfile and directiveOnly > // remain unchanged. >- return doParse(inFileName, parent, jarFileUrl); >+ return doParse(inFileName, parent, jarResource); > } > > /** >@@ -146,13 +146,13 @@ > * @param tagFileJarUrl The location of the tag file. > */ > public Node.Nodes parseTagFileDirectives(String inFileName, >- URL tagFileJarUrl) >+ JarResource jarResource) > throws FileNotFoundException, JasperException, IOException { > boolean isTagFileSave = isTagFile; > boolean directiveOnlySave = directiveOnly; > isTagFile = true; > directiveOnly = true; >- Node.Nodes page = doParse(inFileName, null, tagFileJarUrl); >+ Node.Nodes page = doParse(inFileName, null, jarResource); > directiveOnly = directiveOnlySave; > isTagFile = isTagFileSave; > return page; >@@ -174,7 +174,7 @@ > */ > private Node.Nodes doParse(String inFileName, > Node parent, >- URL jarFileUrl) >+ JarResource jarResource) > throws FileNotFoundException, JasperException, IOException { > > Node.Nodes parsedPage = null; >@@ -182,7 +182,7 @@ > isBomPresent = false; > isDefaultPageEncoding = false; > >- JarFile jarFile = getJarFile(jarFileUrl); >+ JarFile jarFile = (jarResource == null) ? null : jarResource.getJarFile(); > String absFileName = resolveFileName(inFileName); > String jspConfigPageEnc = getJspConfigPageEncoding(absFileName); > >@@ -196,7 +196,8 @@ > compiler.getPageInfo().addDependant(absFileName); > } else { > compiler.getPageInfo().addDependant( >- jarFileUrl.toExternalForm() + absFileName.substring(1)); >+ jarResource.getEntry(absFileName.substring(1)).toString()); >+ > } > } > >@@ -237,7 +238,7 @@ > sourceEnc, inStreamReader, > err); > parsedPage = Parser.parse(this, jspReader, parent, isTagFile, >- directiveOnly, jarFileUrl, >+ directiveOnly, jarResource, > sourceEnc, jspConfigPageEnc, > isDefaultPageEncoding, isBomPresent); > } finally { >Index: java/org/apache/jasper/compiler/TagFileProcessor.java >=================================================================== >--- java/org/apache/jasper/compiler/TagFileProcessor.java (revision 907055) >+++ java/org/apache/jasper/compiler/TagFileProcessor.java (working copy) >@@ -489,7 +489,7 @@ > * @return a TagInfo object assembled from the directives in the tag file. > */ > public static TagInfo parseTagFileDirectives(ParserController pc, >- String name, String path, URL tagFileJarUrl, TagLibraryInfo tagLibInfo) >+ String name, String path, JarResource jarResource, TagLibraryInfo tagLibInfo) > throws JasperException { > > >@@ -497,7 +497,7 @@ > > Node.Nodes page = null; > try { >- page = pc.parseTagFileDirectives(path, tagFileJarUrl); >+ page = pc.parseTagFileDirectives(path, jarResource); > } catch (FileNotFoundException e) { > err.jspError("jsp.error.file.not.found", path); > } catch (IOException e) { >@@ -518,33 +518,28 @@ > private Class<?> loadTagFile(Compiler compiler, String tagFilePath, > TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException { > >- URL tagFileJarUrl = null; >+ JarResource tagJarResouce = null; > if (tagFilePath.startsWith("/META-INF/")) { >- try { >- tagFileJarUrl = new URL("jar:" + >- compiler.getCompilationContext().getTldLocation( >- tagInfo.getTagLibrary().getURI())[0] + "!/"); >- } catch (MalformedURLException e) { >- // Ignore - tagFileJarUrl will be null >- } >+ tagJarResouce = >+ compiler.getCompilationContext().getTldLocation( >+ tagInfo.getTagLibrary().getURI()).getJarResource(); > } >- String tagFileJarPath; >- if (tagFileJarUrl == null) { >- tagFileJarPath = ""; >+ String wrapperUri; >+ if (tagJarResouce == null) { >+ wrapperUri = tagFilePath; > } else { >- tagFileJarPath = tagFileJarUrl.toString(); >+ wrapperUri = tagJarResouce.getEntry(tagFilePath).toString(); > } > > JspCompilationContext ctxt = compiler.getCompilationContext(); > JspRuntimeContext rctxt = ctxt.getRuntimeContext(); >- String wrapperUri = tagFileJarPath + tagFilePath; > JspServletWrapper wrapper = rctxt.getWrapper(wrapperUri); > > synchronized (rctxt) { > if (wrapper == null) { > wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt > .getOptions(), tagFilePath, tagInfo, ctxt >- .getRuntimeContext(), tagFileJarUrl); >+ .getRuntimeContext(), tagJarResouce); > rctxt.addWrapper(wrapperUri, wrapper); > > // Use same classloader and classpath for compiling tag files >@@ -571,7 +566,7 @@ > JspServletWrapper tempWrapper = new JspServletWrapper(ctxt > .getServletContext(), ctxt.getOptions(), > tagFilePath, tagInfo, ctxt.getRuntimeContext(), >- ctxt.getTagFileJarUrl(tagFilePath)); >+ ctxt.getTagFileJarResource(tagFilePath)); > tagClazz = tempWrapper.loadTagFilePrototype(); > tempVector.add(tempWrapper.getJspEngineContext() > .getCompiler()); >@@ -625,15 +620,14 @@ > String tagFilePath = tagFileInfo.getPath(); > if (tagFilePath.startsWith("/META-INF/")) { > // For tags in JARs, add the TLD and the tag as a dependency >- String[] location = >+ TldLocation location = > compiler.getCompilationContext().getTldLocation( > tagFileInfo.getTagInfo().getTagLibrary().getURI()); >+ JarResource jarResource = location.getJarResource(); > // Add TLD >- pageInfo.addDependant("jar:" + location[0] + "!/" + >- location[1]); >+ pageInfo.addDependant(jarResource.getEntry(location.getName()).toString()); > // Add Tag >- pageInfo.addDependant("jar:" + location[0] + "!" + >- tagFilePath); >+ pageInfo.addDependant(jarResource.getEntry(tagFilePath.substring(1)).toString()); > } else { > pageInfo.addDependant(tagFilePath); > } >Index: java/org/apache/jasper/compiler/TldLocationsCache.java >=================================================================== >--- java/org/apache/jasper/compiler/TldLocationsCache.java (revision 907055) >+++ java/org/apache/jasper/compiler/TldLocationsCache.java (working copy) >@@ -96,7 +96,7 @@ > * [0] The location > * [1] If the location is a jar file, this is the location of the tld. > */ >- private Hashtable<String, String[]> mappings; >+ private Hashtable<String, TldLocation> mappings; > > private boolean initialized; > private ServletContext ctxt; >@@ -108,7 +108,7 @@ > */ > public TldLocationsCache(ServletContext ctxt) { > this.ctxt = ctxt; >- mappings = new Hashtable<String, String[]>(); >+ mappings = new Hashtable<String, TldLocation>(); > initialized = false; > } > >@@ -150,7 +150,7 @@ > * Returns null if the uri is not associated with any tag library 'exposed' > * in the web application. > */ >- public String[] getLocation(String uri) throws JasperException { >+ public TldLocation getLocation(String uri) throws JasperException { > if (!initialized) { > init(); > } >@@ -262,12 +262,13 @@ > continue; > if (uriType(tagLoc) == NOROOT_REL_URI) > tagLoc = "/WEB-INF/" + tagLoc; >- String tagLoc2 = null; >+ TldLocation location; > if (tagLoc.endsWith(JAR_EXT)) { >- tagLoc = ctxt.getResource(tagLoc).toString(); >- tagLoc2 = "META-INF/taglib.tld"; >+ location = new TldLocation("META-INF/taglib.tld", ctxt.getResource(tagLoc).toString()); >+ } else { >+ location = new TldLocation(tagLoc); > } >- mappings.put(tagUri, new String[] { tagLoc, tagLoc2 }); >+ mappings.put(tagUri, location); > } > } finally { > if (webXml != null) { >@@ -422,7 +423,13 @@ > // Add implicit map entry only if its uri is not already > // present in the map > if (uri != null && mappings.get(uri) == null) { >- mappings.put(uri, new String[]{ resourcePath, entryName }); >+ TldLocation location; >+ if (entryName == null) { >+ location = new TldLocation(resourcePath); >+ } else { >+ location = new TldLocation(entryName, resourcePath); >+ } >+ mappings.put(uri, location); > } > } catch (JasperException e) { > // Hack - makes exception handling simpler >Index: java/org/apache/jasper/compiler/Parser.java >=================================================================== >--- java/org/apache/jasper/compiler/Parser.java (revision 907055) >+++ java/org/apache/jasper/compiler/Parser.java (working copy) >@@ -60,7 +60,7 @@ > > private boolean directivesOnly; > >- private URL jarFileUrl; >+ private JarResource jarResource; > > private PageInfo pageInfo; > >@@ -79,7 +79,7 @@ > * The constructor > */ > private Parser(ParserController pc, JspReader reader, boolean isTagFile, >- boolean directivesOnly, URL jarFileUrl) { >+ boolean directivesOnly, JarResource jarResource) { > this.parserController = pc; > this.ctxt = pc.getJspCompilationContext(); > this.pageInfo = pc.getCompiler().getPageInfo(); >@@ -88,7 +88,7 @@ > this.scriptlessCount = 0; > this.isTagFile = isTagFile; > this.directivesOnly = directivesOnly; >- this.jarFileUrl = jarFileUrl; >+ this.jarResource = jarResource; > start = reader.mark(); > } > >@@ -106,12 +106,12 @@ > */ > public static Node.Nodes parse(ParserController pc, JspReader reader, > Node parent, boolean isTagFile, boolean directivesOnly, >- URL jarFileUrl, String pageEnc, String jspConfigPageEnc, >+ JarResource jarResource, String pageEnc, String jspConfigPageEnc, > boolean isDefaultPageEncoding, boolean isBomPresent) > throws JasperException { > > Parser parser = new Parser(pc, reader, isTagFile, directivesOnly, >- jarFileUrl); >+ jarResource); > > Node.Root root = new Node.Root(reader.mark(), parent, false); > root.setPageEncoding(pageEnc); >@@ -292,7 +292,7 @@ > } > > try { >- parserController.parse(file, parent, jarFileUrl); >+ parserController.parse(file, parent, jarResource); > } catch (FileNotFoundException ex) { > err.jspError(start, "jsp.error.file.not.found", file); > } catch (Exception ex) { >@@ -381,7 +381,7 @@ > .getCache().get(uri); > } > if (impl == null) { >- String[] location = ctxt.getTldLocation(uri); >+ TldLocation location = ctxt.getTldLocation(uri); > impl = new TagLibraryInfoImpl(ctxt, parserController, > pageInfo, prefix, uri, location, err); > if (ctxt.getOptions().isCaching()) { >@@ -391,8 +391,8 @@ > // Current compilation context needs location of cached > // tag files > for (TagFileInfo info : impl.getTagFiles()) { >- ctxt.setTagFileJarUrl(info.getPath(), >- ctxt.getTagFileJarUrl()); >+ ctxt.setTagFileJarResource(info.getPath(), >+ ctxt.getTagFileJarResource()); > } > } > pageInfo.addTaglib(uri, impl); >Index: java/org/apache/jasper/compiler/TagLibraryInfoImpl.java >=================================================================== >--- java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (revision 907055) >+++ java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (working copy) >@@ -137,7 +137,7 @@ > * Constructor. > */ > public TagLibraryInfoImpl(JspCompilationContext ctxt, ParserController pc, PageInfo pi, >- String prefix, String uriIn, String[] location, ErrorDispatcher err) >+ String prefix, String uriIn, TldLocation location, ErrorDispatcher err) > throws JasperException { > super(prefix, uriIn); > >@@ -146,7 +146,6 @@ > this.pi = pi; > this.err = err; > InputStream in = null; >- JarFile jarFile = null; > > if (location == null) { > // The URI points to the TLD itself or to a JAR file in which the >@@ -154,39 +153,34 @@ > location = generateTLDLocation(uri, ctxt); > } > >+ String tldName = location.getName(); >+ JarResource jarResource = location.getJarResource(); > try { >- if (location[1] == null) { >+ if (jarResource == null) { > // Location points directly to TLD file > try { >- in = getResourceAsStream(location[0]); >+ in = getResourceAsStream(tldName); > if (in == null) { >- throw new FileNotFoundException(location[0]); >+ throw new FileNotFoundException(tldName); > } > } catch (FileNotFoundException ex) { >- err.jspError("jsp.error.file.not.found", location[0]); >+ err.jspError("jsp.error.file.not.found", tldName); > } > >- parseTLD(location[0], in, null); >+ parseTLD(tldName, in, null); > // Add TLD to dependency list > PageInfo pageInfo = ctxt.createCompiler().getPageInfo(); > if (pageInfo != null) { >- pageInfo.addDependant(location[0]); >+ pageInfo.addDependant(tldName); > } > } else { > // Tag library is packaged in JAR file > try { >- URL jarFileUrl = new URL("jar:" + location[0] + "!/"); >- JarURLConnection conn = (JarURLConnection) jarFileUrl >- .openConnection(); >- conn.setUseCaches(false); >- conn.connect(); >- jarFile = conn.getJarFile(); >- ZipEntry jarEntry = jarFile.getEntry(location[1]); >- in = jarFile.getInputStream(jarEntry); >- parseTLD(location[0], in, jarFileUrl); >+ in = jarResource.getEntry(tldName).openStream(); >+ parseTLD(jarResource.getUrl(), in, jarResource); > } catch (Exception ex) { >- err.jspError("jsp.error.tld.unable_to_read", location[0], >- location[1], ex.toString()); >+ err.jspError("jsp.error.tld.unable_to_read", jarResource.getUrl(), >+ jarResource.getUrl(), ex.toString()); > } > } > } finally { >@@ -196,12 +190,6 @@ > } catch (Throwable t) { > } > } >- if (jarFile != null) { >- try { >- jarFile.close(); >- } catch (Throwable t) { >- } >- } > } > > } >@@ -217,7 +205,7 @@ > * in The TLD's input stream @param jarFileUrl The JAR file containing the > * TLD, or null if the tag library is not packaged in a JAR > */ >- private void parseTLD(String uri, InputStream in, URL jarFileUrl) >+ private void parseTLD(String uri, InputStream in, JarResource jarResource) > throws JasperException { > Vector<TagInfo> tagVector = new Vector<TagInfo>(); > Vector<TagFileInfo> tagFileVector = new Vector<TagFileInfo>(); >@@ -257,7 +245,7 @@ > tagVector.addElement(createTagInfo(element, jspversion)); > else if ("tag-file".equals(tname)) { > TagFileInfo tagFileInfo = createTagFileInfo(element, >- jarFileUrl); >+ jarResource); > tagFileVector.addElement(tagFileInfo); > } else if ("function".equals(tname)) { // JSP2.0 > FunctionInfo funcInfo = createFunctionInfo(element); >@@ -314,7 +302,7 @@ > * the name of the TLD entry in the jar file, which is hardcoded to > * META-INF/taglib.tld. > */ >- private String[] generateTLDLocation(String uri, JspCompilationContext ctxt) >+ private TldLocation generateTLDLocation(String uri, JspCompilationContext ctxt) > throws JasperException { > > int uriType = TldLocationsCache.uriType(uri); >@@ -325,24 +313,21 @@ > uri = ctxt.resolveRelativeUri(uri); > } > >- String[] location = new String[2]; >- location[0] = uri; >- if (location[0].endsWith(".jar")) { >+ if (uri.endsWith(".jar")) { > URL url = null; > try { >- url = ctxt.getResource(location[0]); >+ url = ctxt.getResource(uri); > } catch (Exception ex) { >- err.jspError("jsp.error.tld.unable_to_get_jar", location[0], ex >+ err.jspError("jsp.error.tld.unable_to_get_jar", uri, ex > .toString()); > } > if (url == null) { >- err.jspError("jsp.error.tld.missing_jar", location[0]); >+ err.jspError("jsp.error.tld.missing_jar", uri); > } >- location[0] = url.toString(); >- location[1] = "META-INF/taglib.tld"; >+ return new TldLocation("META-INF/taglib.tld", url.toString()); >+ } else { >+ return new TldLocation(uri); > } >- >- return location; > } > > private TagInfo createTagInfo(TreeNode elem, String jspVersion) >@@ -453,7 +438,7 @@ > * > * @return TagInfo corresponding to tag file directives > */ >- private TagFileInfo createTagFileInfo(TreeNode elem, URL jarFileUrl) >+ private TagFileInfo createTagFileInfo(TreeNode elem, JarResource jarResource) > throws JasperException { > > String name = null; >@@ -488,13 +473,13 @@ > // See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 > // This needs to be removed once all the broken code that depends on > // it has been removed >- ctxt.setTagFileJarUrl(path, jarFileUrl); >+ ctxt.setTagFileJarResource(path, jarResource); > } else if (!path.startsWith("/WEB-INF/tags")) { > err.jspError("jsp.error.tagfile.illegalPath", path); > } > > TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives( >- parserController, name, path, jarFileUrl, this); >+ parserController, name, path, jarResource, this); > return new TagFileInfo(name, path, tagInfo); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 48689
: 24933