Author: markt
Date: Mon Jan 13 13:40:48 2014
New Revision: 1557711
URL: http://svn.apache.org/r1557711
Log:
Back-port from XML processing improvements (part 7)
Switch o.a.catalina classes to use the new ErrorHandler
Back-port of http://svn.apache.org/r1547937
Modified:
tomcat/tc6.0.x/trunk/STATUS.txt
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/TldConfig.java
Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1557711&r1=1557710&r2=1557711&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Mon Jan 13 13:40:48 2014
@@ -61,13 +61,6 @@ PATCHES PROPOSED TO BACKPORT:
requires Ant >= 1.8.0).
-1:
-* Back-port from XML processing improvements (part 7)
- Switch o.a.catalina classes to use the new ErrorHandler
- Back-port of http://svn.apache.org/r1547937
-
http://people.apache.org/~markt/patches/2014-01-08-xml-prep-part7-tc6-v1.patch
- +1: markt, kkolinko, remm
- -1:
-
* Back-port from XML processing improvements (part 8)
Switch ParserUtils to use the new ErrorHandler
Back-port of http://svn.apache.org/r1547947
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1557711&r1=1557710&r2=1557711&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/ContextConfig.java
Mon Jan 13 13:40:48 2014
@@ -51,6 +51,7 @@ import org.apache.catalina.deploy.Securi
import org.apache.catalina.util.StringManager;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.descriptor.XmlErrorHandler;
import org.apache.tomcat.util.digester.Digester;
import org.apache.tomcat.util.digester.RuleSet;
import org.xml.sax.ErrorHandler;
@@ -119,7 +120,9 @@ public class ContextConfig implements Li
/**
* Any parse error which occurred while parsing XML descriptors.
+ * @deprecated Unused. Will be removed in Tomcat 7.0.x.
*/
+ @Deprecated
protected SAXParseException parseException = null;
@@ -348,8 +351,11 @@ public class ContextConfig implements Li
if (context instanceof StandardContext) {
((StandardContext)
context).setReplaceWelcomeFiles(true);
}
+
+ XmlErrorHandler handler = new XmlErrorHandler();
+
webDigester.push(context);
- webDigester.setErrorHandler(new ContextErrorHandler());
+ webDigester.setErrorHandler(handler);
if(log.isDebugEnabled()) {
log.debug("Parsing application web.xml file at " +
url.toExternalForm());
@@ -357,8 +363,10 @@ public class ContextConfig implements Li
webDigester.parse(is);
- if (parseException != null) {
+ if (handler.getWarnings().size() > 0 ||
+ handler.getErrors().size() > 0) {
ok = false;
+ handler.logFindings(log, is.getSystemId());
}
} else {
log.info("No web.xml, using defaults " + context );
@@ -374,7 +382,6 @@ public class ContextConfig implements Li
ok = false;
} finally {
webDigester.reset();
- parseException = null;
try {
if (stream != null) {
stream.close();
@@ -664,11 +671,14 @@ public class ContextConfig implements Li
((StandardContext) context).setReplaceWelcomeFiles(true);
digester.setClassLoader(this.getClass().getClassLoader());
digester.setUseContextClassLoader(false);
+ XmlErrorHandler handler = new XmlErrorHandler();
digester.push(context);
- digester.setErrorHandler(new ContextErrorHandler());
+ digester.setErrorHandler(handler);
digester.parse(source);
- if (parseException != null) {
+ if (handler.getWarnings().size() > 0 ||
+ handler.getErrors().size() > 0) {
ok = false;
+ handler.logFindings(log, source.getSystemId());
}
} catch (SAXParseException e) {
log.error(sm.getString("contextConfig.defaultParse"), e);
@@ -681,7 +691,6 @@ public class ContextConfig implements Li
ok = false;
} finally {
digester.reset();
- parseException = null;
try {
if (stream != null) {
stream.close();
@@ -769,12 +778,15 @@ public class ContextConfig implements Li
source.setByteStream(stream);
contextDigester.setClassLoader(this.getClass().getClassLoader());
contextDigester.setUseContextClassLoader(false);
+ XmlErrorHandler handler = new XmlErrorHandler();
contextDigester.push(context.getParent());
contextDigester.push(context);
- contextDigester.setErrorHandler(new ContextErrorHandler());
+ contextDigester.setErrorHandler(handler);
contextDigester.parse(source);
- if (parseException != null) {
+ if (handler.getWarnings().size() > 0 ||
+ handler.getErrors().size() > 0) {
ok = false;
+ handler.logFindings(log, source.getSystemId());
}
if (log.isDebugEnabled())
log.debug("Successfully processed context [" +
context.getName()
@@ -792,7 +804,6 @@ public class ContextConfig implements Li
ok = false;
} finally {
contextDigester.reset();
- parseException = null;
try {
if (stream != null) {
stream.close();
@@ -1322,6 +1333,11 @@ public class ContextConfig implements Li
}
+ /**
+ * @deprecated Unused. Use {@link XmlErrorHandler}. Will be removed in
+ * Tomcat 7.0.x
+ */
+ @Deprecated
protected class ContextErrorHandler
implements ErrorHandler {
@@ -1339,5 +1355,4 @@ public class ContextConfig implements Li
}
-
}
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=1557711&r1=1557710&r2=1557711&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 Mon
Jan 13 13:40:48 2014
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,6 +49,7 @@ import org.apache.catalina.LifecycleList
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.util.StringManager;
+import org.apache.tomcat.util.descriptor.XmlErrorHandler;
import org.apache.tomcat.util.digester.Digester;
import org.xml.sax.InputSource;
@@ -140,7 +141,7 @@ public final class TldConfig implements
* tld.
*/
private static Digester createTldDigester(boolean validation) {
-
+
Digester digester = null;
if (!validation) {
if (tldDigesters[0] == null) {
@@ -174,8 +175,8 @@ public final class TldConfig implements
* descriptor files.
*/
private Digester tldDigester = null;
-
-
+
+
private boolean rescan=true;
private ArrayList<String> listeners = new ArrayList<String>();
@@ -185,8 +186,8 @@ public final class TldConfig implements
/**
* Sets the list of JARs that are known not to contain any TLDs.
*
- * @param jarNames List of comma-separated names of JAR files that are
- * known not to contain any TLDs
+ * @param jarNames List of comma-separated names of JAR files that are
+ * known not to contain any TLDs
*/
public static void setNoTldJars(String jarNames) {
if (jarNames != null) {
@@ -201,9 +202,9 @@ public final class TldConfig implements
/**
* *.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
@@ -214,7 +215,7 @@ public final class TldConfig implements
/**
* *.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.
@@ -232,7 +233,7 @@ public final class TldConfig implements
* *.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
@@ -245,13 +246,13 @@ public final class TldConfig implements
* *.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){
// NO-OP
- }
+ }
public boolean isRescan() {
@@ -400,7 +401,10 @@ public final class TldConfig implements
log.trace(" Processing TLD at '" + name + "'");
}
try {
- tldScanStream(new
InputSource(jarFile.getInputStream(entry)));
+ XmlErrorHandler handler = tldScanStream(
+ new InputSource(jarFile.getInputStream(entry)));
+ handler.logFindings(log, "[" + name + "] in [" +
+ file.getAbsolutePath() + "]");
} catch (Exception e) {
log.error(sm.getString("contextConfig.tldEntryException",
name, jarPath, context.getPath()),
@@ -432,18 +436,21 @@ public final class TldConfig implements
*
* @exception Exception if an exception occurs while scanning this TLD
*/
- private void tldScanStream(InputSource resourceStream)
+ private XmlErrorHandler tldScanStream(InputSource resourceStream)
throws Exception {
+ XmlErrorHandler result = new XmlErrorHandler();
+
synchronized (tldDigester) {
try {
+ tldDigester.setErrorHandler(result);
tldDigester.push(this);
tldDigester.parse(resourceStream);
} finally {
tldDigester.reset();
}
}
-
+ return result;
}
/**
@@ -475,13 +482,14 @@ public final class TldConfig implements
(sm.getString("contextConfig.tldResourcePath",
resourcePath));
}
- tldScanStream(inputSource);
+ XmlErrorHandler handler = tldScanStream(inputSource);
+ handler.logFindings(log, resourcePath);
} catch (Exception e) {
throw new ServletException
(sm.getString("contextConfig.tldFileException", resourcePath,
context.getPath()),
e);
- }
+ }
}
@@ -546,7 +554,7 @@ public final class TldConfig implements
*/
private void tldScanResourcePathsWebInf(DirContext resources,
String rootPath,
- Set tldPaths)
+ Set tldPaths)
throws IOException {
if (log.isTraceEnabled()) {
@@ -588,7 +596,7 @@ public final class TldConfig implements
*
* The latter constitutes a Tomcat-specific extension to the TLD search
* order defined in the JSP spec. It allows tag libraries packaged as JAR
- * files to be shared by web applications by simply dropping them in a
+ * files to be shared by web applications by simply dropping them in a
* location that all web applications have access to (e.g.,
* <CATALINA_HOME>/common/lib).
*
@@ -613,12 +621,12 @@ public final class TldConfig implements
// This is definitely not as clean as using JAR URLs either
// over file or the custom jndi handler, but a lot less
// buggy overall
-
+
// Check that the URL is using file protocol, else ignore
it
if (!"file".equals(urls[i].getProtocol())) {
continue;
}
-
+
File file = null;
try {
file = new File(urls[i].toURI());
@@ -668,7 +676,7 @@ public final class TldConfig implements
log.error(sm.getString("tldConfig.cce", event.getLifecycle()), e);
return;
}
-
+
if (event.getType().equals(Lifecycle.INIT_EVENT)) {
init();
} else if (event.getType().equals(Lifecycle.START_EVENT)) {
@@ -682,20 +690,20 @@ public final class TldConfig implements
listeners.clear();
}
}
-
+
private void init() {
if (tldDigester == null){
// (1) check if the attribute has been defined
// on the context element.
boolean tldValidation = context.getTldValidation();
-
+
// (2) if the attribute wasn't defined on the context
// try the host.
if (!tldValidation) {
tldValidation =
((StandardHost)
context.getParent()).getXmlValidation();
}
-
+
tldDigester = createTldDigester(context.getTldValidation());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]