Indicate that the document is valid when there are only warnings (Bug #161)

This commit is contained in:
Zane U. Ji 2014-03-29 19:22:58 +08:00
parent f65b1a1e61
commit 8251ad478c
5 changed files with 273 additions and 254 deletions

File diff suppressed because it is too large Load Diff

View File

@ -58,16 +58,8 @@ void *ValidationThread::Entry()
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection ); wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
if ( myIsSucceeded ) myPosition = validator->getErrorPosition();
{ myMessage = validator->getLastError();
myPosition = std::make_pair ( 0, 0 );
myMessage = wxEmptyString;
}
else
{
myPosition = validator->getErrorPosition();
myMessage = validator->getLastError();
}
if ( !TestDestroy() ) if ( !TestDestroy() )
{ {

View File

@ -64,12 +64,14 @@ WrapXerces::~WrapXerces()
delete catalogResolver; delete catalogResolver;
} }
// Returns true if the file is valid. But there can be warnings
bool WrapXerces::validate ( const wxString& fileName ) bool WrapXerces::validate ( const wxString& fileName )
{ {
return validateMemory ( NULL, 0, fileName ); return validateMemory ( NULL, 0, fileName );
} }
// tbd: cache grammar // tbd: cache grammar
// Returns true if the content is valid. But there can be warnings
bool WrapXerces::validateMemory ( bool WrapXerces::validateMemory (
const char *utf8Buffer, const char *utf8Buffer,
size_t len, size_t len,
@ -100,6 +102,7 @@ bool WrapXerces::validateMemory (
parser->setFeature ( XMLUni::fgXercesValidationErrorAsFatal, true ); parser->setFeature ( XMLUni::fgXercesValidationErrorAsFatal, true );
parser->setFeature ( XMLUni::fgXercesLoadExternalDTD, true ); parser->setFeature ( XMLUni::fgXercesLoadExternalDTD, true );
mySAX2Handler.reset();
parser->setContentHandler ( &mySAX2Handler ); parser->setContentHandler ( &mySAX2Handler );
#endif #endif
@ -158,7 +161,7 @@ bool WrapXerces::validateMemory (
return false; return false;
} }
return mySAX2Handler.getErrors().empty(); return true;//mySAX2Handler.getErrors().empty();
} }
const wxMBConv &WrapXerces::getMBConv() const wxMBConv &WrapXerces::getMBConv()

View File

@ -44,7 +44,7 @@ class MySAX2Handler : public DefaultHandler
MySAX2Handler() MySAX2Handler()
{ {
mEOL = _T("\n"); mEOL = _T("\n");
resetErrors(); reset();
} }
void error ( const SAXParseException& e ) void error ( const SAXParseException& e )
{ {
@ -60,7 +60,7 @@ class MySAX2Handler : public DefaultHandler
logError ( _("FatalError"), wxLOG_FatalError, e ); logError ( _("FatalError"), wxLOG_FatalError, e );
throw e; throw e;
} }
void resetErrors() void reset()
{ {
mErrors.clear(); mErrors.clear();
mErrorPosition = std::make_pair ( 1, 1 ); mErrorPosition = std::make_pair ( 1, 1 );
@ -98,7 +98,9 @@ class WrapXerces : private boost::noncopyable
WrapXerces(); WrapXerces();
virtual ~WrapXerces(); virtual ~WrapXerces();
// Returns true if the file is valid. But there can be warnings
bool validate ( const wxString &fileName ); bool validate ( const wxString &fileName );
// Returns true if the content is valid. But there can be warnings
bool validateMemory ( const char *utf8Buffer, size_t len, bool validateMemory ( const char *utf8Buffer, size_t len,
const wxString &fileName, wxThread *thread = NULL, const wxString &fileName, wxThread *thread = NULL,
bool forceGrammarCheck = true, /* Must specify a grammar */ bool forceGrammarCheck = true, /* Must specify a grammar */

View File

@ -3923,20 +3923,37 @@ void MyFrame::OnValidateSchema ( wxCommandEvent& event )
wxString fileName = doc->getFullFileName(); wxString fileName = doc->getFullFileName();
std::string utf8Buffer = doc->myGetTextRaw(); std::string utf8Buffer = doc->myGetTextRaw();
std::auto_ptr<WrapXerces> validator ( new WrapXerces() ); std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
if ( !validator->validateMemory ( utf8Buffer.c_str(), utf8Buffer.size(), int severity;
wxString message;
if ( validator->validateMemory ( utf8Buffer.c_str(), utf8Buffer.size(),
fileName ) ) fileName ) )
{ {
statusProgress ( wxEmptyString ); message.Printf ( _ ( "%s is valid" ),
messagePane ( validator->getLastError(), CONST_WARNING ); doc->getShortFileName().c_str() );
std::pair<int, int> posPair = validator->getErrorPosition(); if ( validator->getLastError().empty() )
severity = CONST_INFO;
else
{
severity = CONST_WARNING;
message << _T ( "[br][br]" );
}
}
else
{
severity = CONST_STOP;
}
statusProgress ( wxEmptyString );
message << validator->getLastError();
messagePane ( message, severity );
if ( severity != CONST_INFO )
{
std::pair<int, int> posPair = validator->getErrorPosition();
int cursorPos = int cursorPos =
doc->PositionFromLine ( posPair.first - 1 ); doc->PositionFromLine ( posPair.first - 1 );
doc->SetSelection ( cursorPos, cursorPos ); doc->SetSelection ( cursorPos, cursorPos );
doc->setErrorIndicator ( posPair.first - 1, 0 ); doc->setErrorIndicator ( posPair.first - 1, 0 );
} }
else
documentOk ( _ ( "valid" ) );
} }
void MyFrame::OnCreateSchema ( wxCommandEvent& event ) void MyFrame::OnCreateSchema ( wxCommandEvent& event )