tldmanager.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 868 行 · 第 1/2 页
JAVA
868 行
if (name.startsWith(prefix) && (name.endsWith(".tld") || name.endsWith(".ftld"))) { tldPaths.add(jar.lookup(name)); } } } finally { zipFile.close(); } } for (Path path : tldPaths) { try { TldPreload taglib = parseTldPreload(path); taglibs.add(taglib); if (taglib.getURI() == null && taglib.getConfigException() != null && _loadAllTldException == null) _loadAllTldException = new JspLineParseException(taglib.getConfigException()); } catch (Exception e) { /* if (_loadAllTldException == null) { } else if (e instanceof JspParseException) _loadAllTldException = (JspParseException) e; else _loadAllTldException = new JspParseException(e); */ log.warning(e.getMessage()); } } } /** * Returns the tld parsed at the given location. */ TldTaglib parseTld(String uri, String mapLocation, String location) throws JspParseException, IOException { init(); TldTaglib taglib = null; TldTaglib jsfTaglib = null; for (int i = 0; i < _preloadTaglibs.size(); i++) { TldPreload preload = _preloadTaglibs.get(i); if (uri.equals(preload.getURI()) && (mapLocation == null || mapLocation.equals(preload.getLocation()) || mapLocation.equals(uri))) { if (preload.isJsf()) { if (_isFastJsf) jsfTaglib = parseTld(preload.getPath()); } else if (taglib == null) taglib = parseTld(preload.getPath()); } } if (jsfTaglib != null && taglib != null) { taglib.mergeJsf(jsfTaglib); return taglib; } else if (taglib != null) return taglib; return parseTld(location); } /** * Returns the tld parsed at the given location. */ TldTaglib parseTld(String location) throws JspParseException, IOException { init(); TldTaglib tld = findTld(location); /* XXX: jsp/18n0 handled on init if (tld != null) { try { tld.init(_webApp); } catch (Exception e) { throw new JspParseException(e); } } */ return tld; } /** * Returns the tld parsed at the given location. */ private TldTaglib findTld(String location) throws JspParseException, IOException { InputStream is = null; Path path; if (location.startsWith("file:")) { path = _resourceManager.resolvePath(location); } else if (location.indexOf(':') >= 0 && ! location.startsWith("file:") && location.indexOf(':') < location.indexOf('/')) { if (_loadAllTldException != null) throw _loadAllTldException; return null; /* XXX: jsp/0316 throw new JspParseException(L.l("Unknown taglib `{0}'. Taglibs specified with an absolute URI must either be:\n1) specified in the web.xml\n2) defined in a jar's .tld in META-INF\n3) defined in a .tld in WEB-INF\n4) predefined by Resin", location)); */ } else if (! location.startsWith("/")) path = _resourceManager.resolvePath("WEB-INF/" + location); else path = _resourceManager.resolvePath("." + location); path.setUserPath(location); Path jar = null; if (location.endsWith(".jar")) { path = findJar(location); if (path != null && path.exists()) { jar = JarPath.create(path); if (jar.lookup("META-INF/taglib.tld").exists()) return parseTld(jar.lookup("META-INF/taglib.tld")); else if (jar.lookup("meta-inf/taglib.tld").exists()) return parseTld(jar.lookup("meta-inf/taglib.tld")); else throw new JspParseException(L.l("can't find META-INF/taglib.tld in `{0}'", location)); } else { throw new JspParseException(L.l("Can't find taglib `{0}'. A taglib uri ending in *.jar must point to an actual jar or match a URI in a .tld file.", location)); } } else if (path.exists() && path.canRead() && path.isFile()) return parseTld(path); if (_loadAllTldException != null) throw _loadAllTldException; else throw new JspParseException(L.l("Can't find taglib-location `{0}'. The taglib-location must match a tag library either:\n1) by pointing to a .tld directly, relative to the application's root directory\n2) specified in the web.xml\n3) defined in a jar's .tld in META-INF\n4) defined in a .tld in WEB-INF\n5) predefined by Resin", location)); } /** * Parses the .tld * * @param is the input stream to the taglib */ private TldTaglib parseTld(Path path) throws JspParseException, IOException { SoftReference<TldTaglib> taglibRef = _tldMap.get(path); TldTaglib taglib; if (taglibRef != null) { taglib = taglibRef.get(); if (taglib != null && ! taglib.isModified()) return taglib; } ReadStream is = path.openRead(); try { taglib = parseTld(is); if (path instanceof JarPath) taglib.setJarPath(path.lookup("/")); _tldMap.put(path, new SoftReference<TldTaglib>(taglib)); return taglib; } finally { is.close(); } } /** * Parses the .tld * * @param is the input stream to the taglib */ private TldTaglib parseTld(InputStream is) throws JspParseException, IOException { TldTaglib taglib = new TldTaglib(); if (is instanceof ReadStream) { Path path = ((ReadStream) is).getPath(); path.setUserPath(path.getURL()); } String schema = null; if (_webApp.getJsp() == null || _webApp.getJsp().isValidateTaglibSchema()) { schema = getSchema(); } try { Config config = new Config(); config.setEL(false); config.configure(taglib, is, schema); } catch (ConfigException e) { log.warning(e.toString()); log.log(Level.FINER, e.toString(), e); taglib.setConfigException(e); } catch (Exception e) { log.warning(e.toString()); log.log(Level.FINER, e.toString(), e); taglib.setConfigException(e); } finally { is.close(); } /* XXX: jsp/18n0 handled on init try { taglib.init(_webApp); } catch (Exception e) { throw new JspParseException(e); } */ return taglib; } /** * Parses the .tld * * @param path location of the taglib */ private TldPreload parseTldPreload(Path path) throws JspParseException, IOException { ReadStream is = path.openRead(); try { TldPreload taglib = parseTldPreload(is); taglib.setPath(path); String appDir = _webApp.getAppDir().getPath(); String tagPath = path.getPath(); if (tagPath.startsWith(appDir)) taglib.setLocation(tagPath.substring(appDir.length())); return taglib; } finally { is.close(); } } /** * Parses the .tld * * @param is the input stream to the taglib */ private TldPreload parseTldPreload(InputStream is) throws JspParseException, IOException { boolean isJsfTld = false; if (is instanceof ReadStream) { Path path = ((ReadStream) is).getPath(); isJsfTld = path.getPath().endsWith(".ftld"); path.setUserPath(path.getURL()); } String schema = null; if (_webApp.getJsp() == null || _webApp.getJsp().isValidateTaglibSchema()) { schema = getSchema(); } TldPreload taglib; if (isJsfTld) taglib = new JsfTldPreload(); else taglib = new TldPreload(); try { _config.configure(taglib, is, schema); } catch (ConfigException e) { log.warning(e.toString()); log.log(Level.FINER, e.toString(), e); taglib.setConfigException(e); } catch (Exception e) { log.warning(e.toString()); log.log(Level.FINER, e.toString(), e); taglib.setConfigException(e); } finally { is.close(); } return taglib; } /** * Finds the path to the jar specified by the location. * * @param location the tag-location specified in the web.xml * * @return the found jar or null */ private Path findJar(String location) { Path path; if (location.startsWith("file:")) path = Vfs.lookup(location); else if (location.startsWith("/")) path = _resourceManager.resolvePath("." + location); else path = _resourceManager.resolvePath(location); if (path.exists()) return path; DynamicClassLoader loader; loader = (DynamicClassLoader) Thread.currentThread().getContextClassLoader(); String classPath = loader.getClassPath(); char sep = CauchoSystem.getPathSeparatorChar(); int head = 0; int tail = 0; while ((tail = classPath.indexOf(sep, head)) >= 0) { String sub = classPath.substring(head, tail); path = Vfs.lookup(sub); if (sub.endsWith(location) && path.exists()) return path; head = tail + 1; } if (classPath.length() <= head) return null; String sub = classPath.substring(head); path = Vfs.lookup(sub); if (sub.endsWith(location) && path.exists()) return path; else return null; } /** * Adds the classpath as paths in the MergePath. */ private ArrayList<Path> getClassPath() { return getClassPath(Thread.currentThread().getContextClassLoader()); } /** * Adds the classpath for the loader as paths in the MergePath. * * @param loader class loader whose classpath should be used to search. */ private ArrayList<Path> getClassPath(ClassLoader loader) { String classpath = null; if (loader instanceof DynamicClassLoader) classpath = ((DynamicClassLoader) loader).getClassPath(); else classpath = CauchoSystem.getClassPath(); return getClassPath(classpath); } /** * Adds the classpath for the loader as paths in the MergePath. * * @param classpath class loader whose classpath should be used to search. */ private ArrayList<Path> getClassPath(String classpath) { ArrayList<Path> list = new ArrayList<Path>(); char sep = CauchoSystem.getPathSeparatorChar(); int head = 0; int tail = 0; while (head < classpath.length()) { tail = classpath.indexOf(sep, head); String segment = null; if (tail < 0) { segment = classpath.substring(head); head = classpath.length(); } else { segment = classpath.substring(head, tail); head = tail + 1; } if (! segment.equals("")) { Path path = Vfs.lookup(segment); if (! list.contains(path)) list.add(path); } } return list; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?