import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.util.digester.Digester;
import org.apache.tomcat.util.digester.RuleSet;
-import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
contextDigester.setUseContextClassLoader(false);
contextDigester.push(context.getParent());
contextDigester.push(context);
- ContextErrorHandler errorHandler = new ContextErrorHandler();
+ XmlErrorHandler errorHandler = new XmlErrorHandler();
contextDigester.setErrorHandler(errorHandler);
contextDigester.parse(source);
- if (errorHandler.parseException != null) {
+ if (errorHandler.getWarnings().size() > 0 ||
+ errorHandler.getErrors().size() > 0) {
+ errorHandler.logFindings(log, contextXml.toString());
ok = false;
}
if (log.isDebugEnabled())
if (source == null) return;
- ContextErrorHandler handler = new ContextErrorHandler();
+ XmlErrorHandler handler = new XmlErrorHandler();
// Web digesters and rulesets are shared between contexts but are not
// thread safe. Whilst there should only be one thread at a time
try {
digester.parse(source);
- if (handler.getParseException() != 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.applicationParse",
stream = jarFile.getInputStream(fragmentEntry);
InputSource source = new InputSource(
urlConn.getJarFileURL().toString() +
- File.separatorChar + FRAGMENT_LOCATION);
+ "!/" + FRAGMENT_LOCATION);
source.setByteStream(stream);
parseWebXml(source, fragment, true);
}
return fragments;
}
}
-
-
- protected static class ContextErrorHandler
- implements ErrorHandler {
-
- private SAXParseException parseException = null;
-
- public void error(SAXParseException exception) {
- parseException = exception;
- }
-
- public void fatalError(SAXParseException exception) {
- parseException = exception;
- }
-
- public void warning(SAXParseException exception) {
- parseException = exception;
- }
-
- public SAXParseException getParseException() {
- return parseException;
- }
- }
-
-
}
tldConfig.dirFail=Failed to process directory [{0}] for TLD files
tldConfig.dirScan=Scanning for TLD files in directory [{0}]
tldConfig.execute=Error processing TLD files for context path {0}
-tldConfig.handlerError=Non-fatal error [{0}] reported processing [{1}].
-tldConfig.handlerWarning=Warning [{0}] reported processing [{1}].
tldConfig.jarFail=Failed to process JAR [{0}] for TLD files
tldConfig.webinfFail=Failed to process TLD found at [{0}]
tldConfig.webinfScan=Scanning WEB-INF for TLD files in [{0}]
userConfig.stop=UserConfig: Processing STOP
webRuleSet.absoluteOrdering=<absolute-ordering> element not valid in web-fragment.xml and will be ignored
webRuleSet.relativeOrdering=<ordering> element not valid in web.xml and will be ignored
-
+xmlErrorHandler.error=Non-fatal error [{0}] reported processing [{1}].
+xmlErrorHandler.warning=Warning [{0}] reported processing [{1}].
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.catalina.startup;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.util.digester.Digester;
-import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
/**
}
}
- private static class TldErrorHandler implements ErrorHandler {
-
- private Set<SAXParseException> errors =
- new HashSet<SAXParseException>();
-
- private Set<SAXParseException> warnings =
- new HashSet<SAXParseException>();
-
- @Override
- public void error(SAXParseException exception) throws SAXException {
- // Collect non-fatal errors
- errors.add(exception);
- }
-
- @Override
- public void fatalError(SAXParseException exception) throws SAXException {
- // Re-throw fatal errors
- throw exception;
- }
-
- @Override
- public void warning(SAXParseException exception) throws SAXException {
- // Collect warnings
- warnings.add(exception);
- }
-
- public Set<SAXParseException> getErrors() {
- // Internal use only - don't worry about immutability
- return errors;
- }
-
- public Set<SAXParseException> getWarnings() {
- // Internal use only - don't worry about immutability
- return warnings;
- }
- }
-
// -------------------------------------------------------- Private Methods
try {
InputStream stream = context.getServletContext(
).getResourceAsStream(resourcePath);
- TldErrorHandler handler = tldScanStream(stream);
- processErrorHandler(handler, resourcePath);
+ XmlErrorHandler handler = tldScanStream(stream);
+ handler.logFindings(log, resourcePath);
taglibUris.add(descriptor.getTaglibURI());
webxmlTaglibUris.add(descriptor.getTaglibURI());
} catch (IOException ioe) {
}
InputStream stream = ctxt.getResourceAsStream(path);
try {
- TldErrorHandler handler = tldScanStream(stream);
- processErrorHandler(handler, path);
+ XmlErrorHandler handler = tldScanStream(stream);
+ handler.logFindings(log, path);
} catch (IOException ioe) {
log.warn(sm.getString("tldConfig.webinfFail", path),
ioe);
InputStream stream = null;
try {
stream = new FileInputStream(fileList[i]);
- TldErrorHandler handler = tldScanStream(stream);
- processErrorHandler(handler,
- fileList[i].getAbsolutePath());
+ XmlErrorHandler handler = tldScanStream(stream);
+ handler.logFindings(log, fileList[i].getAbsolutePath());
} catch (IOException ioe) {
log.warn(sm.getString("tldConfig.dirFail",
fileList[i].getAbsolutePath()),
if (!name.startsWith("META-INF/")) continue;
if (!name.endsWith(".tld")) continue;
InputStream stream = jarFile.getInputStream(entry);
- TldErrorHandler handler = tldScanStream(stream);
- processErrorHandler(handler, conn.getURL() + name);
+ XmlErrorHandler handler = tldScanStream(stream);
+ handler.logFindings(log, conn.getURL() + name);
}
} catch (IOException ioe) {
log.warn(sm.getString("tldConfig.jarFail", conn.getURL() + name),
/*
- * Log the non-fatal errors and warnings
- */
- private void processErrorHandler(TldErrorHandler handler, String source) {
- for (SAXParseException e : handler.getWarnings()) {
- log.warn(sm.getString(
- "tldConfig.handlerWarning", e.getMessage(), source));
- }
- for (SAXParseException e : handler.getErrors()) {
- log.warn(sm.getString(
- "tldConfig.handlerError", e.getMessage(), source));
- }
- }
-
-
- /*
* Scan the TLD contents in the specified input stream, and register
* any application event listeners found there. <b>NOTE</b> - This
* method ensure that the InputStream is correctly closed.
*
* @throws IOException If the file cannot be read
*/
- private TldErrorHandler tldScanStream(InputStream resourceStream)
+ private XmlErrorHandler tldScanStream(InputStream resourceStream)
throws IOException {
InputSource source = new InputSource(resourceStream);
- TldErrorHandler result = new TldErrorHandler();
+ XmlErrorHandler result = new XmlErrorHandler();
synchronized (tldDigester) {
try {
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.startup;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.juli.logging.Log;
+import org.apache.tomcat.util.res.StringManager;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class XmlErrorHandler implements ErrorHandler {
+
+ private static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+ private Set<SAXParseException> errors =
+ new HashSet<SAXParseException>();
+
+ private Set<SAXParseException> warnings =
+ new HashSet<SAXParseException>();
+
+ @Override
+ public void error(SAXParseException exception) throws SAXException {
+ // Collect non-fatal errors
+ errors.add(exception);
+ }
+
+ @Override
+ public void fatalError(SAXParseException exception) throws SAXException {
+ // Re-throw fatal errors
+ throw exception;
+ }
+
+ @Override
+ public void warning(SAXParseException exception) throws SAXException {
+ // Collect warnings
+ warnings.add(exception);
+ }
+
+ public Set<SAXParseException> getErrors() {
+ // Internal use only - don't worry about immutability
+ return errors;
+ }
+
+ public Set<SAXParseException> getWarnings() {
+ // Internal use only - don't worry about immutability
+ return warnings;
+ }
+
+ public void logFindings(Log log, String source) {
+ for (SAXParseException e : getWarnings()) {
+ log.warn(sm.getString(
+ "xmlErrorHandler.warning", e.getMessage(), source));
+ }
+ for (SAXParseException e : getErrors()) {
+ log.warn(sm.getString(
+ "xmlErrorHandler.error", e.getMessage(), source));
+ }
+ }
+}