@Throws(JasperException::class) private fun scanJar(conn: JarURLConnection, tldNames: List<String>?, isLocal: Boolean) { val resourcePath: String = conn.getJarFileURL().toString() var tldInfos: Array<TldInfo?> = jarTldCacheLocal.get(resourcePath) if (tldInfos != null && tldInfos.size == 0) { try { conn.getJarFile().close() } catch (ex: IOException) { } return } if (tldInfos == null) { var jarFile: JarFile? = null val tldInfoA: ArrayList<TldInfo> = ArrayList<TldInfo>() try { jarFile = conn.getJarFile() if (tldNames != null) { for (tldName in tldNames) { val entry: JarEntry = jarFile.getJarEntry(tldName) val stream: InputStream = jarFile.getInputStream(entry) tldInfoA.add(scanTld(resourcePath, tldName, stream)) } } else { val entries: Enumeration<JarEntry> = jarFile.entries() while (entries.hasMoreElements()) { val entry: JarEntry = entries.nextElement() val name: String = entry.getName() if (!name.startsWith("META-INF/")) continue if (!name.endsWith(".tld")) continue val stream: InputStream = jarFile.getInputStream(entry) tldInfoA.add(scanTld(resourcePath, name, stream)) } } } catch (ex: IOException) { if (resourcePath.startsWith(FILE_PROTOCOL) && !File(resourcePath).exists()) { if (log.isLoggable(Level.WARNING)) { log.log( Level.WARNING, Localizer.getMessage("jsp.warn.nojar", resourcePath), ex ) } } else { throw JasperException( Localizer.getMessage("jsp.error.jar.io", resourcePath), ex ) } } finally { if (jarFile != null) { try { jarFile.close() } catch (t: Throwable) { } } } tldInfos = tldInfoA.toArray(arrayOfNulls<TldInfo>(tldInfoA.size())) jarTldCacheLocal.put(resourcePath, tldInfos) if (!isLocal) { jarTldCache.put(resourcePath, tldInfos) } } for (tldInfo in tldInfos) { if (scanListeners) { addListener(tldInfo, isLocal) } mapTldLocation(resourcePath, tldInfo, isLocal) } }
Scans the given JarURLConnection for TLD files located in META-INF ( or a subdirectory of it ) . If the scanning in is done as part of the ServletContextInitializer , the listeners in the tlds in this jar file are added to the servlet context , and for any TLD that has a < uri > element , an implicit map entry is added to the taglib map .