Fixed error handling

This commit is contained in:
Zane U. Ji 2013-12-22 23:24:00 +08:00
parent 5ba5c52cad
commit ea705c221c
1 changed files with 27 additions and 12 deletions

View File

@ -122,6 +122,7 @@ bool WrapLibxml::validate ( const std::string& utf8DocBuf,
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( ctxt == NULL ) if ( ctxt == NULL )
{ {
nonParserError = _("Cannot create a parser context");
return false; return false;
} }
@ -156,19 +157,26 @@ bool WrapLibxml::validateRelaxNG (
do { do {
rngParserCtxt = xmlRelaxNGNewParserCtxt ( CONV ( schemaFileName ) ); rngParserCtxt = xmlRelaxNGNewParserCtxt ( CONV ( schemaFileName ) );
if ( rngParserCtxt == NULL ) if ( rngParserCtxt == NULL )
{
nonParserError = _("Cannot create an RNG parser context");
return false; return false;
}
schemaPtr = xmlRelaxNGParse ( rngParserCtxt ); schemaPtr = xmlRelaxNGParse ( rngParserCtxt );
if ( schemaPtr == NULL ) if ( schemaPtr == NULL )
break; break;
ctxtPtr = xmlRelaxNGNewValidCtxt ( schemaPtr ); ctxtPtr = xmlRelaxNGNewValidCtxt ( schemaPtr );
if ( ctxtPtr == NULL ) if ( ctxtPtr == NULL )
{
nonParserError = _("Cannot create an RNG validation context");
break; break;
}
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( ctxt == NULL ) if ( ctxt == NULL )
{
nonParserError = _("Cannot create a parser context");
break; break;
}
int flags = XML_PARSE_DTDVALID; int flags = XML_PARSE_DTDVALID;
if ( !netAccess ) if ( !netAccess )
@ -217,11 +225,16 @@ bool WrapLibxml::validateW3CSchema (
ctxtPtr = xmlSchemaNewValidCtxt ( schemaPtr ); ctxtPtr = xmlSchemaNewValidCtxt ( schemaPtr );
if ( ctxtPtr == NULL ) if ( ctxtPtr == NULL )
{
nonParserError = _("Cannot create a schema validation context");
break; break;
}
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( ctxt == NULL ) if ( ctxt == NULL )
{
nonParserError = _("Cannot create a parser context");
break; break;
}
int flags = XML_PARSE_DTDLOAD; int flags = XML_PARSE_DTDLOAD;
if ( !netAccess ) if ( !netAccess )
@ -278,6 +291,7 @@ bool WrapLibxml::parse (
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( ctxt == NULL ) if ( ctxt == NULL )
{ {
nonParserError = _("Cannot create a parser context");
return false; return false;
} }
@ -338,6 +352,7 @@ bool WrapLibxml::xpath ( const wxString &xpath, const std::string &utf8DocBuf,
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( ctxt == NULL ) if ( ctxt == NULL )
{ {
nonParserError = _("Cannot create a parser context");
return false; return false;
} }
@ -456,7 +471,7 @@ bool WrapLibxml::xslt (
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( !ctxt ) if ( !ctxt )
{ {
nonParserError = _("Cannot create parser context"); nonParserError = _("Cannot create a parser context");
break; break;
} }
@ -469,13 +484,6 @@ bool WrapLibxml::xslt (
else else
doc = xmlCtxtReadFile ( ctxt, CONV ( docUrl ), NULL, flags ); doc = xmlCtxtReadFile ( ctxt, CONV ( docUrl ), NULL, flags );
if ( !doc ) if ( !doc )
{
nonParserError = _("Cannot parse file");
break;
}
// ensure entity warnings are treated as errors
if ( !getLastError().empty() )
break; break;
res = xsltApplyStylesheet ( cur, doc, NULL ); res = xsltApplyStylesheet ( cur, doc, NULL );
@ -494,7 +502,8 @@ bool WrapLibxml::xslt (
xmlFree ( buf ); xmlFree ( buf );
} }
ret = true; // ensure entity warnings are treated as errors
ret = !xmlGetLastError();
} while ( false ); } while ( false );
@ -510,7 +519,10 @@ bool WrapLibxml::bufferWellFormed ( const std::string& buffer )
{ {
xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
if ( !ctxt ) if ( !ctxt )
{
nonParserError = _("Cannot create a parser context");
return false; return false;
}
int flags = XML_PARSE_DTDLOAD; int flags = XML_PARSE_DTDLOAD;
if ( !netAccess ) if ( !netAccess )
@ -555,7 +567,10 @@ int WrapLibxml::saveEncoding (
{ {
xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
if ( !ctxt ) if ( !ctxt )
{
nonParserError = _("Cannot create a parser context");
return -1; return -1;
}
xmlDocPtr docPtr; xmlDocPtr docPtr;
int flags = XML_PARSE_DTDLOAD | XML_PARSE_PEDANTIC /*| XML_PARSE_DTDVALID*/;//XML_PARSE_NONET//XML_PARSE_DTDLOAD//0//(netAccess) ? XML_PARSE_DTDLOAD | XML_PARSE_NOENT : XML_PARSE_DTDLOAD | XML_PARSE_NONET | XML_PARSE_NOENT//0 int flags = XML_PARSE_DTDLOAD | XML_PARSE_PEDANTIC /*| XML_PARSE_DTDVALID*/;//XML_PARSE_NONET//XML_PARSE_DTDLOAD//0//(netAccess) ? XML_PARSE_DTDLOAD | XML_PARSE_NOENT : XML_PARSE_DTDLOAD | XML_PARSE_NONET | XML_PARSE_NOENT//0