W3C home > Mailing lists > Public > www-validator-cvs@w3.org > July 2010

unicorn commit: added error messages for invalid responses

From: Mercurial notifier <nobody@w3.org>
Date: Wed, 07 Jul 2010 14:12:15 +0000
To: Unicorn Updates <www-validator-cvs@w3.org>
Message-Id: <E1OWVMF-0008BR-AT@blinky.w3.org>
changeset:   1313:6191eb74a4f4
user:        Thomas Gambet <tgambet@w3.org>
date:        Tue Jul 06 17:39:28 2010 -0400
files:       src/org/w3c/unicorn/response/impl/DefaultResponseXBeans.java
description:
added error messages for invalid responses


diff -r 967d3db2e09d -r 6191eb74a4f4 src/org/w3c/unicorn/response/impl/DefaultResponseXBeans.java
--- a/src/org/w3c/unicorn/response/impl/DefaultResponseXBeans.java	Tue Jul 06 17:38:55 2010 -0400
+++ b/src/org/w3c/unicorn/response/impl/DefaultResponseXBeans.java	Tue Jul 06 17:39:28 2010 -0400
@@ -6,12 +6,14 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.xmlbeans.XmlError;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
@@ -52,10 +54,20 @@
 		this.observerID = observerID;
 		
 		try {
+			Collection<XmlError> errorList = new ArrayList<XmlError>();
+			XmlOptions xo = new XmlOptions();
+			xo.setUseDefaultNamespace();
+			xo.setErrorListener(errorList);
 			ord = ObservationresponseDocument.Factory.parse(is, new XmlOptions().setCharacterEncoding(charset));
 			or = ord.getObservationresponse();
-			if (!or.validate())
-				throw new UnicornException(new org.w3c.unicorn.util.Message(2, "$message_response_validation_error", null, Framework.mapOfObserver.get(observerID).getName(Property.get(getLang()))));
+			if (!or.validate(xo)) {
+				String content = "";
+				content += "Errors: " + errorList.size();
+			    for (XmlError error : errorList) {
+			    	content += "\n" + error.getMessage();
+			    }
+				throw new UnicornException(new org.w3c.unicorn.util.Message(2, "$message_response_validation_error", content, Framework.mapOfObserver.get(observerID).getName(Property.get(getLang()))));
+			}
 		} catch (XmlException e) {
 			if (e.getMessage().contains("document element namespace mismatch"))
 				throw new UnicornException(new org.w3c.unicorn.util.Message(org.w3c.unicorn.util.Message.ERROR, "$message_response_invalid_schema", null, Framework.mapOfObserver.get(observerID).getName(Property.get("DEFAULT_LANGUAGE"))));
Received on Wednesday, 7 July 2010 14:12:16 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:43 UTC