OSDN Git Service

SDK Manager: don't output XML parse errors to stderr
authorRaphael <raphael@google.com>
Fri, 14 Oct 2011 03:57:05 +0000 (20:57 -0700)
committerRaphael <raphael@google.com>
Fri, 14 Oct 2011 03:58:19 +0000 (20:58 -0700)
This is exactly like change I6f82b040 except now we
remove the stderr output when parsing the addons_list.xml

To put this in context, end-users should not see any
xml parsing error. In this case we get one because the
file doesn't exist on the test server and the web server
returns an HTML page describing the error, which naturally
fails to validate against our XSD. But since the point of
the method is just to validate, errors are irrelevant.

Change-Id: I80b2c7600d1ceffa870ac3d71ef0c0f6ef9f809c

sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonsListFetcher.java

index cb8602f..c83a3c1 100755 (executable)
@@ -23,6 +23,7 @@ import com.android.sdklib.repository.SdkAddonsListConstants;
 import org.w3c.dom.Document;\r
 import org.w3c.dom.NamedNodeMap;\r
 import org.w3c.dom.Node;\r
+import org.xml.sax.ErrorHandler;\r
 import org.xml.sax.InputSource;\r
 import org.xml.sax.SAXException;\r
 import org.xml.sax.SAXParseException;\r
@@ -255,6 +256,20 @@ public class AddonsListFetcher {
             // Parse the old document using a non namespace aware builder\r
             factory.setNamespaceAware(false);\r
             DocumentBuilder builder = factory.newDocumentBuilder();\r
+\r
+            // We don't want the default handler which prints errors to stderr.\r
+            builder.setErrorHandler(new ErrorHandler() {\r
+                public void warning(SAXParseException e) throws SAXException {\r
+                // pass\r
+                }\r
+                public void fatalError(SAXParseException e) throws SAXException {\r
+                    throw e;\r
+                }\r
+                public void error(SAXParseException e) throws SAXException {\r
+                    throw e;\r
+                }\r
+            });\r
+\r
             doc = builder.parse(xml);\r
 \r
             // Prepare a new document using a namespace aware builder\r