SDK Updater: don't load sdk-repo XML that failed to validate. DO NOT MERGE.

This also prints a more obvious message in case Java doesn't
have an XML Schema validator.

SDK BUGS 2219284 2198427

Change-Id: I28aa1104957d2fe7791dcf0377a42d37f777a19d
This commit is contained in:
Raphael
2009-10-29 12:56:16 -07:00
parent 275de810e9
commit 34d8e2790b

View File

@@ -185,25 +185,34 @@ public class RepoSource implements IDescription {
} }
} }
if (!validated) { // If any exception was handled during the URL fetch, display it now.
if (exception[0] != null) {
mFetchError = "Failed to fetch URL"; mFetchError = "Failed to fetch URL";
String reason = "Unknown"; String reason = null;
if (exception[0] != null) { if (exception[0] instanceof FileNotFoundException) {
if (exception[0] instanceof FileNotFoundException) { // FNF has no useful getMessage, so we need to special handle it.
reason = "File not found"; reason = "File not found";
mFetchError += ": " + reason; mFetchError += ": " + reason;
} else if (exception[0] instanceof SSLKeyException) { } else if (exception[0] instanceof SSLKeyException) {
reason = "HTTPS SSL error. You might want to force download through HTTP in the settings."; // That's a common error and we have a pref for it.
mFetchError += ": HTTPS SSL error"; reason = "HTTPS SSL error. You might want to force download through HTTP in the settings.";
} else if (exception[0].getMessage() != null) { mFetchError += ": HTTPS SSL error";
reason = exception[0].getMessage(); } else if (exception[0].getMessage() != null) {
} reason = exception[0].getMessage();
} else {
// We don't know what's wrong. Let's give the exception class at least.
reason = String.format("Unknown (%1$s)", exception[0].getClass().getName());
} }
monitor.setResult("Failed to fetch URL %1$s, reason: %2$s", url, reason); monitor.setResult("Failed to fetch URL %1$s, reason: %2$s", url, reason);
} }
// Stop here if we failed to validate the XML. We don't want to load it.
if (!validated) {
return;
}
monitor.incProgress(1); monitor.incProgress(1);
if (xml != null) { if (xml != null) {
@@ -276,7 +285,7 @@ public class RepoSource implements IDescription {
} }
} }
} catch (IOException e) { } catch (Exception e) {
outException[0] = e; outException[0] = e;
} }
@@ -291,14 +300,26 @@ public class RepoSource implements IDescription {
try { try {
Validator validator = getValidator(); Validator validator = getValidator();
if (validator == null) {
monitor.setResult(
"XML verification failed for %1$s.\nNo suitable XML Schema Validator could be found in your Java environment. Please consider updating your version of Java.",
url);
return false;
}
xml.reset(); xml.reset();
validator.validate(new StreamSource(xml)); validator.validate(new StreamSource(xml));
return true; return true;
} catch (Exception e) { } catch (Exception e) {
String s = e.getMessage();
if (s == null) {
s = e.getClass().getName();
}
monitor.setResult("XML verification failed for %1$s.\nError: %2$s", monitor.setResult("XML verification failed for %1$s.\nError: %2$s",
url, url,
e.getMessage()); s);
} }
return false; return false;
@@ -311,10 +332,14 @@ public class RepoSource implements IDescription {
InputStream xsdStream = SdkRepository.getXsdStream(); InputStream xsdStream = SdkRepository.getXsdStream();
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
if (factory == null) {
return null;
}
// This may throw a SAX Exception if the schema itself is not a valid XSD // This may throw a SAX Exception if the schema itself is not a valid XSD
Schema schema = factory.newSchema(new StreamSource(xsdStream)); Schema schema = factory.newSchema(new StreamSource(xsdStream));
Validator validator = schema.newValidator(); Validator validator = schema == null ? null : schema.newValidator();
return validator; return validator;
} }