196de5490SAndrew Rist /**************************************************************
2cf24b926SMechtilde  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cf24b926SMechtilde  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cf24b926SMechtilde  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
19cf24b926SMechtilde  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25b63233d8Sdamjan #include "precompiled_dbmm.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "dbmm_module.hxx"
28cdf0e10cSrcweir #include "dbmm_global.hrc"
29cdf0e10cSrcweir #include "migrationerror.hxx"
30cdf0e10cSrcweir #include "migrationlog.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /** === begin UNO includes === **/
33cdf0e10cSrcweir /** === end UNO includes === **/
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <comphelper/anytostring.hxx>
36cdf0e10cSrcweir #include <comphelper/string.hxx>
37cdf0e10cSrcweir #include <tools/string.hxx>
38cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <vector>
41cdf0e10cSrcweir #include <map>
42cdf0e10cSrcweir #include <list>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //........................................................................
45cdf0e10cSrcweir namespace dbmm
46cdf0e10cSrcweir {
47cdf0e10cSrcweir //........................................................................
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	/** === begin UNO using === **/
50cdf0e10cSrcweir 	/** === end UNO using === **/
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	//====================================================================
53cdf0e10cSrcweir 	//= LibraryEntry
54cdf0e10cSrcweir 	//====================================================================
55cdf0e10cSrcweir     struct LibraryEntry
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         ScriptType      eType;
58cdf0e10cSrcweir         ::rtl::OUString sOldName;
59cdf0e10cSrcweir         ::rtl::OUString sNewName;
60cdf0e10cSrcweir 
LibraryEntrydbmm::LibraryEntry61cdf0e10cSrcweir         LibraryEntry()
62cdf0e10cSrcweir             :eType( eBasic )
63cdf0e10cSrcweir             ,sOldName()
64cdf0e10cSrcweir             ,sNewName()
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir 
LibraryEntrydbmm::LibraryEntry68cdf0e10cSrcweir         LibraryEntry( const ScriptType& _eType, const ::rtl::OUString& _rOldName, const ::rtl::OUString& _rNewName )
69cdf0e10cSrcweir             :eType( _eType )
70cdf0e10cSrcweir             ,sOldName( _rOldName )
71cdf0e10cSrcweir             ,sNewName( _rNewName )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir     };
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	//====================================================================
77cdf0e10cSrcweir 	//= DocumentEntry
78cdf0e10cSrcweir 	//====================================================================
79cdf0e10cSrcweir     struct DocumentEntry
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         SubDocumentType                 eType;
82cdf0e10cSrcweir         ::rtl::OUString                 sName;
83cdf0e10cSrcweir         ::std::vector< LibraryEntry >   aMovedLibraries;
84cdf0e10cSrcweir 
DocumentEntrydbmm::DocumentEntry85cdf0e10cSrcweir         DocumentEntry()
86cdf0e10cSrcweir             :eType( eForm )
87cdf0e10cSrcweir             ,sName()
88cdf0e10cSrcweir             ,aMovedLibraries()
89cdf0e10cSrcweir         {
90cdf0e10cSrcweir         }
91cdf0e10cSrcweir 
DocumentEntrydbmm::DocumentEntry92cdf0e10cSrcweir         DocumentEntry( const SubDocumentType _eType, const ::rtl::OUString& _rName )
93cdf0e10cSrcweir             :eType( _eType )
94cdf0e10cSrcweir             ,sName( _rName )
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir     };
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	//====================================================================
100cdf0e10cSrcweir 	//= DocumentLogs
101cdf0e10cSrcweir 	//====================================================================
102cdf0e10cSrcweir     typedef ::std::map< DocumentID, DocumentEntry > DocumentLogs;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	//====================================================================
105cdf0e10cSrcweir 	//= ErrorLog
106cdf0e10cSrcweir 	//====================================================================
107cdf0e10cSrcweir     typedef ::std::list< MigrationError >   ErrorLog;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	//====================================================================
110cdf0e10cSrcweir 	//= MigrationLog_Data
111cdf0e10cSrcweir 	//====================================================================
112cdf0e10cSrcweir     struct MigrationLog_Data
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         ::rtl::OUString sBackupLocation;
115cdf0e10cSrcweir         DocumentLogs    aDocumentLogs;
116cdf0e10cSrcweir         ErrorLog        aFailures;
117cdf0e10cSrcweir         ErrorLog        aWarnings;
118cdf0e10cSrcweir     };
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	//====================================================================
121cdf0e10cSrcweir 	//= MigrationLog
122cdf0e10cSrcweir 	//====================================================================
123cdf0e10cSrcweir 	//--------------------------------------------------------------------
MigrationLog()124cdf0e10cSrcweir     MigrationLog::MigrationLog()
125cdf0e10cSrcweir         :m_pData( new MigrationLog_Data )
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	//--------------------------------------------------------------------
~MigrationLog()130cdf0e10cSrcweir     MigrationLog::~MigrationLog()
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	//--------------------------------------------------------------------
logFailure(const MigrationError & _rError)135cdf0e10cSrcweir     void MigrationLog::logFailure( const MigrationError& _rError )
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         m_pData->aFailures.push_back( _rError );
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	//--------------------------------------------------------------------
logRecoverable(const MigrationError & _rError)141cdf0e10cSrcweir     void MigrationLog::logRecoverable( const MigrationError& _rError )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         m_pData->aWarnings.push_back( _rError );
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	//--------------------------------------------------------------------
hadFailure() const147cdf0e10cSrcweir     bool MigrationLog::hadFailure() const
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         return !m_pData->aFailures.empty();
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	//--------------------------------------------------------------------
backedUpDocument(const::rtl::OUString & _rNewDocumentLocation)153cdf0e10cSrcweir     void MigrationLog::backedUpDocument( const ::rtl::OUString& _rNewDocumentLocation )
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir         m_pData->sBackupLocation = _rNewDocumentLocation;
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	//--------------------------------------------------------------------
startedDocument(const SubDocumentType _eType,const::rtl::OUString & _rName)159cdf0e10cSrcweir     DocumentID MigrationLog::startedDocument( const SubDocumentType _eType, const ::rtl::OUString& _rName )
160cdf0e10cSrcweir     {
161cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
162cdf0e10cSrcweir         bool bAlreadyKnown = false;
163cdf0e10cSrcweir         for (   DocumentLogs::const_iterator doc = m_pData->aDocumentLogs.begin();
164cdf0e10cSrcweir                 doc != m_pData->aDocumentLogs.end() && !bAlreadyKnown;
165cdf0e10cSrcweir                 ++doc
166cdf0e10cSrcweir             )
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             bAlreadyKnown = ( doc->second.eType == _eType ) && ( doc->second.sName == _rName );
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir         OSL_ENSURE( !bAlreadyKnown, "MigrationLog::startedDocument: document is already known!" );
171cdf0e10cSrcweir #endif
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         DocumentID nID = (DocumentID)( m_pData->aDocumentLogs.size() + 1 );
174cdf0e10cSrcweir         while ( m_pData->aDocumentLogs.find( nID ) != m_pData->aDocumentLogs.end() )
175cdf0e10cSrcweir             ++nID;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         m_pData->aDocumentLogs[ nID ] = DocumentEntry( _eType, _rName );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         return nID;
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	//--------------------------------------------------------------------
movedLibrary(const DocumentID _nDocID,const ScriptType _eScriptType,const::rtl::OUString & _rOriginalLibName,const::rtl::OUString & _rNewLibName)183cdf0e10cSrcweir     void MigrationLog::movedLibrary( const DocumentID _nDocID, const ScriptType _eScriptType,
184cdf0e10cSrcweir             const ::rtl::OUString& _rOriginalLibName, const ::rtl::OUString& _rNewLibName )
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         OSL_ENSURE( m_pData->aDocumentLogs.find( _nDocID ) != m_pData->aDocumentLogs.end(),
187cdf0e10cSrcweir             "MigrationLog::movedLibrary: document is not known!" );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         DocumentEntry& rDocEntry = m_pData->aDocumentLogs[ _nDocID ];
190cdf0e10cSrcweir         rDocEntry.aMovedLibraries.push_back( LibraryEntry( _eScriptType, _rOriginalLibName, _rNewLibName ) );
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	//--------------------------------------------------------------------
finishedDocument(const DocumentID _nDocID)194cdf0e10cSrcweir     void MigrationLog::finishedDocument( const DocumentID _nDocID )
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         OSL_ENSURE( m_pData->aDocumentLogs.find( _nDocID ) != m_pData->aDocumentLogs.end(),
197cdf0e10cSrcweir             "MigrationLog::finishedDocument: document is not known!" );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         DocumentEntry& rDocEntry = m_pData->aDocumentLogs[ _nDocID ];
200cdf0e10cSrcweir         (void)rDocEntry;
201cdf0e10cSrcweir         // nothing to do here
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	//--------------------------------------------------------------------
getNewLibraryName(DocumentID _nDocID,ScriptType _eScriptType,const::rtl::OUString & _rOriginalLibName) const205cdf0e10cSrcweir     const ::rtl::OUString& MigrationLog::getNewLibraryName( DocumentID _nDocID, ScriptType _eScriptType,
206cdf0e10cSrcweir         const ::rtl::OUString& _rOriginalLibName ) const
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         static ::rtl::OUString s_sEmptyString;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         DocumentLogs::const_iterator docPos = m_pData->aDocumentLogs.find( _nDocID );
211cdf0e10cSrcweir         if ( docPos == m_pData->aDocumentLogs.end() )
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             OSL_ENSURE( false, "MigrationLog::getNewLibraryName: document is not known!" );
214cdf0e10cSrcweir             return s_sEmptyString;
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         const DocumentEntry& rDocEntry( docPos->second );
218cdf0e10cSrcweir         for (   ::std::vector< LibraryEntry >::const_iterator lib = rDocEntry.aMovedLibraries.begin();
219cdf0e10cSrcweir                 lib != rDocEntry.aMovedLibraries.end();
220cdf0e10cSrcweir                 ++lib
221cdf0e10cSrcweir             )
222cdf0e10cSrcweir         {
223cdf0e10cSrcweir             if  (   ( _eScriptType == lib->eType )
224cdf0e10cSrcweir                 &&  ( _rOriginalLibName == lib->sOldName )
225cdf0e10cSrcweir                 )
226cdf0e10cSrcweir                 return lib->sNewName;
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         OSL_ENSURE( false, "MigrationLog::getNewLibraryName: doc is known, but library isn't!" );
230cdf0e10cSrcweir         return s_sEmptyString;
231cdf0e10cSrcweir     }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	//--------------------------------------------------------------------
234cdf0e10cSrcweir     namespace
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir 	    //----------------------------------------------------------------
lcl_appendErrorDescription(::rtl::OUStringBuffer & _inout_rBuffer,const MigrationError & _rError)237cdf0e10cSrcweir         static void lcl_appendErrorDescription( ::rtl::OUStringBuffer& _inout_rBuffer, const MigrationError& _rError )
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             const sal_Char* pAsciiErrorDescription( NULL );
240cdf0e10cSrcweir             ::std::vector< const sal_Char* > aAsciiParameterNames;
241cdf0e10cSrcweir             switch ( _rError.eType )
242cdf0e10cSrcweir             {
243cdf0e10cSrcweir             case ERR_OPENING_SUB_DOCUMENT_FAILED:
244cdf0e10cSrcweir                 pAsciiErrorDescription = "opening '#doc#' failed";
245cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
246cdf0e10cSrcweir                 break;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             case ERR_CLOSING_SUB_DOCUMENT_FAILED:
249cdf0e10cSrcweir                 pAsciiErrorDescription = "closing '#doc#' failed";
250cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
251cdf0e10cSrcweir                 break;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir             case ERR_STORAGE_COMMIT_FAILED:
254cdf0e10cSrcweir                 pAsciiErrorDescription = "committing the changes for document '#doc#' failed";
255cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
256cdf0e10cSrcweir                 break;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             case ERR_STORING_DATABASEDOC_FAILED:
259cdf0e10cSrcweir                 pAsciiErrorDescription = "storing the database document failed";
260cdf0e10cSrcweir                 break;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir             case ERR_COLLECTING_DOCUMENTS_FAILED:
263cdf0e10cSrcweir                 pAsciiErrorDescription = "collecting the forms/reports of the database document failed";
264cdf0e10cSrcweir                 break;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir             case ERR_UNEXPECTED_LIBSTORAGE_ELEMENT:
267cdf0e10cSrcweir                 pAsciiErrorDescription = "unexpected #lib# storage element in document '#doc#', named '#element#'";
268cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
269cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#libstore#" );
270cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#element#" );
271cdf0e10cSrcweir                 break;
272cdf0e10cSrcweir 
273cdf0e10cSrcweir             case ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED:
274cdf0e10cSrcweir                 pAsciiErrorDescription = "creating the database document's storage for #scripttype# scripts failed";
275cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#scripttype#" );
276cdf0e10cSrcweir                 break;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir             case ERR_COMMITTING_SCRIPT_STORAGES_FAILED:
279cdf0e10cSrcweir                 pAsciiErrorDescription = "saving the #scripttype# scripts for document '#doc#' failed";
280cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#scripttype#" );
281cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
282cdf0e10cSrcweir                 break;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir             case ERR_GENERAL_SCRIPT_MIGRATION_FAILURE:
285cdf0e10cSrcweir                 pAsciiErrorDescription = "general error while migrating #scripttype# scripts of document '#doc#'";
286cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#scripttype#" );
287cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
288cdf0e10cSrcweir                 break;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir             case ERR_GENERAL_MACRO_MIGRATION_FAILURE:
291cdf0e10cSrcweir                 pAsciiErrorDescription = "general error during macro migration of document '#doc#'";
292cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
293cdf0e10cSrcweir                 break;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir             case ERR_UNKNOWN_SCRIPT_TYPE:
296cdf0e10cSrcweir                 pAsciiErrorDescription = "unknown script type: #type#";
297cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#type#" );
298cdf0e10cSrcweir                 break;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir             case ERR_UNKNOWN_SCRIPT_LANGUAGE:
301cdf0e10cSrcweir                 pAsciiErrorDescription = "unknown script language: #lang#";
302cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#lang#" );
303cdf0e10cSrcweir                 break;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir             case ERR_UNKNOWN_SCRIPT_NAME_FORMAT:
306cdf0e10cSrcweir                 pAsciiErrorDescription = "unknown script name format: #script#";
307cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#script#" );
308cdf0e10cSrcweir                 break;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir             case ERR_SCRIPT_TRANSLATION_FAILURE:
311cdf0e10cSrcweir                 pAsciiErrorDescription = "analyzing/translating the script URL failed; script type: #type#; script: #code#";
312cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#type#" );
313cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#code#" );
314cdf0e10cSrcweir                 break;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir             case ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT:
317cdf0e10cSrcweir                 pAsciiErrorDescription = "invalid script descriptor format";
318cdf0e10cSrcweir                 break;
319cdf0e10cSrcweir 
320cdf0e10cSrcweir             case ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED:
321cdf0e10cSrcweir                 pAsciiErrorDescription = "adjusting events for document '#doc#' failed";
322cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
323cdf0e10cSrcweir                 break;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir             case ERR_ADJUSTING_DIALOG_EVENTS_FAILED:
326cdf0e10cSrcweir                 pAsciiErrorDescription = "adjusting events for dialog #lib#.#dlg# in document '#doc#' failed";
327cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
328cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#lib#" );
329cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#dlg#" );
330cdf0e10cSrcweir                 break;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir             case ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED:
333cdf0e10cSrcweir                 pAsciiErrorDescription = "adjusting form component events for '#doc#' failed";
334cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
335cdf0e10cSrcweir                 break;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir             case ERR_BIND_SCRIPT_STORAGE_FAILED:
338cdf0e10cSrcweir                 pAsciiErrorDescription = "binding to the script storage failed for document '#doc#'";
339cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
340cdf0e10cSrcweir                 break;
341cdf0e10cSrcweir 
342cdf0e10cSrcweir             case ERR_REMOVE_SCRIPTS_STORAGE_FAILED:
343cdf0e10cSrcweir                 pAsciiErrorDescription = "removing a scripts storage failed for document '#doc#'";
344cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
345cdf0e10cSrcweir                 break;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             case ERR_DOCUMENT_BACKUP_FAILED:
348cdf0e10cSrcweir                 pAsciiErrorDescription = "backing up the document to #location# failed";
349cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#location#" );
350cdf0e10cSrcweir                 break;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir             case ERR_UNKNOWN_SCRIPT_FOLDER:
353cdf0e10cSrcweir                 pAsciiErrorDescription = "unknown script folder '#name#' in document '#doc#'";
354cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
355cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#name#" );
356cdf0e10cSrcweir                 break;
357cdf0e10cSrcweir 
358cdf0e10cSrcweir             case ERR_EXAMINING_SCRIPTS_FOLDER_FAILED:
359cdf0e10cSrcweir                 pAsciiErrorDescription = "examining the 'Scripts' folder failed for document '#doc#'";
360cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
361cdf0e10cSrcweir                 break;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir             case ERR_PASSWORD_VERIFICATION_FAILED:
364cdf0e10cSrcweir                 pAsciiErrorDescription = "password verification failed for document '#doc#', #libtype# library '#name#'";
365cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
366cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#libtype#" );
367cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#name#" );
368cdf0e10cSrcweir                 break;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir             case ERR_NEW_STYLE_REPORT:
371*5973beebSMechtilde                 pAsciiErrorDescription = "#doc# could not be processed, since you don't have the Report Builder extension installed.";
372cdf0e10cSrcweir                 aAsciiParameterNames.push_back( "#doc#" );
373cdf0e10cSrcweir                 break;
374cdf0e10cSrcweir 
375cdf0e10cSrcweir                 // do *not* add a default case here: Without a default, some compilers will warn you when
376cdf0e10cSrcweir                 // you miss a newly-introduced enum value here
377cdf0e10cSrcweir             }
378cdf0e10cSrcweir             OSL_ENSURE( pAsciiErrorDescription, "lcl_appendErrorDescription: no error message!" );
379cdf0e10cSrcweir             if ( pAsciiErrorDescription )
380cdf0e10cSrcweir             {
381cdf0e10cSrcweir                 ::rtl::OUString sSubstituted( ::rtl::OUString::createFromAscii( pAsciiErrorDescription ) );
382cdf0e10cSrcweir                 OSL_ENSURE( aAsciiParameterNames.size() == _rError.aErrorDetails.size(),
383cdf0e10cSrcweir                     "lcl_appendErrorDescription: unexpected number of error message parameters!" );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir                 for ( size_t i=0; i < ::std::min( aAsciiParameterNames.size(), _rError.aErrorDetails.size() ); ++i )
386cdf0e10cSrcweir                 {
387cdf0e10cSrcweir                     ::comphelper::string::searchAndReplaceAsciiI( sSubstituted, aAsciiParameterNames[i],
388cdf0e10cSrcweir                         _rError.aErrorDetails[i] );
389cdf0e10cSrcweir                 }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                 _inout_rBuffer.append( sSubstituted );
392cdf0e10cSrcweir             }
393cdf0e10cSrcweir         }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         //----------------------------------------------------------------
lcl_describeErrors(::rtl::OUStringBuffer & _rBuffer,const ErrorLog & _rErrors,const sal_uInt16 _nHeadingResId)396cdf0e10cSrcweir         void lcl_describeErrors( ::rtl::OUStringBuffer& _rBuffer, const ErrorLog& _rErrors, const sal_uInt16 _nHeadingResId )
397cdf0e10cSrcweir         {
398cdf0e10cSrcweir             _rBuffer.appendAscii( "=== " );
399cdf0e10cSrcweir             _rBuffer.append     ( String( MacroMigrationResId( _nHeadingResId ) ) );
400cdf0e10cSrcweir             _rBuffer.appendAscii( " ===\n" );
401cdf0e10cSrcweir 
402cdf0e10cSrcweir             String sException( MacroMigrationResId( STR_EXCEPTION ) );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir             for (   ErrorLog::const_iterator error = _rErrors.begin();
405cdf0e10cSrcweir                     error != _rErrors.end();
406cdf0e10cSrcweir                     ++error
407cdf0e10cSrcweir                 )
408cdf0e10cSrcweir             {
409cdf0e10cSrcweir                 _rBuffer.append( sal_Unicode( '-' ) );
410cdf0e10cSrcweir                 _rBuffer.append( sal_Unicode( ' ' ) );
411cdf0e10cSrcweir                 lcl_appendErrorDescription( _rBuffer, *error );
412cdf0e10cSrcweir                 _rBuffer.append( sal_Unicode( '\n' ) );
413cdf0e10cSrcweir 
414cdf0e10cSrcweir                 if ( !error->aCaughtException.hasValue() )
415cdf0e10cSrcweir                     continue;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir                 _rBuffer.append( sException );
418cdf0e10cSrcweir                 _rBuffer.append( ::comphelper::anyToString( error->aCaughtException ) );
419cdf0e10cSrcweir                 _rBuffer.append( sal_Unicode( '\n' ) );
420cdf0e10cSrcweir                 _rBuffer.append( sal_Unicode( '\n' ) );
421cdf0e10cSrcweir             }
422cdf0e10cSrcweir         }
423cdf0e10cSrcweir     }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	//--------------------------------------------------------------------
movedAnyLibrary(const DocumentID _nDocID)426cdf0e10cSrcweir     bool MigrationLog::movedAnyLibrary( const DocumentID _nDocID )
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir         DocumentLogs::const_iterator docPos = m_pData->aDocumentLogs.find( _nDocID );
429cdf0e10cSrcweir         if ( docPos == m_pData->aDocumentLogs.end() )
430cdf0e10cSrcweir         {
431cdf0e10cSrcweir             OSL_ENSURE( false, "MigrationLog::movedAnyLibrary: document is not known!" );
432cdf0e10cSrcweir             return false;
433cdf0e10cSrcweir         }
434cdf0e10cSrcweir         return !docPos->second.aMovedLibraries.empty();
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	//--------------------------------------------------------------------
getCompleteLog() const438cdf0e10cSrcweir     ::rtl::OUString MigrationLog::getCompleteLog() const
439cdf0e10cSrcweir     {
440cdf0e10cSrcweir         ::rtl::OUStringBuffer aBuffer;
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         if ( m_pData->sBackupLocation.getLength() )
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir             String sBackedUp( MacroMigrationResId( STR_SAVED_COPY_TO ) );
445cdf0e10cSrcweir             sBackedUp.SearchAndReplaceAllAscii( "$location$", m_pData->sBackupLocation );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir             aBuffer.appendAscii( "=== " );
448cdf0e10cSrcweir             aBuffer.append     ( String( MacroMigrationResId( STR_DATABASE_DOCUMENT ) ) );
449cdf0e10cSrcweir             aBuffer.appendAscii( " ===\n" );
450cdf0e10cSrcweir             aBuffer.append     ( sBackedUp );
451cdf0e10cSrcweir             aBuffer.appendAscii( "\n\n" );
452cdf0e10cSrcweir         }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir         if ( !m_pData->aFailures.empty() )
455cdf0e10cSrcweir         {
456cdf0e10cSrcweir             lcl_describeErrors( aBuffer, m_pData->aFailures
457cdf0e10cSrcweir                 , STR_ERRORS );
458cdf0e10cSrcweir         }
459cdf0e10cSrcweir         else
460cdf0e10cSrcweir         {
461cdf0e10cSrcweir             String sMovedLibTemplate( MacroMigrationResId( STR_MOVED_LIBRARY ) );
462cdf0e10cSrcweir 
463cdf0e10cSrcweir             for (   DocumentLogs::const_iterator doc = m_pData->aDocumentLogs.begin();
464cdf0e10cSrcweir                     doc != m_pData->aDocumentLogs.end();
465cdf0e10cSrcweir                     ++doc
466cdf0e10cSrcweir                 )
467cdf0e10cSrcweir             {
468cdf0e10cSrcweir                 const DocumentEntry& rDoc( doc->second );
469cdf0e10cSrcweir 
470cdf0e10cSrcweir                 if ( rDoc.aMovedLibraries.empty() )
471cdf0e10cSrcweir                     continue;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir                 String sDocTitle( MacroMigrationResId( rDoc.eType == eForm ? STR_FORM : STR_REPORT ) );
474cdf0e10cSrcweir                 sDocTitle.SearchAndReplaceAllAscii( "$name$", rDoc.sName );
475cdf0e10cSrcweir 
476cdf0e10cSrcweir                 aBuffer.appendAscii( "=== " );
477cdf0e10cSrcweir                 aBuffer.append     ( sDocTitle );
478cdf0e10cSrcweir                 aBuffer.appendAscii( " ===\n" );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                 for (   ::std::vector< LibraryEntry >::const_iterator lib = rDoc.aMovedLibraries.begin();
481cdf0e10cSrcweir                         lib != rDoc.aMovedLibraries.end();
482cdf0e10cSrcweir                         ++lib
483cdf0e10cSrcweir                     )
484cdf0e10cSrcweir                 {
485cdf0e10cSrcweir                     String sMovedLib( sMovedLibTemplate );
486cdf0e10cSrcweir                     sMovedLib.SearchAndReplaceAllAscii( "$type$", getScriptTypeDisplayName( lib->eType ) );
487cdf0e10cSrcweir                     sMovedLib.SearchAndReplaceAllAscii( "$old$", lib->sOldName );
488cdf0e10cSrcweir                     sMovedLib.SearchAndReplaceAllAscii( "$new$", lib->sNewName );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir                     aBuffer.append( sMovedLib );
491cdf0e10cSrcweir                     aBuffer.append( sal_Unicode( '\n' ) );
492cdf0e10cSrcweir                 }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir                 aBuffer.append( sal_Unicode( '\n' ) );
495cdf0e10cSrcweir             }
496cdf0e10cSrcweir         }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir         if ( !m_pData->aWarnings.empty() )
499cdf0e10cSrcweir         {
500cdf0e10cSrcweir             lcl_describeErrors( aBuffer, m_pData->aWarnings, STR_WARNINGS );
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         return aBuffer.makeStringAndClear();
504cdf0e10cSrcweir     }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir //........................................................................
507cdf0e10cSrcweir } // namespace dbmm
508cdf0e10cSrcweir //........................................................................
509