2013-12-16 15:05:24 +01:00
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/textbuf.h>
|
2009-11-06 18:06:12 +01:00
|
|
|
#include "xmlctrl.h"
|
|
|
|
#include "validationthread.h"
|
|
|
|
#include "wrapxerces.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <memory>
|
2012-08-27 14:25:08 +02:00
|
|
|
#include "threadreaper.h"
|
2009-11-06 18:06:12 +01:00
|
|
|
|
2012-08-27 14:25:08 +02:00
|
|
|
extern wxCriticalSection xmlcopyeditorCriticalSection;
|
2012-08-15 14:45:24 +02:00
|
|
|
|
2012-08-18 17:41:27 +02:00
|
|
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_VALIDATION_COMPLETED);
|
2012-08-15 14:45:24 +02:00
|
|
|
|
2009-11-06 18:06:12 +01:00
|
|
|
ValidationThread::ValidationThread (
|
2012-08-15 14:45:24 +02:00
|
|
|
wxEvtHandler *handler,
|
2014-04-13 17:16:04 +02:00
|
|
|
const char *utf8Buffer,
|
2013-10-19 02:44:17 +02:00
|
|
|
const wxString &system )
|
2012-08-15 14:45:24 +02:00
|
|
|
: wxThread ( wxTHREAD_JOINABLE )
|
2012-08-27 14:25:08 +02:00
|
|
|
, mStopping ( false )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
2014-04-13 17:16:04 +02:00
|
|
|
if ( utf8Buffer == NULL )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2012-08-15 14:45:24 +02:00
|
|
|
myEventHandler = handler;
|
2014-04-13 17:16:04 +02:00
|
|
|
myBuffer = utf8Buffer;
|
2009-11-06 18:06:12 +01:00
|
|
|
mySystem = system;
|
2012-08-15 14:45:24 +02:00
|
|
|
myIsSucceeded = false;
|
2009-11-06 18:06:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void *ValidationThread::Entry()
|
|
|
|
{
|
2012-08-30 16:37:01 +02:00
|
|
|
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
2009-11-06 18:06:12 +01:00
|
|
|
|
2012-08-27 14:25:08 +02:00
|
|
|
if ( TestDestroy() )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
2013-10-29 11:52:22 +01:00
|
|
|
myBuffer.clear();
|
2012-08-27 14:25:08 +02:00
|
|
|
return NULL;
|
2009-11-06 18:06:12 +01:00
|
|
|
}
|
2012-08-15 14:45:24 +02:00
|
|
|
|
|
|
|
myIsSucceeded = validator->validateMemory (
|
2009-11-06 18:06:12 +01:00
|
|
|
myBuffer.c_str(),
|
2012-08-27 14:25:08 +02:00
|
|
|
myBuffer.size(),
|
2013-10-19 02:44:17 +02:00
|
|
|
mySystem,
|
2013-12-16 15:05:24 +01:00
|
|
|
this,
|
|
|
|
// Don't be too harsh to new created documents, which may haven't
|
|
|
|
// associated any schema yet
|
|
|
|
/*forceCheckGrammar*/false,
|
|
|
|
wxTextBuffer::GetEOL() );
|
2012-08-15 14:45:24 +02:00
|
|
|
|
2013-10-29 11:52:22 +01:00
|
|
|
myBuffer.clear();
|
|
|
|
|
2012-08-15 14:45:24 +02:00
|
|
|
if ( TestDestroy() )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
2012-08-15 14:45:24 +02:00
|
|
|
return NULL;
|
2009-11-06 18:06:12 +01:00
|
|
|
}
|
|
|
|
|
2012-08-15 14:45:24 +02:00
|
|
|
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
|
|
|
|
2014-03-29 12:22:58 +01:00
|
|
|
myPosition = validator->getErrorPosition();
|
|
|
|
myMessage = validator->getLastError();
|
2012-08-15 14:45:24 +02:00
|
|
|
|
2012-08-27 14:25:08 +02:00
|
|
|
if ( !TestDestroy() )
|
|
|
|
{
|
|
|
|
wxCommandEvent event ( wxEVT_COMMAND_VALIDATION_COMPLETED );
|
|
|
|
wxPostEvent ( myEventHandler, event );
|
|
|
|
}
|
2012-08-15 14:45:24 +02:00
|
|
|
|
|
|
|
return NULL;
|
2009-11-06 18:06:12 +01:00
|
|
|
}
|
2012-08-27 14:25:08 +02:00
|
|
|
|
|
|
|
void ValidationThread::PendingDelete ()
|
|
|
|
{
|
|
|
|
Cancel();
|
|
|
|
|
|
|
|
ThreadReaper::get().add ( this );
|
|
|
|
}
|