SLING-7044 : Scripted tag files are not found

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804923 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java b/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java
index c81b977..2dc6f46 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/SlingTldLocationsCache.java
@@ -46,7 +46,7 @@
 
     private static final String TLD_SCHEME = "tld:";
 
-    private final Map<String, TldLocationEntry> tldLocations = new HashMap<String, TldLocationEntry>();
+    private final Map<String, TldLocationEntry> tldLocations = new HashMap<>();
 
     private ServiceRegistration serviceRegistration;
 
@@ -62,7 +62,7 @@
             }
         }
 
-        Dictionary<String, Object> tldConfigPrinterProperties = new Hashtable<String, Object>();
+        Dictionary<String, Object> tldConfigPrinterProperties = new Hashtable<>();
         tldConfigPrinterProperties.put("felix.webconsole.label", "jsptaglibs");
         tldConfigPrinterProperties.put("felix.webconsole.title", "JSP Taglibs");
         tldConfigPrinterProperties.put("felix.webconsole.configprinter.modes", "always");
@@ -81,6 +81,7 @@
 
     // ---------- Tld Location URL support -------------------------------------
 
+    @Override
     public void bundleChanged(final BundleEvent event) {
         if ( event.getType() == BundleEvent.RESOLVED ) {
             this.addBundle(event.getBundle());
@@ -89,7 +90,7 @@
         }
     }
 
-    URL getTldLocationURL(String tldLocation) {
+    public URL getTldLocationURL(String tldLocation) {
         if (tldLocation.startsWith(TLD_SCHEME)) {
             tldLocation = tldLocation.substring(TLD_SCHEME.length());
 
@@ -111,8 +112,9 @@
     @Override
     public String[] getLocation(final String uri) throws JasperException {
         synchronized (tldLocations) {
-            if (tldLocations.containsKey(uri)) {
-                return new String[] { TLD_SCHEME + uri, null };
+            final TldLocationEntry entry = tldLocations.get(uri);
+            if ( entry != null ) {
+                return new String[] { TLD_SCHEME + uri, entry.getTldURL().toString() };
             }
         }
 
@@ -187,7 +189,7 @@
 
     public void printConfiguration(final PrintWriter pw) {
         pw.println("Currently available JSP Taglibs:");
-        final SortedMap<String, String> taglibs = new TreeMap<String, String>();
+        final SortedMap<String, String> taglibs = new TreeMap<>();
 
         for (final Map.Entry<String, TldLocationEntry> entry : tldLocations.entrySet()) {
             final long bundleId = entry.getValue().getBundleId();
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/EmbeddedServletOptions.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/EmbeddedServletOptions.java
deleted file mode 100644
index 827b81b..0000000
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/EmbeddedServletOptions.java
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
- * 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.sling.scripting.jsp.jasper;
-
-import java.io.File;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.apache.sling.scripting.jsp.jasper.compiler.JspConfig;
-import org.apache.sling.scripting.jsp.jasper.compiler.Localizer;
-import org.apache.sling.scripting.jsp.jasper.compiler.OriginalTldLocationsCache;
-import org.apache.sling.scripting.jsp.jasper.compiler.TagPluginManager;
-import org.apache.sling.scripting.jsp.jasper.compiler.TldLocationsCache;
-import org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils;
-
-/**
- * A class to hold all init parameters specific to the JSP engine.
- *
- * @author Anil K. Vijendran
- * @author Hans Bergsten
- * @author Pierre Delisle
- */
-public final class EmbeddedServletOptions implements Options {
-
-    // Logger
-    private Log log = LogFactory.getLog(EmbeddedServletOptions.class);
-
-    private Properties settings = new Properties();
-
-    /**
-     * Should Ant fork its java compiles of JSP pages.
-     */
-    public boolean fork = true;
-
-    /**
-     * Do you want to keep the generated Java files around?
-     */
-    private boolean keepGenerated = true;
-
-    /**
-     * Should white spaces between directives or actions be trimmed?
-     */
-    private boolean trimSpaces = false;
-
-    /**
-     * Determines whether tag handler pooling is enabled.
-     */
-    private boolean isPoolingEnabled = true;
-
-    /**
-     * Do you want support for "mapped" files? This will generate
-     * servlet that has a print statement per line of the JSP file.
-     * This seems like a really nice feature to have for debugging.
-     */
-    private boolean mappedFile = true;
-
-    /**
-     * Do you want stack traces and such displayed in the client's
-     * browser? If this is false, such messages go to the standard
-     * error or a log file if the standard error is redirected.
-     */
-    private boolean sendErrorToClient = false;
-
-    /**
-     * Do we want to include debugging information in the class file?
-     */
-    private boolean classDebugInfo = true;
-
-    /**
-     * Is the generation of SMAP info for JSR45 debuggin suppressed?
-     */
-    private boolean isSmapSuppressed = false;
-
-    /**
-     * Should SMAP info for JSR45 debugging be dumped to a file?
-     */
-    private boolean isSmapDumped = false;
-
-    /**
-     * Are Text strings to be generated as char arrays?
-     */
-    private boolean genStringAsCharArray = false;
-
-    private boolean errorOnUseBeanInvalidClassAttribute = true;
-
-    /**
-     * I want to see my generated servlets. Which directory are they
-     * in?
-     */
-    private String scratchDir;
-
-    /**
-     * Need to have this as is for versions 4 and 5 of IE. Can be set from
-     * the initParams so if it changes in the future all that is needed is
-     * to have a jsp initParam of type ieClassId="<value>"
-     */
-    private String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
-
-    /**
-     * What classpath should I use while compiling generated servlets?
-     */
-    private String classpath = null;
-
-    /**
-     * Compiler to use.
-     */
-    private String compiler = null;
-
-    /**
-     * Compiler target VM.
-     */
-    private String compilerTargetVM = "1.5";
-
-    /**
-     * The compiler source VM.
-     */
-    private String compilerSourceVM = "1.5";
-
-    /**
-     * The compiler class name.
-     */
-    private String compilerClassName = null;
-
-    /**
-     * Cache for the TLD locations
-     */
-    private TldLocationsCache tldLocationsCache = null;
-
-    /**
-     * Jsp config information
-     */
-    private JspConfig jspConfig = null;
-
-    /**
-     * TagPluginManager
-     */
-    private TagPluginManager tagPluginManager = null;
-
-    /**
-     * Java platform encoding to generate the JSP
-     * page servlet.
-     */
-    private String javaEncoding = "UTF8";
-
-    /**
-     * Is generation of X-Powered-By response header enabled/disabled?
-     */
-    private boolean xpoweredBy;
-
-    /**
-     * Should we include a source fragment in exception messages, which could be displayed
-     * to the developer ?
-     */
-    private boolean displaySourceFragment = true;
-
-
-    public String getProperty(String name ) {
-        return settings.getProperty( name );
-    }
-
-    public void setProperty(String name, String value ) {
-        if (name != null && value != null){
-            settings.setProperty( name, value );
-        }
-    }
-
-    /**
-     * Are we keeping generated code around?
-     */
-    public boolean getKeepGenerated() {
-        return keepGenerated;
-    }
-
-    /**
-     * Should white spaces between directives or actions be trimmed?
-     */
-    public boolean getTrimSpaces() {
-        return trimSpaces;
-    }
-
-    public boolean isPoolingEnabled() {
-        return isPoolingEnabled;
-    }
-
-    /**
-     * Are we supporting HTML mapped servlets?
-     */
-    public boolean getMappedFile() {
-        return mappedFile;
-    }
-
-    /**
-     * Should errors be sent to client or thrown into stderr?
-     */
-    public boolean getSendErrorToClient() {
-        return sendErrorToClient;
-    }
-
-    /**
-     * Should class files be compiled with debug information?
-     */
-    public boolean getClassDebugInfo() {
-        return classDebugInfo;
-    }
-
-    /**
-     * Is the generation of SMAP info for JSR45 debuggin suppressed?
-     */
-    public boolean isSmapSuppressed() {
-        return isSmapSuppressed;
-    }
-
-    /**
-     * Should SMAP info for JSR45 debugging be dumped to a file?
-     */
-    public boolean isSmapDumped() {
-        return isSmapDumped;
-    }
-
-    /**
-     * Are Text strings to be generated as char arrays?
-     */
-    public boolean genStringAsCharArray() {
-        return this.genStringAsCharArray;
-    }
-
-    /**
-     * Class ID for use in the plugin tag when the browser is IE.
-     */
-    public String getIeClassId() {
-        return ieClassId;
-    }
-
-    /**
-     * What is my scratch dir?
-     */
-    public String getScratchDir() {
-        return scratchDir;
-    }
-
-    /**
-     * What classpath should I use while compiling the servlets
-     * generated from JSP files?
-     */
-    public String getClassPath() {
-        return classpath;
-    }
-
-    /**
-     * Return <code>null</code> to force use of the <code>JasperLoader</code>.
-     */
-    public ClassLoader getJspClassLoader() {
-        return null;
-    }
-
-    /**
-     * Is generation of X-Powered-By response header enabled/disabled?
-     */
-    public boolean isXpoweredBy() {
-        return xpoweredBy;
-    }
-
-    /**
-     * Compiler to use.
-     */
-    public String getCompiler() {
-        return compiler;
-    }
-
-    /**
-     * @see Options#getCompilerTargetVM
-     */
-    public String getCompilerTargetVM() {
-        return compilerTargetVM;
-    }
-
-    /**
-     * @see Options#getCompilerSourceVM
-     */
-    public String getCompilerSourceVM() {
-        return compilerSourceVM;
-    }
-
-    /**
-     * Java compiler class to use.
-     */
-    public String getCompilerClassName() {
-        return compilerClassName;
-    }
-
-    public boolean getErrorOnUseBeanInvalidClassAttribute() {
-        return errorOnUseBeanInvalidClassAttribute;
-    }
-
-    public void setErrorOnUseBeanInvalidClassAttribute(boolean b) {
-        errorOnUseBeanInvalidClassAttribute = b;
-    }
-
-    public TldLocationsCache getTldLocationsCache() {
-        return tldLocationsCache;
-    }
-
-    public void setTldLocationsCache( TldLocationsCache tldC ) {
-        tldLocationsCache = tldC;
-    }
-
-    public String getJavaEncoding() {
-        return javaEncoding;
-    }
-
-    public boolean getFork() {
-        return fork;
-    }
-
-    public JspConfig getJspConfig() {
-        return jspConfig;
-    }
-
-    public TagPluginManager getTagPluginManager() {
-        return tagPluginManager;
-    }
-
-    /**
-     * Should we include a source fragment in exception messages, which could be displayed
-     * to the developer ?
-     */
-    public boolean getDisplaySourceFragment() {
-        return displaySourceFragment;
-    }
-
-    /**
-     * Create an EmbeddedServletOptions object using data available from
-     * ServletConfig and ServletContext.
-     */
-    public EmbeddedServletOptions(ServletConfig config,
-            ServletContext context) {
-
-        // JVM version numbers
-        try {
-            if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.4) {
-                compilerSourceVM = compilerTargetVM = "1.5";
-            } else {
-                compilerSourceVM = compilerTargetVM = "1.4";
-            }
-        } catch (NumberFormatException e) {
-            // Ignore
-        }
-
-        @SuppressWarnings("unchecked")
-        Enumeration<String> enumeration=config.getInitParameterNames();
-        while( enumeration.hasMoreElements() ) {
-            String k=enumeration.nextElement();
-            String v=config.getInitParameter( k );
-            setProperty( k, v);
-        }
-
-        // quick hack
-        String validating=config.getInitParameter( "validating");
-        if( "false".equals( validating )) ParserUtils.validating=false;
-
-        String keepgen = config.getInitParameter("keepgenerated");
-        if (keepgen != null) {
-            if (keepgen.equalsIgnoreCase("true")) {
-                this.keepGenerated = true;
-            } else if (keepgen.equalsIgnoreCase("false")) {
-                this.keepGenerated = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.keepgen"));
-                }
-            }
-        }
-
-
-        String trimsp = config.getInitParameter("trimSpaces");
-        if (trimsp != null) {
-            if (trimsp.equalsIgnoreCase("true")) {
-                trimSpaces = true;
-            } else if (trimsp.equalsIgnoreCase("false")) {
-                trimSpaces = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.trimspaces"));
-                }
-            }
-        }
-
-        this.isPoolingEnabled = true;
-        String poolingEnabledParam
-        = config.getInitParameter("enablePooling");
-        if (poolingEnabledParam != null
-                && !poolingEnabledParam.equalsIgnoreCase("true")) {
-            if (poolingEnabledParam.equalsIgnoreCase("false")) {
-                this.isPoolingEnabled = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.enablePooling"));
-                }
-            }
-        }
-
-        String mapFile = config.getInitParameter("mappedfile");
-        if (mapFile != null) {
-            if (mapFile.equalsIgnoreCase("true")) {
-                this.mappedFile = true;
-            } else if (mapFile.equalsIgnoreCase("false")) {
-                this.mappedFile = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.mappedFile"));
-                }
-            }
-        }
-
-        String senderr = config.getInitParameter("sendErrToClient");
-        if (senderr != null) {
-            if (senderr.equalsIgnoreCase("true")) {
-                this.sendErrorToClient = true;
-            } else if (senderr.equalsIgnoreCase("false")) {
-                this.sendErrorToClient = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.sendErrToClient"));
-                }
-            }
-        }
-
-        String debugInfo = config.getInitParameter("classdebuginfo");
-        if (debugInfo != null) {
-            if (debugInfo.equalsIgnoreCase("true")) {
-                this.classDebugInfo  = true;
-            } else if (debugInfo.equalsIgnoreCase("false")) {
-                this.classDebugInfo  = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.classDebugInfo"));
-                }
-            }
-        }
-
-        String suppressSmap = config.getInitParameter("suppressSmap");
-        if (suppressSmap != null) {
-            if (suppressSmap.equalsIgnoreCase("true")) {
-                isSmapSuppressed = true;
-            } else if (suppressSmap.equalsIgnoreCase("false")) {
-                isSmapSuppressed = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.suppressSmap"));
-                }
-            }
-        }
-
-        String dumpSmap = config.getInitParameter("dumpSmap");
-        if (dumpSmap != null) {
-            if (dumpSmap.equalsIgnoreCase("true")) {
-                isSmapDumped = true;
-            } else if (dumpSmap.equalsIgnoreCase("false")) {
-                isSmapDumped = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.dumpSmap"));
-                }
-            }
-        }
-
-        String genCharArray = config.getInitParameter("genStrAsCharArray");
-        if (genCharArray != null) {
-            if (genCharArray.equalsIgnoreCase("true")) {
-                genStringAsCharArray = true;
-            } else if (genCharArray.equalsIgnoreCase("false")) {
-                genStringAsCharArray = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.genchararray"));
-                }
-            }
-        }
-
-        String errBeanClass =
-            config.getInitParameter("errorOnUseBeanInvalidClassAttribute");
-        if (errBeanClass != null) {
-            if (errBeanClass.equalsIgnoreCase("true")) {
-                errorOnUseBeanInvalidClassAttribute = true;
-            } else if (errBeanClass.equalsIgnoreCase("false")) {
-                errorOnUseBeanInvalidClassAttribute = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.errBean"));
-                }
-            }
-        }
-
-        String ieClassId = config.getInitParameter("ieClassId");
-        if (ieClassId != null)
-            this.ieClassId = ieClassId;
-
-        String classpath = config.getInitParameter("classpath");
-        if (classpath != null)
-            this.classpath = classpath;
-
-        /*
-         * scratchdir
-         */
-        File scratchDir;
-        String dir = config.getInitParameter("scratchdir");
-        if (dir != null) {
-            scratchDir = new File(dir);
-        } else {
-            // First try the Servlet 2.2 javax.servlet.context.tempdir property
-            scratchDir = (File) context.getAttribute(Constants.TMP_DIR);
-            if (scratchDir == null) {
-                // Not running in a Servlet 2.2 container.
-                // Try to get the JDK 1.2 java.io.tmpdir property
-                dir = System.getProperty("java.io.tmpdir");
-                if (dir != null)
-                    scratchDir = new File(dir);
-            }
-        }
-        if (scratchDir == null) {
-            log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir"));
-            return;
-        }
-
-        if (!(scratchDir.exists() && scratchDir.canRead() &&
-                scratchDir.canWrite() && scratchDir.isDirectory()))
-            log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir",
-                    scratchDir.getAbsolutePath()));
-
-        this.scratchDir = scratchDir.getAbsolutePath();
-        this.compiler = config.getInitParameter("compiler");
-
-        String compilerTargetVM = config.getInitParameter("compilerTargetVM");
-        if(compilerTargetVM != null) {
-            this.compilerTargetVM = compilerTargetVM;
-        }
-
-        String compilerSourceVM = config.getInitParameter("compilerSourceVM");
-        if(compilerSourceVM != null) {
-            this.compilerSourceVM = compilerSourceVM;
-        }
-
-        String javaEncoding = config.getInitParameter("javaEncoding");
-        if (javaEncoding != null) {
-            this.javaEncoding = javaEncoding;
-        }
-
-        String compilerClassName = config.getInitParameter("compilerClassName");
-        if (compilerClassName != null) {
-            this.compilerClassName = compilerClassName;
-        }
-
-        String fork = config.getInitParameter("fork");
-        if (fork != null) {
-            if (fork.equalsIgnoreCase("true")) {
-                this.fork = true;
-            } else if (fork.equalsIgnoreCase("false")) {
-                this.fork = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.fork"));
-                }
-            }
-        }
-
-        String xpoweredBy = config.getInitParameter("xpoweredBy");
-        if (xpoweredBy != null) {
-            if (xpoweredBy.equalsIgnoreCase("true")) {
-                this.xpoweredBy = true;
-            } else if (xpoweredBy.equalsIgnoreCase("false")) {
-                this.xpoweredBy = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.xpoweredBy"));
-                }
-            }
-        }
-
-        String displaySourceFragment = config.getInitParameter("displaySourceFragment");
-        if (displaySourceFragment != null) {
-            if (displaySourceFragment.equalsIgnoreCase("true")) {
-                this.displaySourceFragment = true;
-            } else if (displaySourceFragment.equalsIgnoreCase("false")) {
-                this.displaySourceFragment = false;
-            } else {
-                if (log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage("jsp.warning.displaySourceFragment"));
-                }
-            }
-        }
-
-        // Setup the global Tag Libraries location cache for this
-        // web-application.
-        tldLocationsCache = new OriginalTldLocationsCache(context);
-
-        // Setup the jsp config info for this web app.
-        jspConfig = new JspConfig(context);
-
-        // Create a Tag plugin instance
-        tagPluginManager = new TagPluginManager(context);
-    }
-
-}
-
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
index a8bea31..f0a9a89 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/JspCompilationContext.java
@@ -108,7 +108,7 @@
         }
 
         this.rctxt = rctxt;
-        this.tagFileJarUrls = new HashMap<String, URL>();
+        this.tagFileJarUrls = new HashMap<>();
         this.basePackageName = Constants.JSP_PACKAGE_NAME;
         this.defaultIsSession = defaultIsSession;
     }
@@ -269,6 +269,14 @@
         this.tagFileJarUrls.put(tagFile, tagFileURL);
     }
 
+    public URL getTagFileUrl(String tagFile) {
+        return this.tagFileJarUrls.get("tagfile:" + tagFile);
+    }
+
+    public void setTagFileUrl(String tagFile, URL tagFileURL) {
+        this.tagFileJarUrls.put("tagfile:" + tagFile, tagFileURL);
+    }
+
     /**
      * Returns the JAR file in which the tag file for which this
      * JspCompilationContext was created is packaged, or null if this
@@ -562,7 +570,7 @@
 
     private static final String canonicalURI(String s) {
        if (s == null) return null;
-       StringBuffer result = new StringBuffer();
+       StringBuilder result = new StringBuilder();
        final int len = s.length();
        int pos = 0;
        while (pos < len) {
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspUtil.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspUtil.java
index b937729..8e5ad07 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspUtil.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/JspUtil.java
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
+import java.net.URL;
 import java.util.Vector;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
@@ -612,6 +613,7 @@
      * (not thread-safe)
      * @deprecated
      */
+    @Deprecated
     public static void resetTemporaryVariableName() {
         tempSequenceNumber = 0;
     }
@@ -621,6 +623,7 @@
      * (not thread-safe)
      * @deprecated
      */
+    @Deprecated
     public static String nextTemporaryVariableName() {
         return Constants.TEMP_VARIABLE_NAME_PREFIX + (tempSequenceNumber++);
     }
@@ -834,22 +837,31 @@
 
         InputStream in = null;
 
-    if (jarFile != null) {
-        String jarEntryName = fname.substring(1, fname.length());
-        ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
-        if (jarEntry == null) {
-        err.jspError("jsp.error.file.not.found", fname);
+        if (jarFile != null) {
+            String jarEntryName = fname.substring(1, fname.length());
+            ZipEntry jarEntry = jarFile.getEntry(jarEntryName);
+            if (jarEntry == null) {
+                err.jspError("jsp.error.file.not.found", fname);
+            }
+            in = jarFile.getInputStream(jarEntry);
+        } else {
+            if  ( fname.startsWith(META_INF_TAGS) ) {
+                final URL url = ctxt.getTagFileUrl(fname);
+                if ( url != null ) {
+                    return url.openConnection().getInputStream();
+                }
+            }
+            in = ctxt.getResourceAsStream(fname);
+            if ( in == null ) {
+                in = ctxt.getInputStream(fname);
+            }
         }
-        in = jarFile.getInputStream(jarEntry);
-    } else {
-        in = ctxt.getResourceAsStream(fname);
-    }
 
-    if (in == null) {
-        err.jspError("jsp.error.file.not.found", fname);
-    }
+        if (in == null) {
+             err.jspError("jsp.error.file.not.found", fname);
+        }
 
-    return in;
+        return in;
     }
 
     /**
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/OriginalTldLocationsCache.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/OriginalTldLocationsCache.java
deleted file mode 100644
index b98886a..0000000
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/OriginalTldLocationsCache.java
+++ /dev/null
@@ -1,549 +0,0 @@
-/*
- * 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.sling.scripting.jsp.jasper.compiler;
-
-import java.io.InputStream;
-import java.net.JarURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.net.URLConnection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import javax.servlet.ServletContext;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.apache.sling.scripting.jsp.jasper.Constants;
-import org.apache.sling.scripting.jsp.jasper.JasperException;
-import org.apache.sling.scripting.jsp.jasper.xmlparser.ParserUtils;
-import org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode;
-import org.xml.sax.InputSource;
-
-/**
- * A container for all tag libraries that are defined "globally"
- * for the web application.
- *
- * Tag Libraries can be defined globally in one of two ways:
- *   1. Via <taglib> elements in web.xml:
- *      the uri and location of the tag-library are specified in
- *      the <taglib> element.
- *   2. Via packaged jar files that contain .tld files
- *      within the META-INF directory, or some subdirectory
- *      of it. The taglib is 'global' if it has the <uri>
- *      element defined.
- *
- * A mapping between the taglib URI and its associated TaglibraryInfoImpl
- * is maintained in this container.
- * Actually, that's what we'd like to do. However, because of the
- * way the classes TagLibraryInfo and TagInfo have been defined,
- * it is not currently possible to share an instance of TagLibraryInfo
- * across page invocations. A bug has been submitted to the spec lead.
- * In the mean time, all we do is save the 'location' where the
- * TLD associated with a taglib URI can be found.
- *
- * When a JSP page has a taglib directive, the mappings in this container
- * are first searched (see method getLocation()).
- * If a mapping is found, then the location of the TLD is returned.
- * If no mapping is found, then the uri specified
- * in the taglib directive is to be interpreted as the location for
- * the TLD of this tag library.
- *
- * @author Pierre Delisle
- * @author Jan Luehe
- */
-
-public class OriginalTldLocationsCache extends TldLocationsCache {
-
-    // Logger
-    private Log log = LogFactory.getLog(TldLocationsCache.class);
-
-    /**
-     * The types of URI one may specify for a tag library
-     */
-    public static final int ABS_URI = 0;
-    public static final int ROOT_REL_URI = 1;
-    public static final int NOROOT_REL_URI = 2;
-
-    private static final String WEB_XML = "/WEB-INF/web.xml";
-    private static final String FILE_PROTOCOL = "file:";
-    private static final String JAR_FILE_SUFFIX = ".jar";
-
-    // Names of JARs that are known not to contain any TLDs
-    private static HashSet<String> noTldJars;
-
-    /**
-     * The mapping of the 'global' tag library URI to the location (resource
-     * path) of the TLD associated with that tag library. The location is
-     * returned as a String array:
-     *    [0] The location
-     *    [1] If the location is a jar file, this is the location of the tld.
-     */
-    private Hashtable mappings;
-
-    private boolean initialized;
-    private ServletContext ctxt;
-    private boolean redeployMode;
-
-    //*********************************************************************
-    // Constructor and Initilizations
-
-    /*
-     * Initializes the set of JARs that are known not to contain any TLDs
-     */
-    static {
-        noTldJars = new HashSet<String>();
-        // Bootstrap JARs
-        noTldJars.add("bootstrap.jar");
-        noTldJars.add("commons-daemon.jar");
-        noTldJars.add("tomcat-juli.jar");
-        // Main JARs
-        noTldJars.add("annotations-api.jar");
-        noTldJars.add("catalina.jar");
-        noTldJars.add("catalina-ant.jar");
-        noTldJars.add("catalina-ha.jar");
-        noTldJars.add("catalina-tribes.jar");
-        noTldJars.add("el-api.jar");
-        noTldJars.add("jasper.jar");
-        noTldJars.add("jasper-el.jar");
-        noTldJars.add("jasper-jdt.jar");
-        noTldJars.add("jsp-api.jar");
-        noTldJars.add("servlet-api.jar");
-        noTldJars.add("tomcat-coyote.jar");
-        noTldJars.add("tomcat-dbcp.jar");
-        // i18n JARs
-        noTldJars.add("tomcat-i18n-en.jar");
-        noTldJars.add("tomcat-i18n-es.jar");
-        noTldJars.add("tomcat-i18n-fr.jar");
-        noTldJars.add("tomcat-i18n-ja.jar");
-        // Misc JARs not included with Tomcat
-        noTldJars.add("ant.jar");
-        noTldJars.add("commons-dbcp.jar");
-        noTldJars.add("commons-beanutils.jar");
-        noTldJars.add("commons-fileupload-1.0.jar");
-        noTldJars.add("commons-pool.jar");
-        noTldJars.add("commons-digester.jar");
-        noTldJars.add("commons-logging.jar");
-        noTldJars.add("commons-collections.jar");
-        noTldJars.add("jmx.jar");
-        noTldJars.add("jmx-tools.jar");
-        noTldJars.add("xercesImpl.jar");
-        noTldJars.add("xmlParserAPIs.jar");
-        noTldJars.add("xml-apis.jar");
-        // JARs from J2SE runtime
-        noTldJars.add("sunjce_provider.jar");
-        noTldJars.add("ldapsec.jar");
-        noTldJars.add("localedata.jar");
-        noTldJars.add("dnsns.jar");
-        noTldJars.add("tools.jar");
-        noTldJars.add("sunpkcs11.jar");
-    }
-
-    public OriginalTldLocationsCache(ServletContext ctxt) {
-        this(ctxt, true);
-    }
-
-    /** Constructor.
-     *
-     * @param ctxt the servlet context of the web application in which Jasper
-     * is running
-     * @param redeployMode if true, then the compiler will allow redeploying
-     * a tag library from the same jar, at the expense of slowing down the
-     * server a bit. Note that this may only work on JDK 1.3.1_01a and later,
-     * because of JDK bug 4211817 fixed in this release.
-     * If redeployMode is false, a faster but less capable mode will be used.
-     */
-    public OriginalTldLocationsCache(ServletContext ctxt, boolean redeployMode) {
-        this.ctxt = ctxt;
-        this.redeployMode = redeployMode;
-        mappings = new Hashtable();
-        initialized = false;
-    }
-
-    /**
-     * Sets the list of JARs that are known not to contain any TLDs.
-     *
-     * @param jarNames List of comma-separated names of JAR files that are
-     * known not to contain any TLDs
-     */
-    public static void setNoTldJars(String jarNames) {
-        if (jarNames != null) {
-            noTldJars.clear();
-            StringTokenizer tokenizer = new StringTokenizer(jarNames, ",");
-            while (tokenizer.hasMoreElements()) {
-                noTldJars.add(tokenizer.nextToken());
-            }
-        }
-    }
-
-    /**
-     * Gets the 'location' of the TLD associated with the given taglib 'uri'.
-     *
-     * Returns null if the uri is not associated with any tag library 'exposed'
-     * in the web application. A tag library is 'exposed' either explicitly in
-     * web.xml or implicitly via the uri tag in the TLD of a taglib deployed
-     * in a jar file (WEB-INF/lib).
-     *
-     * @param uri The taglib uri
-     *
-     * @return An array of two Strings: The first element denotes the real
-     * path to the TLD. If the path to the TLD points to a jar file, then the
-     * second element denotes the name of the TLD entry in the jar file.
-     * Returns null if the uri is not associated with any tag library 'exposed'
-     * in the web application.
-     */
-    public String[] getLocation(String uri) throws JasperException {
-        if (!initialized) {
-            init();
-        }
-        return (String[]) mappings.get(uri);
-    }
-
-    /**
-     * Returns the type of a URI:
-     *     ABS_URI
-     *     ROOT_REL_URI
-     *     NOROOT_REL_URI
-     */
-    public static int uriType(String uri) {
-        if (uri.indexOf(':') != -1) {
-            return ABS_URI;
-        } else if (uri.startsWith("/")) {
-            return ROOT_REL_URI;
-        } else {
-            return NOROOT_REL_URI;
-        }
-    }
-
-    private void init() throws JasperException {
-        if (initialized) return;
-        try {
-            processWebDotXml();
-            scanJars();
-            processTldsInFileSystem("/WEB-INF/");
-            initialized = true;
-        } catch (Exception ex) {
-            throw new JasperException(Localizer.getMessage(
-                    "jsp.error.internal.tldinit", ex.getMessage()));
-        }
-    }
-
-    /*
-     * Populates taglib map described in web.xml.
-     */
-    private void processWebDotXml() throws Exception {
-
-        InputStream is = null;
-
-        try {
-            // Acquire input stream to web application deployment descriptor
-            String altDDName = (String)ctxt.getAttribute(
-                                                    Constants.ALT_DD_ATTR);
-            URL uri = null;
-            if (altDDName != null) {
-                try {
-                    uri = new URL(FILE_PROTOCOL+altDDName.replace('\\', '/'));
-                } catch (MalformedURLException e) {
-                    if (log.isWarnEnabled()) {
-                        log.warn(Localizer.getMessage(
-                                            "jsp.error.internal.filenotfound",
-                                            altDDName));
-                    }
-                }
-            } else {
-                uri = ctxt.getResource(WEB_XML);
-                if (uri == null && log.isWarnEnabled()) {
-                    log.warn(Localizer.getMessage(
-                                            "jsp.error.internal.filenotfound",
-                                            WEB_XML));
-                }
-            }
-
-            if (uri == null) {
-                return;
-            }
-            is = uri.openStream();
-            InputSource ip = new InputSource(is);
-            ip.setSystemId(uri.toExternalForm());
-
-            // Parse the web application deployment descriptor
-            TreeNode webtld = null;
-            // altDDName is the absolute path of the DD
-            if (altDDName != null) {
-                webtld = new ParserUtils().parseXMLDocument(altDDName, ip);
-            } else {
-                webtld = new ParserUtils().parseXMLDocument(WEB_XML, ip);
-            }
-
-            // Allow taglib to be an element of the root or jsp-config (JSP2.0)
-            TreeNode jspConfig = webtld.findChild("jsp-config");
-            if (jspConfig != null) {
-                webtld = jspConfig;
-            }
-            Iterator taglibs = webtld.findChildren("taglib");
-            while (taglibs.hasNext()) {
-
-                // Parse the next <taglib> element
-                TreeNode taglib = (TreeNode) taglibs.next();
-                String tagUri = null;
-                String tagLoc = null;
-                TreeNode child = taglib.findChild("taglib-uri");
-                if (child != null)
-                    tagUri = child.getBody();
-                child = taglib.findChild("taglib-location");
-                if (child != null)
-                    tagLoc = child.getBody();
-
-                // Save this location if appropriate
-                if (tagLoc == null)
-                    continue;
-                if (uriType(tagLoc) == NOROOT_REL_URI)
-                    tagLoc = "/WEB-INF/" + tagLoc;
-                String tagLoc2 = null;
-                if (tagLoc.endsWith(JAR_FILE_SUFFIX)) {
-                    tagLoc = ctxt.getResource(tagLoc).toString();
-                    tagLoc2 = "META-INF/taglib.tld";
-                }
-                mappings.put(tagUri, new String[] { tagLoc, tagLoc2 });
-            }
-        } finally {
-            if (is != null) {
-                try {
-                    is.close();
-                } catch (Throwable t) {}
-            }
-        }
-    }
-
-    /**
-     * Scans the given JarURLConnection for TLD files located in META-INF
-     * (or a subdirectory of it), adding an implicit map entry to the taglib
-     * map for any TLD that has a <uri> element.
-     *
-     * @param conn The JarURLConnection to the JAR file to scan
-     * @param ignore true if any exceptions raised when processing the given
-     * JAR should be ignored, false otherwise
-     */
-    private void scanJar(JarURLConnection conn, boolean ignore)
-                throws JasperException {
-
-        JarFile jarFile = null;
-        String resourcePath = conn.getJarFileURL().toString();
-        try {
-            if (redeployMode) {
-                conn.setUseCaches(false);
-            }
-            jarFile = conn.getJarFile();
-            Enumeration entries = jarFile.entries();
-            while (entries.hasMoreElements()) {
-                JarEntry entry = (JarEntry) entries.nextElement();
-                String name = entry.getName();
-                if (!name.startsWith("META-INF/")) continue;
-                if (!name.endsWith(".tld")) continue;
-                InputStream stream = jarFile.getInputStream(entry);
-                try {
-                    String uri = getUriFromTld(resourcePath, stream);
-                    // 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, name });
-                    }
-                } finally {
-                    if (stream != null) {
-                        try {
-                            stream.close();
-                        } catch (Throwable t) {
-                            // do nothing
-                        }
-                    }
-                }
-            }
-        } catch (Exception ex) {
-            if (!redeployMode) {
-                // if not in redeploy mode, close the jar in case of an error
-                if (jarFile != null) {
-                    try {
-                        jarFile.close();
-                    } catch (Throwable t) {
-                        // ignore
-                    }
-                }
-            }
-            if (!ignore) {
-                throw new JasperException(ex);
-            }
-        } finally {
-            if (redeployMode) {
-                // if in redeploy mode, always close the jar
-                if (jarFile != null) {
-                    try {
-                        jarFile.close();
-                    } catch (Throwable t) {
-                        // ignore
-                    }
-                }
-            }
-        }
-    }
-
-    /*
-     * Searches the filesystem under /WEB-INF for any TLD files, and adds
-     * an implicit map entry to the taglib map for any TLD that has a <uri>
-     * element.
-     */
-    private void processTldsInFileSystem(String startPath)
-            throws Exception {
-
-        Set dirList = ctxt.getResourcePaths(startPath);
-        if (dirList != null) {
-            Iterator it = dirList.iterator();
-            while (it.hasNext()) {
-                String path = (String) it.next();
-                if (path.endsWith("/")) {
-                    processTldsInFileSystem(path);
-                }
-                if (!path.endsWith(".tld")) {
-                    continue;
-                }
-                InputStream stream = ctxt.getResourceAsStream(path);
-                String uri = null;
-                try {
-                    uri = getUriFromTld(path, stream);
-                } finally {
-                    if (stream != null) {
-                        try {
-                            stream.close();
-                        } catch (Throwable t) {
-                            // do nothing
-                        }
-                    }
-                }
-                // 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[] { path, null });
-                }
-            }
-        }
-    }
-
-    /*
-     * Returns the value of the uri element of the given TLD, or null if the
-     * given TLD does not contain any such element.
-     */
-    private String getUriFromTld(String resourcePath, InputStream in)
-        throws JasperException
-    {
-        // Parse the tag library descriptor at the specified resource path
-        TreeNode tld = new ParserUtils().parseXMLDocument(resourcePath, in);
-        TreeNode uri = tld.findChild("uri");
-        if (uri != null) {
-            String body = uri.getBody();
-            if (body != null)
-                return body;
-        }
-
-        return null;
-    }
-
-    /*
-     * Scans all JARs accessible to the webapp's classloader and its
-     * parent classloaders for TLDs.
-     *
-     * The list of JARs always includes the JARs under WEB-INF/lib, as well as
-     * all shared JARs in the classloader delegation chain of the webapp's
-     * classloader.
-     *
-     * Considering JARs in the classloader delegation chain constitutes a
-     * Tomcat-specific extension to the TLD search
-     * order defined in the JSP spec. It allows tag libraries packaged as JAR
-     * files to be shared by web applications by simply dropping them in a
-     * location that all web applications have access to (e.g.,
-     * <CATALINA_HOME>/common/lib).
-     *
-     * The set of shared JARs to be scanned for TLDs is narrowed down by
-     * the <tt>noTldJars</tt> class variable, which contains the names of JARs
-     * that are known not to contain any TLDs.
-     */
-    private void scanJars() throws Exception {
-
-        ClassLoader webappLoader
-            = Thread.currentThread().getContextClassLoader();
-        ClassLoader loader = webappLoader;
-
-        while (loader != null) {
-            if (loader instanceof URLClassLoader) {
-                URL[] urls = ((URLClassLoader) loader).getURLs();
-                for (int i=0; i<urls.length; i++) {
-                    URLConnection conn = urls[i].openConnection();
-                    if (conn instanceof JarURLConnection) {
-                        if (needScanJar(loader, webappLoader,
-                                        ((JarURLConnection) conn).getJarFile().getName())) {
-                            scanJar((JarURLConnection) conn, true);
-                        }
-                    } else {
-                        String urlStr = urls[i].toString();
-                        if (urlStr.startsWith(FILE_PROTOCOL)
-                                && urlStr.endsWith(JAR_FILE_SUFFIX)
-                                && needScanJar(loader, webappLoader, urlStr)) {
-                            URL jarURL = new URL("jar:" + urlStr + "!/");
-                            scanJar((JarURLConnection) jarURL.openConnection(),
-                                    true);
-                        }
-                    }
-                }
-            }
-
-            loader = loader.getParent();
-        }
-    }
-
-    /*
-     * Determines if the JAR file with the given <tt>jarPath</tt> needs to be
-     * scanned for TLDs.
-     *
-     * @param loader The current classloader in the parent chain
-     * @param webappLoader The webapp classloader
-     * @param jarPath The JAR file path
-     *
-     * @return TRUE if the JAR file identified by <tt>jarPath</tt> needs to be
-     * scanned for TLDs, FALSE otherwise
-     */
-    private boolean needScanJar(ClassLoader loader, ClassLoader webappLoader,
-                                String jarPath) {
-        if (loader == webappLoader) {
-            // JARs under WEB-INF/lib must be scanned unconditionally according
-            // to the spec.
-            return true;
-        } else {
-            String jarName = jarPath;
-            int slash = jarPath.lastIndexOf('/');
-            if (slash >= 0) {
-                jarName = jarPath.substring(slash + 1);
-            }
-            return (!noTldJars.contains(jarName));
-        }
-    }
-}
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ParserController.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ParserController.java
index 3df2b93..136bfb7 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ParserController.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ParserController.java
@@ -5,9 +5,9 @@
  * 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.
@@ -74,7 +74,7 @@
      * Constructor
      */
     public ParserController(JspCompilationContext ctxt, Compiler compiler) {
-        this.ctxt = ctxt; 
+        this.ctxt = ctxt;
         this.compiler = compiler;
         this.err = compiler.getErrorDispatcher();
     }
@@ -95,7 +95,7 @@
     public Node.Nodes parse(String inFileName)
     throws FileNotFoundException, JasperException, IOException {
         // If we're parsing a packaged tag file or a resource included by it
-        // (using an include directive), ctxt.getTagFileJar() returns the 
+        // (using an include directive), ctxt.getTagFileJar() returns the
         // JAR file from which to read the tag file or included resource,
         // respectively.
         isTagFile = ctxt.isTagFile();
@@ -123,7 +123,7 @@
      * Extracts tag file directive information from the tag file with the
      * given name.
      *
-     * This is invoked by the compiler 
+     * This is invoked by the compiler
      *
      * @param inFileName The name of the tag file to be parsed.
      */
@@ -158,7 +158,6 @@
             Node parent,
             URL jarFileUrl)
     throws FileNotFoundException, JasperException, IOException {
-
         Node.Nodes parsedPage = null;
         isEncodingSpecifiedInProlog = false;
         isBomPresent = false;
@@ -245,7 +244,7 @@
      *
      * @param absFileName The URI to match
      *
-     * @return The value of the <page-encoding> attribute of the 
+     * @return The value of the <page-encoding> attribute of the
      * jsp-property-group with matching URL pattern
      */
     private String getJspConfigPageEncoding(String absFileName)
@@ -326,7 +325,7 @@
                  * We need to be careful, because the page may be encoded in
                  * ISO-8859-1 (or something entirely different), and may
                  * contain byte sequences that will cause a UTF-8 converter to
-                 * throw exceptions. 
+                 * throw exceptions.
                  *
                  * It is safe to use a source encoding of ISO-8859-1 in this
                  * case, as there are no invalid byte sequences in ISO-8859-1,
@@ -348,11 +347,11 @@
 
         /*
          * At this point, 'isExternal' or 'isXml' is FALSE.
-         * Search for jsp:root action, in order to determine if we're dealing 
-         * with XML or standard syntax (unless we already know what we're 
+         * Search for jsp:root action, in order to determine if we're dealing
+         * with XML or standard syntax (unless we already know what we're
          * dealing with, i.e., when 'isExternal' is TRUE and 'isXml' is FALSE).
          * No check for XML prolog, since nothing prevents a page from
-         * outputting XML and still using JSP syntax (in this case, the 
+         * outputting XML and still using JSP syntax (in this case, the
          * XML prolog is treated as template text).
          */
         JspReader jspReader = null;
@@ -397,7 +396,7 @@
                 }
             }
         }
-        
+
     }
 
     /*
@@ -510,9 +509,9 @@
     private String resolveFileName(String inFileName) {
         String fileName = inFileName.replace('\\', '/');
         boolean isAbsolute = fileName.startsWith("/");
-        fileName = isAbsolute ? fileName 
+        fileName = isAbsolute ? fileName
                 : (String) baseDirStack.peek() + fileName;
-        String baseDir = 
+        String baseDir =
             fileName.substring(0, fileName.lastIndexOf("/") + 1);
         baseDirStack.push(baseDir);
         return fileName;
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java
index ea5b729..d485fc6 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java
@@ -533,7 +533,6 @@
      */
     private void loadTagFile(Compiler compiler, String tagFilePath,
             Node.CustomTag n, PageInfo parentPageInfo) throws JasperException {
-
         JspCompilationContext ctxt = compiler.getCompilationContext();
         JspRuntimeContext rctxt = ctxt.getRuntimeContext();
 
@@ -671,7 +670,7 @@
     public void loadTagFiles(Compiler compiler, Node.Nodes page)
             throws JasperException {
 
-        tempVector = new Vector<Compiler>();
+        tempVector = new Vector<>();
         page.visit(new TagFileLoaderVisitor(compiler));
     }
 
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagLibraryInfoImpl.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagLibraryInfoImpl.java
index 413f9be..d831ca0 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagLibraryInfoImpl.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagLibraryInfoImpl.java
@@ -23,6 +23,7 @@
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.JarURLConnection;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Enumeration;
@@ -82,6 +83,7 @@
         }
     }
 
+    @Override
     public String toString() {
         StringWriter sw = new StringWriter();
         PrintWriter out = new PrintWriter(sw);
@@ -200,6 +202,7 @@
 
     }
 
+    @Override
     public TagLibraryInfo[] getTagLibraryInfos() {
         Collection coll = pi.getTaglibs();
         return (TagLibraryInfo[]) coll.toArray(new TagLibraryInfo[0]);
@@ -477,7 +480,24 @@
 
         if (path.startsWith("/META-INF/tags")) {
             // Tag file packaged in JAR
-            ctxt.setTagFileJarUrl(path, jarFileUrl);
+            if ( jarFileUrl != null ) {
+                ctxt.setTagFileJarUrl(path, jarFileUrl);
+            } else {
+                final URL baseUrl = ctxt.getOptions().getTldLocationsCache().getTldLocationURL(uri);
+                if ( baseUrl != null ) {
+                    final String baseUrlStr = baseUrl.toString();
+                    final int index = baseUrlStr.indexOf("/META-INF/");
+                    if ( index != -1 ) {
+                        URL finalUrl;
+                        try {
+                            finalUrl = new URL(baseUrlStr.substring(0, index) + path);
+                            ctxt.setTagFileUrl(path, finalUrl);
+                        } catch (MalformedURLException e) {
+                            // we ignore this
+                        }
+                    }
+                }
+            }
         } else if (!path.startsWith("/WEB-INF/tags")) {
             err.jspError("jsp.error.tagfile.illegalPath", path);
         }
@@ -492,7 +512,7 @@
         String type = null;
         String expectedType = null;
         String methodSignature = null;
-        boolean required = false, rtexprvalue = false, reqTime = false, isFragment = false, deferredValue = false, deferredMethod = false;
+        boolean required = false, rtexprvalue = false, isFragment = false, deferredValue = false, deferredMethod = false;
 
         Iterator list = elem.findChildren();
         while (list.hasNext()) {
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TldLocationsCache.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TldLocationsCache.java
index dd3f00f..0ef2bc3 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TldLocationsCache.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TldLocationsCache.java
@@ -17,6 +17,8 @@
 
 package org.apache.sling.scripting.jsp.jasper.compiler;
 
+import java.net.URL;
+
 import org.apache.sling.scripting.jsp.jasper.JasperException;
 
 
@@ -64,6 +66,8 @@
 
     public abstract String[] getLocation(String uri) throws JasperException;
 
+    public abstract URL getTldLocationURL(String tldLocation);
+
     /**
      * Returns the type of a URI:
      *     ABS_URI
diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ProtectedFunctionMapper.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ProtectedFunctionMapper.java
index d80f32e..064d61a 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ProtectedFunctionMapper.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/runtime/ProtectedFunctionMapper.java
@@ -5,9 +5,9 @@
  * 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.
@@ -17,12 +17,13 @@
 
 package org.apache.sling.scripting.jsp.jasper.runtime;
 
-import java.util.HashMap;
+import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
-import java.lang.reflect.Method;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashMap;
+
 import javax.servlet.jsp.el.FunctionMapper;
 
 import org.apache.sling.scripting.jsp.jasper.security.SecurityUtil;
@@ -30,7 +31,7 @@
 /**
  * Maps EL functions to their Java method counterparts. Keeps the actual Method
  * objects protected so that JSP pages can't indirectly do reflection.
- * 
+ *
  * @author Mark Roth
  * @author Kin-man Chung
  */
@@ -40,12 +41,12 @@
     /**
      * Maps "prefix:name" to java.lang.Method objects.
      */
-    private HashMap fnmap = null;
+    private HashMap<String, Method> fnmap;
 
     /**
      * If there is only one function in the map, this is the Method for it.
      */
-    private Method theMethod = null;
+    private Method theMethod;
 
     /**
      * Constructor has protected access.
@@ -58,29 +59,30 @@
      * retrieve an instance of the ProtectedFunctionMapper. This is necessary
      * since generated code does not have access to create instances of classes
      * in this package.
-     * 
+     *
      * @return A new protected function mapper.
      */
     public static ProtectedFunctionMapper getInstance() {
         ProtectedFunctionMapper funcMapper;
         if (SecurityUtil.isPackageProtectionEnabled()) {
-            funcMapper = (ProtectedFunctionMapper) AccessController
-                    .doPrivileged(new PrivilegedAction() {
-                        public Object run() {
+            funcMapper = AccessController
+                    .doPrivileged(new PrivilegedAction<ProtectedFunctionMapper>() {
+                        @Override
+                        public ProtectedFunctionMapper run() {
                             return new ProtectedFunctionMapper();
                         }
                     });
         } else {
             funcMapper = new ProtectedFunctionMapper();
         }
-        funcMapper.fnmap = new java.util.HashMap();
+        funcMapper.fnmap = new java.util.HashMap<>();
         return funcMapper;
     }
 
     /**
      * Stores a mapping from the given EL function prefix and name to the given
      * Java method.
-     * 
+     *
      * @param fnQName
      *            The EL function qualified name (including prefix)
      * @param c
@@ -92,15 +94,16 @@
      * @throws RuntimeException
      *             if no method with the given signature could be found.
      */
-    public void mapFunction(String fnQName, final Class c,
-            final String methodName, final Class[] args) {
+    public void mapFunction(String fnQName, final Class<?> c,
+            final String methodName, final Class<?>[] args) {
         java.lang.reflect.Method method;
         if (SecurityUtil.isPackageProtectionEnabled()) {
             try {
-                method = (java.lang.reflect.Method) AccessController
-                        .doPrivileged(new PrivilegedExceptionAction() {
+                method = AccessController
+                        .doPrivileged(new PrivilegedExceptionAction<Method>() {
 
-                            public Object run() throws Exception {
+                            @Override
+                            public Method run() throws Exception {
                                 return c.getDeclaredMethod(methodName, args);
                             }
                         });
@@ -126,7 +129,7 @@
      * Creates an instance for this class, and stores the Method for the given
      * EL function prefix and name. This method is used for the case when there
      * is only one function in the EL expression.
-     * 
+     *
      * @param fnQName
      *            The EL function qualified name (including prefix)
      * @param c
@@ -139,22 +142,24 @@
      *             if no method with the given signature could be found.
      */
     public static ProtectedFunctionMapper getMapForFunction(String fnQName,
-            final Class c, final String methodName, final Class[] args) {
+            final Class<?> c, final String methodName, final Class<?>[] args) {
         java.lang.reflect.Method method;
         ProtectedFunctionMapper funcMapper;
         if (SecurityUtil.isPackageProtectionEnabled()) {
-            funcMapper = (ProtectedFunctionMapper) AccessController
-                    .doPrivileged(new PrivilegedAction() {
-                        public Object run() {
+            funcMapper = AccessController
+                    .doPrivileged(new PrivilegedAction<ProtectedFunctionMapper>() {
+                        @Override
+                        public ProtectedFunctionMapper run() {
                             return new ProtectedFunctionMapper();
                         }
                     });
 
             try {
-                method = (java.lang.reflect.Method) AccessController
-                        .doPrivileged(new PrivilegedExceptionAction() {
+                method = AccessController
+                        .doPrivileged(new PrivilegedExceptionAction<Method>() {
 
-                            public Object run() throws Exception {
+                            @Override
+                            public Method run() throws Exception {
                                 return c.getDeclaredMethod(methodName, args);
                             }
                         });
@@ -180,16 +185,17 @@
     /**
      * Resolves the specified local name and prefix into a Java.lang.Method.
      * Returns null if the prefix and local name are not found.
-     * 
+     *
      * @param prefix
      *            the prefix of the function
      * @param localName
      *            the short name of the function
      * @return the result of the method mapping. Null means no entry found.
      */
+    @Override
     public Method resolveFunction(String prefix, String localName) {
         if (this.fnmap != null) {
-            return (Method) this.fnmap.get(prefix + ":" + localName);
+            return this.fnmap.get(prefix + ":" + localName);
         }
         return theMethod;
     }