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