* The <code>Digester</code> we will use to process web application
* deployment descriptor files.
*/
- protected static Digester webDigester = null;
+ protected Digester webDigester = null;
/**
- * The <code>Rule</code> used to parse the web.xml
- */
- protected static WebRuleSet webRuleSet = new WebRuleSet();
-
- /**
- * Attribute value used to turn on/off XML validation
+ * The <code>Digester</code>s available to process web application
+ * deployment descriptor files.
*/
- protected static boolean xmlValidation = false;
-
-
+ protected static Digester[] webDigesters = new Digester[4];
+
/**
- * Attribute value used to turn on/off XML namespace awarenes.
+ * The <code>Rule</code> used to parse the web.xml
*/
- protected static boolean xmlNamespaceAware = false;
+ protected static WebRuleSet webRuleSet = new WebRuleSet();
-
/**
* Deployment count.
*/
* Create (if necessary) and return a Digester configured to process the
* web application deployment descriptor (web.xml).
*/
- protected static Digester createWebDigester() {
- Digester webDigester =
- createWebXmlDigester(xmlNamespaceAware, xmlValidation);
- return webDigester;
- }
-
-
- /**
- * Create (if necessary) and return a Digester configured to process the
- * web application deployment descriptor (web.xml).
- */
public static Digester createWebXmlDigester(boolean namespaceAware,
boolean validation) {
- Digester webDigester = DigesterFactory.newDigester(xmlValidation,
- xmlNamespaceAware,
- webRuleSet);
- return webDigester;
+ Digester digester = null;
+ if (!namespaceAware && !validation) {
+ if (webDigesters[0] == null) {
+ webDigesters[0] = DigesterFactory.newDigester(validation,
+ namespaceAware, webRuleSet);
+ }
+ digester = webDigesters[0];
+ } else if (!namespaceAware && validation) {
+ if (webDigesters[1] == null) {
+ webDigesters[1] = DigesterFactory.newDigester(validation,
+ namespaceAware, webRuleSet);
+ }
+ digester = webDigesters[1];
+ } else if (namespaceAware && !validation) {
+ if (webDigesters[2] == null) {
+ webDigesters[2] = DigesterFactory.newDigester(validation,
+ namespaceAware, webRuleSet);
+ }
+ digester = webDigesters[2];
+ } else {
+ if (webDigesters[3] == null) {
+ webDigesters[3] = DigesterFactory.newDigester(validation,
+ namespaceAware, webRuleSet);
+ }
+ digester = webDigesters[3];
+ }
+ return digester;
}
protected void init() {
// Called from StandardContext.init()
- if (webDigester == null){
- webDigester = createWebDigester();
- webDigester.getParser();
- }
-
if (contextDigester == null){
contextDigester = createContextDigester();
contextDigester.getParser();
if (log.isDebugEnabled())
log.debug(sm.getString("contextConfig.start"));
+ // Process the default and application web.xml files
// Set properties based on default context
+ boolean useXmlValidation = context.getXmlValidation();
+ boolean useXmlNamespaceAware = context.getXmlNamespaceAware();
+
Container container = context.getParent();
+ // Use the value from the host if:
+ // - override is false on the context
+ // - value has been set to false / not set on the context
if( !context.getOverride() ) {
if( container instanceof Host ) {
- // Reset the value only if the attribute wasn't
- // set on the context.
- xmlValidation = context.getXmlValidation();
- if (!xmlValidation) {
- xmlValidation = ((Host)container).getXmlValidation();
+ if (!useXmlValidation) {
+ useXmlValidation = ((Host)container).getXmlValidation();
}
- xmlNamespaceAware = context.getXmlNamespaceAware();
- if (!xmlNamespaceAware){
- xmlNamespaceAware
+ if (!useXmlNamespaceAware){
+ useXmlNamespaceAware
= ((Host)container).getXmlNamespaceAware();
}
- container = container.getParent();
}
}
-
- // Process the default and application web.xml files
+
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("contextConfig.xmlSettings",
+ context.getName(), Boolean.valueOf(useXmlValidation),
+ Boolean.valueOf(useXmlNamespaceAware)));
+ }
+ webDigester = createWebXmlDigester(useXmlNamespaceAware, useXmlValidation);
+
defaultWebConfig();
applicationWebConfig();
if (!context.getIgnoreAnnotations()) {
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.tomcat.util.digester.Digester;
import org.xml.sax.InputSource;
+
/**
* Startup event listener for a <b>Context</b> that configures application
* listeners configured in any TLD files.
private static org.apache.juli.logging.Log log=
org.apache.juli.logging.LogFactory.getLog( TldConfig.class );
+ /**
+ * The string resources for this package.
+ */
+ private static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+ /**
+ * The <code>Digester</code>s available to process tld files.
+ */
+ private static Digester[] tldDigesters = new Digester[4];
+
+ private static final TldRuleSet tldRuleSet = new TldRuleSet();
+
/*
* Initializes the set of JARs that are known not to contain any TLDs
*/
noTldJars.add("sunpkcs11.jar");
}
+ /**
+ * Create (if necessary) and return a Digester configured to process the
+ * tld.
+ */
+ private static Digester createTldDigester(boolean namespaceAware,
+ boolean validation) {
+
+ Digester digester = null;
+ if (!namespaceAware && !validation) {
+ if (tldDigesters[0] == null) {
+ tldDigesters[0] = DigesterFactory.newDigester(validation,
+ namespaceAware, tldRuleSet);
+ }
+ digester = tldDigesters[0];
+ } else if (!namespaceAware && validation) {
+ if (tldDigesters[1] == null) {
+ tldDigesters[1] = DigesterFactory.newDigester(validation,
+ namespaceAware, tldRuleSet);
+ }
+ digester = tldDigesters[1];
+ } else if (namespaceAware && !validation) {
+ if (tldDigesters[2] == null) {
+ tldDigesters[2] = DigesterFactory.newDigester(validation,
+ namespaceAware, tldRuleSet);
+ }
+ digester = tldDigesters[2];
+ } else {
+ if (tldDigesters[3] == null) {
+ tldDigesters[3] = DigesterFactory.newDigester(validation,
+ namespaceAware, tldRuleSet);
+ }
+ digester = tldDigesters[3];
+ }
+ return digester;
+ }
+
// ----------------------------------------------------- Instance Variables
/**
- * The string resources for this package.
- */
- private static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
- /**
* The <code>Digester</code> we will use to process tag library
* descriptor files.
*/
- private static Digester tldDigester = null;
+ private Digester tldDigester = null;
/**
* Attribute value used to turn on/off TLD validation
*/
- private static boolean tldValidation = false;
+ private boolean tldValidation = false;
/**
* Attribute value used to turn on/off TLD namespace awarenes.
*/
- private static boolean tldNamespaceAware = false;
+ private boolean tldNamespaceAware = false;
private boolean rescan=true;
* @param tldValidation true to enable xml instance validation
*/
public void setTldValidation(boolean tldValidation){
- TldConfig.tldValidation = tldValidation;
+ this.tldValidation = tldValidation;
}
/**
*
*/
public boolean getTldValidation(){
- return tldValidation;
+ return this.tldValidation;
}
/**
*
*/
public boolean getTldNamespaceAware(){
- return tldNamespaceAware;
+ return this.tldNamespaceAware;
}
* @param tldNamespaceAware true to enable namespace awareness
*/
public void setTldNamespaceAware(boolean tldNamespaceAware){
- TldConfig.tldNamespaceAware = tldNamespaceAware;
+ this.tldNamespaceAware = tldNamespaceAware;
}
public void execute() throws Exception {
long t1=System.currentTimeMillis();
- File tldCache=null;
-
- // Option to not rescan
- if( ! rescan ) {
- // find the cache
- if( tldCache!= null && tldCache.exists()) {
- // just read it...
- processCache(tldCache);
- return;
- }
- }
-
/*
* Acquire the list of TLD resource paths, possibly embedded in JAR
* files, to be processed
Set<String> resourcePaths = tldScanResourcePaths();
Map<String, File> jarPaths = getJarPaths();
- // Check to see if we can use cached listeners
- if (tldCache != null && tldCache.exists()) {
- long lastModified = getLastModified(resourcePaths, jarPaths);
- if (lastModified < tldCache.lastModified()) {
- processCache(tldCache);
- return;
- }
- }
-
// Scan each accumulated resource path for TLDs to be processed
Iterator<String> paths = resourcePaths.iterator();
while (paths.hasNext()) {
String list[] = getTldListeners();
- if( tldCache!= null ) {
- log.debug( "Saving tld cache: " + tldCache + " " + list.length);
- try {
- FileOutputStream out=new FileOutputStream(tldCache);
- ObjectOutputStream oos=new ObjectOutputStream( out );
- oos.writeObject( list );
- oos.close();
- } catch( IOException ex ) {
- ex.printStackTrace();
- }
- }
-
if( log.isDebugEnabled() )
log.debug( "Adding tld listeners:" + list.length);
for( int i=0; list!=null && i<list.length; i++ ) {
// -------------------------------------------------------- Private Methods
- /*
- * Returns the last modification date of the given sets of resources.
- *
- * @param resourcePaths
- * @param jarPaths
- *
- * @return Last modification date
- */
- private long getLastModified(Set<String> resourcePaths,
- Map<String, File> jarPaths) throws Exception {
-
- long lastModified = 0;
-
- Iterator<String> paths = resourcePaths.iterator();
- while (paths.hasNext()) {
- String path = paths.next();
- URL url = context.getServletContext().getResource(path);
- if (url == null) {
- log.debug( "Null url "+ path );
- break;
- }
- long lastM = url.openConnection().getLastModified();
- if (lastM > lastModified) lastModified = lastM;
- if (log.isDebugEnabled()) {
- log.debug( "Last modified " + path + " " + lastM);
- }
- }
-
- if (jarPaths != null) {
- Iterator<File> files = jarPaths.values().iterator();
- while (files.hasNext()) {
- File jarFile = files.next();
- long lastM = jarFile.lastModified();
- if (lastM > lastModified) lastModified = lastM;
- if (log.isDebugEnabled()) {
- log.debug("Last modified " + jarFile.getAbsolutePath()
- + " " + lastM);
- }
- }
- }
-
- return lastModified;
- }
-
- private void processCache(File tldCache ) throws IOException {
- // read the cache and return;
- try {
- FileInputStream in=new FileInputStream(tldCache);
- ObjectInputStream ois=new ObjectInputStream( in );
- String list[]=(String [])ois.readObject();
- if( log.isDebugEnabled() )
- log.debug("Reusing tldCache " + tldCache + " " + list.length);
- for( int i=0; list!=null && i<list.length; i++ ) {
- context.addApplicationListener(list[i]);
- }
- ois.close();
- } catch( ClassNotFoundException ex ) {
- ex.printStackTrace();
- }
- }
-
/**
* Scan the JAR file at the specified resource path for TLDs in the
* <code>META-INF</code> subdirectory, and scan each TLD for application
setTldNamespaceAware(context.getTldNamespaceAware());
// (2) if the attribute wasn't defined on the context
- // try the host.
- if (!tldValidation) {
- setTldValidation(
- ((StandardHost) context.getParent()).getXmlValidation());
- }
+ // and override is not set on the context try the host.
+ if (!context.getOverride()) {
+ if (!tldValidation) {
+ setTldValidation(
+ ((StandardHost) context.getParent()).getXmlValidation());
+ }
- if (!tldNamespaceAware) {
- setTldNamespaceAware(
+ if (!tldNamespaceAware) {
+ setTldNamespaceAware(
((StandardHost) context.getParent()).getXmlNamespaceAware());
+ }
}
-
- tldDigester = DigesterFactory.newDigester(tldValidation,
- tldNamespaceAware,
- new TldRuleSet());
- tldDigester.getParser();
+ tldDigester = createTldDigester(tldNamespaceAware, tldValidation);
}
}
}