Package org.apache.jasper.runtime
Class TldScanner
- java.lang.Object
-
- org.apache.jasper.runtime.TldScanner
-
- All Implemented Interfaces:
javax.servlet.ServletContainerInitializer
public class TldScanner extends java.lang.Object implements javax.servlet.ServletContainerInitializer
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. Viaelements in web.xml: the uri and location of the tag-library are specified in the 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 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
TldScanner.TldInfo
-
Field Summary
Fields Modifier and Type Field Description static int
ABS_URI
The types of URI one may specify for a tag libraryprivate boolean
blockExternal
private javax.servlet.ServletContext
ctxt
private boolean
doneScanning
private static java.lang.String
EAR_LIB_CLASSLOADER
private static java.lang.String
FILE_PROTOCOL
private static java.lang.String
IS_STANDALONE_ATTRIBUTE_NAME
private boolean
isValidationEnabled
private static java.lang.String
JAR_FILE_SUFFIX
private static java.util.Map<java.lang.String,TldScanner.TldInfo[]>
jarTldCache
private java.util.Map<java.lang.String,TldScanner.TldInfo[]>
jarTldCacheLocal
A local cache for keeping track which jars have been scanned.private static java.util.logging.Logger
log
private java.util.HashMap<java.lang.String,java.lang.String[]>
mappings
The mapping of the 'global' tag library URI (as defined in the tld) to the location (resource path) of the TLD associated with that tag library.static int
NOROOT_REL_URI
static int
ROOT_REL_URI
private boolean
scanListeners
private static java.util.HashSet<java.lang.String>
systemUris
private static java.util.HashSet<java.lang.String>
systemUrisJsf
private boolean
useMyFaces
private static java.lang.String
WEB_XML
-
Constructor Summary
Constructors Constructor Description TldScanner()
Default Constructor.TldScanner(javax.servlet.ServletContext ctxt, boolean isValidationEnabled)
Constructor used in Jasper
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addListener(TldScanner.TldInfo tldInfo, boolean isLocal)
private boolean
addManifestClassPath(java.util.List<java.lang.String> scannedJars, java.util.List<java.lang.String> newJars, java.net.JarURLConnection jconn)
java.lang.String[]
getLocation(java.lang.String uri)
Gets the 'location' of the TLD associated with the given taglib 'uri'.(package private) java.util.Map<java.net.URI,java.util.List<java.lang.String>>
getTldListenerMap()
(package private) java.util.Map<java.net.URI,java.util.List<java.lang.String>>
getTldMap()
private void
mapTldLocation(java.lang.String resourcePath, TldScanner.TldInfo tldInfo, boolean isLocal)
void
onStartup(java.util.Set<java.lang.Class<?>> c, javax.servlet.ServletContext ctxt)
private void
processTldsInFileSystem(java.lang.String startPath)
private void
processWebDotXml()
private void
scanJar(java.net.JarURLConnection conn, java.util.List<java.lang.String> tldNames, boolean isLocal)
Scans the given JarURLConnection for TLD files located in META-INF (or a subdirectory of it).private void
scanJars()
private TldScanner.TldInfo
scanTld(java.lang.String resourcePath, java.lang.String entryName, java.io.InputStream stream)
Scan the given TLD for uri and listeners elements.private void
scanTlds()
Scan the all the tlds accessible in the web app.static int
uriType(java.lang.String uri)
Returns the type of a URI: ABS_URI ROOT_REL_URI NOROOT_REL_URI
-
-
-
Field Detail
-
log
private static java.util.logging.Logger log
-
ABS_URI
public static final int ABS_URI
The types of URI one may specify for a tag library- See Also:
- Constant Field Values
-
ROOT_REL_URI
public static final int ROOT_REL_URI
- See Also:
- Constant Field Values
-
NOROOT_REL_URI
public static final int NOROOT_REL_URI
- See Also:
- Constant Field Values
-
WEB_XML
private static final java.lang.String WEB_XML
- See Also:
- Constant Field Values
-
FILE_PROTOCOL
private static final java.lang.String FILE_PROTOCOL
- See Also:
- Constant Field Values
-
JAR_FILE_SUFFIX
private static final java.lang.String JAR_FILE_SUFFIX
- See Also:
- Constant Field Values
-
systemUris
private static java.util.HashSet<java.lang.String> systemUris
-
systemUrisJsf
private static java.util.HashSet<java.lang.String> systemUrisJsf
-
jarTldCache
private static java.util.Map<java.lang.String,TldScanner.TldInfo[]> jarTldCache
-
EAR_LIB_CLASSLOADER
private static final java.lang.String EAR_LIB_CLASSLOADER
- See Also:
- Constant Field Values
-
IS_STANDALONE_ATTRIBUTE_NAME
private static final java.lang.String IS_STANDALONE_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
mappings
private java.util.HashMap<java.lang.String,java.lang.String[]> mappings
The mapping of the 'global' tag library URI (as defined in the tld) to the location (resource path) of the TLD associated with that tag library. The location is returned as a String array: [0] The location of the tld file or the jar file that contains the tld [1] If the location is a jar file, this is the location of the tld.
-
jarTldCacheLocal
private java.util.Map<java.lang.String,TldScanner.TldInfo[]> jarTldCacheLocal
A local cache for keeping track which jars have been scanned.
-
ctxt
private javax.servlet.ServletContext ctxt
-
isValidationEnabled
private boolean isValidationEnabled
-
useMyFaces
private boolean useMyFaces
-
scanListeners
private boolean scanListeners
-
doneScanning
private boolean doneScanning
-
blockExternal
private boolean blockExternal
-
-
Constructor Detail
-
TldScanner
public TldScanner()
Default Constructor. This is only used for implementing ServletContainerInitializer. ServletContext will be supplied in the method onStartUp;
-
TldScanner
public TldScanner(javax.servlet.ServletContext ctxt, boolean isValidationEnabled)
Constructor used in Jasper
-
-
Method Detail
-
onStartup
public void onStartup(java.util.Set<java.lang.Class<?>> c, javax.servlet.ServletContext ctxt) throws javax.servlet.ServletException
- Specified by:
onStartup
in interfacejavax.servlet.ServletContainerInitializer
- Throws:
javax.servlet.ServletException
-
getLocation
public java.lang.String[] getLocation(java.lang.String uri) throws JasperException
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).- Parameters:
uri
- The taglib uri- Returns:
- 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. This method may be called when the scanning is in one of states: 1. Called from jspc script, then a full tld scan is required. 2. The is the first call after servlet initialization, then system jars that are knwon to have tlds but not listeners need to be scanned. 3. Sebsequent calls, no need to scans.
- Throws:
JasperException
-
getTldMap
java.util.Map<java.net.URI,java.util.List<java.lang.String>> getTldMap()
-
getTldListenerMap
java.util.Map<java.net.URI,java.util.List<java.lang.String>> getTldListenerMap()
-
uriType
public static int uriType(java.lang.String uri)
Returns the type of a URI: ABS_URI ROOT_REL_URI NOROOT_REL_URI
-
scanTlds
private void scanTlds() throws JasperException
Scan the all the tlds accessible in the web app. For performance reasons, this is done in two stages. At servlet initialization time, we only scan the jar files for listeners. The container passes a list of system jar files that are known to contain tlds with listeners. The rest of the jar files will be scanned when a JSP page with a tld referenced is compiled.- Throws:
JasperException
-
processWebDotXml
private void processWebDotXml() throws java.lang.Exception
- Throws:
java.lang.Exception
-
scanJar
private void scanJar(java.net.JarURLConnection conn, java.util.List<java.lang.String> tldNames, boolean isLocal) throws JasperException
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 aelement, an implicit map entry is added to the taglib map. - Parameters:
conn
- The JarURLConnection to the JAR file to scantldNames
- the list of tld element to scan. The null value indicates all the tlds in this case.isLocal
- True if the jar file is under WEB-INF false otherwise- Throws:
JasperException
-
addListener
private void addListener(TldScanner.TldInfo tldInfo, boolean isLocal)
-
mapTldLocation
private void mapTldLocation(java.lang.String resourcePath, TldScanner.TldInfo tldInfo, boolean isLocal)
-
processTldsInFileSystem
private void processTldsInFileSystem(java.lang.String startPath) throws JasperException
- Throws:
JasperException
-
scanTld
private TldScanner.TldInfo scanTld(java.lang.String resourcePath, java.lang.String entryName, java.io.InputStream stream) throws JasperException
Scan the given TLD for uri and listeners elements.- Parameters:
resourcePath
- the resource path for the jar file or the tld file.entryName
- If the resource path is a jar file, then the name of the tld file in the jar, else should be null.stream
- The input stream for the tld- Returns:
- The TldInfo for this tld
- Throws:
JasperException
-
scanJars
private void scanJars() throws java.lang.Exception
- Throws:
java.lang.Exception
-
addManifestClassPath
private boolean addManifestClassPath(java.util.List<java.lang.String> scannedJars, java.util.List<java.lang.String> newJars, java.net.JarURLConnection jconn)
-
-