Author: markt Date: Sun Apr 25 12:56:32 2010 New Revision: 937791 URL: http://svn.apache.org/viewvc?rev=937791&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48689 Access TLD files through a new JarResource interface to make extending Jasper simpler, particularly in OSGi environments. Patch provided by Jarek Gawor.
Added: tomcat/trunk/java/org/apache/jasper/compiler/JarResource.java (with props) tomcat/trunk/java/org/apache/jasper/compiler/JarURLResource.java (with props) tomcat/trunk/java/org/apache/jasper/compiler/TldLocation.java (with props) Modified: tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java tomcat/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java tomcat/trunk/java/org/apache/jasper/compiler/Parser.java tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java (original) +++ tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java Sun Apr 25 12:56:32 2010 @@ -30,10 +30,12 @@ import javax.servlet.ServletContext; 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 @@ public class JspCompilationContext { 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 @@ public class JspCompilationContext { 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 @@ public class JspCompilationContext { } 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 @@ public class JspCompilationContext { 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 @@ public class JspCompilationContext { 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 { // May not be in a JAR in some IDE environments result = context.getResource(canonicalURI(res)); @@ -333,12 +335,12 @@ public class JspCompilationContext { * 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); } /** @@ -347,8 +349,8 @@ public class JspCompilationContext { * 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 ==================== */ @@ -549,8 +551,8 @@ public class JspCompilationContext { * 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; } Modified: tomcat/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java Sun Apr 25 12:56:32 2010 @@ -195,7 +195,7 @@ class ImplicitTagLibraryInfo extends Tag tagInfo = TagFileProcessor.parseTagFileDirectives(pc, shortName, path, - pc.getJspCompilationContext().getTagFileJarUrl(path), + pc.getJspCompilationContext().getTagFileJarResource(path), this); } catch (JasperException je) { throw new RuntimeException(je.toString(), je); Added: tomcat/trunk/java/org/apache/jasper/compiler/JarResource.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JarResource.java?rev=937791&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/JarResource.java (added) +++ tomcat/trunk/java/org/apache/jasper/compiler/JarResource.java Sun Apr 25 12:56:32 2010 @@ -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); + +} Propchange: tomcat/trunk/java/org/apache/jasper/compiler/JarResource.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/java/org/apache/jasper/compiler/JarURLResource.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JarURLResource.java?rev=937791&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/JarURLResource.java (added) +++ tomcat/trunk/java/org/apache/jasper/compiler/JarURLResource.java Sun Apr 25 12:56:32 2010 @@ -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); + } + } +} Propchange: tomcat/trunk/java/org/apache/jasper/compiler/JarURLResource.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java Sun Apr 25 12:56:32 2010 @@ -1271,7 +1271,7 @@ class JspDocumentParser 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); Modified: tomcat/trunk/java/org/apache/jasper/compiler/Parser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Parser.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Parser.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Parser.java Sun Apr 25 12:56:32 2010 @@ -60,7 +60,7 @@ class Parser implements TagConstants { private boolean directivesOnly; - private URL jarFileUrl; + private JarResource jarResource; private PageInfo pageInfo; @@ -79,7 +79,7 @@ class Parser implements TagConstants { * 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 @@ class Parser implements TagConstants { this.scriptlessCount = 0; this.isTagFile = isTagFile; this.directivesOnly = directivesOnly; - this.jarFileUrl = jarFileUrl; + this.jarResource = jarResource; start = reader.mark(); } @@ -106,12 +106,12 @@ class Parser implements TagConstants { */ 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); @@ -295,7 +295,7 @@ class Parser implements TagConstants { } 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) { @@ -384,7 +384,7 @@ class Parser implements TagConstants { .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()) { @@ -394,8 +394,8 @@ class Parser implements TagConstants { // 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); Modified: tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/ParserController.java Sun Apr 25 12:56:32 2010 @@ -100,7 +100,7 @@ class ParserController implements TagCon // respectively. isTagFile = ctxt.isTagFile(); directiveOnly = false; - return doParse(inFileName, null, ctxt.getTagFileJarUrl()); + return doParse(inFileName, null, ctxt.getTagFileJarResource()); } /** @@ -117,7 +117,7 @@ class ParserController implements TagCon // respectively. isTagFile = ctxt.isTagFile(); directiveOnly = true; - return doParse(inFileName, null, ctxt.getTagFileJarUrl()); + return doParse(inFileName, null, ctxt.getTagFileJarResource()); } @@ -130,11 +130,11 @@ class ParserController implements TagCon * 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 @@ class ParserController implements TagCon * @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 @@ class ParserController implements TagCon */ private Node.Nodes doParse(String inFileName, Node parent, - URL jarFileUrl) + JarResource jarResource) throws FileNotFoundException, JasperException, IOException { Node.Nodes parsedPage = null; @@ -182,7 +182,7 @@ class ParserController implements TagCon 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 @@ class ParserController implements TagCon compiler.getPageInfo().addDependant(absFileName); } else { compiler.getPageInfo().addDependant( - jarFileUrl.toExternalForm() + absFileName.substring(1)); + jarResource.getEntry(absFileName.substring(1)).toString()); + } } @@ -237,7 +238,7 @@ class ParserController implements TagCon sourceEnc, inStreamReader, err); parsedPage = Parser.parse(this, jspReader, parent, isTagFile, - directiveOnly, jarFileUrl, + directiveOnly, jarResource, sourceEnc, jspConfigPageEnc, isDefaultPageEncoding, isBomPresent); } finally { Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java Sun Apr 25 12:56:32 2010 @@ -489,7 +489,7 @@ class TagFileProcessor { * @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 @@ class TagFileProcessor { 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 @@ class TagFileProcessor { 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 - } - } - String tagFileJarPath; - if (tagFileJarUrl == null) { - tagFileJarPath = ""; + tagJarResouce = + compiler.getCompilationContext().getTldLocation( + tagInfo.getTagLibrary().getURI()).getJarResource(); + } + 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 @@ class TagFileProcessor { 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 @@ class TagFileProcessor { 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); } Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java Sun Apr 25 12:56:32 2010 @@ -137,7 +137,7 @@ class TagLibraryInfoImpl extends TagLibr * 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 @@ class TagLibraryInfoImpl extends TagLibr 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 @@ class TagLibraryInfoImpl extends TagLibr 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 @@ class TagLibraryInfoImpl extends TagLibr } catch (Throwable t) { } } - if (jarFile != null) { - try { - jarFile.close(); - } catch (Throwable t) { - } - } } } @@ -217,7 +205,7 @@ class TagLibraryInfoImpl extends TagLibr * 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 @@ class TagLibraryInfoImpl extends TagLibr 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 @@ class TagLibraryInfoImpl extends TagLibr * 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 @@ class TagLibraryInfoImpl extends TagLibr 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 @@ class TagLibraryInfoImpl extends TagLibr * * @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 @@ class TagLibraryInfoImpl extends TagLibr // 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); } Added: tomcat/trunk/java/org/apache/jasper/compiler/TldLocation.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TldLocation.java?rev=937791&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TldLocation.java (added) +++ tomcat/trunk/java/org/apache/jasper/compiler/TldLocation.java Sun Apr 25 12:56:32 2010 @@ -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; + } +} Propchange: tomcat/trunk/java/org/apache/jasper/compiler/TldLocation.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java Sun Apr 25 12:56:32 2010 @@ -97,7 +97,7 @@ public class TldLocationsCache { * [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; @@ -109,7 +109,7 @@ public class TldLocationsCache { */ public TldLocationsCache(ServletContext ctxt) { this.ctxt = ctxt; - mappings = new Hashtable<String, String[]>(); + mappings = new Hashtable<String, TldLocation>(); initialized = false; } @@ -151,7 +151,7 @@ public class TldLocationsCache { * 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(); } @@ -263,12 +263,13 @@ public class TldLocationsCache { 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) { @@ -423,7 +424,13 @@ public class TldLocationsCache { // 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 Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java (original) +++ tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java Sun Apr 25 12:56:32 2010 @@ -35,6 +35,7 @@ import org.apache.jasper.JasperException 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; @@ -107,7 +108,7 @@ public class JspServletWrapper { String tagFilePath, TagInfo tagInfo, JspRuntimeContext rctxt, - URL tagFileJarUrl) { + JarResource tagJarResource) { this.isTagFile = true; this.config = null; // not used @@ -116,7 +117,7 @@ public class JspServletWrapper { this.tripCount = 0; ctxt = new JspCompilationContext(jspUri, tagInfo, options, servletContext, this, rctxt, - tagFileJarUrl); + tagJarResource); } public JspCompilationContext getJspEngineContext() { Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=937791&r1=937790&r2=937791&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Sun Apr 25 12:56:32 2010 @@ -158,6 +158,11 @@ <bug>48358</bug>: Add support for limiting the number of JSPs that are loaded at any one time. Based on a patch by Isabel Drost. (markt) </add> + <add> + <bug>48689</bug>: Access TLD files through a new JarResource interface + to make extending Jasper simpler, particularly in OSGi environments. + Patch provided by Jarek Gawor. (markt) + </add> </changelog> </subsection> <subsection name="High Availability"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org