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 );
if ( myIsSucceeded )
{
myPosition = std::make_pair ( 0, 0 );
myMessage = wxEmptyString;
}
else
{
myPosition = validator->getErrorPosition();
myMessage = validator->getLastError();
}
if ( !TestDestroy() )
{

View File

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

View File

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

View File

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