You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/09/10 23:41:02 UTC
svn commit: r694006 -
/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/xml/XmlUtil.java
Author: etnu
Date: Wed Sep 10 14:41:02 2008
New Revision: 694006
URL: http://svn.apache.org/viewvc?rev=694006&view=rev
Log:
Added handlers to XmlUtil's parse method to intercept logging messages and send them to java.util.logging.Logger instead of standard error.
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/xml/XmlUtil.java
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/xml/XmlUtil.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/xml/XmlUtil.java?rev=694006&r1=694005&r2=694006&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/xml/XmlUtil.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/xml/XmlUtil.java Wed Sep 10 14:41:02 2008
@@ -21,6 +21,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@@ -29,11 +30,28 @@
import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
public class XmlUtil {
+ private static final Logger LOG = Logger.getLogger(XmlUtil.class.getName());
+ // Handles xml errors so that they're not logged to stderr.
+ private static final ErrorHandler errorHandler = new ErrorHandler() {
+ public void error(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+ public void fatalError(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+ public void warning(SAXParseException exception) {
+ // warnings can be ignored.
+ LOG.log(Level.INFO, "XmlUtil warning", exception);
+ }
+ };
private XmlUtil() {}
@@ -183,7 +201,9 @@
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
InputSource is = new InputSource(new StringReader(xml.trim()));
- return factory.newDocumentBuilder().parse(is).getDocumentElement();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setErrorHandler(errorHandler);
+ return builder.parse(is).getDocumentElement();
} catch (SAXParseException e) {
throw new XmlException(e.getMessage()+" At: ("+e.getLineNumber()+ ',' +e.getColumnNumber()+ ')', e);
} catch (SAXException e) {