Author: markt Date: Wed Nov 13 14:52:53 2013 New Revision: 1541538 URL: http://svn.apache.org/r1541538 Log: Make the web application path available to the TldResourcePath
Modified: tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java Modified: tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java?rev=1541538&r1=1541537&r2=1541538&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java (original) +++ tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java Wed Nov 13 14:52:53 2013 @@ -176,9 +176,10 @@ public class TldScanner { if (resourcePath.endsWith(".jar")) { // if the path points to a jar file, the TLD is presumed to be // inside at META-INF/taglib.tld - tldResourcePath = new TldResourcePath(url, "META-INF/taglib.tld"); + tldResourcePath = new TldResourcePath( + url, resourcePath, "META-INF/taglib.tld"); } else { - tldResourcePath = new TldResourcePath(url); + tldResourcePath = new TldResourcePath(url, resourcePath); } // parse TLD but store using the URI supplied in the descriptor TaglibXml tld = tldParser.parse(tldResourcePath); @@ -235,7 +236,7 @@ public class TldScanner { private void parseTld(String resourcePath) throws IOException, SAXException { TldResourcePath tldResourcePath = - new TldResourcePath(context.getResource(resourcePath)); + new TldResourcePath(context.getResource(resourcePath), resourcePath); parseTld(tldResourcePath); } @@ -262,7 +263,8 @@ public class TldScanner { private boolean jarFound = false; @Override - public void scan(JarURLConnection urlConn, boolean isWebapp) throws IOException { + public void scan(JarURLConnection urlConn, String webappPath, + boolean isWebapp) throws IOException { if (!jarFound) { jarFound = true; } @@ -280,7 +282,7 @@ public class TldScanner { } found = true; TldResourcePath tldResourcePath = - new TldResourcePath(jarURL, entryName); + new TldResourcePath(jarURL, webappPath, entryName); try { parseTld(tldResourcePath); } catch (SAXException e) { @@ -301,7 +303,8 @@ public class TldScanner { } @Override - public void scan(File file, boolean isWebapp) throws IOException { + public void scan(File file, final String webappPath, boolean isWebapp) + throws IOException { if (!jarFound) { jarFound = true; } @@ -320,7 +323,7 @@ public class TldScanner { try { URL url = file.toUri().toURL(); - TldResourcePath path = new TldResourcePath(url); + TldResourcePath path = new TldResourcePath(url, webappPath); parseTld(path); tldFound = true; } catch (SAXException e) { Modified: tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java?rev=1541538&r1=1541537&r2=1541538&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java (original) +++ tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java Wed Nov 13 14:52:53 2013 @@ -30,12 +30,13 @@ public interface JarScannerCallback { * A JAR was found (probably packaged in a WAR) and may be accessed for * further processing via the provided URL connection. * - * @param urlConn The connection to the identified JAR - * @param isWebapp Indicates if the JAR was found within a web application. - * If <code>false</code> the JAR should be treated as - * being provided by the container + * @param urlConn The connection to the identified JAR + * @param webappPath The path, if any, to the JAR within the web application + * @param isWebapp Indicates if the JAR was found within a web + * application. If <code>false</code> the JAR should + * be treated as being provided by the container */ - public void scan(JarURLConnection urlConn, boolean isWebapp) + public void scan(JarURLConnection urlConn, String webappPath, boolean isWebapp) throws IOException; /** @@ -43,12 +44,14 @@ public interface JarScannerCallback { * class path) and may be accessed for further processing via the provided * file. * - * @param file The file for the identified JAR. - * @param isWebapp Indicates if the JAR was found within a web application. - * If <code>false</code> the JAR should be treated as - * being provided by the container + * @param file The file for the identified JAR. + * @param webappPath The path, if any, to the file within the web + * application + * @param isWebapp Indicates if the JAR was found within a web + * application. If <code>false</code> the JAR should + * be treated as being provided by the container */ - public void scan(File file, boolean isWebapp) throws IOException; + public void scan(File file, String webappPath, boolean isWebapp) throws IOException; /** * A directory structure was found within the web application at Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java?rev=1541538&r1=1541537&r2=1541538&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java Wed Nov 13 14:52:53 2013 @@ -40,25 +40,29 @@ import org.apache.tomcat.util.scan.JarFa */ public class TldResourcePath { private final URL url; + private final String webappPath; private final String entryName; /** * Constructor identifying a TLD resource directly. * - * @param url the location of the TLD + * @param url the location of the TLD + * @param webappPath the web application path, if any, of the TLD */ - public TldResourcePath(URL url) { - this(url, null); + public TldResourcePath(URL url, String webappPath) { + this(url, webappPath, null); } /** * Constructor identifying a TLD packaged within a JAR file. * - * @param url the location of the JAR - * @param entryName the name of the entry in the JAR + * @param url the location of the JAR + * @param webappPath the web application path, if any, of the JAR + * @param entryName the name of the entry in the JAR */ - public TldResourcePath(URL url, String entryName) { + public TldResourcePath(URL url, String webappPath, String entryName) { this.url = url; + this.webappPath = webappPath; this.entryName = entryName; } @@ -72,6 +76,17 @@ public class TldResourcePath { } /** + * Returns the path within the web application, if any, that the resource + * returned by {@link #getUrl()} was obtained from. + * + * @return the web application path or @null if the the resource is not + * located within a web application + */ + public String getWebappPath() { + return webappPath; + } + + /** * Returns the name of the JAR entry that contains the TLD. * May be null to indicate the URL refers directly to the TLD itself. * @@ -121,11 +136,17 @@ public class TldResourcePath { } TldResourcePath other = (TldResourcePath) o; - return url.equals(other.url) && Objects.equals(entryName, other.entryName); + + return url.equals(other.url) && + Objects.equals(webappPath, other.webappPath) && + Objects.equals(entryName, other.entryName); } @Override public int hashCode() { - return url.hashCode() * 31 + Objects.hashCode(entryName); + int result = url.hashCode(); + result = result * 31 + Objects.hashCode(webappPath); + result = result * 31 + Objects.hashCode(entryName); + return result; } } Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java?rev=1541538&r1=1541537&r2=1541538&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/web/FragmentJarScannerCallback.java Wed Nov 13 14:52:53 2013 @@ -48,7 +48,7 @@ public class FragmentJarScannerCallback } @Override - public void scan(JarURLConnection jarConn, boolean isWebapp) + public void scan(JarURLConnection jarConn, String webappPath, boolean isWebapp) throws IOException { URL url = jarConn.getURL(); @@ -104,7 +104,7 @@ public class FragmentJarScannerCallback } @Override - public void scan(File file, boolean isWebapp) throws IOException { + public void scan(File file, String webappPath, boolean isWebapp) throws IOException { InputStream stream = null; WebXml fragment = new WebXml(); Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java?rev=1541538&r1=1541537&r2=1541538&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java Wed Nov 13 14:52:53 2013 @@ -155,7 +155,7 @@ public class StandardJarScanner implemen URL url = null; try { url = context.getResource(path); - process(scanType, callback, url, true); + process(scanType, callback, url, path, true); } catch (IOException e) { log.warn(sm.getString("jarScan.webinflibFail", url), e); } @@ -228,7 +228,7 @@ public class StandardJarScanner implemen "jarScan.classloaderJarScan", urls[i])); } try { - process(scanType, callback, urls[i], isWebapp); + process(scanType, callback, urls[i], null, isWebapp); } catch (IOException ioe) { log.warn(sm.getString( "jarScan.classloaderFail", urls[i]), @@ -282,7 +282,7 @@ public class StandardJarScanner implemen * and all directories. */ private void process(JarScanType scanType, JarScannerCallback callback, - URL url, boolean isWebapp) throws IOException { + URL url, String webappPath, boolean isWebapp) throws IOException { if (log.isTraceEnabled()) { log.trace(sm.getString("jarScan.jarUrlStart", url)); @@ -290,7 +290,7 @@ public class StandardJarScanner implemen URLConnection conn = url.openConnection(); if (conn instanceof JarURLConnection) { - callback.scan((JarURLConnection) conn, isWebapp); + callback.scan((JarURLConnection) conn, webappPath, isWebapp); } else { String urlStr = url.toString(); if (urlStr.startsWith("file:") || urlStr.startsWith("jndi:") || @@ -298,7 +298,7 @@ public class StandardJarScanner implemen if (urlStr.endsWith(Constants.JAR_EXT)) { URL jarURL = new URL("jar:" + urlStr + "!/"); callback.scan((JarURLConnection) jarURL.openConnection(), - isWebapp); + webappPath, isWebapp); } else { File f; try { @@ -308,15 +308,15 @@ public class StandardJarScanner implemen URL jarURL = new URL("jar:" + urlStr + "!/"); callback.scan( (JarURLConnection) jarURL.openConnection(), - isWebapp); + webappPath, isWebapp); } else if (f.isDirectory()) { if (scanType == JarScanType.PLUGGABILITY) { - callback.scan(f, isWebapp); + callback.scan(f, webappPath, isWebapp); } else { File metainf = new File(f.getAbsoluteFile() + File.separator + "META-INF"); if (metainf.isDirectory()) { - callback.scan(f, isWebapp); + callback.scan(f, webappPath, isWebapp); } } } Modified: tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java?rev=1541538&r1=1541537&r2=1541538&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java (original) +++ tomcat/trunk/test/org/apache/tomcat/util/descriptor/tld/TestTldParser.java Wed Nov 13 14:52:53 2013 @@ -166,7 +166,7 @@ public class TestTldParser { private TaglibXml parse(String pathname) throws IOException, SAXException { File file = new File(pathname); - TldResourcePath path = new TldResourcePath(file.toURI().toURL()); + TldResourcePath path = new TldResourcePath(file.toURI().toURL(), null); return parser.parse(path); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org