Author: markt Date: Wed Jan 8 17:49:03 2014 New Revision: 1556585 URL: http://svn.apache.org/r1556585 Log: Back-port some XML processing improvements (part 1) The patch could have been smaller but I opted to align some of the code with Tomcat 7 (which meant re-ordering methods in places) to make it easier to compare 6.0.x code with 7.0.x code. This covers: - always process TLDS with a namespace aware parser - enable validation with STRICT_SERVLET_COMPLIANCE (Servlet 2.5, SRV.14.4.3)
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/catalina/Context.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/Constants.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagPluginManager.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspCServletContext.java tomcat/tc6.0.x/trunk/java/org/apache/jasper/xmlparser/ParserUtils.java tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Wed Jan 8 17:49:03 2014 @@ -40,32 +40,6 @@ PATCHES PROPOSED TO BACKPORT: exclude lists in TldConfig.java, TldLocationsCache.java, see r1476932. -1: -* Back-port some XML processing improvements (part 1) - The patch could have been smaller but I opted to align some of the code with - Tomcat 7 (which meant re-ordering methods in places) to make it easier to - compare 6.0.x code with 7.0.x code. - http://people.apache.org/~markt/patches/2013-12-20-xml-prep-part1-tc6-v2.patch - +1: markt, remm, jboynes - +1: kkolinko: - I do not like that you change the values of validation flags when - STRICT_SERVLET_COMPLIANCE is set. This was a feature required for - Servlet 3.0, but I do not remember the same requirement for Servlet - 2.5. - I expect that with this change the bug #351040 in Eclipse IDE will - become visible with Tomcat 6, while it is currently observed with - Tomcat 7 only. It is not our policy to provide workarounds for 3rd - party bugs, so this is not a veto. - https://bugs.eclipse.org/bugs/show_bug.cgi?id=351040 - The rest of the patch is OK. - markt: - Servlet 2.5, SRV.14.4.3 requires validation for a J2EE compliant - implementation. The Eclipse bug is annoying but easy to workaround and - only present when using STRICT_SERVLET_COMPLIANCE. - kkolinko: - Thank you for the chapter number. I am changing my vote to +1. It'd - be better to mention the chapter number in the changelog. - -1: - * Back-port some XML processing improvements (part 2) JspC passes configuration with ServletContext init params so a real implementation is required. This is essentially a back-port of Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/Context.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/Context.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/Context.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/Context.java Wed Jan 8 17:49:03 2014 @@ -542,6 +542,82 @@ public interface Context extends Contain public void setWrapperClass(String wrapperClass); + /** + * Will the parsing of the web.xml file for this Context be performed by a + * namespace aware parser? + * + * @return true if namespace awareness is enabled. + */ + public boolean getXmlNamespaceAware(); + + + /** + * Controls whether the parsing of the web.xml file for this Context will be + * performed by a namespace aware parser. + * + * @param xmlNamespaceAware true to enable namespace awareness + */ + public void setXmlNamespaceAware(boolean xmlNamespaceAware); + + + /** + * Will the parsing of the web.xml file for this Context be performed by a + * validating parser? + * + * @return true if validation is enabled. + */ + public boolean getXmlValidation(); + + + /** + * Controls whether the parsing of the web.xml file for this Context will be + * performed by a validating parser. + * + * @param xmlValidation true to enable xml validation + */ + public void setXmlValidation(boolean xmlValidation); + + + /** + * *.tld files are always parsed using a namespace aware parser. + * + * @return Always <code>true</code> + * + * @deprecated This option will be removed in 8.0.x. + */ + @Deprecated + public boolean getTldNamespaceAware(); + + + /** + * *.tld files are always parsed using a namespace aware parser. + * + * @param tldNamespaceAware ignored + * + * @deprecated This option will be removed in 8.0.x. + */ + @Deprecated + public void setTldNamespaceAware(boolean tldNamespaceAware); + + + /** + * Will the parsing of *.tld files for this Context be performed by a + * validating parser? + * + * @return true if validation is enabled. + */ + public boolean getTldValidation(); + + + /** + * Controls whether the parsing of *.tld files for this Context will be + * performed by a validating parser. + * + * @param tldValidation true to enable xml validation + */ + public void setTldValidation(boolean tldValidation); + + // --------------------------------------------------------- Public Methods @@ -1097,77 +1173,5 @@ public interface Context extends Contain * @param listener Class name of a ContainerListener class to be removed */ public void removeWrapperListener(String listener); - - - /** - * Will the parsing of the web.xml file for this Context be performed by a - * namespace aware parser? - * - * @return true if namespace awareness is enabled. - */ - public boolean getXmlNamespaceAware(); - - - /** - * Will the parsing of the web.xml file for this Context be performed by a - * validating parser? - * - * @return true if validation is enabled. - */ - public boolean getXmlValidation(); - - - /** - * Controls whether the parsing of the web.xml file for this Context will be - * performed by a validating parser. - * - * @param xmlValidation true to enable xml validation - */ - public void setXmlValidation(boolean xmlValidation); - - - /** - * Controls whether the parsing of the web.xml file for this Context will be - * performed by a namespace aware parser. - * - * @param xmlNamespaceAware true to enable namespace awareness - */ - public void setXmlNamespaceAware(boolean xmlNamespaceAware); - - - /** - * Controls whether the parsing of *.tld files for this Context will be - * performed by a validating parser. - * - * @param tldValidation true to enable xml validation - */ - public void setTldValidation(boolean tldValidation); - - - /** - * Will the parsing of *.tld files for this Context be performed by a - * validating parser? - * - * @return true if validation is enabled. - */ - public boolean getTldValidation(); - - - /** - * Will the parsing of *.tld files for this Context be performed by a - * namespace aware parser? - * - * @return true if namespace awareness is enabled. - */ - public boolean getTldNamespaceAware(); - - - /** - * Controls whether the parsing of *.tld files for this Context will be - * performed by a namespace aware parser. - * - * @param tldNamespaceAware true to enable namespace awareness - */ - public void setTldNamespaceAware(boolean tldNamespaceAware); } Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/Globals.java Wed Jan 8 17:49:03 2014 @@ -352,4 +352,12 @@ public final class Globals { (System.getSecurityManager() != null); + /** + * Name of the ServletContext init-param that determines if the JSP engine + * should validate *.tld files when parsing them. + * <p> + * This must be kept in sync with org.apache.jasper.Constants + */ + public static final String JASPER_XML_VALIDATION_TLD_INIT_PARAM = + "org.apache.jasper.XML_VALIDATE_TLD"; } Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java Wed Jan 8 17:49:03 2014 @@ -24,7 +24,9 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -251,6 +253,13 @@ public class ApplicationContext * @param name Name of the initialization parameter to retrieve */ public String getInitParameter(final String name) { + // Special handling for XML settings as the context setting must + // always override anything that might have been set by an application. + if (Globals.JASPER_XML_VALIDATION_TLD_INIT_PARAM.equals(name) && + context.getTldValidation()) { + return "true"; + } + return parameters.get(name); } @@ -269,8 +278,15 @@ public class ApplicationContext * Return the names of the context's initialization parameters, or an * empty enumeration if the context has no initialization parameters. */ - public Enumeration getInitParameterNames() { - return (new Enumerator(parameters.keySet())); + public Enumeration<String> getInitParameterNames() { + Set<String> names = new HashSet<String>(); + names.addAll(parameters.keySet()); + // Special handling for XML settings as these attributes will always be + // available if they have been set on the context + if (context.getTldValidation()) { + names.add(Globals.JASPER_XML_VALIDATION_TLD_INIT_PARAM); + } + return Collections.enumeration(names); } Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/StandardContext.java Wed Jan 8 17:49:03 2014 @@ -680,13 +680,13 @@ public class StandardContext /** * Attribute value used to turn on/off XML validation */ - private boolean webXmlValidation = false; + private boolean webXmlValidation = Globals.STRICT_SERVLET_COMPLIANCE; /** * Attribute value used to turn on/off XML namespace validation */ - private boolean webXmlNamespaceAware = false; + private boolean webXmlNamespaceAware = Globals.STRICT_SERVLET_COMPLIANCE; /** * Attribute value used to turn on/off TLD processing @@ -696,13 +696,7 @@ public class StandardContext /** * Attribute value used to turn on/off XML validation */ - private boolean tldValidation = false; - - - /** - * Attribute value used to turn on/off TLD XML namespace validation - */ - private boolean tldNamespaceAware = false; + private boolean tldValidation = Globals.STRICT_SERVLET_COMPLIANCE; /** @@ -5888,13 +5882,13 @@ public class StandardContext public boolean getTldNamespaceAware(){ - return tldNamespaceAware; + return true; } public void setTldNamespaceAware(boolean tldNamespaceAware){ - this.tldNamespaceAware= tldNamespaceAware; - } + // NO-OP; + } public void setTldValidation(boolean tldValidation){ Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml Wed Jan 8 17:49:03 2014 @@ -263,6 +263,10 @@ description="Flag to set to cause the system.out and system.err to be redirected to the logger when executing a servlet" type="boolean"/> + <attribute name="tldValidation" + description="Should the parsing of *.tld files be performed by a validating parser?" + type="boolean"/> + <attribute name="unloadDelay" description="Amount of ms that the container will wait for servlets to unload" type="long"/> @@ -290,6 +294,14 @@ description="The pathname to the work directory for this context" type="java.lang.String"/> + <attribute name="xmlValidation" + description="Should the parsing of web.xml be performed by a validating parser?" + type="boolean"/> + + <attribute name="xmlNamespaceAware" + description="Should the parsing of web.xml be performed by a namespace aware parser?" + type="boolean"/> + <operation name="addValve" description="Add a valve to this Context" impact="ACTION" @@ -493,11 +505,11 @@ type="boolean"/> <attribute name="xmlNamespaceAware" - description="Attribute value used to turn on/off XML namespace awareness" + description="Controls whether the parsing of the web.xml file for Contexts of this Host will be performed by a namespace aware parser. If false, it may still be enabled per Context using the Context's xmlNamespaceAware attribute." type="boolean"/> <attribute name="xmlValidation" - description="Attribute value used to turn on/off XML validation" + description="Controls whether the parsing of the web.xml file and *.tld files for Contexts of this Host will be performed by a validating parser. If false, it may still be enabled per Context using the Context's xmlValidation attribute." type="boolean"/> <attribute name="children" Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java Wed Jan 8 17:49:03 2014 @@ -124,14 +124,6 @@ public final class TldConfig implements } - // ----------------------------------------------------- Instance Variables - - /** - * The Context we are associated with. - */ - private Context context = null; - - /** * The string resources for this package. */ @@ -139,23 +131,51 @@ public final class TldConfig implements StringManager.getManager(Constants.Package); /** - * The <code>Digester</code> we will use to process tag library - * descriptor files. + * The <code>Digester</code>s available to process tld files. */ - private static Digester tldDigester = null; - + private static Digester[] tldDigesters = new Digester[2]; /** - * Attribute value used to turn on/off TLD validation + * Create (if necessary) and return a Digester configured to process the + * tld. */ - private static boolean tldValidation = false; + private static Digester createTldDigester(boolean validation) { + + Digester digester = null; + if (!validation) { + if (tldDigesters[0] == null) { + tldDigesters[0] = DigesterFactory.newDigester(validation, + true, new TldRuleSet()); + tldDigesters[0].getParser(); + } + digester = tldDigesters[0]; + } else { + if (tldDigesters[1] == null) { + tldDigesters[1] = DigesterFactory.newDigester(validation, + true, new TldRuleSet()); + tldDigesters[1].getParser(); + } + digester = tldDigesters[1]; + } + return digester; + } + // ----------------------------------------------------- Instance Variables + /** - * Attribute value used to turn on/off TLD namespace awarenes. + * The Context we are associated with. */ - private static boolean tldNamespaceAware = false; + private Context context = null; + + /** + * The <code>Digester</code> we will use to process tag library + * descriptor files. + */ + private Digester tldDigester = null; + + private boolean rescan=true; private ArrayList<String> listeners = new ArrayList<String>(); @@ -179,40 +199,58 @@ public final class TldConfig implements } /** - * Set the validation feature of the XML parser used when - * parsing xml instances. - * @param tldValidation true to enable xml instance validation + * *.tld are parsed using the TLD validation setting of the associated + * context. + * + * @param tldValidation ignore + * + * @deprecated This option will be removed in 7.0.x. */ + @Deprecated public void setTldValidation(boolean tldValidation){ - TldConfig.tldValidation = tldValidation; + // NO-OP } /** - * Get the server.xml <host> attribute's xmlValidation. + * *.tld are parsed using the TLD validation setting of the associated + * context. + * * @return true if validation is enabled. * + * @deprecated This option will be removed in 7.0.x. */ + @Deprecated public boolean getTldValidation(){ - return tldValidation; + Context context = getContext(); + if (context == null) { + return false; + } + return context.getTldValidation(); } /** - * Get the server.xml <host> attribute's xmlNamespaceAware. - * @return true if namespace awarenes is enabled. + * *.tld files are always parsed using a namespace aware parser. * + * @return Always <code>true</code> + * + * @deprecated This option will be removed in 7.0.x. */ + @Deprecated public boolean getTldNamespaceAware(){ - return tldNamespaceAware; + return true; } /** - * Set the namespace aware feature of the XML parser used when - * parsing xml instances. - * @param tldNamespaceAware true to enable namespace awareness + * *.tld files are always parsed using a namespace aware parser. + * + * @param tldNamespaceAware ignored + * + * @deprecated This option will be removed in 7.0.x. */ + @Deprecated public void setTldNamespaceAware(boolean tldNamespaceAware){ - TldConfig.tldNamespaceAware = tldNamespaceAware; + // NO-OP } @@ -649,25 +687,16 @@ public final class TldConfig implements if (tldDigester == null){ // (1) check if the attribute has been defined // on the context element. - setTldValidation(context.getTldValidation()); - setTldNamespaceAware(context.getTldNamespaceAware()); - + boolean tldValidation = context.getTldValidation(); + // (2) if the attribute wasn't defined on the context // try the host. if (!tldValidation) { - setTldValidation( - ((StandardHost) context.getParent()).getXmlValidation()); + tldValidation = + ((StandardHost) context.getParent()).getXmlValidation(); } - if (!tldNamespaceAware) { - setTldNamespaceAware( - ((StandardHost) context.getParent()).getXmlNamespaceAware()); - } - - tldDigester = DigesterFactory.newDigester(tldValidation, - tldNamespaceAware, - new TldRuleSet()); - tldDigester.getParser(); + tldDigester = createTldDigester(context.getTldValidation()); } } } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/Constants.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/Constants.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/Constants.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/Constants.java Wed Jan 8 17:49:03 2014 @@ -205,4 +205,12 @@ public class Constants { System.getProperty("org.apache.catalina.SESSION_PARAMETER_NAME", "jsessionid"); + /** + * Name of the ServletContext init-param that determines if the XML parsers + * used for *.tld files will be validating or not. + * <p> + * This must be kept in sync with org.apache.catalina.Globals + */ + public static final String XML_VALIDATION_TLD_INIT_PARAM = + "org.apache.jasper.XML_VALIDATE_TLD"; } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/EmbeddedServletOptions.java Wed Jan 8 17:49:03 2014 @@ -404,10 +404,6 @@ public final class EmbeddedServletOption setProperty( k, v); } - // quick hack - String validating=config.getInitParameter( "validating"); - if( "false".equals( validating )) ParserUtils.validating=false; - String keepgen = config.getInitParameter("keepgenerated"); if (keepgen != null) { if (keepgen.equalsIgnoreCase("true")) { Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/JspC.java Wed Jan 8 17:49:03 2014 @@ -123,6 +123,7 @@ public class JspC extends Task implement protected static final String SWITCH_ENCODING = "-javaEncoding"; protected static final String SWITCH_SMAP = "-smap"; protected static final String SWITCH_DUMP_SMAP = "-dumpsmap"; + protected static final String SWITCH_VALIDATE_TLD = "-validateTld"; protected static final String SHOW_SUCCESS ="-s"; protected static final String LIST_ERRORS = "-l"; @@ -143,6 +144,7 @@ public class JspC extends Task implement protected URLClassLoader loader = null; protected boolean trimSpaces = false; protected boolean genStringAsCharArray = false; + protected boolean validateTld; protected boolean xpoweredBy; protected boolean mappedFile = false; protected boolean poolingEnabled = true; @@ -351,6 +353,8 @@ public class JspC extends Task implement smapSuppressed = false; } else if (tok.equals(SWITCH_DUMP_SMAP)) { smapDumped = true; + } else if (tok.equals(SWITCH_VALIDATE_TLD)) { + setValidateTld(true); } else { if (tok.startsWith("-")) { throw new JasperException("Unrecognized option: " + tok + @@ -836,10 +840,14 @@ public class JspC extends Task implement } } - public void setValidateXml( boolean b ) { - org.apache.jasper.xmlparser.ParserUtils.validating=b; + public void setValidateTld( boolean b ) { + this.validateTld = b; } + public boolean isValidateTld() { + return validateTld; + } + public void setListErrors( boolean b ) { listErrors = b; } @@ -1425,6 +1433,10 @@ public class JspC extends Task implement } catch (MalformedURLException me) { System.out.println("**" + me); } + if (isValidateTld()) { + context.setInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM, "true"); + } + rctxt = new JspRuntimeContext(context, this); jspConfig = new JspConfig(context); tagPluginManager = new TagPluginManager(context); Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/ImplicitTagLibraryInfo.java Wed Jan 8 17:49:03 2014 @@ -29,6 +29,7 @@ import javax.servlet.jsp.tagext.TagFileI import javax.servlet.jsp.tagext.TagInfo; import javax.servlet.jsp.tagext.TagLibraryInfo; +import org.apache.jasper.Constants; import org.apache.jasper.JasperException; import org.apache.jasper.JspCompilationContext; import org.apache.jasper.xmlparser.ParserUtils; @@ -123,7 +124,11 @@ class ImplicitTagLibraryInfo extends Tag pi.addDependant(path); } - ParserUtils pu = new ParserUtils(); + boolean validate = Boolean.parseBoolean( + ctxt.getServletContext().getInitParameter( + Constants.XML_VALIDATION_TLD_INIT_PARAM)); + + ParserUtils pu = new ParserUtils(validate); TreeNode tld = pu.parseXMLDocument(uri, in); if (tld.findAttribute("version") != null) { Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspConfig.java Wed Jan 8 17:49:03 2014 @@ -24,6 +24,7 @@ import java.net.URL; import javax.servlet.ServletContext; +import org.apache.jasper.Constants; import org.apache.jasper.JasperException; import org.apache.jasper.xmlparser.ParserUtils; import org.apache.jasper.xmlparser.TreeNode; @@ -87,7 +88,10 @@ public class JspConfig { InputSource ip = new InputSource(is); ip.setSystemId(uri.toExternalForm()); - ParserUtils pu = new ParserUtils(); + boolean validate = Boolean.parseBoolean( + ctxt.getInitParameter(Constants.XML_VALIDATION_TLD_INIT_PARAM)); + + ParserUtils pu = new ParserUtils(validate); TreeNode webApp = pu.parseXMLDocument(WEB_XML, ip); if (webApp == null Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/JspDocumentParser.java Wed Jan 8 17:49:03 2014 @@ -1414,16 +1414,24 @@ class JspDocumentParser throws Exception { SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(true); + factory.setNamespaceAware(true); // Preserve xmlns attributes factory.setFeature( "http://xml.org/sax/features/namespace-prefixes", true); + factory.setValidating(validating); - //factory.setFeature( - // "http://xml.org/sax/features/validation", - // validating); + if (validating) { + // Enable DTD validation + factory.setFeature( + "http://xml.org/sax/features/validation", + true); + // Enable schema validation + factory.setFeature( + "http://apache.org/xml/features/validation/schema", + true); + } // Configure the parser SAXParser saxParser = factory.newSAXParser(); Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagLibraryInfoImpl.java Wed Jan 8 17:49:03 2014 @@ -45,6 +45,7 @@ import javax.servlet.jsp.tagext.TagVaria import javax.servlet.jsp.tagext.ValidationMessage; import javax.servlet.jsp.tagext.VariableInfo; +import org.apache.jasper.Constants; import org.apache.jasper.JasperException; import org.apache.jasper.JspCompilationContext; import org.apache.jasper.xmlparser.ParserUtils; @@ -217,8 +218,12 @@ class TagLibraryInfoImpl extends TagLibr Vector tagFileVector = new Vector(); Hashtable functionTable = new Hashtable(); + boolean validate = Boolean.parseBoolean( + ctxt.getServletContext().getInitParameter( + Constants.XML_VALIDATION_TLD_INIT_PARAM)); + // Create an iterator over the child elements of our <taglib> element - ParserUtils pu = new ParserUtils(); + ParserUtils pu = new ParserUtils(validate); TreeNode tld = pu.parseXMLDocument(uri, in); // Check to see if the <taglib> root element contains a 'version' Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagPluginManager.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagPluginManager.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagPluginManager.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TagPluginManager.java Wed Jan 8 17:49:03 2014 @@ -74,7 +74,7 @@ public class TagPluginManager { if (is == null) return; - TreeNode root = (new ParserUtils()).parseXMLDocument(TAG_PLUGINS_XML, + TreeNode root = (new ParserUtils(false)).parseXMLDocument(TAG_PLUGINS_XML, is); if (root == null) { return; Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java Wed Jan 8 17:49:03 2014 @@ -292,13 +292,17 @@ public class TldLocationsCache { InputSource ip = new InputSource(is); ip.setSystemId(uri.toExternalForm()); + boolean validate = Boolean.parseBoolean( + ctxt.getInitParameter( + Constants.XML_VALIDATION_TLD_INIT_PARAM)); + // Parse the web application deployment descriptor TreeNode webtld = null; // altDDName is the absolute path of the DD if (altDDName != null) { - webtld = new ParserUtils().parseXMLDocument(altDDName, ip); + webtld = new ParserUtils(validate).parseXMLDocument(altDDName, ip); } else { - webtld = new ParserUtils().parseXMLDocument(WEB_XML, ip); + webtld = new ParserUtils(validate).parseXMLDocument(WEB_XML, ip); } // Allow taglib to be an element of the root or jsp-config (JSP2.0) @@ -460,8 +464,12 @@ public class TldLocationsCache { private String getUriFromTld(String resourcePath, InputStream in) throws JasperException { + boolean validate = Boolean.parseBoolean( + ctxt.getInitParameter( + Constants.XML_VALIDATION_TLD_INIT_PARAM)); + // Parse the tag library descriptor at the specified resource path - TreeNode tld = new ParserUtils().parseXMLDocument(resourcePath, in); + TreeNode tld = new ParserUtils(validate).parseXMLDocument(resourcePath, in); TreeNode uri = tld.findChild("uri"); if (uri != null) { String body = uri.getBody(); Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspCServletContext.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspCServletContext.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspCServletContext.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/servlet/JspCServletContext.java Wed Jan 8 17:49:03 2014 @@ -437,5 +437,7 @@ public class JspCServletContext implemen } - + public boolean setInitParameter(String name, String value) { + return false; + } } Modified: tomcat/tc6.0.x/trunk/java/org/apache/jasper/xmlparser/ParserUtils.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jasper/xmlparser/ParserUtils.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jasper/xmlparser/ParserUtils.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jasper/xmlparser/ParserUtils.java Wed Jan 8 17:49:03 2014 @@ -47,7 +47,7 @@ import org.xml.sax.SAXParseException; * use a separate class loader for the parser to be used. * * @author Craig R. McClanahan - * @version $Id:$ + * @version $Id$ */ public class ParserUtils { @@ -61,9 +61,28 @@ public class ParserUtils { */ static EntityResolver entityResolver = new MyEntityResolver(); - // Turn off for JSP 2.0 until switch over to using xschema. + /** + * @deprecated Unused. Will be removed in Tomcat 7. + * Use {@link ParserUtils#ParserUtils(boolean)} instead. + */ + @Deprecated public static boolean validating = false; + private final boolean useValidation; + + /** + * @deprecated Unused. Will be removed in Tomcat 7. + * Use {@link ParserUtils#ParserUtils(boolean)} instead. + */ + @Deprecated + public ParserUtils() { + this(true); + } + + public ParserUtils(boolean useValidation) { + this.useValidation = useValidation; + } + // --------------------------------------------------------- Public Methods @@ -87,7 +106,7 @@ public class ParserUtils { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); - factory.setValidating(validating); + factory.setValidating(useValidation); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(entityResolver); builder.setErrorHandler(errorHandler); Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java Wed Jan 8 17:49:03 2014 @@ -488,13 +488,35 @@ public class Digester extends DefaultHan /** * Return the SAXParserFactory we will use, creating one if necessary. + * @throws ParserConfigurationException + * @throws SAXNotSupportedException + * @throws SAXNotRecognizedException */ - public SAXParserFactory getFactory() { + public SAXParserFactory getFactory() throws SAXNotRecognizedException, + SAXNotSupportedException, ParserConfigurationException { if (factory == null) { factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(namespaceAware); + // Preserve xmlns attributes + if (namespaceAware) { + factory.setFeature( + "http://xml.org/sax/features/namespace-prefixes", + true); + } + factory.setValidating(validating); + if (validating) { + // Enable DTD validation + factory.setFeature( + "http://xml.org/sax/features/validation", + true); + // Enable schema validation + factory.setFeature( + "http://apache.org/xml/features/validation/schema", + true); + } } return (factory); Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Wed Jan 8 17:49:03 2014 @@ -83,6 +83,18 @@ <fix> Add missing JavaEE 5 XML schema definitions. (markt) </fix> + <fix> + When Catalina parses TLD files, always use a namespace aware parser to + be consistent with how Jasper parses TLD files. The + <code>tldNamespaceAware</code> attribute of the Context is now ignored. + </fix> + <fix> + As per section SRV.14.4.3 of the Servlet 2.5 specification, a namespace + aware, validating parser will be used when processing <code>*.tld</code> + and <code>web.xml</code> files if the system property + <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> is set to + <code>true</code>. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/config/context.xml Wed Jan 8 17:49:03 2014 @@ -338,20 +338,15 @@ connector used to access this Context.</p> </attribute> - <attribute name="tldNamespaceAware" required="false"> - <p>If the value of this flag is <code>true</code>, the TLD files - XML validation will be namespace-aware. If you turn this flag on, - you should probably also turn <code>tldValidation</code> on. The - default value for this flag is <code>false</code>, and setting it - to true will incur a performance penalty. - </p> - </attribute> - <attribute name="tldValidation" required="false"> <p>If the value of this flag is <code>true</code>, the TLD files - will be XML validated on context startup. The default value for - this flag is <code>false</code>, and setting it to true will incur - a performance penalty.</p> + will be XML validated on context startup. If the + <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> + <a href="systemprops.html">system property</a> is set to + <code>true</code>, the default value of this attribute will be + <code>true</code>, else the default value will be <code>false</code>. + Setting this attribute to <code>true</code> will incur a performance + penalty.</p> </attribute> <attribute name="useHttpOnly" required="false"> @@ -366,6 +361,34 @@ Context. If not specified, a standard default value will be used.</p> </attribute> + <attribute name="xmlNamespaceAware" required="false"> + <p>If the value of this flag is <code>true</code>, the parsing of the + <code>web.xml</code> file for this web application will be + namespace-aware. Note that <code>*.tld</code>, <code>*.jspx</code> and + <code>*.tagx</code> files are always parsed using a namespace-aware + parser and that the <code>tagPlugins.xml</code> file (if any) is never + parsed using a namespace-aware parser. Note also that if you turn this + flag on, you should probably also turn <code>xmlValidation</code> on. If + the <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> + <a href="systemprops.html">system property</a> is set to + <code>true</code>, the default value of this attribute will be + <code>true</code>, else the default value will be <code>false</code>. + Setting this attribute to <code>true</code> will incur a performance + penalty.</p> + </attribute> + + <attribute name="xmlValidation" required="false"> + <p>If the value of this flag is <code>true</code>, the parsing of the + <code>web.xml</code> file for this web application will use a validating + parser. If the + <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> + <a href="systemprops.html">system property</a> is set to + <code>true</code>, the default value of this attribute will be + <code>true</code>, else the default value will be <code>false</code>. + Setting this attribute to <code>true</code> will incur a performance + penalty.</p> + </attribute> + </attributes> Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml?rev=1556585&r1=1556584&r2=1556585&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml Wed Jan 8 17:49:03 2014 @@ -298,6 +298,12 @@ <p>If this is <code>true</code> the default value will be changed for: <ul> <li><code>org.apache.catalina.connector.Request. ALLOW_EMPTY_QUERY_STRING</code> property</li> + <li>The <code>webXmlValidation</code> attribute of any + <a href="context.html">Context</a> element.</li> + <li>The <code>webXmlNamespaceAware</code> attribute of any + <a href="context.html">Context</a> element.</li> + <li>The <code>tldValidation</code> attribute of any + <a href="context.html">Context</a> element.</li> </ul> </p> <p>If not specified, the default value of <code>false</code> will be used.</p> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org