Tag: cws_dev300_odbmacros3 User: fs Date: 2008-05-19 20:20:58+0000 Modified: dba/dbaccess/source/ext/macromigration/migrationlog.cxx
Log: parametrize the error messages for better readability File Changes: Directory: /dba/dbaccess/source/ext/macromigration/ =================================================== File [changed]: migrationlog.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/migrationlog.cxx?r1=1.4.2.4&r2=1.4.2.5 Delta lines: +138 -45 ---------------------- --- migrationlog.cxx 2008-05-11 21:12:22+0000 1.4.2.4 +++ migrationlog.cxx 2008-05-19 20:20:55+0000 1.4.2.5 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: migrationlog.cxx,v $ - * $Revision: 1.4.2.4 $ + * $Revision: 1.4.2.5 $ * * This file is part of OpenOffice.org. * @@ -40,6 +40,7 @@ /** === end UNO includes === **/ #include <comphelper/anytostring.hxx> +#include <comphelper/string.hxx> #include <tools/string.hxx> #include <rtl/ustrbuf.hxx> @@ -240,41 +241,150 @@ namespace { //---------------------------------------------------------------- - static void lcl_appendErrorDescription( ::rtl::OUStringBuffer& _inout_rBuffer, const MigrationErrorType _eErrorType ) + static void lcl_appendErrorDescription( ::rtl::OUStringBuffer& _inout_rBuffer, const MigrationError& _rError ) { const sal_Char* pAsciiErrorDescription( NULL ); - switch ( _eErrorType ) + ::std::vector< const sal_Char* > aAsciiParameterNames; + switch ( _rError.eType ) { - case ERR_OPENING_SUB_DOCUMENT_FAILED: pAsciiErrorDescription = "opening a sub document failed"; break; - case ERR_CLOSING_SUB_DOCUMENT_FAILED: pAsciiErrorDescription = "closing a sub document failed"; break; - case ERR_STORAGE_COMMIT_FAILED: pAsciiErrorDescription = "committing a storage failed"; break; - case ERR_STORING_DATABASEDOC_FAILED: pAsciiErrorDescription = "storing the database document failed"; break; - case ERR_COLLECTING_DOCUMENTS_FAILED: pAsciiErrorDescription = "collecting the forms/reports of the database document failed"; break; - case ERR_UNEXPECTED_LIBSTORAGE_ELEMENT: pAsciiErrorDescription = "unexpected library storage element"; break; - case ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED: pAsciiErrorDescription = "creating the database document's scripts storage failed"; break; - case ERR_COMMITTING_SCRIPT_STORAGES_FAILED: pAsciiErrorDescription = "committing the script storages failed"; break; - case ERR_GENERAL_SCRIPT_MIGRATION_FAILURE: pAsciiErrorDescription = "general error during script migration"; break; - case ERR_GENERAL_MACRO_MIGRATION_FAILURE: pAsciiErrorDescription = "general error during macro migration"; break; - case ERR_UNKNOWN_SCRIPT_TYPE: pAsciiErrorDescription = "unknown script type"; break; - case ERR_UNKNOWN_SCRIPT_LANGUAGE: pAsciiErrorDescription = "unknown script language"; break; - case ERR_UNKNOWN_SCRIPT_NAME_FORMAT: pAsciiErrorDescription = "unknown script name format"; break; - case ERR_SCRIPT_TRANSLATION_FAILURE: pAsciiErrorDescription = "analyzing/translating the script URL failed"; break; - case ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT: pAsciiErrorDescription = "invalid script descriptor format"; break; - case ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED: pAsciiErrorDescription = "adjusting document events failed"; break; - case ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED: pAsciiErrorDescription = "adjusting form component events failed"; break; - case ERR_BIND_SCRIPT_STORAGE_FAILED: pAsciiErrorDescription = "binding to the script storage failed"; break; - case ERR_REMOVE_SCRIPTS_STORAGE_FAILED: pAsciiErrorDescription = "removing a scripts storage failed"; break; - case ERR_DOCUMENT_BACKUP_FAILED: pAsciiErrorDescription = "document backup failed"; break; - case ERR_UNKNOWN_SCRIPT_FOLDER: pAsciiErrorDescription = "unknown script folder"; break; - case ERR_EXAMINING_SCRIPTS_FOLDER_FAILED: pAsciiErrorDescription = "examining the 'Scripts' folder failed"; break; - case ERR_PASSWORD_VERIFICATION_FAILED: pAsciiErrorDescription = "library password verification failed"; break; + case ERR_OPENING_SUB_DOCUMENT_FAILED: + pAsciiErrorDescription = "opening form/report '#name#' failed"; + aAsciiParameterNames.push_back( "#name#" ); + break; + + case ERR_CLOSING_SUB_DOCUMENT_FAILED: + pAsciiErrorDescription = "closing form/report '#name#' failed"; + aAsciiParameterNames.push_back( "#name#" ); + break; + + case ERR_STORAGE_COMMIT_FAILED: + pAsciiErrorDescription = "committing the changes for document '#name#' failed"; + aAsciiParameterNames.push_back( "#name#" ); + break; + + case ERR_STORING_DATABASEDOC_FAILED: + pAsciiErrorDescription = "storing the database document failed"; + break; + + case ERR_COLLECTING_DOCUMENTS_FAILED: + pAsciiErrorDescription = "collecting the forms/reports of the database document failed"; + break; + + case ERR_UNEXPECTED_LIBSTORAGE_ELEMENT: + pAsciiErrorDescription = "unexpected library storage element in storage #libstore#, named #element#"; + aAsciiParameterNames.push_back( "#libstore#" ); + aAsciiParameterNames.push_back( "#element#" ); + break; + + case ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED: + pAsciiErrorDescription = "creating the database document's storage for #scripttype# scripts failed"; + aAsciiParameterNames.push_back( "#scripttype#" ); + break; + + case ERR_COMMITTING_SCRIPT_STORAGES_FAILED: + pAsciiErrorDescription = "saving the #scripttype# scripts for document #doc# failed"; + aAsciiParameterNames.push_back( "#scripttype#" ); + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_GENERAL_SCRIPT_MIGRATION_FAILURE: + pAsciiErrorDescription = "general error during migrationg #scripttype# scripts of document #doc#"; + aAsciiParameterNames.push_back( "#scripttype#" ); + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_GENERAL_MACRO_MIGRATION_FAILURE: + pAsciiErrorDescription = "general error during macro migration of document #doc#"; + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_UNKNOWN_SCRIPT_TYPE: + pAsciiErrorDescription = "unknown script type: #type#"; + aAsciiParameterNames.push_back( "#type#" ); + break; + + case ERR_UNKNOWN_SCRIPT_LANGUAGE: + pAsciiErrorDescription = "unknown script language: #lang#"; + aAsciiParameterNames.push_back( "#lang#" ); + break; + + case ERR_UNKNOWN_SCRIPT_NAME_FORMAT: + pAsciiErrorDescription = "unknown script name format: #script#"; + aAsciiParameterNames.push_back( "#script#" ); + break; + + case ERR_SCRIPT_TRANSLATION_FAILURE: + pAsciiErrorDescription = "analyzing/translating the script URL failed; script type: #type#; script: #code#"; + aAsciiParameterNames.push_back( "#type#" ); + aAsciiParameterNames.push_back( "#code#" ); + break; + + case ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT: + pAsciiErrorDescription = "invalid script descriptor format"; + break; + + case ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED: + pAsciiErrorDescription = "adjusting events for document #doc# failed"; + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED: + pAsciiErrorDescription = "adjusting form component events for #doc# failed"; + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_BIND_SCRIPT_STORAGE_FAILED: + pAsciiErrorDescription = "binding to the script storage failed for document #doc# (mode: #mode#)"; + aAsciiParameterNames.push_back( "#doc#" ); + aAsciiParameterNames.push_back( "#mode#" ); + break; + + case ERR_REMOVE_SCRIPTS_STORAGE_FAILED: + pAsciiErrorDescription = "removing a scripts storage failed for document #doc#"; + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_DOCUMENT_BACKUP_FAILED: + pAsciiErrorDescription = "backuping up the document to #location# failed"; + aAsciiParameterNames.push_back( "#location#" ); + break; + + case ERR_UNKNOWN_SCRIPT_FOLDER: + pAsciiErrorDescription = "unknown script folder #name# in document #doc#"; + aAsciiParameterNames.push_back( "#name#" ); + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_EXAMINING_SCRIPTS_FOLDER_FAILED: + pAsciiErrorDescription = "examining the 'Scripts' folder failed for document #doc# failed"; + aAsciiParameterNames.push_back( "#doc#" ); + break; + + case ERR_PASSWORD_VERIFICATION_FAILED: + pAsciiErrorDescription = "password verification failed for document #doc#, #libtype# library '#name#'"; + aAsciiParameterNames.push_back( "#doc#" ); + aAsciiParameterNames.push_back( "#libtype#" ); + aAsciiParameterNames.push_back( "#name#" ); + break; // do *not* add a default case here: Without a default, some compilers will warn you when // you miss a newly-introduced enum value here } OSL_ENSURE( pAsciiErrorDescription, "lcl_appendErrorDescription: no error message!" ); if ( pAsciiErrorDescription ) - _inout_rBuffer.appendAscii( pAsciiErrorDescription ); + { + ::rtl::OUString sSubstituted( ::rtl::OUString::createFromAscii( pAsciiErrorDescription ) ); + OSL_ENSURE( aAsciiParameterNames.size() == _rError.aErrorDetails.size(), + "lcl_appendErrorDescription: unexpected number of error message parameters!" ); + + for ( size_t i=0; i < ::std::min( aAsciiParameterNames.size(), _rError.aErrorDetails.size() ); ++i ) + { + ::comphelper::string::searchAndReplaceAsciiI( sSubstituted, aAsciiParameterNames[i], + _rError.aErrorDetails[i] ); + } + + _inout_rBuffer.append( sSubstituted ); + } } //---------------------------------------------------------------- @@ -294,25 +404,8 @@ ) { _rBuffer.append( sType ); - lcl_appendErrorDescription( _rBuffer, error->eType ); - _rBuffer.append( sal_Unicode( '\n' ) ); - - if ( !error->aErrorDetails.empty() ) - { - _rBuffer.append( sDetails ); - for ( ::std::vector< ::rtl::OUString >::const_iterator detail = error->aErrorDetails.begin(); - detail != error->aErrorDetails.end(); - ++detail - ) - { - if ( detail != error->aErrorDetails.begin() ) - _rBuffer.append( sal_Unicode( ',' ) ); - - _rBuffer.append( sal_Unicode( ' ' ) ); - _rBuffer.append( *detail ); - } + lcl_appendErrorDescription( _rBuffer, *error ); _rBuffer.append( sal_Unicode( '\n' ) ); - } if ( !error->aCaughtException.hasValue() ) continue; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
