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