diff --git a/src/xercescatalogresolver.cpp b/src/xercescatalogresolver.cpp index 3c346a3..28057a3 100755 --- a/src/xercescatalogresolver.cpp +++ b/src/xercescatalogresolver.cpp @@ -72,6 +72,8 @@ InputSource *XercesCatalogResolver::resolveEntity ( if ( publicID == NULL || *publicID == '\0' ) return NULL; + // Since public IDs consist of ANSII characters, it doesn't matter how + // publicID is encoded as long as it's a multibyte string char *narrowPublicId = XMLString::transcode ( publicID ); if ( narrowPublicId == NULL ) return NULL; diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index 2c19b05..2d299c2 100755 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -2920,25 +2920,23 @@ void MyFrame::OnNew ( wxCommandEvent& WXUNUSED ( event ) ) ReadFile::run ( templateFileLocal, buffer ); wxString documentContents = wxString ( buffer.c_str(), wxConvUTF8, buffer.size() ); - newDocument ( documentContents, - wxString ( templateFileLocal.c_str(), wxConvUTF8, templateFileLocal.size() ) ); + newDocument ( buffer, templateFile ); } void MyFrame::newDocument ( const wxString& s, const wxString& path, bool canSave ) { std::string bufferUtf8 = ( const char * ) s.mb_str ( wxConvUTF8 ); - std::string pathUtf8 = ( const char * ) path.mb_str ( wxConvUTF8 ); - newDocument ( bufferUtf8, pathUtf8, canSave ); + newDocument ( bufferUtf8, path, canSave ); } -void MyFrame::newDocument ( const std::string& s, const std::string& path, bool canSave ) +void MyFrame::newDocument ( const std::string& s, const wxString& path, bool canSave ) { XmlDoc *doc; wxString documentLabel; documentLabel.Printf ( _ ( "Document%i" ), documentCount++ ); - std::string auxPath = getAuxPath ( path ); + wxString auxPath = getAuxPath ( path ); Freeze(); doc = ( s.empty() ) ? @@ -3068,7 +3066,7 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile ) XmlDoc *doc; int type = getFileType ( fileName ); - std::string auxPath = getAuxPath ( ( const char * ) fileName.mb_str ( wxConvLocal ) ); + wxString auxPath = getAuxPath ( fileName ); char *docBuffer = NULL; size_t docBufferLen = 0; @@ -3267,7 +3265,7 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile ) wxID_ANY, finalBuffer, finalBufferLen, - ( const char * ) fileName.mb_str ( wxConvLocal ), + fileName, auxPath ); #ifdef __WXMSW__ doc->SetUndoCollection ( false ); @@ -6183,26 +6181,26 @@ void MyFrame::OnDropFiles ( wxDropFilesEvent& event ) } #endif -std::string MyFrame::getAuxPath ( const std::string& fileName ) +wxString MyFrame::getAuxPath ( const wxString& fileName ) { - if ( fileName.find ( ".xsl" ) != std::string::npos || - fileName.find ( ".XSL" ) != std::string::npos ) - return xslDtdPath; - else if ( fileName.find ( ".rss" ) != std::string::npos || - fileName.find ( ".RSS" ) != std::string::npos ) - return rssDtdPath; - else if ( fileName.find ( ".xtm" ) != std::string::npos || - fileName.find ( ".xtmm" ) != std::string::npos || - fileName.find ( ".XTM" ) != std::string::npos || - fileName.find ( ".XTMM" ) != std::string::npos ) - return xtmDtdPath; - else if ( fileName.find ( ".lzx" ) != std::string::npos || - fileName.find ( ".LZX" ) != std::string::npos ) - return lzxDtdPath; - else if ( fileName.find ( ".xlf" ) != std::string::npos || - fileName.find ( ".XLF" ) != std::string::npos ) - return xliffDtdPath; - return ""; + if ( fileName.Find ( _T ( ".xsl" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".XSL" ) ) != wxNOT_FOUND ) + return wxString ( xslDtdPath.c_str(), wxConvUTF8 ); + else if ( fileName.Find ( _T ( ".rss" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".RSS" ) ) != wxNOT_FOUND ) + return wxString ( rssDtdPath.c_str(), wxConvUTF8 ); + else if ( fileName.Find ( _T ( ".xtm" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".xtmm" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".XTM" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".XTMM" ) ) != wxNOT_FOUND ) + return wxString ( xtmDtdPath.c_str(), wxConvUTF8 ); + else if ( fileName.Find ( _T ( ".lzx" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".LZX" ) ) != wxNOT_FOUND ) + return wxString ( lzxDtdPath.c_str(), wxConvUTF8 ); + else if ( fileName.Find ( _T ( ".xlf" ) ) != wxNOT_FOUND || + fileName.Find ( _T ( ".XLF" ) ) != wxNOT_FOUND ) + return wxString ( xliffDtdPath.c_str(), wxConvUTF8 ); + return wxEmptyString; } void MyFrame::OnActivateApp ( wxActivateEvent& event ) diff --git a/src/xmlcopyeditor.h b/src/xmlcopyeditor.h index ca4cd1c..9f5b54b 100755 --- a/src/xmlcopyeditor.h +++ b/src/xmlcopyeditor.h @@ -328,7 +328,7 @@ class MyFrame : public wxFrame // public to allow access from CommandPanel XmlDoc *getActiveDocument(); void newDocument ( const wxString& s, const wxString& path = wxEmptyString, bool canSave = false ); - void newDocument ( const std::string& s, const std::string& path = "", bool canSave = false ); + void newDocument ( const std::string& s, const wxString& path = wxEmptyString, bool canSave = false ); void statusProgress ( const wxString& s ); // public to allow InsertPanel access @@ -523,7 +523,7 @@ class MyFrame : public wxFrame bool ignoreEncoding = false, bool isXml = true ); void removeUtf8Bom ( std::string& buffer ); - std::string getAuxPath ( const std::string& fileName ); + wxString getAuxPath ( const wxString& fileName ); wxMenuBar *getMenuBar(); wxToolBar *getToolBar(); diff --git a/src/xmlctrl.cpp b/src/xmlctrl.cpp index f9d6b89..21f45c6 100755 --- a/src/xmlctrl.cpp +++ b/src/xmlctrl.cpp @@ -55,8 +55,8 @@ XmlCtrl::XmlCtrl ( wxWindowID id, const char *buffer, // could be NULL size_t bufferLen, - const std::string& basePathParameter, - const std::string& auxPathParameter, + const wxString& basePathParameter, + const wxString& auxPathParameter, const wxPoint& position, const wxSize& size, long style @@ -1954,7 +1954,7 @@ bool XmlCtrl::backgroundValidate() return backgroundValidate ( bufferUtf8.c_str(), - basePath.c_str(), + basePath.mb_str(), bufferUtf8.size() ); } diff --git a/src/xmlctrl.h b/src/xmlctrl.h index 22a3626..3b67645 100755 --- a/src/xmlctrl.h +++ b/src/xmlctrl.h @@ -102,8 +102,8 @@ class XmlCtrl: public wxStyledTextCtrl wxWindowID id = wxID_ANY, const char *buffer = NULL, size_t bufferLen = 0, - const std::string& basePath = "", - const std::string& auxPath = "", + const wxString& basePath = wxEmptyString, + const wxString& auxPath = wxEmptyString, const wxPoint &position = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0 ); @@ -161,7 +161,7 @@ class XmlCtrl: public wxStyledTextCtrl std::map > elementMap; std::set entitySet; std::map elementStructureMap; - std::string basePath, auxPath; + wxString basePath, auxPath; XmlCtrlProperties properties; wxString getLastAttributeName ( int pos ); int getAttributeStartPos ( int pos ); diff --git a/src/xmldoc.cpp b/src/xmldoc.cpp index 13d94ba..0414ced 100755 --- a/src/xmldoc.cpp +++ b/src/xmldoc.cpp @@ -30,8 +30,8 @@ XmlDoc::XmlDoc ( //const std::string& buffer, const char *buffer, size_t bufferLen, - const std::string& basePath, - const std::string& auxPath, + const wxString& basePath, + const wxString& auxPath, const wxPoint &position, const wxSize& size, long style ) diff --git a/src/xmldoc.h b/src/xmldoc.h index d0a9bae..c936cdf 100755 --- a/src/xmldoc.h +++ b/src/xmldoc.h @@ -38,8 +38,8 @@ class XmlDoc : public XmlCtrl //const std::string& buffer = DEFAULT_XML_DECLARATION_UTF8, const char *buffer = NULL, size_t bufferLen = 0, - const std::string& basePath = "", - const std::string& auxPath = "", + const wxString& basePath = wxEmptyString, + const wxString& auxPath = wxEmptyString, const wxPoint& position = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0 ); diff --git a/src/xmlpromptgenerator.cpp b/src/xmlpromptgenerator.cpp index 16a0bef..8b19c09 100755 --- a/src/xmlpromptgenerator.cpp +++ b/src/xmlpromptgenerator.cpp @@ -44,8 +44,8 @@ using namespace xercesc; XmlPromptGenerator::XmlPromptGenerator ( - const std::string& basePath, - const std::string& auxPath ) : d ( new PromptGeneratorData() ) + const wxString& basePath, + const wxString& auxPath ) : d ( new PromptGeneratorData() ) { XML_SetUserData ( p, d.get() ); d->p = p; @@ -62,7 +62,7 @@ XmlPromptGenerator::XmlPromptGenerator ( XML_SetEntityDeclHandler ( p, entitydeclhandler ); XML_SetExternalEntityRefHandlerArg ( p, d.get() ); XML_SetExternalEntityRefHandler ( p, externalentityrefhandler ); - XML_SetBase ( p, basePath.c_str() ); + XML_SetBase ( p, d->basePath.utf8_str() ); if ( !auxPath.empty() ) XML_UseForeignDTD ( p, true ); @@ -303,17 +303,17 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( // auxPath req'd? if ( !systemId && !publicId ) { - ReadFile::run ( d->auxPath, buffer ); + ReadFile::run ( ( const char * ) d->auxPath.mb_str(), buffer ); if ( buffer.empty() ) { return XML_STATUS_ERROR; } - std::string encoding = XmlEncodingHandler::get ( buffer ); - XML_Parser dtdParser = XML_ExternalEntityParserCreate ( d->p, context, encoding.c_str() ); + d->encoding = XmlEncodingHandler::get ( buffer ); + XML_Parser dtdParser = XML_ExternalEntityParserCreate ( d->p, context, d->encoding.c_str() ); if ( !dtdParser ) return XML_STATUS_ERROR; - XML_SetBase ( dtdParser, d->auxPath.c_str() ); + XML_SetBase ( dtdParser, d->auxPath.utf8_str() ); ret = XML_Parse ( dtdParser, buffer.c_str(), buffer.size(), true ); XML_ParserFree ( dtdParser ); return ret; @@ -395,13 +395,13 @@ void XmlPromptGenerator::handleSchema ( return; // first check for XML Schema association const char **schemaAttr = ( const char ** ) attr; // now redundant; could use attr - std::string path; + wxString path; for ( ; *schemaAttr; schemaAttr += 2 ) { // no namespace if ( !strcmp ( *schemaAttr, "xsi:noNamespaceSchemaLocation" ) ) { - path = * ( schemaAttr + 1 ); + path = wxString ( schemaAttr[1], wxConvUTF8 ); break; } // with namespace -- check if this works @@ -412,7 +412,7 @@ void XmlPromptGenerator::handleSchema ( searchIterator++; if ( *searchIterator ) { - path = searchIterator + 1; + path = wxString ( searchIterator + 1, wxConvUTF8 ); break; } } @@ -422,16 +422,16 @@ void XmlPromptGenerator::handleSchema ( { return; } - - std::string schemaPath = PathResolver::run ( path, ( d->auxPath.empty() ) ? d->basePath : d->auxPath); + + wxString schemaPath = PathResolver::run ( path, ( d->auxPath.empty() ) ? d->basePath : d->auxPath); std::auto_ptr parser ( new XercesDOMParser() ); parser->setDoNamespaces ( true ); parser->setDoSchema ( true ); parser->setValidationSchemaFullChecking ( true ); - Grammar *rootGrammar = parser->loadGrammar ( schemaPath.c_str(), Grammar::SchemaGrammarType ); + Grammar *rootGrammar = parser->loadGrammar ( schemaPath.mb_str(), Grammar::SchemaGrammarType ); if ( !rootGrammar ) { return; diff --git a/src/xmlpromptgenerator.h b/src/xmlpromptgenerator.h index ebbaa19..ad56349 100755 --- a/src/xmlpromptgenerator.h +++ b/src/xmlpromptgenerator.h @@ -38,7 +38,8 @@ struct PromptGeneratorData : public ParserData std::map > requiredAttributeMap; std::map elementStructureMap; std::set entitySet; - std::string basePath, auxPath, rootElement; + wxString basePath, auxPath; + std::string encoding, rootElement; bool isRootElement, grammarFound; unsigned attributeValueCutoff; XML_Parser p; @@ -51,8 +52,8 @@ class XmlPromptGenerator : public WrapExpat { public: XmlPromptGenerator ( - const std::string& basePath = "", - const std::string& auxPath = "" ); + const wxString& basePath = wxEmptyString, + const wxString& auxPath = wxEmptyString ); virtual ~XmlPromptGenerator(); void getAttributeMap ( std::map > >