MCPcopy Index your code
hub / github.com/apache/tomcat / TldCache

Class TldCache

java/org/apache/jasper/compiler/TldCache.java:41–226  ·  view source on GitHub ↗

This class caches parsed instances of TLD files to remove the need for the same TLD to be parsed for each JSP that references it. It does not protect against multiple threads processing the same new TLD, but it does ensure that each all threads will use the same TLD object after parsing.

Source from the content-addressed store, hash-verified

39 * all threads will use the same TLD object after parsing.
40 */
41public class TldCache {
42
43 /**
44 * The ServletContext attribute name used to store the TldCache instance.
45 */
46 public static final String SERVLET_CONTEXT_ATTRIBUTE_NAME = TldCache.class.getName();
47
48 /**
49 * The servlet context associated with this cache.
50 */
51 private final ServletContext servletContext;
52
53 /**
54 * Maps TLD URIs to their resource paths.
55 */
56 private final Map<String,TldResourcePath> uriTldResourcePathMap = new HashMap<>();
57
58 /**
59 * Maps TLD resource paths to their cached tag library XML data.
60 */
61 private final Map<TldResourcePath,TaglibXmlCacheEntry> tldResourcePathTaglibXmlMap = new HashMap<>();
62
63 /**
64 * The parser used to parse TLD files.
65 */
66 private final TldParser tldParser;
67
68
69 /**
70 * Returns the TldCache instance for the given servlet context.
71 *
72 * @param servletContext the servlet context
73 * @return the TldCache instance
74 */
75 public static TldCache getInstance(ServletContext servletContext) {
76 if (servletContext == null) {
77 throw new IllegalArgumentException(
78 Localizer.getMessage("org.apache.jasper.compiler.TldCache.servletContextNull"));
79 }
80 return (TldCache) servletContext.getAttribute(SERVLET_CONTEXT_ATTRIBUTE_NAME);
81 }
82
83
84 /**
85 * Creates a new TldCache.
86 *
87 * @param servletContext the servlet context
88 * @param uriTldResourcePathMap the pre-scanned URI to resource path mappings
89 * @param tldResourcePathTaglibXmlMap the pre-parsed TLD data
90 */
91 public TldCache(ServletContext servletContext, Map<String,TldResourcePath> uriTldResourcePathMap,
92 Map<TldResourcePath,TaglibXml> tldResourcePathTaglibXmlMap) {
93 this.servletContext = servletContext;
94 this.uriTldResourcePathMap.putAll(uriTldResourcePathMap);
95 for (Entry<TldResourcePath,TaglibXml> entry : tldResourcePathTaglibXmlMap.entrySet()) {
96 TldResourcePath tldResourcePath = entry.getKey();
97 long[] lastModified = getLastModified(tldResourcePath);
98 TaglibXmlCacheEntry cacheEntry =

Callers

nothing calls this directly

Calls 1

getNameMethod · 0.65

Tested by

no test coverage detected