Author: chabotc
Date: Thu Oct 9 01:35:08 2008
New Revision: 703101
URL: http://svn.apache.org/viewvc?rev=703101&view=rev
Log:
SHINDIG-642 add verbose xml parsing errors to the gadget spec parser
Modified:
incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php?rev=703101&r1=703100&r2=703101&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php Thu Oct 9
01:35:08 2008
@@ -27,9 +27,17 @@
if (empty($xml)) {
throw new SpecParserException("Empty XML document");
}
+ // make sure we can generate a detailed error report
+ libxml_use_internal_errors(true);
//TODO add libxml_get_errors() functionality so we can have a
bit more understandable errors..
if (($doc = simplexml_load_string($xml, 'SimpleXMLElement',
LIBXML_NOCDATA)) == false) {
- throw new SpecParserException("Invalid XML document");
+ $errors = libxml_get_errors();
+ $xmlErrors = '';
+ foreach ($errors as $error) {
+ $xmlErrors .= $this->displayXmlError($error);
+ }
+ libxml_clear_errors();
+ throw new SpecParserException("<b>Invalid XML
Document</b> <br>" . $xmlErrors);
}
if (count($doc->ModulePrefs) != 1) {
throw new SpecParserException("Missing or duplicated
<ModulePrefs>");
@@ -100,7 +108,7 @@
$gadget->links[] = $this->processLink($link);
}
foreach ($ModulePrefs->Locale as $locale) {
- $gadget->localeSpecs[] = $this->processLocale($locale,
$context);
+ $gadget->localeSpecs[] = $this->processLocale($locale);
}
}
@@ -114,7 +122,7 @@
return $link;
}
- private function processLocale($locale, $context)
+ private function processLocale($locale)
{
$attributes = $locale->attributes();
$messageAttr = isset($attributes['messages']) ?
trim($attributes['messages']) : '';
@@ -221,4 +229,25 @@
$oauthSpec = new OAuthSpec($OAuthSpec->Service);
$gadget->setOAuthSpec($oauthSpec);
}
+
+ private function displayXmlError($error)
+ {
+ $return = '';
+ switch ($error->level) {
+ case LIBXML_ERR_WARNING:
+ $return .= "Warning [{$error->code}]: ";
+ break;
+ case LIBXML_ERR_ERROR:
+ $return .= "Error [{$error->code}]: ";
+ break;
+ case LIBXML_ERR_FATAL:
+ $return .= "Fatal Error [{$error->code}]: ";
+ break;
+ }
+ $return .= trim($error->message) . ", Line: {$error->line}" . "
Column: {$error->column}";
+ if ($error->file) {
+ $return .= "File: {$error->file}";
+ }
+ return "$return\n";
+ }
}