Don't use XMLString::transcode to convert a name to native code-page Return constant references rather than objects
This commit is contained in:
parent
9a9cf0e724
commit
9a3a9c6280
|
@ -100,15 +100,10 @@ void InsertPanel::update (
|
||||||
{
|
{
|
||||||
list->Clear();
|
list->Clear();
|
||||||
lastDoc = doc;
|
lastDoc = doc;
|
||||||
std::set<std::string> entitySet = doc->getEntitySet();
|
const std::set<wxString> &entitySet = doc->getEntitySet();
|
||||||
entitySet.insert ( "amp" );
|
std::set<wxString>::const_iterator it;
|
||||||
entitySet.insert ( "apos" );
|
|
||||||
entitySet.insert ( "gt" );
|
|
||||||
entitySet.insert ( "lt" );
|
|
||||||
entitySet.insert ( "quot" );
|
|
||||||
std::set<std::string>::iterator it;
|
|
||||||
for ( it = entitySet.begin(); it != entitySet.end(); it++ )
|
for ( it = entitySet.begin(); it != entitySet.end(); it++ )
|
||||||
list->Append ( wxString ( it->c_str(), wxConvUTF8, it->size() ) );
|
list->Append ( *it );
|
||||||
list->Show ( true );
|
list->Show ( true );
|
||||||
|
|
||||||
wxSize clientSize = GetClientSize();
|
wxSize clientSize = GetClientSize();
|
||||||
|
@ -140,14 +135,14 @@ void InsertPanel::update (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<wxString> elementSet;
|
const std::set<wxString> &elementSet = doc->getChildren (
|
||||||
elementSet = doc->getChildren ( ( type == INSERT_PANEL_TYPE_SIBLING ) ? grandparent : parent );
|
( type == INSERT_PANEL_TYPE_SIBLING ) ? grandparent : parent );
|
||||||
if ( elementSet.empty() )
|
if ( elementSet.empty() )
|
||||||
{
|
{
|
||||||
list->Show ( false );
|
list->Show ( false );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::set<wxString>::iterator it;
|
std::set<wxString>::const_iterator it;
|
||||||
for ( it = elementSet.begin(); it != elementSet.end(); it++ )
|
for ( it = elementSet.begin(); it != elementSet.end(); it++ )
|
||||||
list->Append ( *it );
|
list->Append ( *it );
|
||||||
list->Show ( true );
|
list->Show ( true );
|
||||||
|
|
|
@ -82,15 +82,14 @@ void LocationPanel::update (
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string structure = doc->getElementStructure ( parent );
|
wxString structure = doc->getElementStructure ( parent );
|
||||||
|
|
||||||
if (!structure.empty () )
|
if (!structure.empty () )
|
||||||
{
|
{
|
||||||
indentStructure( structure );
|
indentStructure( structure );
|
||||||
structureEdit->Show ( true );
|
structureEdit->Show ( true );
|
||||||
wxString wideStructure = wxString ( structure.c_str(), wxConvUTF8, structure.size() );
|
|
||||||
structureEdit->SetReadOnly ( false );
|
structureEdit->SetReadOnly ( false );
|
||||||
structureEdit->SetText ( wideStructure );
|
structureEdit->SetText ( structure );
|
||||||
structureEdit->SetReadOnly ( true );
|
structureEdit->SetReadOnly ( true );
|
||||||
|
|
||||||
wxSize clientSize = GetClientSize();
|
wxSize clientSize = GetClientSize();
|
||||||
|
@ -115,12 +114,12 @@ void LocationPanel::update (
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationPanel::indentStructure ( std::string& structure )
|
void LocationPanel::indentStructure ( wxString& structure )
|
||||||
{
|
{
|
||||||
std::string indented;
|
wxString indented;
|
||||||
char *s = (char *) structure.c_str();
|
wxString::const_iterator s = structure.begin();
|
||||||
int indent = 0;
|
int indent = 0;
|
||||||
const char *indentMark = "\t";
|
const static wxString indentMark ( _T("\t") );
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
bool justSeenContent = false;
|
bool justSeenContent = false;
|
||||||
|
@ -136,7 +135,7 @@ void LocationPanel::indentStructure ( std::string& structure )
|
||||||
indented += *s;
|
indented += *s;
|
||||||
for ( int i = 0; i < indent; i++ )
|
for ( int i = 0; i < indent; i++ )
|
||||||
{
|
{
|
||||||
indented += (char *)indentMark;
|
indented += indentMark;
|
||||||
}
|
}
|
||||||
if (justSeenContent)
|
if (justSeenContent)
|
||||||
indented += *s;
|
indented += *s;
|
||||||
|
@ -146,7 +145,7 @@ void LocationPanel::indentStructure ( std::string& structure )
|
||||||
indented += '\n';
|
indented += '\n';
|
||||||
|
|
||||||
for (int i = 0; indent && i < indent; i++)
|
for (int i = 0; indent && i < indent; i++)
|
||||||
indented += (char *)indentMark;
|
indented += indentMark;
|
||||||
justSeenContent = false;
|
justSeenContent = false;
|
||||||
}
|
}
|
||||||
else if (*s == ')')
|
else if (*s == ')')
|
||||||
|
@ -157,13 +156,13 @@ void LocationPanel::indentStructure ( std::string& structure )
|
||||||
}
|
}
|
||||||
indent--;
|
indent--;
|
||||||
for (int i = 0; indent && i < indent; i++)
|
for (int i = 0; indent && i < indent; i++)
|
||||||
indented += (char *)indentMark;
|
indented += indentMark;
|
||||||
indented += *s;
|
indented += *s;
|
||||||
indented += '\n';
|
indented += '\n';
|
||||||
if (*( s + 1 ) && *(s + 1) != ')' )
|
if (*( s + 1 ) && *(s + 1) != ')' )
|
||||||
{
|
{
|
||||||
for (int i = 0; i < indent; i++)
|
for (int i = 0; i < indent; i++)
|
||||||
indented += (char *)indentMark;
|
indented += indentMark;
|
||||||
}
|
}
|
||||||
justSeenContent = false;
|
justSeenContent = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class LocationPanel : public wxPanel
|
||||||
XmlDoc *docParameter = NULL,
|
XmlDoc *docParameter = NULL,
|
||||||
const wxString& parent = wxEmptyString );
|
const wxString& parent = wxEmptyString );
|
||||||
private:
|
private:
|
||||||
void indentStructure ( std::string& structure );
|
void indentStructure ( wxString& structure );
|
||||||
MyFrame *parentWindow;
|
MyFrame *parentWindow;
|
||||||
XmlDoc *doc;
|
XmlDoc *doc;
|
||||||
wxBoxSizer *sizer;
|
wxBoxSizer *sizer;
|
||||||
|
|
|
@ -14,7 +14,7 @@ ValidationThread::ValidationThread (
|
||||||
bool *success,
|
bool *success,
|
||||||
bool *release,
|
bool *release,
|
||||||
std::pair<int, int> *position,
|
std::pair<int, int> *position,
|
||||||
std::string *message ) : wxThread()
|
wxString *message ) : wxThread()
|
||||||
{
|
{
|
||||||
if (!buffer || !success || !position || !message )
|
if (!buffer || !success || !position || !message )
|
||||||
{
|
{
|
||||||
|
@ -69,7 +69,7 @@ void *ValidationThread::Entry()
|
||||||
{
|
{
|
||||||
*mySuccessPtr = true;
|
*mySuccessPtr = true;
|
||||||
*myPositionPtr = std::make_pair ( 0, 0 );
|
*myPositionPtr = std::make_pair ( 0, 0 );
|
||||||
*myMessagePtr = "";
|
*myMessagePtr = wxEmptyString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef VALIDATION_THREAD_H
|
#ifndef VALIDATION_THREAD_H
|
||||||
#define VALIDATION_THREAD_H
|
#define VALIDATION_THREAD_H
|
||||||
|
|
||||||
|
#include <wx/wx.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <wx/thread.h>
|
#include <wx/thread.h>
|
||||||
|
@ -16,14 +17,14 @@ public:
|
||||||
bool *finished,
|
bool *finished,
|
||||||
bool *success,
|
bool *success,
|
||||||
bool *release, std::pair<int, int> *position,
|
bool *release, std::pair<int, int> *position,
|
||||||
std::string *message );
|
wxString *message );
|
||||||
virtual void *Entry();
|
virtual void *Entry();
|
||||||
virtual void OnExit();
|
virtual void OnExit();
|
||||||
private:
|
private:
|
||||||
std::string myBuffer, mySystem, myCatalogPath, myCatalogUtilityPath;
|
std::string myBuffer, mySystem, myCatalogPath, myCatalogUtilityPath;
|
||||||
bool *myFinishedPtr, *mySuccessPtr, *myReleasePtr;
|
bool *myFinishedPtr, *mySuccessPtr, *myReleasePtr;
|
||||||
std::pair<int, int> *myPositionPtr;
|
std::pair<int, int> *myPositionPtr;
|
||||||
std::string *myMessagePtr;
|
wxString *myMessagePtr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -80,26 +80,22 @@ bool WrapXerces::validate ( const std::string& fileName )
|
||||||
catch ( XMLException& e )
|
catch ( XMLException& e )
|
||||||
{
|
{
|
||||||
delete parser;
|
delete parser;
|
||||||
char *err = XMLString::transcode ( e.getMessage() );
|
lastError = toString ( e.getMessage() );
|
||||||
lastError = err;
|
|
||||||
XMLString::release ( &err );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch ( SAXParseException& e )
|
catch ( SAXParseException& e )
|
||||||
{
|
{
|
||||||
delete parser;
|
delete parser;
|
||||||
char *err = XMLString::transcode ( e.getMessage() );
|
lastError << _T ( "Validation stopped at line " )
|
||||||
std::stringstream ss;
|
<< e.getLineNumber() << _T ( ", column " ) << e.getColumnNumber()
|
||||||
ss << "Validation stopped at line " << e.getLineNumber() << ", column " << e.getColumnNumber() << ": " << err;
|
<< ": " << toString ( e.getMessage() );
|
||||||
lastError = ss.str();
|
|
||||||
errorPosition = std::make_pair ( e.getLineNumber(), e.getColumnNumber() );
|
errorPosition = std::make_pair ( e.getLineNumber(), e.getColumnNumber() );
|
||||||
XMLString::release ( &err );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
delete parser;
|
delete parser;
|
||||||
lastError = "Unexpected validation error";
|
lastError = _T ( "Unexpected validation error" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
delete parser;
|
delete parser;
|
||||||
|
@ -142,38 +138,33 @@ bool WrapXerces::validateMemory (
|
||||||
catch ( XMLException& e )
|
catch ( XMLException& e )
|
||||||
{
|
{
|
||||||
delete parser;
|
delete parser;
|
||||||
lastError = "";
|
lastError = wxEmptyString;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch ( SAXParseException& e )
|
catch ( SAXParseException& e )
|
||||||
{
|
{
|
||||||
delete parser;
|
delete parser;
|
||||||
char *err = XMLString::transcode ( e.getMessage() );
|
lastError << _T ( "Ln " ) << e.getLineNumber() << _T ( " Col " )
|
||||||
std::stringstream ss;
|
<< e.getColumnNumber() << _T ( ": " ) << toString ( e.getMessage() );
|
||||||
ss << "Ln " << e.getLineNumber() << " Col " << e.getColumnNumber() << ": " << err;
|
|
||||||
lastError = ss.str();
|
|
||||||
errorPosition = std::make_pair ( e.getLineNumber(), e.getColumnNumber() );
|
errorPosition = std::make_pair ( e.getLineNumber(), e.getColumnNumber() );
|
||||||
XMLString::release ( &err );
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch ( ... )
|
catch ( ... )
|
||||||
{
|
{
|
||||||
delete parser;
|
delete parser;
|
||||||
lastError = "";
|
lastError = wxEmptyString;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
delete parser;
|
delete parser;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WrapXerces::getLastError()
|
const wxString &WrapXerces::getLastError()
|
||||||
{
|
{
|
||||||
char *rawError, *it;
|
int i = lastError.Find( _T ( "Message:" ) );
|
||||||
rawError = (char *)lastError.c_str();
|
if ( i != wxNOT_FOUND )
|
||||||
it = strstr ( rawError, "Message:" );
|
|
||||||
if ( it )
|
|
||||||
{
|
{
|
||||||
lastError = it + 8;
|
lastError = lastError.substr( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastError;
|
return lastError;
|
||||||
|
@ -183,3 +174,10 @@ std::pair<int, int> WrapXerces::getErrorPosition()
|
||||||
{
|
{
|
||||||
return errorPosition;
|
return errorPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString WrapXerces::toString ( const XMLCh *str )
|
||||||
|
{
|
||||||
|
static wxMBConvUTF16 conv;
|
||||||
|
|
||||||
|
return wxString ( ( const char * ) str, conv );
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define WRAP_XERCES
|
#define WRAP_XERCES
|
||||||
#define XERCES_TMPLSINC
|
#define XERCES_TMPLSINC
|
||||||
|
|
||||||
|
#include <wx/wx.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||||
|
@ -37,11 +38,12 @@ class WrapXerces
|
||||||
~WrapXerces();
|
~WrapXerces();
|
||||||
bool validate ( const std::string& fileName );
|
bool validate ( const std::string& fileName );
|
||||||
bool validateMemory ( const char *buffer, const char *system, unsigned len );
|
bool validateMemory ( const char *buffer, const char *system, unsigned len );
|
||||||
std::string getLastError();
|
const wxString &getLastError();
|
||||||
std::pair<int, int> getErrorPosition();
|
std::pair<int, int> getErrorPosition();
|
||||||
|
static wxString toString ( const XMLCh *str );
|
||||||
private:
|
private:
|
||||||
XercesCatalogResolver *catalogResolver;
|
XercesCatalogResolver *catalogResolver;
|
||||||
std::string lastError;
|
wxString lastError;
|
||||||
std::pair<int, int> errorPosition;
|
std::pair<int, int> errorPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1296,10 +1296,8 @@ void MyFrame::OnCheckWellformedness ( wxCommandEvent& event )
|
||||||
auto_ptr<WrapExpat> we ( new WrapExpat() );
|
auto_ptr<WrapExpat> we ( new WrapExpat() );
|
||||||
if ( !we->parse ( utf8Buffer.c_str() ) )
|
if ( !we->parse ( utf8Buffer.c_str() ) )
|
||||||
{
|
{
|
||||||
std::string error = we->getLastError();
|
|
||||||
wxString werror = wxString ( error.c_str(), wxConvUTF8, error.size() );
|
|
||||||
statusProgress ( wxEmptyString );
|
statusProgress ( wxEmptyString );
|
||||||
messagePane ( werror, CONST_WARNING );
|
messagePane ( we->getLastError(), CONST_WARNING );
|
||||||
std::pair<int, int> posPair = we->getErrorPosition();
|
std::pair<int, int> posPair = we->getErrorPosition();
|
||||||
-- ( posPair.first );
|
-- ( posPair.first );
|
||||||
int cursorPos =
|
int cursorPos =
|
||||||
|
@ -3944,9 +3942,6 @@ void MyFrame::OnValidateSchema ( wxCommandEvent& event )
|
||||||
statusProgress ( _ ( "Validation in progress..." ) );
|
statusProgress ( _ ( "Validation in progress..." ) );
|
||||||
doc->clearErrorIndicators();
|
doc->clearErrorIndicators();
|
||||||
|
|
||||||
std::string error;
|
|
||||||
wxString wideError;
|
|
||||||
|
|
||||||
std::auto_ptr<WrapXerces> validator (
|
std::auto_ptr<WrapXerces> validator (
|
||||||
new WrapXerces( catalogPath, catalogUtilityPath )
|
new WrapXerces( catalogPath, catalogUtilityPath )
|
||||||
);
|
);
|
||||||
|
@ -3954,9 +3949,7 @@ void MyFrame::OnValidateSchema ( wxCommandEvent& event )
|
||||||
if ( !validator->validate ( fileNameLocal ) )
|
if ( !validator->validate ( fileNameLocal ) )
|
||||||
{
|
{
|
||||||
statusProgress ( wxEmptyString );
|
statusProgress ( wxEmptyString );
|
||||||
error = validator->getLastError();
|
messagePane ( validator->getLastError(), CONST_WARNING );
|
||||||
wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
|
|
||||||
messagePane ( wideError, CONST_WARNING );
|
|
||||||
std::pair<int, int> posPair = validator->getErrorPosition();
|
std::pair<int, int> posPair = validator->getErrorPosition();
|
||||||
|
|
||||||
int cursorPos =
|
int cursorPos =
|
||||||
|
@ -4675,11 +4668,9 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
|
||||||
|
|
||||||
if ( !we->parse ( utf8Buffer ) )
|
if ( !we->parse ( utf8Buffer ) )
|
||||||
{
|
{
|
||||||
std::string error = we->getLastError();
|
//if ( we->isEncodingError() )
|
||||||
wxString werror = wxString ( error.c_str(), wxConvUTF8, error.size() );
|
// ;
|
||||||
if ( we->isEncodingError() )
|
messagePane ( we->getLastError(), CONST_WARNING );
|
||||||
;
|
|
||||||
messagePane ( werror, CONST_WARNING );
|
|
||||||
}
|
}
|
||||||
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
|
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
|
||||||
if ( success )
|
if ( success )
|
||||||
|
@ -5842,15 +5833,12 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
|
||||||
std::auto_ptr<WrapExpat> wellformedparser ( new WrapExpat() );
|
std::auto_ptr<WrapExpat> wellformedparser ( new WrapExpat() );
|
||||||
if ( !wellformedparser->parse ( utf8Buffer ) )
|
if ( !wellformedparser->parse ( utf8Buffer ) )
|
||||||
{
|
{
|
||||||
std::string error = wellformedparser->getLastError();
|
|
||||||
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );
|
|
||||||
wxString message;
|
wxString message;
|
||||||
message.Printf (
|
message.Printf (
|
||||||
_ ( "Cannot associate %s: %s" ),
|
_ ( "Cannot associate %s: %s" ),
|
||||||
type.c_str(),
|
type.c_str(),
|
||||||
wideError.c_str() );
|
wellformedparser->getLastError() );
|
||||||
messagePane ( message,
|
messagePane ( message, CONST_STOP );
|
||||||
CONST_STOP );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
132
src/xmlctrl.cpp
132
src/xmlctrl.cpp
|
@ -187,7 +187,7 @@ void XmlCtrl::OnIdle ( wxIdleEvent& event )
|
||||||
{
|
{
|
||||||
clearErrorIndicators ( GetLineCount() );
|
clearErrorIndicators ( GetLineCount() );
|
||||||
setErrorIndicator ( validationPosition.first - 1, 0 );
|
setErrorIndicator ( validationPosition.first - 1, 0 );
|
||||||
frame->statusProgress ( wxString ( validationMessage.c_str(), wxConvUTF8, validationMessage.size() ) );
|
frame->statusProgress ( validationMessage );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,15 +486,14 @@ void XmlCtrl::handleOpenAngleBracket ( wxKeyEvent& event )
|
||||||
if ( elementMap.find ( parent ) == elementMap.end() )
|
if ( elementMap.find ( parent ) == elementMap.end() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxString choice, conversion;
|
wxString choice;
|
||||||
std::set<std::string> childSet = elementMap[parent];
|
std::set<wxString> &childSet = elementMap[parent];
|
||||||
std::set<std::string>::iterator it;
|
std::set<wxString>::iterator it;
|
||||||
for ( it = childSet.begin(); it != childSet.end(); it++ )
|
for ( it = childSet.begin(); it != childSet.end(); it++ )
|
||||||
{
|
{
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
choice.append ( _T ( "<" ) );
|
choice.append ( _T ( "<" ) );
|
||||||
conversion = wxString ( it->c_str(), wxConvUTF8, it->size() );
|
choice.append ( *it );
|
||||||
choice.append ( conversion );
|
|
||||||
}
|
}
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
UserListShow ( 0, choice );
|
UserListShow ( 0, choice );
|
||||||
|
@ -520,9 +519,7 @@ void XmlCtrl::handleCloseAngleBracket ( wxKeyEvent& event )
|
||||||
wxString elementName = getLastElementName ( pos );
|
wxString elementName = getLastElementName ( pos );
|
||||||
if ( !elementName.empty() )
|
if ( !elementName.empty() )
|
||||||
{
|
{
|
||||||
std::map<std::string, std::set<std::string> > map;
|
attributeMap[elementName]; // Just want to put it there
|
||||||
std::string elementNameUtf8 = ( const char * ) elementName.mb_str ( wxConvUTF8 );
|
|
||||||
attributeMap.insert ( make_pair ( elementNameUtf8, map ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// exit condition 1
|
// exit condition 1
|
||||||
|
@ -571,8 +568,6 @@ void XmlCtrl::handleEquals ( wxKeyEvent& event )
|
||||||
if ( AutoCompActive() )
|
if ( AutoCompActive() )
|
||||||
AutoCompCancel();
|
AutoCompCancel();
|
||||||
|
|
||||||
wxString choice, elementName, attributeName, conversion;
|
|
||||||
std::string elementNameUtf8, attributeNameUtf8;
|
|
||||||
int pos = GetCurrentPos();
|
int pos = GetCurrentPos();
|
||||||
if ( pos <= 0 || getLexerStyleAt ( pos - 1 ) != wxSTC_H_ATTRIBUTE )
|
if ( pos <= 0 || getLexerStyleAt ( pos - 1 ) != wxSTC_H_ATTRIBUTE )
|
||||||
{
|
{
|
||||||
|
@ -583,19 +578,15 @@ void XmlCtrl::handleEquals ( wxKeyEvent& event )
|
||||||
SetSelection ( pos + 2, pos + 2 );
|
SetSelection ( pos + 2, pos + 2 );
|
||||||
|
|
||||||
// tbd: identify possible attribute values
|
// tbd: identify possible attribute values
|
||||||
|
wxString choice, elementName, attributeName;
|
||||||
elementName = getLastElementName ( pos );
|
elementName = getLastElementName ( pos );
|
||||||
attributeName = getLastAttributeName ( pos );
|
attributeName = getLastAttributeName ( pos );
|
||||||
|
|
||||||
elementNameUtf8 = elementName.mb_str ( wxConvUTF8 );
|
std::set<wxString> &valueSet = attributeMap[elementName][attributeName];
|
||||||
attributeNameUtf8 = attributeName.mb_str ( wxConvUTF8 );
|
|
||||||
|
|
||||||
std::set<std::string> valueSet;
|
|
||||||
|
|
||||||
valueSet = attributeMap[elementNameUtf8][attributeNameUtf8];
|
|
||||||
if ( valueSet.empty() )
|
if ( valueSet.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::set<std::string>::iterator valueSetIterator;
|
std::set<wxString>::iterator valueSetIterator;
|
||||||
int cutoff = BUFSIZ;
|
int cutoff = BUFSIZ;
|
||||||
for ( valueSetIterator = valueSet.begin();
|
for ( valueSetIterator = valueSet.begin();
|
||||||
valueSetIterator != valueSet.end();
|
valueSetIterator != valueSet.end();
|
||||||
|
@ -605,11 +596,7 @@ void XmlCtrl::handleEquals ( wxKeyEvent& event )
|
||||||
break;
|
break;
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
choice.Append ( _T ( "<" ) );
|
choice.Append ( _T ( "<" ) );
|
||||||
conversion = wxString (
|
choice.Append ( *valueSetIterator );
|
||||||
valueSetIterator->c_str(),
|
|
||||||
wxConvUTF8,
|
|
||||||
valueSetIterator->size() );
|
|
||||||
choice.Append ( conversion );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
|
@ -621,12 +608,7 @@ void XmlCtrl::handleSpace ( wxKeyEvent& event )
|
||||||
if ( AutoCompActive() )
|
if ( AutoCompActive() )
|
||||||
AutoCompCancel();
|
AutoCompCancel();
|
||||||
|
|
||||||
wxString elementName, choice, conversion;
|
|
||||||
std::string elementNameUtf8;
|
|
||||||
int pos = GetCurrentPos();
|
int pos = GetCurrentPos();
|
||||||
std::map<std::string, std::set<std::string> > currentAttributeMap;
|
|
||||||
std::map<std::string, std::set<std::string> >::iterator
|
|
||||||
attributeIterator;
|
|
||||||
if ( pos <= 2 )
|
if ( pos <= 2 )
|
||||||
{
|
{
|
||||||
event.Skip();
|
event.Skip();
|
||||||
|
@ -665,30 +647,24 @@ void XmlCtrl::handleSpace ( wxKeyEvent& event )
|
||||||
}
|
}
|
||||||
|
|
||||||
AddText ( _T ( " " ) );
|
AddText ( _T ( " " ) );
|
||||||
elementName = getLastElementName ( pos );
|
|
||||||
wxString tag = GetTextRange ( tagStartPos, pos );
|
|
||||||
|
|
||||||
elementNameUtf8 = elementName.mb_str ( wxConvUTF8 );
|
wxString elementName = getLastElementName ( pos );
|
||||||
if ( attributeMap.find ( elementNameUtf8 ) == attributeMap.end() )
|
if ( attributeMap.find ( elementName ) == attributeMap.end() )
|
||||||
return;
|
return;
|
||||||
currentAttributeMap = attributeMap[elementNameUtf8];
|
|
||||||
for (
|
|
||||||
attributeIterator = currentAttributeMap.begin();
|
|
||||||
attributeIterator != currentAttributeMap.end();
|
|
||||||
attributeIterator++ )
|
|
||||||
{
|
|
||||||
conversion = wxString (
|
|
||||||
attributeIterator->first.c_str(),
|
|
||||||
wxConvUTF8,
|
|
||||||
attributeIterator->first.size() );
|
|
||||||
|
|
||||||
|
wxString choice;
|
||||||
|
wxString tag = GetTextRange ( tagStartPos, pos );
|
||||||
|
std::map<wxString, std::set<wxString> > &curAttMap = attributeMap[elementName];
|
||||||
|
std::map<wxString, std::set<wxString> >::iterator it;
|
||||||
|
for ( it = curAttMap.begin(); it != curAttMap.end(); it++ )
|
||||||
|
{
|
||||||
// avoid duplicate attributes
|
// avoid duplicate attributes
|
||||||
if ( tag.Contains ( conversion + _T ( "=" ) ) )
|
if ( tag.Contains ( it->first + _T ( "=" ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
choice.Append ( _T ( "<" ) );
|
choice.Append ( _T ( "<" ) );
|
||||||
choice.Append ( conversion );
|
choice.Append ( it->first );
|
||||||
}
|
}
|
||||||
if ( !choice.empty() )
|
if ( !choice.empty() )
|
||||||
{
|
{
|
||||||
|
@ -720,14 +696,13 @@ void XmlCtrl::handleAmpersand ( wxKeyEvent& event )
|
||||||
{
|
{
|
||||||
AddText ( _T ( "&" ) );
|
AddText ( _T ( "&" ) );
|
||||||
wxString choice;
|
wxString choice;
|
||||||
std::set<std::string>::iterator it;
|
std::set<wxString>::iterator it = entitySet.begin();
|
||||||
it = entitySet.begin();
|
choice += *it;
|
||||||
choice += wxString ( it->c_str(), wxConvUTF8, it->size() );
|
|
||||||
choice += _T ( ";" );
|
choice += _T ( ";" );
|
||||||
for ( it++; it != entitySet.end(); it++ )
|
for ( it++; it != entitySet.end(); it++ )
|
||||||
{
|
{
|
||||||
choice += _T ( "<" );
|
choice += _T ( "<" );
|
||||||
choice += wxString ( it->c_str(), wxConvUTF8, it->size() );
|
choice += *it;
|
||||||
choice += _T ( ";" );
|
choice += _T ( ";" );
|
||||||
}
|
}
|
||||||
UserListShow ( 0, choice );
|
UserListShow ( 0, choice );
|
||||||
|
@ -967,26 +942,13 @@ wxString XmlCtrl::getLastElementName ( int pos )
|
||||||
return GetTextRange ( startPos, iteratorPos );
|
return GetTextRange ( startPos, iteratorPos );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<wxString> XmlCtrl::getChildren ( const wxString& parent )
|
const std::set<wxString> &XmlCtrl::getChildren ( const wxString& parent )
|
||||||
{
|
{
|
||||||
std::string parentUtf8 = ( const char * ) parent.mb_str ( wxConvUTF8 );
|
static std::set<wxString> mySet;
|
||||||
std::set<wxString> mySet;
|
if ( elementMap.find ( parent ) == elementMap.end() )
|
||||||
|
|
||||||
if ( elementMap.find ( parentUtf8 ) == elementMap.end() )
|
|
||||||
return mySet;
|
return mySet;
|
||||||
|
|
||||||
std::set<std::string> myUtf8Set = elementMap[parentUtf8];
|
return elementMap[parent];
|
||||||
std::string currentUtf8;
|
|
||||||
wxString currentWide;
|
|
||||||
|
|
||||||
std::set<std::string>::iterator it;
|
|
||||||
for ( it = myUtf8Set.begin(); it != myUtf8Set.end(); it++ )
|
|
||||||
{
|
|
||||||
currentUtf8 = *it;
|
|
||||||
currentWide = wxString ( currentUtf8.c_str(), wxConvUTF8, currentUtf8.size() );
|
|
||||||
mySet.insert ( currentWide );
|
|
||||||
}
|
|
||||||
return mySet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString XmlCtrl::getLastAttributeName ( int pos )
|
wxString XmlCtrl::getLastAttributeName ( int pos )
|
||||||
|
@ -1095,11 +1057,11 @@ void XmlCtrl::updatePromptMaps ( const char *buffer, size_t bufferLen )
|
||||||
xpg->getElementStructureMap ( elementStructureMap );
|
xpg->getElementStructureMap ( elementStructureMap );
|
||||||
xpg->getEntitySet ( entitySet );
|
xpg->getEntitySet ( entitySet );
|
||||||
grammarFound = xpg->getGrammarFound();
|
grammarFound = xpg->getGrammarFound();
|
||||||
entitySet.insert ( "amp" );
|
entitySet.insert ( _T ( "amp" ) );
|
||||||
entitySet.insert ( "apos" );
|
entitySet.insert ( _T ( "apos" ) );
|
||||||
entitySet.insert ( "quot" );
|
entitySet.insert ( _T ( "quot" ) );
|
||||||
entitySet.insert ( "lt" );
|
entitySet.insert ( _T ( "lt" ) );
|
||||||
entitySet.insert ( "gt" );
|
entitySet.insert ( _T ( "gt" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlCtrl::applyProperties (
|
void XmlCtrl::applyProperties (
|
||||||
|
@ -1823,16 +1785,15 @@ wxString XmlCtrl::getOpenTag ( const wxString& element )
|
||||||
{
|
{
|
||||||
wxString openTag;
|
wxString openTag;
|
||||||
openTag = _T ( "<" ) + element;
|
openTag = _T ( "<" ) + element;
|
||||||
std::set<std::string> requiredAttributeSet;
|
std::set<wxString> requiredAttributeSet;
|
||||||
std::set<std::string>::iterator it;
|
std::set<wxString>::iterator it;
|
||||||
std::string key = ( const char * ) element.mb_str ( wxConvUTF8 );
|
requiredAttributeSet = requiredAttributeMap[element];
|
||||||
requiredAttributeSet = requiredAttributeMap[key];
|
|
||||||
if ( !requiredAttributeSet.empty() )
|
if ( !requiredAttributeSet.empty() )
|
||||||
{
|
{
|
||||||
for ( it = requiredAttributeSet.begin(); it != requiredAttributeSet.end(); it++ )
|
for ( it = requiredAttributeSet.begin(); it != requiredAttributeSet.end(); it++ )
|
||||||
{
|
{
|
||||||
openTag += _T ( " " );
|
openTag += _T ( " " );
|
||||||
openTag += wxString ( it->c_str(), wxConvUTF8, it->size() );
|
openTag += *it;
|
||||||
openTag += _T ( "=\"\"" );
|
openTag += _T ( "=\"\"" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1970,31 +1931,24 @@ void XmlCtrl::toggleLineBackground()
|
||||||
SetCaretLineBackground ( ( lineBackgroundState == BACKGROUND_STATE_NORMAL ) ? baseBackground : alternateBackground );
|
SetCaretLineBackground ( ( lineBackgroundState == BACKGROUND_STATE_NORMAL ) ? baseBackground : alternateBackground );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> XmlCtrl::getEntitySet()
|
const std::set<wxString> &XmlCtrl::getEntitySet()
|
||||||
{
|
{
|
||||||
return entitySet;
|
return entitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<std::string> XmlCtrl::getAttributes ( const wxString& parent )
|
const std::set<std::string> &XmlCtrl::getAttributes ( const wxString& parent )
|
||||||
{
|
{
|
||||||
std::set<std::string> retVal;
|
static std::set<std::string> retVal;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string XmlCtrl::getElementStructure ( const wxString& element )
|
wxString XmlCtrl::getElementStructure ( const wxString& element )
|
||||||
{
|
{
|
||||||
std::string stdElement, ret;
|
if ( elementStructureMap.find ( element ) == elementStructureMap.end() )
|
||||||
stdElement = element.mb_str ( wxConvUTF8);
|
|
||||||
|
|
||||||
if ( elementStructureMap.find ( stdElement ) == elementStructureMap.end() )
|
|
||||||
{
|
{
|
||||||
ret = "";
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
else
|
return elementStructureMap[element];
|
||||||
{
|
|
||||||
ret = elementStructureMap[stdElement];
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlCtrl::backgroundValidate()
|
bool XmlCtrl::backgroundValidate()
|
||||||
|
|
|
@ -130,10 +130,10 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
void clearErrorIndicators ( int maxLine = 0 );
|
void clearErrorIndicators ( int maxLine = 0 );
|
||||||
wxString getParent();
|
wxString getParent();
|
||||||
wxString getLastElementName ( int pos );
|
wxString getLastElementName ( int pos );
|
||||||
std::set<wxString> getChildren ( const wxString& parent );
|
const std::set<wxString> &getChildren ( const wxString& parent );
|
||||||
std::set<std::string> getEntitySet();
|
const std::set<wxString> &getEntitySet();
|
||||||
std::set<std::string> getAttributes ( const wxString& parent );
|
const std::set<std::string> &getAttributes ( const wxString& parent );
|
||||||
std::string getElementStructure ( const wxString& parent );
|
wxString getElementStructure ( const wxString& parent );
|
||||||
bool canInsertAt ( int pos );
|
bool canInsertAt ( int pos );
|
||||||
int getTagStartPos ( int pos );
|
int getTagStartPos ( int pos );
|
||||||
void toggleLineBackground();
|
void toggleLineBackground();
|
||||||
|
@ -153,7 +153,7 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
validationSuccess;
|
validationSuccess;
|
||||||
bool *validationReleasePtr;
|
bool *validationReleasePtr;
|
||||||
std::pair<int, int> validationPosition;
|
std::pair<int, int> validationPosition;
|
||||||
std::string validationMessage;
|
wxString validationMessage;
|
||||||
|
|
||||||
int type;
|
int type;
|
||||||
bool *protectTags;
|
bool *protectTags;
|
||||||
|
@ -163,12 +163,12 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
int currentMaxLine;
|
int currentMaxLine;
|
||||||
int lineBackgroundState;
|
int lineBackgroundState;
|
||||||
wxColour baseBackground, alternateBackground;
|
wxColour baseBackground, alternateBackground;
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
attributeMap;
|
attributeMap;
|
||||||
std::map<std::string, std::set<std::string> > requiredAttributeMap;
|
std::map<wxString, std::set<wxString> > requiredAttributeMap;
|
||||||
std::map<std::string, std::set<std::string> > elementMap;
|
std::map<wxString, std::set<wxString> > elementMap;
|
||||||
std::set<std::string> entitySet;
|
std::set<wxString> entitySet;
|
||||||
std::map<std::string, std::string> elementStructureMap;
|
std::map<wxString, wxString> elementStructureMap;
|
||||||
std::string catalogPath, catalogUtilityPath, basePath, auxPath;
|
std::string catalogPath, catalogUtilityPath, basePath, auxPath;
|
||||||
XmlCtrlProperties properties;
|
XmlCtrlProperties properties;
|
||||||
wxString getLastAttributeName ( int pos );
|
wxString getLastAttributeName ( int pos );
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
#include <xercesc/validators/schema/SchemaValidator.hpp>
|
#include <xercesc/validators/schema/SchemaValidator.hpp>
|
||||||
#include <xercesc/validators/common/ContentSpecNode.hpp>
|
#include <xercesc/validators/common/ContentSpecNode.hpp>
|
||||||
#include <xercesc/validators/schema/SchemaSymbols.hpp>
|
#include <xercesc/validators/schema/SchemaSymbols.hpp>
|
||||||
//#include "wrapxerces.h"
|
#include "wrapxerces.h" // Delearation of toString()
|
||||||
|
|
||||||
using namespace xercesc;
|
using namespace xercesc;
|
||||||
|
|
||||||
|
@ -99,34 +99,19 @@ void XMLCALL XmlPromptGenerator::starthandler (
|
||||||
|
|
||||||
d->push ( el );
|
d->push ( el );
|
||||||
|
|
||||||
std::string parent, element;
|
wxString parent ( d->getParent().c_str(), wxConvUTF8 );
|
||||||
parent = d->getParent();
|
wxString element ( el, wxConvUTF8 );
|
||||||
element = el;
|
|
||||||
|
|
||||||
// update elementMap
|
// update elementMap
|
||||||
if ( d->elementMap.find ( parent ) == d->elementMap.end() )
|
|
||||||
{
|
|
||||||
std::set<std::string> childSet;
|
|
||||||
childSet.insert ( element );
|
|
||||||
d->elementMap.insert ( make_pair ( parent, childSet ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
d->elementMap[parent].insert ( element );
|
d->elementMap[parent].insert ( element );
|
||||||
|
|
||||||
std::string attributeName, attributeValue;
|
wxString attributeName, attributeValue;
|
||||||
|
|
||||||
// update attributeMap
|
// update attributeMap
|
||||||
// case 1: element unknown, no attributes
|
|
||||||
if ( ! ( *attr ) && d->attributeMap.find ( element ) == d->attributeMap.end() )
|
|
||||||
{
|
|
||||||
std::map<std::string, std::set<std::string> > currentAttributeMap;
|
|
||||||
d->attributeMap.insert ( make_pair ( element, currentAttributeMap ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( ; *attr; attr += 2 )
|
for ( ; *attr; attr += 2 )
|
||||||
{
|
{
|
||||||
attributeName = *attr;
|
attributeName = wxString ( *attr, wxConvUTF8 );
|
||||||
attributeValue = * ( attr + 1 );
|
attributeValue = wxString ( * ( attr + 1 ), wxConvUTF8 );
|
||||||
|
|
||||||
if (d->attributeMap[element][attributeName].size() < d->attributeValueCutoff)
|
if (d->attributeMap[element][attributeName].size() < d->attributeValueCutoff)
|
||||||
d->attributeMap[element][attributeName].insert ( attributeValue );
|
d->attributeMap[element][attributeName].insert ( attributeValue );
|
||||||
|
@ -146,32 +131,32 @@ bool XmlPromptGenerator::getGrammarFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlPromptGenerator::getAttributeMap (
|
void XmlPromptGenerator::getAttributeMap (
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
&attributeMap )
|
&attributeMap )
|
||||||
{
|
{
|
||||||
attributeMap = d->attributeMap;
|
attributeMap = d->attributeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlPromptGenerator::getRequiredAttributeMap (
|
void XmlPromptGenerator::getRequiredAttributeMap (
|
||||||
std::map<std::string, std::set<std::string> >& requiredAttributeMap )
|
std::map<wxString, std::set<wxString> >& requiredAttributeMap )
|
||||||
{
|
{
|
||||||
requiredAttributeMap = d->requiredAttributeMap;
|
requiredAttributeMap = d->requiredAttributeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlPromptGenerator::getElementMap (
|
void XmlPromptGenerator::getElementMap (
|
||||||
std::map<std::string, std::set<std::string> > &elementMap )
|
std::map<wxString, std::set<wxString> > &elementMap )
|
||||||
{
|
{
|
||||||
elementMap = d->elementMap;
|
elementMap = d->elementMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlPromptGenerator::getEntitySet (
|
void XmlPromptGenerator::getEntitySet (
|
||||||
std::set<std::string> &entitySet )
|
std::set<wxString> &entitySet )
|
||||||
{
|
{
|
||||||
entitySet = d->entitySet;
|
entitySet = d->entitySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlPromptGenerator::getElementStructureMap (
|
void XmlPromptGenerator::getElementStructureMap (
|
||||||
std::map<std::string, std::string> &elementStructureMap )
|
std::map<wxString, wxString> &elementStructureMap )
|
||||||
{
|
{
|
||||||
elementStructureMap = d->elementStructureMap;
|
elementStructureMap = d->elementStructureMap;
|
||||||
}
|
}
|
||||||
|
@ -208,60 +193,59 @@ void XMLCALL XmlPromptGenerator::elementdeclhandler (
|
||||||
PromptGeneratorData *d;
|
PromptGeneratorData *d;
|
||||||
d = ( PromptGeneratorData * ) data;
|
d = ( PromptGeneratorData * ) data;
|
||||||
|
|
||||||
std::string myElement = name;
|
wxString myElement ( name, wxConvUTF8 );
|
||||||
|
|
||||||
std::set<std::string> children;
|
getContent ( *model, d->elementStructureMap[myElement], d->elementMap[myElement] );
|
||||||
getContent ( *model, d->elementStructureMap[myElement], children );
|
|
||||||
if ( !children.empty() )
|
|
||||||
d->elementMap[myElement] = children;
|
|
||||||
|
|
||||||
XML_FreeContentModel ( d->p, model );
|
XML_FreeContentModel ( d->p, model );
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlPromptGenerator::getContent (
|
void XmlPromptGenerator::getContent (
|
||||||
const XML_Content &content,
|
const XML_Content &content,
|
||||||
std::string &contentModel,
|
wxString &contentModel,
|
||||||
std::set<std::string> &list )
|
std::set<wxString> &list )
|
||||||
{
|
{
|
||||||
|
wxString name;
|
||||||
switch ( content.type )
|
switch ( content.type )
|
||||||
{
|
{
|
||||||
case XML_CTYPE_EMPTY:
|
case XML_CTYPE_EMPTY:
|
||||||
contentModel += "EMPTY";
|
contentModel += _T("EMPTY");
|
||||||
return;
|
return;
|
||||||
case XML_CTYPE_ANY:
|
case XML_CTYPE_ANY:
|
||||||
contentModel += "ANY";
|
contentModel += _T("ANY");
|
||||||
return;
|
return;
|
||||||
case XML_CTYPE_NAME:
|
case XML_CTYPE_NAME:
|
||||||
list.insert ( content.name );
|
name = wxString ( content.name, wxConvUTF8 );
|
||||||
contentModel += content.name;
|
list.insert ( name );
|
||||||
|
contentModel += name;
|
||||||
break;
|
break;
|
||||||
case XML_CTYPE_CHOICE:
|
case XML_CTYPE_CHOICE:
|
||||||
case XML_CTYPE_SEQ:
|
case XML_CTYPE_SEQ:
|
||||||
case XML_CTYPE_MIXED:
|
case XML_CTYPE_MIXED:
|
||||||
default:
|
default:
|
||||||
std::string sep;
|
wxString sep;
|
||||||
sep = ( content.type == XML_CTYPE_CHOICE ) ? "|" : ",";//_T("|") : _T(",");
|
sep = ( content.type == XML_CTYPE_CHOICE ) ? _T("|") : _T(",");
|
||||||
contentModel += ( content.type == XML_CTYPE_MIXED ) ? "(#PCDATA|" : "(";
|
contentModel += ( content.type == XML_CTYPE_MIXED ) ? _T("(#PCDATA|") : _T("(");
|
||||||
for ( unsigned i = 0; i < content.numchildren; i++ )
|
for ( unsigned i = 0; i < content.numchildren; i++ )
|
||||||
{
|
{
|
||||||
if ( i > 0 )
|
if ( i > 0 )
|
||||||
contentModel += sep;
|
contentModel += sep;
|
||||||
getContent ( content.children[i], contentModel, list);
|
getContent ( content.children[i], contentModel, list);
|
||||||
}
|
}
|
||||||
contentModel += ")";//_T(")");
|
contentModel += _T(")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( content.quant )
|
switch ( content.quant )
|
||||||
{
|
{
|
||||||
case XML_CQUANT_OPT:
|
case XML_CQUANT_OPT:
|
||||||
contentModel += "?";//_T("?");
|
contentModel += _T("?");
|
||||||
break;
|
break;
|
||||||
case XML_CQUANT_REP:
|
case XML_CQUANT_REP:
|
||||||
contentModel += "*";//_T("*");
|
contentModel += _T("*");
|
||||||
break;
|
break;
|
||||||
case XML_CQUANT_PLUS:
|
case XML_CQUANT_PLUS:
|
||||||
contentModel += "+";//_T("+");
|
contentModel += _T("+");
|
||||||
break;
|
break;
|
||||||
case XML_CQUANT_NONE:
|
case XML_CQUANT_NONE:
|
||||||
default:
|
default:
|
||||||
|
@ -280,7 +264,7 @@ void XMLCALL XmlPromptGenerator::attlistdeclhandler (
|
||||||
PromptGeneratorData *d;
|
PromptGeneratorData *d;
|
||||||
d = ( PromptGeneratorData * ) data;
|
d = ( PromptGeneratorData * ) data;
|
||||||
|
|
||||||
std::set<std::string> &attributeValues = d->attributeMap[elname][attname];
|
std::set<wxString> &attributeValues = d->attributeMap[elname][attname];
|
||||||
if ( *att_type == '(' ) // change to exclude _known_ identifiers?
|
if ( *att_type == '(' ) // change to exclude _known_ identifiers?
|
||||||
{
|
{
|
||||||
const char *s, *word;
|
const char *s, *word;
|
||||||
|
@ -292,7 +276,7 @@ void XMLCALL XmlPromptGenerator::attlistdeclhandler (
|
||||||
while ( *s != '|' && *s != ')' )
|
while ( *s != '|' && *s != ')' )
|
||||||
s++;
|
s++;
|
||||||
|
|
||||||
std::string currentValue ( word, s - word );
|
wxString currentValue ( word, wxConvUTF8, s - word );
|
||||||
attributeValues.insert ( currentValue );
|
attributeValues.insert ( currentValue );
|
||||||
|
|
||||||
while ( *s != '|' && *s != ')')
|
while ( *s != '|' && *s != ')')
|
||||||
|
@ -302,7 +286,7 @@ void XMLCALL XmlPromptGenerator::attlistdeclhandler (
|
||||||
|
|
||||||
if ( isrequired )
|
if ( isrequired )
|
||||||
{
|
{
|
||||||
d->requiredAttributeMap[elname].insert ( attname );
|
d->requiredAttributeMap[elname].insert ( wxString ( attname, wxConvUTF8 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +391,7 @@ void XMLCALL XmlPromptGenerator::entitydeclhandler (
|
||||||
!publicId &&
|
!publicId &&
|
||||||
!notationName )
|
!notationName )
|
||||||
{
|
{
|
||||||
d->entitySet.insert ( entityName );
|
d->entitySet.insert ( wxString ( entityName, wxConvUTF8 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,26 +400,28 @@ void XmlPromptGenerator::handleSchema (
|
||||||
const XML_Char *el,
|
const XML_Char *el,
|
||||||
const XML_Char **attr )
|
const XML_Char **attr )
|
||||||
{
|
{
|
||||||
|
if ( !d->isRootElement )
|
||||||
|
return;
|
||||||
// first check for XML Schema association
|
// first check for XML Schema association
|
||||||
XML_Char **schemaAttr = ( XML_Char ** ) attr; // now redundant; could use attr
|
const char **schemaAttr = ( const XML_Char ** ) attr; // now redundant; could use attr
|
||||||
std::string path;
|
std::string path;
|
||||||
for ( ; d->isRootElement && *schemaAttr; schemaAttr += 2 )
|
for ( ; *schemaAttr; schemaAttr += 2 )
|
||||||
{
|
{
|
||||||
// no namespace
|
// no namespace
|
||||||
if ( !strcmp ( ( const char * ) *schemaAttr, "xsi:noNamespaceSchemaLocation" ) )
|
if ( !strcmp ( *schemaAttr, "xsi:noNamespaceSchemaLocation" ) )
|
||||||
{
|
{
|
||||||
path = ( const char * ) * ( schemaAttr + 1 );
|
path = * ( schemaAttr + 1 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// with namespace -- check if this works
|
// with namespace -- check if this works
|
||||||
else if ( !strcmp ( ( const char * ) *schemaAttr, "xsi:schemaLocation" ) )
|
else if ( !strcmp ( *schemaAttr, "xsi:schemaLocation" ) )
|
||||||
{
|
{
|
||||||
char *searchIterator;
|
const char *searchIterator = * ( schemaAttr + 1 );
|
||||||
for ( searchIterator = ( char * ) * ( schemaAttr + 1 ); *searchIterator && *searchIterator != ' ' && *searchIterator != '\t' && *searchIterator != '\n'; searchIterator++ )
|
while ( *searchIterator && *searchIterator != ' ' && *searchIterator != '\t' && *searchIterator != '\n' )
|
||||||
;
|
searchIterator++;
|
||||||
if ( *searchIterator )
|
if ( *searchIterator )
|
||||||
{
|
{
|
||||||
path = ( const char * ) ( searchIterator + 1 );
|
path = searchIterator + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,39 +470,29 @@ void XmlPromptGenerator::handleSchema (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *s;
|
|
||||||
while ( elemEnum.hasMoreElements() )
|
while ( elemEnum.hasMoreElements() )
|
||||||
{
|
{
|
||||||
const SchemaElementDecl& curElem = elemEnum.nextElement();
|
const SchemaElementDecl& curElem = elemEnum.nextElement();
|
||||||
|
|
||||||
std::string element;
|
wxString element;
|
||||||
std::set<std::string> children;
|
|
||||||
|
|
||||||
const QName *qnm = curElem.getElementName();
|
const QName *qnm = curElem.getElementName();
|
||||||
if ( qnm )
|
if ( qnm == NULL )
|
||||||
{
|
continue;
|
||||||
s = XMLString::transcode ( qnm->getRawName() ); // this includes any prefix:localname combinations
|
element = WrapXerces::toString ( qnm->getRawName() ); // this includes any prefix:localname combinations
|
||||||
element = s;
|
|
||||||
XMLString::release( &s );
|
|
||||||
}
|
|
||||||
if ( element.empty() )
|
if ( element.empty() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const XMLCh* fmtCntModel = curElem.getFormattedContentModel();
|
const XMLCh* fmtCntModel = curElem.getFormattedContentModel();
|
||||||
if ( fmtCntModel != NULL ) // tbd: this does not yet pick up prefix:localname combinations
|
if ( fmtCntModel != NULL ) // tbd: this does not yet pick up prefix:localname combinations
|
||||||
{
|
{
|
||||||
std::string structure;
|
wxString structure = WrapXerces::toString ( fmtCntModel );
|
||||||
s = XMLString::transcode ( fmtCntModel );
|
d->elementStructureMap[element] = structure;
|
||||||
structure = s;
|
|
||||||
XMLString::release( &s );
|
|
||||||
d->elementStructureMap.insert ( make_pair ( element, structure ) );
|
|
||||||
}
|
}
|
||||||
const ContentSpecNode *spec = curElem.getContentSpec();
|
const ContentSpecNode *spec = curElem.getContentSpec();
|
||||||
if ( spec != NULL )
|
if ( spec != NULL )
|
||||||
{
|
{
|
||||||
getContent ( spec, children );
|
getContent ( spec, d->elementMap[element] );
|
||||||
if ( !children.empty() )
|
|
||||||
d->elementMap.insert ( make_pair ( element, children ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch attributes
|
// fetch attributes
|
||||||
|
@ -526,7 +502,7 @@ void XmlPromptGenerator::handleSchema (
|
||||||
XMLAttDefList& attIter = curElem.getAttDefList();
|
XMLAttDefList& attIter = curElem.getAttDefList();
|
||||||
for ( unsigned int i = 0; i < attIter.getAttDefCount(); i++ )
|
for ( unsigned int i = 0; i < attIter.getAttDefCount(); i++ )
|
||||||
{
|
{
|
||||||
std::string attribute, attributeValue;
|
wxString attribute, attributeValue;
|
||||||
|
|
||||||
XMLAttDef& attr = attIter.getAttDef ( i );
|
XMLAttDef& attr = attIter.getAttDef ( i );
|
||||||
XMLAttDef::DefAttTypes ty = attr.getDefaultType();
|
XMLAttDef::DefAttTypes ty = attr.getDefaultType();
|
||||||
|
@ -535,24 +511,16 @@ void XmlPromptGenerator::handleSchema (
|
||||||
SchemaAttDef *pAttr = ( SchemaAttDef * ) &attr;
|
SchemaAttDef *pAttr = ( SchemaAttDef * ) &attr;
|
||||||
|
|
||||||
const QName *qnm = pAttr->getAttName();
|
const QName *qnm = pAttr->getAttName();
|
||||||
if ( qnm )
|
if ( qnm == NULL )
|
||||||
{
|
continue;
|
||||||
s = XMLString::transcode ( qnm->getRawName() );
|
attribute = WrapXerces::toString ( qnm->getRawName() );
|
||||||
attribute = s;
|
|
||||||
XMLString::release( &s );
|
|
||||||
}
|
|
||||||
if ( attribute.empty() )
|
if ( attribute.empty() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Value
|
// Value
|
||||||
if ( pAttr->getValue() )
|
attributeValue = WrapXerces::toString ( pAttr->getValue() );
|
||||||
{
|
|
||||||
s = XMLString::transcode ( pAttr->getValue() );
|
|
||||||
attributeValue = s;
|
|
||||||
XMLString::release( &s );
|
|
||||||
}
|
|
||||||
|
|
||||||
d->attributeMap[element][attribute].insert( attributeValue );
|
d->attributeMap[element][attribute].insert( attributeValue );
|
||||||
|
|
||||||
if ( ty == XMLAttDef::Required || ty == XMLAttDef::Required_And_Fixed)
|
if ( ty == XMLAttDef::Required || ty == XMLAttDef::Required_And_Fixed)
|
||||||
d->requiredAttributeMap[element].insert ( attribute );
|
d->requiredAttributeMap[element].insert ( attribute );
|
||||||
}
|
}
|
||||||
|
@ -563,17 +531,16 @@ void XmlPromptGenerator::handleSchema (
|
||||||
|
|
||||||
void XmlPromptGenerator::getContent (
|
void XmlPromptGenerator::getContent (
|
||||||
const ContentSpecNode *spec,
|
const ContentSpecNode *spec,
|
||||||
std::set<std::string> &list )
|
std::set<wxString> &list )
|
||||||
{
|
{
|
||||||
//if ( spec == NULL) return;
|
//if ( spec == NULL) return;
|
||||||
|
|
||||||
const QName *qnm = spec->getElement();
|
const QName *qnm = spec->getElement();
|
||||||
if ( qnm )
|
if ( qnm )
|
||||||
{
|
{
|
||||||
char *element = XMLString::transcode ( qnm->getRawName() );
|
wxString element = WrapXerces::toString ( qnm->getRawName() );
|
||||||
if ( element != NULL )
|
if ( !element.IsEmpty() )
|
||||||
list.insert( element );
|
list.insert( element );
|
||||||
XMLString::release( &element );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( spec->getFirst() != NULL)
|
if ( spec->getFirst() != NULL)
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#ifndef XML_PROMPT_GENERATOR_H
|
#ifndef XML_PROMPT_GENERATOR_H
|
||||||
#define XML_PROMPT_GENERATOR_H
|
#define XML_PROMPT_GENERATOR_H
|
||||||
|
|
||||||
|
#include <wx/wx.h>
|
||||||
//#include <expat.h>
|
//#include <expat.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
@ -30,12 +31,12 @@
|
||||||
|
|
||||||
struct PromptGeneratorData : public ParserData
|
struct PromptGeneratorData : public ParserData
|
||||||
{
|
{
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
attributeMap;
|
attributeMap;
|
||||||
std::map<std::string, std::set<std::string> > elementMap;
|
std::map<wxString, std::set<wxString> > elementMap;
|
||||||
std::map<std::string, std::set<std::string> > requiredAttributeMap;
|
std::map<wxString, std::set<wxString> > requiredAttributeMap;
|
||||||
std::map<std::string, std::string> elementStructureMap;
|
std::map<wxString, wxString> elementStructureMap;
|
||||||
std::set<std::string> entitySet;
|
std::set<wxString> entitySet;
|
||||||
std::string catalogPath, basePath, auxPath, rootElement;
|
std::string catalogPath, basePath, auxPath, rootElement;
|
||||||
bool isRootElement, grammarFound;
|
bool isRootElement, grammarFound;
|
||||||
unsigned attributeValueCutoff;
|
unsigned attributeValueCutoff;
|
||||||
|
@ -51,17 +52,17 @@ class XmlPromptGenerator : public WrapExpat
|
||||||
const std::string& auxPath = "" );
|
const std::string& auxPath = "" );
|
||||||
virtual ~XmlPromptGenerator();
|
virtual ~XmlPromptGenerator();
|
||||||
void getAttributeMap (
|
void getAttributeMap (
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
&attributeMap );
|
&attributeMap );
|
||||||
void getRequiredAttributeMap (
|
void getRequiredAttributeMap (
|
||||||
std::map<std::string, std::set<std::string> > &requiredAttributeMap );
|
std::map<wxString, std::set<wxString> > &requiredAttributeMap );
|
||||||
void getElementMap (
|
void getElementMap (
|
||||||
std::map<std::string, std::set<std::string> > &elementMap );
|
std::map<wxString, std::set<wxString> > &elementMap );
|
||||||
void getEntitySet (
|
void getEntitySet (
|
||||||
std::set<std::string> &entitySet );
|
std::set<wxString> &entitySet );
|
||||||
bool getGrammarFound();
|
bool getGrammarFound();
|
||||||
void getElementStructureMap (
|
void getElementStructureMap (
|
||||||
std::map<std::string, std::string> &elementStructureMap );
|
std::map<wxString, wxString> &elementStructureMap );
|
||||||
private:
|
private:
|
||||||
std::auto_ptr<PromptGeneratorData> d;
|
std::auto_ptr<PromptGeneratorData> d;
|
||||||
static void XMLCALL starthandler (
|
static void XMLCALL starthandler (
|
||||||
|
@ -84,8 +85,8 @@ class XmlPromptGenerator : public WrapExpat
|
||||||
XML_Content *model );
|
XML_Content *model );
|
||||||
static void getContent (
|
static void getContent (
|
||||||
const XML_Content &content,
|
const XML_Content &content,
|
||||||
std::string &contentModel,
|
wxString &contentModel,
|
||||||
std::set<std::string> &list );
|
std::set<wxString> &list );
|
||||||
static void XMLCALL attlistdeclhandler (
|
static void XMLCALL attlistdeclhandler (
|
||||||
void *userData,
|
void *userData,
|
||||||
const XML_Char *elname,
|
const XML_Char *elname,
|
||||||
|
@ -115,7 +116,7 @@ class XmlPromptGenerator : public WrapExpat
|
||||||
const XML_Char **attr );
|
const XML_Char **attr );
|
||||||
static void getContent (
|
static void getContent (
|
||||||
const xercesc::ContentSpecNode *spec,
|
const xercesc::ContentSpecNode *spec,
|
||||||
std::set<std::string> &list );
|
std::set<wxString> &list );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <wx/wx.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -27,11 +28,11 @@
|
||||||
#include "xmlshallowvalidator.h"
|
#include "xmlshallowvalidator.h"
|
||||||
|
|
||||||
XmlShallowValidator::XmlShallowValidator (
|
XmlShallowValidator::XmlShallowValidator (
|
||||||
std::map<std::string, std::set<std::string> > &elementMap,
|
std::map<wxString, std::set<wxString> > &elementMap,
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
&attributeMap,
|
&attributeMap,
|
||||||
std::map<std::string, std::set<std::string> > &requiredAttributeMap,
|
std::map<wxString, std::set<wxString> > &requiredAttributeMap,
|
||||||
std::set<std::string> &entitySet,
|
std::set<wxString> &entitySet,
|
||||||
int maxLine,
|
int maxLine,
|
||||||
bool segmentOnly ) : vd ( new XmlShallowValidatorData() )
|
bool segmentOnly ) : vd ( new XmlShallowValidatorData() )
|
||||||
{
|
{
|
||||||
|
@ -71,30 +72,34 @@ void XMLCALL XmlShallowValidator::start ( void *data,
|
||||||
++ ( vd->depth );
|
++ ( vd->depth );
|
||||||
|
|
||||||
//check element ok
|
//check element ok
|
||||||
std::string parent = vd->getParent();
|
wxString parent ( vd->getParent().c_str(), wxConvUTF8 );
|
||||||
if ( parent.empty() )
|
if ( parent.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( vd->elementMap.empty() )
|
if ( vd->elementMap.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !vd->elementMap[parent].count ( vd->getElement() ) )
|
wxString element ( vd->getElement().c_str(), wxConvUTF8 );
|
||||||
|
if ( !vd->elementMap[parent].count ( element ) )
|
||||||
{
|
{
|
||||||
vd->isValid = false;
|
vd->isValid = false;
|
||||||
vd->positionVector.push_back (
|
vd->positionVector.push_back (
|
||||||
make_pair ( XML_GetCurrentLineNumber ( vd->p ), XML_GetCurrentColumnNumber ( vd->p ) ) );
|
make_pair ( XML_GetCurrentLineNumber ( vd->p ), XML_GetCurrentColumnNumber ( vd->p ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::set<std::string> > attributeMap;
|
element = wxString ( el, wxConvUTF8 );
|
||||||
size_t requiredAttributeCount = vd->requiredAttributeMap[el].size();
|
|
||||||
std::string currentAttribute;
|
std::map<wxString, std::set<wxString> > attributeMap;
|
||||||
|
size_t requiredAttributeCount = vd->requiredAttributeMap[element].size();
|
||||||
|
wxString currentAttribute;
|
||||||
|
|
||||||
while ( *attr )
|
while ( *attr )
|
||||||
{
|
{
|
||||||
attributeMap = vd->attributeMap[el];
|
attributeMap = vd->attributeMap[element];
|
||||||
|
|
||||||
// check for existence
|
// check for existence
|
||||||
if ( !attributeMap.count ( *attr ) )
|
currentAttribute = wxString ( *attr, wxConvUTF8 );
|
||||||
|
if ( !attributeMap.count ( currentAttribute ) )
|
||||||
{
|
{
|
||||||
vd->isValid = false;
|
vd->isValid = false;
|
||||||
vd->positionVector.push_back ( make_pair (
|
vd->positionVector.push_back ( make_pair (
|
||||||
|
@ -102,9 +107,8 @@ void XMLCALL XmlShallowValidator::start ( void *data,
|
||||||
XML_GetCurrentColumnNumber ( vd->p ) ) );
|
XML_GetCurrentColumnNumber ( vd->p ) ) );
|
||||||
}
|
}
|
||||||
// check for requirement
|
// check for requirement
|
||||||
currentAttribute = ( const char * ) *attr;
|
if ( vd->requiredAttributeMap[element].find ( currentAttribute ) !=
|
||||||
if ( vd->requiredAttributeMap[el].find ( currentAttribute ) !=
|
vd->requiredAttributeMap[element].end() )
|
||||||
vd->requiredAttributeMap[el].end() )
|
|
||||||
--requiredAttributeCount;
|
--requiredAttributeCount;
|
||||||
|
|
||||||
attr += 2;
|
attr += 2;
|
||||||
|
|
|
@ -33,11 +33,11 @@ struct XmlShallowValidatorData : public ParserData
|
||||||
{
|
{
|
||||||
XmlShallowValidatorData()
|
XmlShallowValidatorData()
|
||||||
{}
|
{}
|
||||||
std::map<std::string, std::set<std::string> > elementMap;
|
std::map<wxString, std::set<wxString> > elementMap;
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
attributeMap;
|
attributeMap;
|
||||||
std::map<std::string, std::set<std::string> > requiredAttributeMap;
|
std::map<wxString, std::set<wxString> > requiredAttributeMap;
|
||||||
std::set<std::string> entitySet;
|
std::set<wxString> entitySet;
|
||||||
std::vector<std::pair<int, int> > positionVector;
|
std::vector<std::pair<int, int> > positionVector;
|
||||||
bool isValid, segmentOnly;
|
bool isValid, segmentOnly;
|
||||||
int depth, maxLine;
|
int depth, maxLine;
|
||||||
|
@ -49,11 +49,11 @@ class XmlShallowValidator : public WrapExpat
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XmlShallowValidator (
|
XmlShallowValidator (
|
||||||
std::map<std::string, std::set<std::string> > &elementMap,
|
std::map<wxString, std::set<wxString> > &elementMap,
|
||||||
std::map<std::string, std::map<std::string, std::set<std::string> > >
|
std::map<wxString, std::map<wxString, std::set<wxString> > >
|
||||||
&attributeMap,
|
&attributeMap,
|
||||||
std::map<std::string, std::set<std::string> > &requiredAttributeMap,
|
std::map<wxString, std::set<wxString> > &requiredAttributeMap,
|
||||||
std::set<std::string> &entitySet,
|
std::set<wxString> &entitySet,
|
||||||
int maxLine = 0,
|
int maxLine = 0,
|
||||||
bool segmentOnly = false );
|
bool segmentOnly = false );
|
||||||
virtual ~XmlShallowValidator();
|
virtual ~XmlShallowValidator();
|
||||||
|
|
Loading…
Reference in New Issue