Bug #215 [Windows] Fails to load RelaxNG schema

This commit is contained in:
Zane U. Ji 2014-12-14 16:43:15 +08:00
parent 589c744c27
commit e9f263c4d9
3 changed files with 18 additions and 31 deletions

View File

@ -145,7 +145,7 @@ bool WrapLibxml::validate ( const std::string& utf8DocBuf,
} }
bool WrapLibxml::validateRelaxNG ( bool WrapLibxml::validateRelaxNG (
const wxString &schemaFileName, const wxString &schemaUrl,
const std::string &utf8DocBuf, const std::string &utf8DocBuf,
const wxString &docFileName ) const wxString &docFileName )
{ {
@ -159,9 +159,7 @@ bool WrapLibxml::validateRelaxNG (
xmlRelaxNGPtr schemaPtr = NULL; xmlRelaxNGPtr schemaPtr = NULL;
do { do {
xmlChar *url = xmlFileNameToURL ( schemaFileName ); rngParserCtxt = xmlRelaxNGNewParserCtxt ( schemaUrl.utf8_str() );
rngParserCtxt = xmlRelaxNGNewParserCtxt ( ( const char * ) url );
xmlFree ( url );
if ( rngParserCtxt == NULL ) if ( rngParserCtxt == NULL )
{ {
nonParserError = _("Cannot create an RNG parser context"); nonParserError = _("Cannot create an RNG parser context");
@ -187,7 +185,7 @@ bool WrapLibxml::validateRelaxNG (
int flags = XML_PARSE_DTDVALID; int flags = XML_PARSE_DTDVALID;
if ( !netAccess ) if ( !netAccess )
flags |= XML_PARSE_NONET; flags |= XML_PARSE_NONET;
url = xmlFileNameToURL ( docFileName ); xmlChar *url = xmlFileNameToURL ( docFileName );
docPtr = xmlCtxtReadMemory ( ctxt, utf8DocBuf.c_str(), docPtr = xmlCtxtReadMemory ( ctxt, utf8DocBuf.c_str(),
utf8DocBuf.length(), ( const char * ) url, "UTF-8", flags ); utf8DocBuf.length(), ( const char * ) url, "UTF-8", flags );
xmlFree ( url ); xmlFree ( url );

View File

@ -50,7 +50,7 @@ class WrapLibxml
const std::string &utf8DocBuf, const std::string &utf8DocBuf,
const wxString &docFileName ); const wxString &docFileName );
bool validateRelaxNG ( bool validateRelaxNG (
const wxString &schemaFileName, const wxString &schemaUrl,
const std::string &utf8DocBuf, const std::string &utf8DocBuf,
const wxString &docFileName ); const wxString &docFileName );
bool validateW3CSchema ( bool validateW3CSchema (

View File

@ -3825,20 +3825,19 @@ void MyFrame::OnValidateRelaxNG ( wxCommandEvent& event )
if ( ad.ShowModal() != wxID_OK ) if ( ad.ShowModal() != wxID_OK )
return; return;
wxString path = lastRelaxNGSchema = ad.getUrl(); const wxString &url = lastRelaxNGSchema = ad.getUrl();
if ( url.empty() )
if ( path.empty() )
{ {
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
return; return;
} }
validateRelaxNG ( doc, path, fileName ); validateRelaxNG ( doc, url, fileName );
} }
void MyFrame::validateRelaxNG ( void MyFrame::validateRelaxNG (
XmlDoc *doc, XmlDoc *doc,
const wxString& schemaName, const wxString& schemaUrl,
wxString& fileName ) // not const: may change if empty/document modified wxString& fileName ) // not const: may change if empty/document modified
{ {
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
@ -3846,13 +3845,11 @@ void MyFrame::validateRelaxNG (
if ( !doc ) if ( !doc )
return; return;
doc->clearErrorIndicators(); doc->clearErrorIndicators();
statusProgress ( _ ( "RELAX NG validation in progress..." ) ); statusProgress ( _ ( "RELAX NG validation in progress..." ) );
auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) ); auto_ptr<WrapLibxml> wl ( new WrapLibxml ( libxmlNetAccess ) );
if ( !wl->validateRelaxNG ( schemaUrl, doc->myGetTextRaw(), fileName ) )
if ( !wl->validateRelaxNG ( schemaName, doc->myGetTextRaw(), fileName ) )
{ {
wxString wideError = wl->getLastError(); wxString wideError = wl->getLastError();
statusProgress ( wxEmptyString ); statusProgress ( wxEmptyString );
@ -3883,10 +3880,10 @@ void MyFrame::OnValidatePreset ( wxCommandEvent& event )
wxString fileName = doc->getFullFileName(); wxString fileName = doc->getFullFileName();
int id = event.GetId(); int id = event.GetId();
wxString schemaFileName = validationPresetMap[id]; const wxString &schemaUrl = validationPresetMap[id];
if ( schemaFileName.empty() ) if ( schemaUrl.empty() )
return; return;
validateRelaxNG ( doc, schemaFileName, fileName ); validateRelaxNG ( doc, schemaUrl, fileName );
} }
void MyFrame::OnValidateSchema ( wxCommandEvent& event ) void MyFrame::OnValidateSchema ( wxCommandEvent& event )
@ -5115,32 +5112,24 @@ wxMenuBar *MyFrame::getMenuBar()
if ( wxDirExists ( rngDir ) ) if ( wxDirExists ( rngDir ) )
{ {
wxString rngMask, rngFile, displayName, shortcutString; wxString rngMask, rngFile, rngUrl, displayName, shortcutString;
rngMask = rngDir + wxFileName::GetPathSeparator() + _T ( "*.rng" ); rngMask = rngDir + wxFileName::GetPathSeparator() + _T ( "*.rng" );
rngFile = wxFindFirstFile ( rngMask, wxFILE ); rngFile = wxFindFirstFile ( rngMask, wxFILE );
int id = ID_VALIDATE_PRESET1; int id = ID_VALIDATE_PRESET1;
if ( !rngFile.empty() ) while ( id <= ID_VALIDATE_PRESET9 && !rngFile.empty() )
{ {
validationPresetMap.insert ( make_pair ( id, rngFile ) ); rngUrl = WrapLibxml::FileNameToURL ( rngFile );
validationPresetMap.insert ( make_pair ( id, rngUrl ) );
wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL ); wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL );
displayName.Replace ( _T ( ".rng" ), _T ( "" ) ); displayName.Replace ( _T ( ".rng" ), _T ( "" ) );
shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 ); shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 );
validationMenu->Append ( id, displayName + shortcutString, displayName ); validationMenu->Append ( id, displayName + shortcutString, displayName );
for ( id = ID_VALIDATE_PRESET2; id <= ID_VALIDATE_PRESET9; ++id ) id++;
{
rngFile = wxFindNextFile(); rngFile = wxFindNextFile();
if ( rngFile.empty() )
break;
validationPresetMap.insert ( make_pair ( id, rngFile ) );
wxFileName::SplitPath ( rngFile, NULL, NULL, &displayName, NULL );
shortcutString.Printf ( _ ( "\tCtrl+%i" ), ( id - ID_VALIDATE_PRESET1 ) + 1 );
displayName.Replace ( _T ( ".rng" ), _T ( "" ) );
validationMenu->Append ( id, displayName + shortcutString, displayName );
}
} }
} }