xref: /aoo41x/main/sw/source/ui/dbui/dbmgr.cxx (revision 60e513e9)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #if STLPORT_VERSION>=321
27cdf0e10cSrcweir #include <cstdarg>
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <stdio.h>
31cdf0e10cSrcweir #include <unotxdoc.hxx>
32cdf0e10cSrcweir #include <com/sun/star/text/NotePrintMode.hpp>
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sdb/XDocumentDataSource.hpp>
36cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
39cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedExecution.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
43cdf0e10cSrcweir #include <com/sun/star/text/MailMergeEvent.hpp>
44cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
45cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
46cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
47cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
48cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp>
49cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
50cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
51cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
52cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
53cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
54cdf0e10cSrcweir #include <dbconfig.hxx>
55cdf0e10cSrcweir #include <swdbtoolsclient.hxx>
56cdf0e10cSrcweir #include <pagedesc.hxx>
57cdf0e10cSrcweir #include <vcl/lstbox.hxx>
58cdf0e10cSrcweir #include <unotools/tempfile.hxx>
59cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
60cdf0e10cSrcweir #include <svl/urihelper.hxx>
61cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
62cdf0e10cSrcweir #include <svl/svstdarr.hxx>
63cdf0e10cSrcweir #include <svl/zforlist.hxx>
64cdf0e10cSrcweir #include <svl/zformat.hxx>
65cdf0e10cSrcweir #include <svl/stritem.hxx>
66cdf0e10cSrcweir #include <svl/eitem.hxx>
67cdf0e10cSrcweir #include <vcl/oldprintadaptor.hxx>
68cdf0e10cSrcweir #include <sfx2/docfile.hxx>
69cdf0e10cSrcweir #include <sfx2/progress.hxx>
70cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
71cdf0e10cSrcweir #include <svl/mailenum.hxx>
72cdf0e10cSrcweir #include <cmdid.h>
73cdf0e10cSrcweir #include <swmodule.hxx>
74cdf0e10cSrcweir #include <view.hxx>
75cdf0e10cSrcweir #include <docsh.hxx>
76cdf0e10cSrcweir #include <edtwin.hxx>
77cdf0e10cSrcweir #include <wrtsh.hxx>
78cdf0e10cSrcweir #include <fldbas.hxx>
79cdf0e10cSrcweir #include <initui.hxx>
80cdf0e10cSrcweir #include <swundo.hxx>
81cdf0e10cSrcweir #include <flddat.hxx>
82cdf0e10cSrcweir #include <modcfg.hxx>
83cdf0e10cSrcweir #include <shellio.hxx>
84cdf0e10cSrcweir #include <dbui.hxx>
85cdf0e10cSrcweir #include <dbmgr.hxx>
86cdf0e10cSrcweir #include <doc.hxx>
87cdf0e10cSrcweir #include <swwait.hxx>
88cdf0e10cSrcweir #include <swunohelper.hxx>
89cdf0e10cSrcweir #include <dbui.hrc>
90cdf0e10cSrcweir #include <globals.hrc>
91cdf0e10cSrcweir #include <statstr.hrc>
92cdf0e10cSrcweir #include <mmconfigitem.hxx>
93cdf0e10cSrcweir #include <sfx2/request.hxx>
94cdf0e10cSrcweir #include <hintids.hxx>
95cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
96cdf0e10cSrcweir #include <com/sun/star/sdbc/XRowSet.hpp>
97cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
98cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
99cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
100cdf0e10cSrcweir #include <com/sun/star/sdb/XColumn.hpp>
101cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
102cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
103cdf0e10cSrcweir #include <com/sun/star/mail/MailAttachment.hpp>
104cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
105cdf0e10cSrcweir #include <comphelper/types.hxx>
106cdf0e10cSrcweir #include <comphelper/property.hxx>
107cdf0e10cSrcweir #include <mailmergehelper.hxx>
108cdf0e10cSrcweir #include <maildispatcher.hxx>
109cdf0e10cSrcweir #include <svtools/htmlcfg.hxx>
110cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
111cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp>
112cdf0e10cSrcweir #include <editeng/langitem.hxx>
113cdf0e10cSrcweir #include <svl/numuno.hxx>
114cdf0e10cSrcweir 
115cdf0e10cSrcweir #include <unomailmerge.hxx>
116cdf0e10cSrcweir #include <sfx2/event.hxx>
117cdf0e10cSrcweir #include <vcl/msgbox.hxx>
118cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
119cdf0e10cSrcweir #include <vos/mutex.hxx>
120cdf0e10cSrcweir #include <rtl/textenc.h>
121cdf0e10cSrcweir #include <ndindex.hxx>
122cdf0e10cSrcweir #include <pam.hxx>
123cdf0e10cSrcweir #include <swcrsr.hxx>
124cdf0e10cSrcweir #include <swevent.hxx>
125cdf0e10cSrcweir #include <osl/file.hxx>
126cdf0e10cSrcweir #include <swabstdlg.hxx>
127cdf0e10cSrcweir #include <fmthdft.hxx>
128cdf0e10cSrcweir #include <dbui.hrc>
129cdf0e10cSrcweir #include <envelp.hrc>
130cdf0e10cSrcweir #include <memory>
131cdf0e10cSrcweir #include <vector>
132cdf0e10cSrcweir #include <unomid.h>
133cdf0e10cSrcweir #include <section.hxx>
134cdf0e10cSrcweir 
135cdf0e10cSrcweir using namespace ::osl;
136cdf0e10cSrcweir using namespace ::svx;
137cdf0e10cSrcweir using namespace ::com::sun::star;
138cdf0e10cSrcweir using namespace ::com::sun::star::text;
139cdf0e10cSrcweir using namespace ::com::sun::star::uno;
140cdf0e10cSrcweir using namespace ::com::sun::star::container;
141cdf0e10cSrcweir using namespace ::com::sun::star::frame;
142cdf0e10cSrcweir using namespace ::com::sun::star::lang;
143cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
144cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
145cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
146cdf0e10cSrcweir using namespace ::com::sun::star::beans;
147cdf0e10cSrcweir using namespace ::com::sun::star::util;
148cdf0e10cSrcweir using namespace ::com::sun::star::task;
149cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir #define DB_SEP_SPACE  	0
152cdf0e10cSrcweir #define DB_SEP_TAB  	1
153cdf0e10cSrcweir #define DB_SEP_RETURN   2
154cdf0e10cSrcweir #define DB_SEP_NEWLINE  3
155cdf0e10cSrcweir 
156cdf0e10cSrcweir SV_IMPL_PTRARR(SwDSParamArr, SwDSParamPtr);
157cdf0e10cSrcweir const sal_Char cCursor[] = "Cursor";
158cdf0e10cSrcweir const sal_Char cCommand[] = "Command";
159cdf0e10cSrcweir const sal_Char cCommandType[] = "CommandType";
160cdf0e10cSrcweir const sal_Char cDataSourceName[] = "DataSourceName";
161cdf0e10cSrcweir const sal_Char cSelection[] = "Selection";
162cdf0e10cSrcweir const sal_Char cActiveConnection[] = "ActiveConnection";
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // -----------------------------------------------------------------------------
165cdf0e10cSrcweir // Use nameless namespace to avoid to rubbish the global namespace
166cdf0e10cSrcweir // -----------------------------------------------------------------------------
167cdf0e10cSrcweir namespace
168cdf0e10cSrcweir {
169cdf0e10cSrcweir 
170cdf0e10cSrcweir bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<XResultSet>& xResultSet )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir     uno::Reference<XPropertySet> xPrSet(xResultSet, UNO_QUERY);
173cdf0e10cSrcweir     if(xPrSet.is())
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         try
176cdf0e10cSrcweir         {
177cdf0e10cSrcweir             sal_Bool bFinal = sal_False;
178cdf0e10cSrcweir             Any aFinal = xPrSet->getPropertyValue(C2U("IsRowCountFinal"));
179cdf0e10cSrcweir             aFinal >>= bFinal;
180cdf0e10cSrcweir             if(!bFinal)
181cdf0e10cSrcweir             {
182cdf0e10cSrcweir                 xResultSet->last();
183cdf0e10cSrcweir                 xResultSet->first();
184cdf0e10cSrcweir             }
185cdf0e10cSrcweir             Any aCount = xPrSet->getPropertyValue(C2U("RowCount"));
186cdf0e10cSrcweir             if( aCount >>= rCount )
187cdf0e10cSrcweir                 return true;
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir         catch(Exception&)
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir     return false;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir // #122799# copy compatibility options
196cdf0e10cSrcweir void lcl_CopyCompatibilityOptions( SwWrtShell& rSourceShell, SwWrtShell& rTargetShell)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     IDocumentSettingAccess* pIDsa = rSourceShell.getIDocumentSettingAccess();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     rTargetShell.SetParaSpaceMax( pIDsa->get(IDocumentSettingAccess::PARA_SPACE_MAX));
201cdf0e10cSrcweir     rTargetShell.SetParaSpaceMaxAtPages(pIDsa->get(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES));
202cdf0e10cSrcweir     rTargetShell.SetTabCompat( pIDsa->get(IDocumentSettingAccess::TAB_COMPAT));
203cdf0e10cSrcweir     rTargetShell.SetAddExtLeading( pIDsa->get(IDocumentSettingAccess::ADD_EXT_LEADING));
204cdf0e10cSrcweir     rTargetShell.SetUseVirDev( pIDsa->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE));
205cdf0e10cSrcweir     rTargetShell.SetAddParaSpacingToTableCells( pIDsa->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS));
206cdf0e10cSrcweir     rTargetShell.SetUseFormerLineSpacing( pIDsa->get(IDocumentSettingAccess::OLD_LINE_SPACING));
207cdf0e10cSrcweir     rTargetShell.SetUseFormerObjectPositioning( pIDsa->get(IDocumentSettingAccess::USE_FORMER_OBJECT_POS));
208cdf0e10cSrcweir     rTargetShell.SetConsiderWrapOnObjPos( pIDsa->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION));
209cdf0e10cSrcweir     rTargetShell.SetUseFormerTextWrapping( pIDsa->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING));
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir /* -----------------09.12.2002 12:35-----------------
213cdf0e10cSrcweir  *
214cdf0e10cSrcweir  * --------------------------------------------------*/
215cdf0e10cSrcweir 
216cdf0e10cSrcweir class SwConnectionDisposedListener_Impl : public cppu::WeakImplHelper1
217cdf0e10cSrcweir < lang::XEventListener >
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     SwNewDBMgr&     rDBMgr;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
222cdf0e10cSrcweir public:
223cdf0e10cSrcweir     SwConnectionDisposedListener_Impl(SwNewDBMgr& rMgr);
224cdf0e10cSrcweir     ~SwConnectionDisposedListener_Impl();
225cdf0e10cSrcweir 
226cdf0e10cSrcweir };
227cdf0e10cSrcweir // -----------------------------------------------------------------------------
228cdf0e10cSrcweir struct SwNewDBMgr_Impl
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     SwDSParam*          pMergeData;
231cdf0e10cSrcweir     AbstractMailMergeDlg*     pMergeDialog;
232cdf0e10cSrcweir     uno::Reference<lang::XEventListener> xDisposeListener;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     SwNewDBMgr_Impl(SwNewDBMgr& rDBMgr)
235cdf0e10cSrcweir        :pMergeData(0)
236cdf0e10cSrcweir        ,pMergeDialog(0)
237cdf0e10cSrcweir        ,xDisposeListener(new SwConnectionDisposedListener_Impl(rDBMgr))
238cdf0e10cSrcweir         {}
239cdf0e10cSrcweir };
240cdf0e10cSrcweir /*-- 24.10.2003 15:54:18---------------------------------------------------
241cdf0e10cSrcweir 
242cdf0e10cSrcweir   -----------------------------------------------------------------------*/
243cdf0e10cSrcweir void lcl_InitNumberFormatter(SwDSParam& rParam, uno::Reference<XDataSource> xSource)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     uno::Reference<XMultiServiceFactory> xMgr = ::comphelper::getProcessServiceFactory();
246cdf0e10cSrcweir     if( xMgr.is() )
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         uno::Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.util.NumberFormatter" ));
249cdf0e10cSrcweir         rParam.xFormatter = uno::Reference<util::XNumberFormatter>(xInstance, UNO_QUERY) ;
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir     if(!xSource.is())
252cdf0e10cSrcweir         xSource = SwNewDBMgr::getDataSourceAsParent(rParam.xConnection, rParam.sDataSource);
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     uno::Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
255cdf0e10cSrcweir     if(xSourceProps.is())
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
258cdf0e10cSrcweir         if(aFormats.hasValue())
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             uno::Reference<XNumberFormatsSupplier> xSuppl;
261cdf0e10cSrcweir             aFormats >>= xSuppl;
262cdf0e10cSrcweir             if(xSuppl.is())
263cdf0e10cSrcweir             {
264cdf0e10cSrcweir                 uno::Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
265cdf0e10cSrcweir                 Any aNull = xSettings->getPropertyValue(C2U("NullDate"));
266cdf0e10cSrcweir                 aNull >>= rParam.aNullDate;
267cdf0e10cSrcweir 				if(rParam.xFormatter.is())
268cdf0e10cSrcweir 					rParam.xFormatter->attachNumberFormatsSupplier(xSuppl);
269cdf0e10cSrcweir             }
270cdf0e10cSrcweir         }
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir }
273cdf0e10cSrcweir /* -----------------------------17.07.00 17:04--------------------------------
274cdf0e10cSrcweir 
275cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
276cdf0e10cSrcweir sal_Bool lcl_MoveAbsolute(SwDSParam* pParam, long nAbsPos)
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
279cdf0e10cSrcweir 	try
280cdf0e10cSrcweir 	{
281cdf0e10cSrcweir 		if(pParam->bScrollable)
282cdf0e10cSrcweir 		{
283cdf0e10cSrcweir 			bRet = pParam->xResultSet->absolute( nAbsPos );
284cdf0e10cSrcweir 		}
285cdf0e10cSrcweir 		else
286cdf0e10cSrcweir 		{
287cdf0e10cSrcweir             DBG_ERROR("no absolute positioning available");
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir 	}
290cdf0e10cSrcweir 	catch(Exception aExcept)
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 	}
293cdf0e10cSrcweir 	return bRet;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir /* -----------------------------17.07.00 17:23--------------------------------
296cdf0e10cSrcweir 
297cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
298cdf0e10cSrcweir sal_Bool lcl_GetColumnCnt(SwDSParam* pParam,
299cdf0e10cSrcweir 	const String& rColumnName, long nLanguage, String& rResult, double* pNumber)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     uno::Reference< XColumnsSupplier > xColsSupp( pParam->xResultSet, UNO_QUERY );
302cdf0e10cSrcweir     uno::Reference<XNameAccess> xCols;
303cdf0e10cSrcweir     try
304cdf0e10cSrcweir     {
305cdf0e10cSrcweir         xCols = xColsSupp->getColumns();
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir     catch( lang::DisposedException& )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir     }
310cdf0e10cSrcweir 	if(!xCols.is() || !xCols->hasByName(rColumnName))
311cdf0e10cSrcweir 		return sal_False;
312cdf0e10cSrcweir 	Any aCol = xCols->getByName(rColumnName);
313cdf0e10cSrcweir     uno::Reference< XPropertySet > xColumnProps;
314cdf0e10cSrcweir     aCol >>= xColumnProps;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	SwDBFormatData aFormatData;
317cdf0e10cSrcweir     if(!pParam->xFormatter.is())
318cdf0e10cSrcweir 	{
319cdf0e10cSrcweir         uno::Reference<XDataSource> xSource = SwNewDBMgr::getDataSourceAsParent(
320cdf0e10cSrcweir 									pParam->xConnection,pParam->sDataSource);
321cdf0e10cSrcweir         lcl_InitNumberFormatter(*pParam, xSource );
322cdf0e10cSrcweir 	}
323cdf0e10cSrcweir     aFormatData.aNullDate = pParam->aNullDate;
324cdf0e10cSrcweir 	aFormatData.xFormatter = pParam->xFormatter;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     MsLangId::convertLanguageToLocale( (LanguageType)nLanguage, aFormatData.aLocale );
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	rResult = SwNewDBMgr::GetDBField( xColumnProps, aFormatData, pNumber);
329cdf0e10cSrcweir 	return sal_True;
330cdf0e10cSrcweir };
331cdf0e10cSrcweir /*--------------------------------------------------------------------
332cdf0e10cSrcweir 	Beschreibung: Daten importieren
333cdf0e10cSrcweir  --------------------------------------------------------------------*/
334cdf0e10cSrcweir sal_Bool SwNewDBMgr::MergeNew(const SwMergeDescriptor& rMergeDesc )
335cdf0e10cSrcweir {
336cdf0e10cSrcweir     SetMergeType( rMergeDesc.nMergeType );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     DBG_ASSERT(!bInMerge && !pImpl->pMergeData, "merge already activated!");
339cdf0e10cSrcweir 
340cdf0e10cSrcweir     SwDBData aData;
341cdf0e10cSrcweir     aData.nCommandType = CommandType::TABLE;
342cdf0e10cSrcweir     uno::Reference<XResultSet>  xResSet;
343cdf0e10cSrcweir     Sequence<Any> aSelection;
344cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     aData.sDataSource = rMergeDesc.rDescriptor.getDataSource();
347cdf0e10cSrcweir     rMergeDesc.rDescriptor[daCommand]      >>= aData.sCommand;
348cdf0e10cSrcweir     rMergeDesc.rDescriptor[daCommandType]  >>= aData.nCommandType;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     if ( rMergeDesc.rDescriptor.has(daCursor) )
351cdf0e10cSrcweir         rMergeDesc.rDescriptor[daCursor] >>= xResSet;
352cdf0e10cSrcweir     if ( rMergeDesc.rDescriptor.has(daSelection) )
353cdf0e10cSrcweir         rMergeDesc.rDescriptor[daSelection] >>= aSelection;
354cdf0e10cSrcweir     if ( rMergeDesc.rDescriptor.has(daConnection) )
355cdf0e10cSrcweir         rMergeDesc.rDescriptor[daConnection] >>= xConnection;
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     if(!aData.sDataSource.getLength() || !aData.sCommand.getLength() || !xResSet.is())
358cdf0e10cSrcweir 	{
359cdf0e10cSrcweir 		return sal_False;
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     pImpl->pMergeData = new SwDSParam(aData, xResSet, aSelection);
363cdf0e10cSrcweir     SwDSParam*  pTemp = FindDSData(aData, sal_False);
364cdf0e10cSrcweir 	if(pTemp)
365cdf0e10cSrcweir         *pTemp = *pImpl->pMergeData;
366cdf0e10cSrcweir 	else
367cdf0e10cSrcweir 	{
368cdf0e10cSrcweir         //#94779# calls from the calculator may have added a connection with an invalid commandtype
369cdf0e10cSrcweir         //"real" data base connections added here have to re-use the already available
370cdf0e10cSrcweir         //DSData and set the correct CommandType
371cdf0e10cSrcweir         SwDBData aTempData(aData);
372cdf0e10cSrcweir 		aData.nCommandType = -1;
373cdf0e10cSrcweir 		pTemp = FindDSData(aData, sal_False);
374cdf0e10cSrcweir 		if(pTemp)
375cdf0e10cSrcweir 			*pTemp = *pImpl->pMergeData;
376cdf0e10cSrcweir 		else
377cdf0e10cSrcweir         {
378cdf0e10cSrcweir 			SwDSParam* pInsert = new SwDSParam(*pImpl->pMergeData);
379cdf0e10cSrcweir 			aDataSourceParams.Insert(pInsert, aDataSourceParams.Count());
380cdf0e10cSrcweir 			try
381cdf0e10cSrcweir 			{
382cdf0e10cSrcweir                 uno::Reference<XComponent> xComponent(pInsert->xConnection, UNO_QUERY);
383cdf0e10cSrcweir 				if(xComponent.is())
384cdf0e10cSrcweir 					xComponent->addEventListener(pImpl->xDisposeListener);
385cdf0e10cSrcweir 			}
386cdf0e10cSrcweir 			catch(Exception&)
387cdf0e10cSrcweir 			{
388cdf0e10cSrcweir 			}
389cdf0e10cSrcweir         }
390cdf0e10cSrcweir 	}
391cdf0e10cSrcweir     if(!pImpl->pMergeData->xConnection.is())
392cdf0e10cSrcweir         pImpl->pMergeData->xConnection = xConnection;
393cdf0e10cSrcweir     // add an XEventListener
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	try{
396cdf0e10cSrcweir 		//set to start position
397cdf0e10cSrcweir         if(pImpl->pMergeData->aSelection.getLength())
398cdf0e10cSrcweir 		{
399cdf0e10cSrcweir 			sal_Int32 nPos = 0;
400cdf0e10cSrcweir 			pImpl->pMergeData->aSelection.getConstArray()[ pImpl->pMergeData->nSelectionIndex++ ] >>= nPos;
401cdf0e10cSrcweir             pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->absolute( nPos );
402cdf0e10cSrcweir             pImpl->pMergeData->CheckEndOfDB();
403cdf0e10cSrcweir             if(pImpl->pMergeData->nSelectionIndex >= pImpl->pMergeData->aSelection.getLength())
404cdf0e10cSrcweir                 pImpl->pMergeData->bEndOfDB = sal_True;
405cdf0e10cSrcweir 		}
406cdf0e10cSrcweir 		else
407cdf0e10cSrcweir 		{
408cdf0e10cSrcweir             pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->first();
409cdf0e10cSrcweir             pImpl->pMergeData->CheckEndOfDB();
410cdf0e10cSrcweir 		}
411cdf0e10cSrcweir 	}
412cdf0e10cSrcweir     catch(Exception&)
413cdf0e10cSrcweir 	{
414cdf0e10cSrcweir         pImpl->pMergeData->bEndOfDB = sal_True;
415cdf0e10cSrcweir         pImpl->pMergeData->CheckEndOfDB();
416cdf0e10cSrcweir 		DBG_ERROR("exception in MergeNew()");
417cdf0e10cSrcweir 	}
418cdf0e10cSrcweir 
419cdf0e10cSrcweir     uno::Reference<XDataSource> xSource = SwNewDBMgr::getDataSourceAsParent(xConnection,aData.sDataSource);
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	lcl_InitNumberFormatter(*pImpl->pMergeData, xSource);
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     rMergeDesc.rSh.ChgDBData(aData);
424cdf0e10cSrcweir 	bInMerge = sal_True;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 	if (IsInitDBFields())
427cdf0e10cSrcweir 	{
428cdf0e10cSrcweir 		// Bei Datenbankfeldern ohne DB-Name DB-Name von Dok einsetzen
429cdf0e10cSrcweir 		SvStringsDtor aDBNames(1, 1);
430cdf0e10cSrcweir 		aDBNames.Insert( new String(), 0);
431cdf0e10cSrcweir         SwDBData aInsertData = rMergeDesc.rSh.GetDBData();
432cdf0e10cSrcweir         String sDBName = aInsertData.sDataSource;
433cdf0e10cSrcweir 		sDBName += DB_DELIM;
434cdf0e10cSrcweir         sDBName += (String)aInsertData.sCommand;
435cdf0e10cSrcweir 		sDBName += DB_DELIM;
436cdf0e10cSrcweir         sDBName += String::CreateFromInt32(aInsertData.nCommandType);
437cdf0e10cSrcweir         rMergeDesc.rSh.ChangeDBFields( aDBNames, sDBName);
438cdf0e10cSrcweir 		SetInitDBFields(sal_False);
439cdf0e10cSrcweir 	}
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
442cdf0e10cSrcweir     switch(rMergeDesc.nMergeType)
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir 		case DBMGR_MERGE:
445cdf0e10cSrcweir             bRet = Merge(&rMergeDesc.rSh);   // Mischen
446cdf0e10cSrcweir 			break;
447cdf0e10cSrcweir 
448cdf0e10cSrcweir         case DBMGR_MERGE_MAILMERGE: // printing merge from 'old' merge dialog or from UNO-component
449cdf0e10cSrcweir 		case DBMGR_MERGE_MAILING:
450cdf0e10cSrcweir         case DBMGR_MERGE_MAILFILES:
451cdf0e10cSrcweir         case DBMGR_MERGE_SINGLE_FILE:
452cdf0e10cSrcweir             // save files and send them as e-Mail if required
453cdf0e10cSrcweir             bRet = MergeMailFiles(&rMergeDesc.rSh,
454cdf0e10cSrcweir                     rMergeDesc);
455cdf0e10cSrcweir 			break;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 		default:    	// Einfuegen der selektierten Eintraege
458cdf0e10cSrcweir 						// (war: InsertRecord)
459cdf0e10cSrcweir             ImportFromConnection(&rMergeDesc.rSh);
460cdf0e10cSrcweir 			break;
461cdf0e10cSrcweir 	}
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	EndMerge();
464cdf0e10cSrcweir 	return bRet;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir /*--------------------------------------------------------------------
468cdf0e10cSrcweir 	Beschreibung: Daten importieren
469cdf0e10cSrcweir  --------------------------------------------------------------------*/
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 
472cdf0e10cSrcweir sal_Bool SwNewDBMgr::Merge(SwWrtShell* pSh)
473cdf0e10cSrcweir {
474cdf0e10cSrcweir 	pSh->StartAllAction();
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	pSh->ViewShell::UpdateFlds(sal_True);
477cdf0e10cSrcweir 	pSh->SetModified();
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	pSh->EndAllAction();
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	return sal_True;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir /*--------------------------------------------------------------------
485cdf0e10cSrcweir 	Beschreibung:
486cdf0e10cSrcweir  --------------------------------------------------------------------*/
487cdf0e10cSrcweir void SwNewDBMgr::ImportFromConnection(	SwWrtShell* pSh )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir     if(pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB)
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		{
492cdf0e10cSrcweir 			pSh->StartAllAction();
493cdf0e10cSrcweir             pSh->StartUndo(UNDO_EMPTY);
494cdf0e10cSrcweir 			sal_Bool bGroupUndo(pSh->DoesGroupUndo());
495cdf0e10cSrcweir 			pSh->DoGroupUndo(sal_False);
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 			if( pSh->HasSelection() )
498cdf0e10cSrcweir 				pSh->DelRight();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 			SwWait *pWait = 0;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 			{
503cdf0e10cSrcweir 				sal_uLong i = 0;
504cdf0e10cSrcweir 				do {
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 					ImportDBEntry(pSh);
507cdf0e10cSrcweir 					if( 10 == ++i )
508cdf0e10cSrcweir 						pWait = new SwWait( *pSh->GetView().GetDocShell(), sal_True);
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 				} while(ToNextMergeRecord());
511cdf0e10cSrcweir 			}
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 			pSh->DoGroupUndo(bGroupUndo);
514cdf0e10cSrcweir             pSh->EndUndo(UNDO_EMPTY);
515cdf0e10cSrcweir 			pSh->EndAllAction();
516cdf0e10cSrcweir 			delete pWait;
517cdf0e10cSrcweir 		}
518cdf0e10cSrcweir 	}
519cdf0e10cSrcweir }
520cdf0e10cSrcweir /*-----------------24.02.97 10.30-------------------
521cdf0e10cSrcweir 
522cdf0e10cSrcweir --------------------------------------------------*/
523cdf0e10cSrcweir 
524cdf0e10cSrcweir String 	lcl_FindColumn(const String& sFormatStr,sal_uInt16  &nUsedPos, sal_uInt8 &nSeparator)
525cdf0e10cSrcweir {
526cdf0e10cSrcweir 	String sReturn;
527cdf0e10cSrcweir 	sal_uInt16 nLen = sFormatStr.Len();
528cdf0e10cSrcweir 	nSeparator = 0xff;
529cdf0e10cSrcweir 	while(nUsedPos < nLen && nSeparator == 0xff)
530cdf0e10cSrcweir 	{
531cdf0e10cSrcweir 		sal_Unicode cAkt = sFormatStr.GetChar(nUsedPos);
532cdf0e10cSrcweir 		switch(cAkt)
533cdf0e10cSrcweir 		{
534cdf0e10cSrcweir 			case ',':
535cdf0e10cSrcweir 				nSeparator = DB_SEP_SPACE;
536cdf0e10cSrcweir 			break;
537cdf0e10cSrcweir 			case ';':
538cdf0e10cSrcweir 				nSeparator = DB_SEP_RETURN;
539cdf0e10cSrcweir 			break;
540cdf0e10cSrcweir 			case ':':
541cdf0e10cSrcweir 				nSeparator = DB_SEP_TAB;
542cdf0e10cSrcweir 			break;
543cdf0e10cSrcweir 			case '#':
544cdf0e10cSrcweir 				nSeparator = DB_SEP_NEWLINE;
545cdf0e10cSrcweir 			break;
546cdf0e10cSrcweir 			default:
547cdf0e10cSrcweir 				sReturn += cAkt;
548cdf0e10cSrcweir 		}
549cdf0e10cSrcweir 		nUsedPos++;
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 	}
552cdf0e10cSrcweir 	return sReturn;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir 
555cdf0e10cSrcweir /*--------------------------------------------------------------------
556cdf0e10cSrcweir 	Beschreibung:
557cdf0e10cSrcweir  --------------------------------------------------------------------*/
558cdf0e10cSrcweir void SwNewDBMgr::ImportDBEntry(SwWrtShell* pSh)
559cdf0e10cSrcweir {
560cdf0e10cSrcweir     if(pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB)
561cdf0e10cSrcweir 	{
562cdf0e10cSrcweir         uno::Reference< XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, UNO_QUERY );
563cdf0e10cSrcweir         uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
564cdf0e10cSrcweir         String sFormatStr;
565cdf0e10cSrcweir 		sal_uInt16 nFmtLen = sFormatStr.Len();
566cdf0e10cSrcweir 		if( nFmtLen )
567cdf0e10cSrcweir 		{
568cdf0e10cSrcweir 			const char cSpace = ' ';
569cdf0e10cSrcweir 			const char cTab = '\t';
570cdf0e10cSrcweir 			sal_uInt16 nUsedPos = 0;
571cdf0e10cSrcweir 			sal_uInt8	nSeparator;
572cdf0e10cSrcweir 			String sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
573cdf0e10cSrcweir 			while( sColumn.Len() )
574cdf0e10cSrcweir 			{
575cdf0e10cSrcweir 				if(!xCols->hasByName(sColumn))
576cdf0e10cSrcweir 					return;
577cdf0e10cSrcweir 				Any aCol = xCols->getByName(sColumn);
578cdf0e10cSrcweir                 uno::Reference< XPropertySet > xColumnProp;
579cdf0e10cSrcweir                 aCol >>= xColumnProp;
580cdf0e10cSrcweir 				if(xColumnProp.is())
581cdf0e10cSrcweir 				{
582cdf0e10cSrcweir 					SwDBFormatData aDBFormat;
583cdf0e10cSrcweir 					String sInsert = GetDBField( xColumnProp,	aDBFormat);
584cdf0e10cSrcweir 					if( DB_SEP_SPACE == nSeparator )
585cdf0e10cSrcweir 							sInsert += cSpace;
586cdf0e10cSrcweir 					else if( DB_SEP_TAB == nSeparator)
587cdf0e10cSrcweir 							sInsert += cTab;
588cdf0e10cSrcweir 					pSh->Insert(sInsert);
589cdf0e10cSrcweir 					if( DB_SEP_RETURN == nSeparator)
590cdf0e10cSrcweir 						pSh->SplitNode();
591cdf0e10cSrcweir 					else if(DB_SEP_NEWLINE == nSeparator)
592cdf0e10cSrcweir 							pSh->InsertLineBreak();
593cdf0e10cSrcweir 				}
594cdf0e10cSrcweir 				else
595cdf0e10cSrcweir 				{
596cdf0e10cSrcweir 					// Spalte nicht gefunden -> Fehler anzeigen
597cdf0e10cSrcweir 					String sInsert = '?';
598cdf0e10cSrcweir 					sInsert += sColumn;
599cdf0e10cSrcweir 					sInsert += '?';
600cdf0e10cSrcweir 					pSh->Insert(sInsert);
601cdf0e10cSrcweir 				}
602cdf0e10cSrcweir 				sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
603cdf0e10cSrcweir 			}
604cdf0e10cSrcweir 			pSh->SplitNode();
605cdf0e10cSrcweir 		}
606cdf0e10cSrcweir 		else
607cdf0e10cSrcweir 		{
608cdf0e10cSrcweir 			String sStr;
609cdf0e10cSrcweir             Sequence<rtl::OUString> aColNames = xCols->getElementNames();
610cdf0e10cSrcweir             const rtl::OUString* pColNames = aColNames.getConstArray();
611cdf0e10cSrcweir 			long nLength = aColNames.getLength();
612cdf0e10cSrcweir 			for(long i = 0; i < nLength; i++)
613cdf0e10cSrcweir 			{
614cdf0e10cSrcweir 				Any aCol = xCols->getByName(pColNames[i]);
615cdf0e10cSrcweir                 uno::Reference< XPropertySet > xColumnProp;
616cdf0e10cSrcweir                 aCol >>= xColumnProp;
617cdf0e10cSrcweir 				SwDBFormatData aDBFormat;
618cdf0e10cSrcweir 				sStr += GetDBField( xColumnProp, aDBFormat);
619cdf0e10cSrcweir 				if (i < nLength - 1)
620cdf0e10cSrcweir 					sStr += '\t';
621cdf0e10cSrcweir 			}
622cdf0e10cSrcweir             pSh->SwEditShell::Insert2(sStr);
623cdf0e10cSrcweir 			pSh->SwFEShell::SplitNode();	// Zeilenvorschub
624cdf0e10cSrcweir 		}
625cdf0e10cSrcweir 	}
626cdf0e10cSrcweir }
627cdf0e10cSrcweir /*--------------------------------------------------------------------
628cdf0e10cSrcweir 	Beschreibung: Listbox mit Tabellenliste fuellen
629cdf0e10cSrcweir  --------------------------------------------------------------------*/
630cdf0e10cSrcweir sal_Bool SwNewDBMgr::GetTableNames(ListBox* pListBox, const String& rDBName)
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
633cdf0e10cSrcweir     String sOldTableName(pListBox->GetSelectEntry());
634cdf0e10cSrcweir 	pListBox->Clear();
635cdf0e10cSrcweir     SwDSParam* pParam = FindDSConnection(rDBName, sal_False);
636cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
637cdf0e10cSrcweir     if(pParam && pParam->xConnection.is())
638cdf0e10cSrcweir         xConnection = pParam->xConnection;
639cdf0e10cSrcweir     else
640cdf0e10cSrcweir     {
641cdf0e10cSrcweir         rtl::OUString sDBName(rDBName);
642cdf0e10cSrcweir         if ( sDBName.getLength() )
643cdf0e10cSrcweir             xConnection = RegisterConnection( sDBName );
644cdf0e10cSrcweir     }
645cdf0e10cSrcweir 	if(xConnection.is())
646cdf0e10cSrcweir 	{
647cdf0e10cSrcweir         uno::Reference<XTablesSupplier> xTSupplier = uno::Reference<XTablesSupplier>(xConnection, UNO_QUERY);
648cdf0e10cSrcweir 		if(xTSupplier.is())
649cdf0e10cSrcweir 		{
650cdf0e10cSrcweir             uno::Reference<XNameAccess> xTbls = xTSupplier->getTables();
651cdf0e10cSrcweir             Sequence<rtl::OUString> aTbls = xTbls->getElementNames();
652cdf0e10cSrcweir             const rtl::OUString* pTbls = aTbls.getConstArray();
653cdf0e10cSrcweir 			for(long i = 0; i < aTbls.getLength(); i++)
654cdf0e10cSrcweir             {
655cdf0e10cSrcweir                 sal_uInt16 nEntry = pListBox->InsertEntry(pTbls[i]);
656cdf0e10cSrcweir                 pListBox->SetEntryData(nEntry, (void*)0);
657cdf0e10cSrcweir             }
658cdf0e10cSrcweir 		}
659cdf0e10cSrcweir         uno::Reference<XQueriesSupplier> xQSupplier = uno::Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
660cdf0e10cSrcweir 		if(xQSupplier.is())
661cdf0e10cSrcweir 		{
662cdf0e10cSrcweir             uno::Reference<XNameAccess> xQueries = xQSupplier->getQueries();
663cdf0e10cSrcweir             Sequence<rtl::OUString> aQueries = xQueries->getElementNames();
664cdf0e10cSrcweir             const rtl::OUString* pQueries = aQueries.getConstArray();
665cdf0e10cSrcweir 			for(long i = 0; i < aQueries.getLength(); i++)
666cdf0e10cSrcweir             {
667cdf0e10cSrcweir                 sal_uInt16 nEntry = pListBox->InsertEntry(pQueries[i]);
668cdf0e10cSrcweir                 pListBox->SetEntryData(nEntry, (void*)1);
669cdf0e10cSrcweir             }
670cdf0e10cSrcweir         }
671cdf0e10cSrcweir 		if (sOldTableName.Len())
672cdf0e10cSrcweir 			pListBox->SelectEntry(sOldTableName);
673cdf0e10cSrcweir 		bRet = sal_True;
674cdf0e10cSrcweir 	}
675cdf0e10cSrcweir 	return bRet;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir /*--------------------------------------------------------------------
679cdf0e10cSrcweir 	Beschreibung: Listbox mit Spaltennamen einer Datenbank fuellen
680cdf0e10cSrcweir  --------------------------------------------------------------------*/
681cdf0e10cSrcweir sal_Bool SwNewDBMgr::GetColumnNames(ListBox* pListBox,
682cdf0e10cSrcweir 			const String& rDBName, const String& rTableName, sal_Bool bAppend)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir 	if (!bAppend)
685cdf0e10cSrcweir 		pListBox->Clear();
686cdf0e10cSrcweir     SwDBData aData;
687cdf0e10cSrcweir     aData.sDataSource = rDBName;
688cdf0e10cSrcweir     aData.sCommand = rTableName;
689cdf0e10cSrcweir     aData.nCommandType = -1;
690cdf0e10cSrcweir     SwDSParam* pParam = FindDSData(aData, sal_False);
691cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
692cdf0e10cSrcweir     if(pParam && pParam->xConnection.is())
693cdf0e10cSrcweir         xConnection = pParam->xConnection;
694cdf0e10cSrcweir     else
695cdf0e10cSrcweir     {
696cdf0e10cSrcweir         rtl::OUString sDBName(rDBName);
697cdf0e10cSrcweir         xConnection = RegisterConnection( sDBName );
698cdf0e10cSrcweir     }
699cdf0e10cSrcweir     uno::Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
700cdf0e10cSrcweir 	if(xColsSupp.is())
701cdf0e10cSrcweir 	{
702cdf0e10cSrcweir         uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
703cdf0e10cSrcweir         const Sequence<rtl::OUString> aColNames = xCols->getElementNames();
704cdf0e10cSrcweir         const rtl::OUString* pColNames = aColNames.getConstArray();
705cdf0e10cSrcweir 		for(int nCol = 0; nCol < aColNames.getLength(); nCol++)
706cdf0e10cSrcweir 		{
707cdf0e10cSrcweir 			pListBox->InsertEntry(pColNames[nCol]);
708cdf0e10cSrcweir 		}
709cdf0e10cSrcweir         ::comphelper::disposeComponent( xColsSupp );
710cdf0e10cSrcweir     }
711cdf0e10cSrcweir     return(sal_True);
712cdf0e10cSrcweir }
713cdf0e10cSrcweir /* -----------------------------08.06.01 15:11--------------------------------
714cdf0e10cSrcweir 
715cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
716cdf0e10cSrcweir sal_Bool SwNewDBMgr::GetColumnNames(ListBox* pListBox,
717cdf0e10cSrcweir         uno::Reference< XConnection> xConnection,
718cdf0e10cSrcweir         const String& rTableName, sal_Bool bAppend)
719cdf0e10cSrcweir {
720cdf0e10cSrcweir 	if (!bAppend)
721cdf0e10cSrcweir 		pListBox->Clear();
722cdf0e10cSrcweir     uno::Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
723cdf0e10cSrcweir 	if(xColsSupp.is())
724cdf0e10cSrcweir 	{
725cdf0e10cSrcweir         uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
726cdf0e10cSrcweir         const Sequence<rtl::OUString> aColNames = xCols->getElementNames();
727cdf0e10cSrcweir         const rtl::OUString* pColNames = aColNames.getConstArray();
728cdf0e10cSrcweir 		for(int nCol = 0; nCol < aColNames.getLength(); nCol++)
729cdf0e10cSrcweir 		{
730cdf0e10cSrcweir 			pListBox->InsertEntry(pColNames[nCol]);
731cdf0e10cSrcweir 		}
732cdf0e10cSrcweir         ::comphelper::disposeComponent( xColsSupp );
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir 	return(sal_True);
735cdf0e10cSrcweir }
736cdf0e10cSrcweir 
737cdf0e10cSrcweir /*--------------------------------------------------------------------
738cdf0e10cSrcweir 	Beschreibung: CTOR
739cdf0e10cSrcweir  --------------------------------------------------------------------*/
740cdf0e10cSrcweir 
741cdf0e10cSrcweir SwNewDBMgr::SwNewDBMgr() :
742cdf0e10cSrcweir             nMergeType(DBMGR_INSERT),
743cdf0e10cSrcweir             bInitDBFields(sal_False),
744cdf0e10cSrcweir             bInMerge(sal_False),
745cdf0e10cSrcweir             bMergeSilent(sal_False),
746cdf0e10cSrcweir             bMergeLock(sal_False),
747cdf0e10cSrcweir             pImpl(new SwNewDBMgr_Impl(*this)),
748cdf0e10cSrcweir             pMergeEvtSrc(NULL)
749cdf0e10cSrcweir {
750cdf0e10cSrcweir }
751cdf0e10cSrcweir /* -----------------------------18.07.00 08:56--------------------------------
752cdf0e10cSrcweir 
753cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
754cdf0e10cSrcweir SwNewDBMgr::~SwNewDBMgr()
755cdf0e10cSrcweir {
756cdf0e10cSrcweir     for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.Count(); nPos++)
757cdf0e10cSrcweir     {
758cdf0e10cSrcweir         SwDSParam* pParam = aDataSourceParams[nPos];
759cdf0e10cSrcweir         if(pParam->xConnection.is())
760cdf0e10cSrcweir         {
761cdf0e10cSrcweir             try
762cdf0e10cSrcweir             {
763cdf0e10cSrcweir                 uno::Reference<XComponent> xComp(pParam->xConnection, UNO_QUERY);
764cdf0e10cSrcweir                 if(xComp.is())
765cdf0e10cSrcweir                     xComp->dispose();
766cdf0e10cSrcweir             }
767cdf0e10cSrcweir             catch(const RuntimeException& )
768cdf0e10cSrcweir             {
769cdf0e10cSrcweir                 //may be disposed already since multiple entries may have used the same connection
770cdf0e10cSrcweir             }
771cdf0e10cSrcweir         }
772cdf0e10cSrcweir     }
773cdf0e10cSrcweir     delete pImpl;
774cdf0e10cSrcweir }
775cdf0e10cSrcweir 
776cdf0e10cSrcweir /*--------------------------------------------------------------------
777cdf0e10cSrcweir 	Beschreibung:	Serienbriefe als einzelne Dokumente speichern
778cdf0e10cSrcweir  --------------------------------------------------------------------*/
779cdf0e10cSrcweir String lcl_FindUniqueName(SwWrtShell* pTargetShell, const String& rStartingPageDesc, sal_uLong nDocNo )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir     do
782cdf0e10cSrcweir     {
783cdf0e10cSrcweir         String sTest = rStartingPageDesc;
784cdf0e10cSrcweir         sTest += String::CreateFromInt32( nDocNo );
785cdf0e10cSrcweir         if( !pTargetShell->FindPageDescByName( sTest ) )
786cdf0e10cSrcweir             return sTest;
787cdf0e10cSrcweir         ++nDocNo;
788cdf0e10cSrcweir     }while(true);
789cdf0e10cSrcweir }
790cdf0e10cSrcweir void lcl_CopyDynamicDefaults( const SwDoc& rSource, SwDoc& rTarget )
791cdf0e10cSrcweir {
792cdf0e10cSrcweir     sal_uInt16 __FAR_DATA aRangeOfDefaults[] = {
793cdf0e10cSrcweir         RES_FRMATR_BEGIN, RES_FRMATR_END-1,
794cdf0e10cSrcweir         RES_CHRATR_BEGIN, RES_CHRATR_END-1,
795cdf0e10cSrcweir         RES_PARATR_BEGIN, RES_PARATR_END-1,
796cdf0e10cSrcweir         // --> OD 2008-02-25 #refactorlists##
797cdf0e10cSrcweir         RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
798cdf0e10cSrcweir         // <--
799cdf0e10cSrcweir         RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
800cdf0e10cSrcweir         0
801cdf0e10cSrcweir     };
802cdf0e10cSrcweir 
803cdf0e10cSrcweir     SfxItemSet aNewDefaults( rTarget.GetAttrPool(), aRangeOfDefaults );
804cdf0e10cSrcweir 
805cdf0e10cSrcweir     sal_uInt16 nWhich;
806cdf0e10cSrcweir     sal_uInt16 nRange = 0;
807cdf0e10cSrcweir     while( aRangeOfDefaults[nRange] != 0)
808cdf0e10cSrcweir     {
809cdf0e10cSrcweir         for( nWhich = aRangeOfDefaults[nRange]; nWhich < aRangeOfDefaults[nRange + 1]; ++nWhich )
810cdf0e10cSrcweir         {
811cdf0e10cSrcweir             const SfxPoolItem& rSourceAttr = rSource.GetDefault( nWhich );
812cdf0e10cSrcweir             if( rSourceAttr != rTarget.GetDefault( nWhich ) )
813cdf0e10cSrcweir                 aNewDefaults.Put( rSourceAttr );
814cdf0e10cSrcweir         }
815cdf0e10cSrcweir         nRange += 2;
816cdf0e10cSrcweir     }
817cdf0e10cSrcweir     if( aNewDefaults.Count() )
818cdf0e10cSrcweir         rTarget.SetDefault( aNewDefaults );
819cdf0e10cSrcweir }
820cdf0e10cSrcweir void lcl_CopyFollowPageDesc(
821cdf0e10cSrcweir                             SwWrtShell& rTargetShell,
822cdf0e10cSrcweir                             const SwPageDesc& rSourcePageDesc,
823cdf0e10cSrcweir                             const SwPageDesc& rTargetPageDesc,
824cdf0e10cSrcweir                             const sal_uLong nDocNo )
825cdf0e10cSrcweir {
826cdf0e10cSrcweir     //now copy the follow page desc, too
827cdf0e10cSrcweir     const SwPageDesc* pFollowPageDesc = rSourcePageDesc.GetFollow();
828cdf0e10cSrcweir     String sFollowPageDesc = pFollowPageDesc->GetName();
829cdf0e10cSrcweir     if( sFollowPageDesc != rSourcePageDesc.GetName() )
830cdf0e10cSrcweir     {
831cdf0e10cSrcweir         SwDoc* pTargetDoc = rTargetShell.GetDoc();
832cdf0e10cSrcweir         String sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo );
833cdf0e10cSrcweir         sal_uInt16 nNewDesc = pTargetDoc->MakePageDesc( sNewFollowPageDesc );
834cdf0e10cSrcweir         SwPageDesc& rTargetFollowPageDesc = pTargetDoc->_GetPageDesc( nNewDesc );
835cdf0e10cSrcweir 
836cdf0e10cSrcweir         pTargetDoc->CopyPageDesc( *pFollowPageDesc, rTargetFollowPageDesc, sal_False );
837cdf0e10cSrcweir         SwPageDesc aDesc( rTargetPageDesc );
838cdf0e10cSrcweir         aDesc.SetFollow( &rTargetFollowPageDesc );
839cdf0e10cSrcweir         pTargetDoc->ChgPageDesc( rTargetPageDesc.GetName(), aDesc );
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir }
842cdf0e10cSrcweir 
843cdf0e10cSrcweir void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell )
844cdf0e10cSrcweir {
845cdf0e10cSrcweir     //reset all links of the sections of synchronized labels
846cdf0e10cSrcweir     sal_uInt16 nSections = rWorkShell.GetSectionFmtCount();
847cdf0e10cSrcweir     for( sal_uInt16 nSection = 0; nSection < nSections; ++nSection )
848cdf0e10cSrcweir     {
849cdf0e10cSrcweir         SwSectionData aSectionData( *rWorkShell.GetSectionFmt( nSection ).GetSection() );
850cdf0e10cSrcweir         if( aSectionData.GetType() == FILE_LINK_SECTION )
851cdf0e10cSrcweir         {
852cdf0e10cSrcweir             aSectionData.SetType( CONTENT_SECTION );
853cdf0e10cSrcweir             aSectionData.SetLinkFileName( String() );
854cdf0e10cSrcweir             rWorkShell.UpdateSection( nSection, aSectionData );
855cdf0e10cSrcweir         }
856cdf0e10cSrcweir     }
857cdf0e10cSrcweir     rWorkShell.SetLabelDoc( sal_False );
858cdf0e10cSrcweir }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
861cdf0e10cSrcweir         const SwMergeDescriptor& rMergeDescriptor)
862cdf0e10cSrcweir {
863cdf0e10cSrcweir 	//check if the doc is synchronized and contains at least one linked section
864cdf0e10cSrcweir     sal_Bool bSynchronizedDoc = pSourceShell->IsLabelDoc() && pSourceShell->GetSectionFmtCount() > 1;
865cdf0e10cSrcweir 	sal_Bool bLoop = sal_True;
866cdf0e10cSrcweir     sal_Bool bEMail = rMergeDescriptor.nMergeType == DBMGR_MERGE_MAILING;
867cdf0e10cSrcweir     const bool bAsSingleFile = rMergeDescriptor.nMergeType == DBMGR_MERGE_SINGLE_FILE;
868cdf0e10cSrcweir 
869cdf0e10cSrcweir     ::rtl::Reference< MailDispatcher >          xMailDispatcher;
870cdf0e10cSrcweir     ::rtl::OUString sBodyMimeType;
871cdf0e10cSrcweir     rtl_TextEncoding eEncoding = ::gsl_getSystemTextEncoding();
872cdf0e10cSrcweir 
873cdf0e10cSrcweir     if(bEMail)
874cdf0e10cSrcweir     {
875cdf0e10cSrcweir         xMailDispatcher.set( new MailDispatcher(rMergeDescriptor.xSmtpServer));
876cdf0e10cSrcweir         if(!rMergeDescriptor.bSendAsAttachment && rMergeDescriptor.bSendAsHTML)
877cdf0e10cSrcweir         {
878cdf0e10cSrcweir             sBodyMimeType = ::rtl::OUString::createFromAscii("text/html; charset=");
879cdf0e10cSrcweir             sBodyMimeType += ::rtl::OUString::createFromAscii(
880cdf0e10cSrcweir                                 rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
881cdf0e10cSrcweir             SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
882cdf0e10cSrcweir             eEncoding = pHtmlOptions->GetTextEncoding();
883cdf0e10cSrcweir         }
884cdf0e10cSrcweir         else
885cdf0e10cSrcweir             sBodyMimeType =
886cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("text/plain; charset=UTF-8; format=flowed");
887cdf0e10cSrcweir     }
888cdf0e10cSrcweir 
889cdf0e10cSrcweir     uno::Reference< XPropertySet > xColumnProp;
890cdf0e10cSrcweir 	{
891cdf0e10cSrcweir 		sal_Bool bColumnName = sEMailAddrFld.Len() > 0;
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 		if (bColumnName)
894cdf0e10cSrcweir 		{
895cdf0e10cSrcweir             uno::Reference< XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, UNO_QUERY );
896cdf0e10cSrcweir             uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
897cdf0e10cSrcweir 			if(!xCols->hasByName(sEMailAddrFld))
898cdf0e10cSrcweir 				return sal_False;
899cdf0e10cSrcweir 			Any aCol = xCols->getByName(sEMailAddrFld);
900cdf0e10cSrcweir             aCol >>= xColumnProp;
901cdf0e10cSrcweir 		}
902cdf0e10cSrcweir 
903cdf0e10cSrcweir         SfxDispatcher* pSfxDispatcher = pSourceShell->GetView().GetViewFrame()->GetDispatcher();
904cdf0e10cSrcweir         SwDocShell* pSourrceDocSh = pSourceShell->GetView().GetDocShell();
905cdf0e10cSrcweir         pSfxDispatcher->Execute( pSourrceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
906cdf0e10cSrcweir         // has document been saved successfully?
907cdf0e10cSrcweir         if( !pSourrceDocSh->IsModified() )
908cdf0e10cSrcweir 		{
909cdf0e10cSrcweir             SfxMedium* pOrig = pSourceShell->GetView().GetDocShell()->GetMedium();
910cdf0e10cSrcweir             String sSourceDocumentURL(pOrig->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ));
911cdf0e10cSrcweir 			const SfxFilter* pSfxFlt = SwIoSystem::GetFileFilter(
912cdf0e10cSrcweir                                                     sSourceDocumentURL, ::aEmptyStr );
913cdf0e10cSrcweir             const SfxFilter* pStoreToFilter = pSfxFlt;
914cdf0e10cSrcweir             SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
915cdf0e10cSrcweir             const String* pStoreToFilterOptions = 0;
916cdf0e10cSrcweir             // if a save_to filter is set then use it - otherwise use the default
917cdf0e10cSrcweir             if( bEMail && !rMergeDescriptor.bSendAsAttachment )
918cdf0e10cSrcweir             {
919cdf0e10cSrcweir                 String sExtension( String::CreateFromAscii(
920cdf0e10cSrcweir                         rMergeDescriptor.bSendAsHTML ? "html" : "txt" ));
921cdf0e10cSrcweir                 pStoreToFilter = pFilterContainer->GetFilter4Extension(sExtension, SFX_FILTER_EXPORT);
922cdf0e10cSrcweir             }
923cdf0e10cSrcweir             else if( rMergeDescriptor.sSaveToFilter.Len())
924cdf0e10cSrcweir             {
925cdf0e10cSrcweir                 const SfxFilter* pFilter =
926cdf0e10cSrcweir                         pFilterContainer->GetFilter4FilterName( rMergeDescriptor.sSaveToFilter );
927cdf0e10cSrcweir                 if(pFilter)
928cdf0e10cSrcweir                 {
929cdf0e10cSrcweir                     pStoreToFilter = pFilter;
930cdf0e10cSrcweir                     if(rMergeDescriptor.sSaveToFilterOptions.Len())
931cdf0e10cSrcweir                         pStoreToFilterOptions = &rMergeDescriptor.sSaveToFilterOptions;
932cdf0e10cSrcweir                 }
933cdf0e10cSrcweir             }
934cdf0e10cSrcweir 			bCancel = sal_False;
935cdf0e10cSrcweir 
936cdf0e10cSrcweir             // in case of creating a single resulting file this has to be created here
937cdf0e10cSrcweir             SwWrtShell* pTargetShell = 0;
938cdf0e10cSrcweir 
939cdf0e10cSrcweir             // the shell will be explicitly closed at the end of the method, but it is
940cdf0e10cSrcweir             // still more safe to use SfxObjectShellLock here
941cdf0e10cSrcweir             SfxObjectShellLock xTargetDocShell;
942cdf0e10cSrcweir 
943cdf0e10cSrcweir             SwView* pTargetView = 0;
944cdf0e10cSrcweir             std::auto_ptr< utl::TempFile > aTempFile;
945cdf0e10cSrcweir             String sModifiedStartingPageDesc;
946cdf0e10cSrcweir             String sStartingPageDesc;
947cdf0e10cSrcweir             sal_uInt16 nStartingPageNo = 0;
948cdf0e10cSrcweir             bool bPageStylesWithHeaderFooter = false;
949cdf0e10cSrcweir             if(bAsSingleFile || rMergeDescriptor.bCreateSingleFile)
950cdf0e10cSrcweir             {
951cdf0e10cSrcweir                 // create a target docshell to put the merged document into
952cdf0e10cSrcweir                 xTargetDocShell = new SwDocShell( SFX_CREATE_MODE_STANDARD );
953cdf0e10cSrcweir                 xTargetDocShell->DoInitNew( 0 );
954cdf0e10cSrcweir                 SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 );
955cdf0e10cSrcweir 
956cdf0e10cSrcweir                 pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() );
957cdf0e10cSrcweir 
958cdf0e10cSrcweir                 //initiate SelectShell() to create sub shells
959cdf0e10cSrcweir                 pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
960cdf0e10cSrcweir                 pTargetShell = pTargetView->GetWrtShellPtr();
961cdf0e10cSrcweir                 //copy the styles from the source to the target document
962cdf0e10cSrcweir                 SwgReaderOption aOpt;
963cdf0e10cSrcweir                 aOpt.SetTxtFmts( sal_True );
964cdf0e10cSrcweir                 aOpt.SetFrmFmts( sal_True );
965cdf0e10cSrcweir                 aOpt.SetPageDescs( sal_True );
966cdf0e10cSrcweir                 aOpt.SetNumRules( sal_True );
967cdf0e10cSrcweir                 aOpt.SetMerge( sal_False );
968cdf0e10cSrcweir                 pTargetView->GetDocShell()->LoadStylesFromFile(
969cdf0e10cSrcweir                         sSourceDocumentURL, aOpt, sal_True );
970cdf0e10cSrcweir                 //determine the page style and number used at the start of the source document
971cdf0e10cSrcweir                 pSourceShell->SttEndDoc(sal_True);
972cdf0e10cSrcweir                 nStartingPageNo = pSourceShell->GetVirtPageNum();
973cdf0e10cSrcweir                 sStartingPageDesc = sModifiedStartingPageDesc = pSourceShell->GetPageDesc(
974cdf0e10cSrcweir                                             pSourceShell->GetCurPageDesc()).GetName();
975cdf0e10cSrcweir                 // #122799# copy compatibility options
976cdf0e10cSrcweir                 lcl_CopyCompatibilityOptions( *pSourceShell, *pTargetShell);
977cdf0e10cSrcweir                 // #72821# copy dynamic defaults
978cdf0e10cSrcweir                 lcl_CopyDynamicDefaults( *pSourceShell->GetDoc(), *pTargetShell->GetDoc() );
979cdf0e10cSrcweir                 // #i72517#
980cdf0e10cSrcweir                 const SwPageDesc* pSourcePageDesc = pSourceShell->FindPageDescByName( sStartingPageDesc );
981cdf0e10cSrcweir                 const SwFrmFmt& rMaster = pSourcePageDesc->GetMaster();
982cdf0e10cSrcweir                 bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive()  ||
983cdf0e10cSrcweir                                                 rMaster.GetFooter().IsActive();
984cdf0e10cSrcweir 
985cdf0e10cSrcweir             }
986cdf0e10cSrcweir 
987cdf0e10cSrcweir             PrintMonitor aPrtMonDlg(&pSourceShell->GetView().GetEditWin(), PrintMonitor::MONITOR_TYPE_PRINT);
988cdf0e10cSrcweir             aPrtMonDlg.aDocName.SetText(pSourceShell->GetView().GetDocShell()->GetTitle(22));
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 			aPrtMonDlg.aCancel.SetClickHdl(LINK(this, SwNewDBMgr, PrtCancelHdl));
991cdf0e10cSrcweir             if (!IsMergeSilent())
992cdf0e10cSrcweir                 aPrtMonDlg.Show();
993cdf0e10cSrcweir 
994cdf0e10cSrcweir 			// Progress, um KeyInputs zu unterbinden
995cdf0e10cSrcweir             SfxProgress aProgress(pSourrceDocSh, ::aEmptyStr, 1);
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 			// Alle Dispatcher sperren
998cdf0e10cSrcweir             SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst(pSourrceDocSh);
999cdf0e10cSrcweir 			while (pViewFrm)
1000cdf0e10cSrcweir 			{
1001cdf0e10cSrcweir 				pViewFrm->GetDispatcher()->Lock(sal_True);
1002cdf0e10cSrcweir                 pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pSourrceDocSh);
1003cdf0e10cSrcweir 			}
1004cdf0e10cSrcweir 			sal_uLong nDocNo = 1;
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir             long nStartRow, nEndRow;
1007cdf0e10cSrcweir             // collect temporary files
1008cdf0e10cSrcweir             ::std::vector< String> aFilesToRemove;
1009cdf0e10cSrcweir             do
1010cdf0e10cSrcweir             {
1011cdf0e10cSrcweir                 nStartRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0;
1012cdf0e10cSrcweir                 {
1013cdf0e10cSrcweir 					String sPath(sSubject);
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir                     String sAddress;
1016cdf0e10cSrcweir                     if( !bEMail && bColumnName )
1017cdf0e10cSrcweir 					{
1018cdf0e10cSrcweir 						SwDBFormatData aDBFormat;
1019cdf0e10cSrcweir 						aDBFormat.xFormatter = pImpl->pMergeData->xFormatter;
1020cdf0e10cSrcweir 						aDBFormat.aNullDate = pImpl->pMergeData->aNullDate;
1021cdf0e10cSrcweir 						sAddress = GetDBField( xColumnProp,	aDBFormat);
1022cdf0e10cSrcweir 						if (!sAddress.Len())
1023cdf0e10cSrcweir 							sAddress = '_';
1024cdf0e10cSrcweir 						sPath += sAddress;
1025cdf0e10cSrcweir 					}
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir                     // create a new temporary file name - only done once in case of bCreateSingleFile
1028cdf0e10cSrcweir                     if( 1 == nDocNo || (!rMergeDescriptor.bCreateSingleFile && !bAsSingleFile) )
1029cdf0e10cSrcweir                     {
1030cdf0e10cSrcweir                         INetURLObject aEntry(sPath);
1031cdf0e10cSrcweir                         String sLeading;
1032cdf0e10cSrcweir                         //#i97667# if the name is from a database field then it will be used _as is_
1033cdf0e10cSrcweir                         if( sAddress.Len() )
1034cdf0e10cSrcweir                             sLeading = sAddress;
1035cdf0e10cSrcweir                         else
1036cdf0e10cSrcweir                             sLeading = aEntry.GetBase();
1037cdf0e10cSrcweir                         aEntry.removeSegment();
1038cdf0e10cSrcweir                         sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
1039cdf0e10cSrcweir                         String sExt( pStoreToFilter->GetDefaultExtension() );
1040cdf0e10cSrcweir                         sExt.EraseLeadingChars('*');
1041cdf0e10cSrcweir                         aTempFile = std::auto_ptr< utl::TempFile >(
1042cdf0e10cSrcweir                                 new utl::TempFile(sLeading,&sExt,&sPath ));
1043cdf0e10cSrcweir                         if( bAsSingleFile )
1044cdf0e10cSrcweir                             aTempFile->EnableKillingFile();
1045cdf0e10cSrcweir                     }
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir                     if( !aTempFile->IsValid() )
1048cdf0e10cSrcweir 					{
1049cdf0e10cSrcweir 						ErrorHandler::HandleError( ERRCODE_IO_NOTSUPPORTED );
1050cdf0e10cSrcweir 						bLoop = sal_False;
1051cdf0e10cSrcweir 						bCancel = sal_True;
1052cdf0e10cSrcweir 					}
1053cdf0e10cSrcweir 					else
1054cdf0e10cSrcweir 					{
1055cdf0e10cSrcweir                         INetURLObject aTempFileURL(aTempFile->GetURL());
1056cdf0e10cSrcweir                         aPrtMonDlg.aPrinter.SetText( aTempFileURL.GetBase() );
1057cdf0e10cSrcweir 						String sStat(SW_RES(STR_STATSTR_LETTER));	// Brief
1058cdf0e10cSrcweir 						sStat += ' ';
1059cdf0e10cSrcweir 						sStat += String::CreateFromInt32( nDocNo );
1060cdf0e10cSrcweir 						aPrtMonDlg.aPrintInfo.SetText(sStat);
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 						// Rechenzeit fuer Save-Monitor:
1063cdf0e10cSrcweir 						for (sal_uInt16 i = 0; i < 10; i++)
1064cdf0e10cSrcweir 							Application::Reschedule();
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 						// Create and save new document
1067cdf0e10cSrcweir                         // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
1068cdf0e10cSrcweir                         SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
1069cdf0e10cSrcweir                         SfxMedium* pWorkMed = new SfxMedium( sSourceDocumentURL, STREAM_STD_READ, sal_True );
1070cdf0e10cSrcweir                         pWorkMed->SetFilter( pSfxFlt );
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir                         if (xWorkDocSh->DoLoad(pWorkMed))
1073cdf0e10cSrcweir 						{
1074cdf0e10cSrcweir                             //create a view frame for the document
1075cdf0e10cSrcweir                             SfxViewFrame* pWorkFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 );
1076cdf0e10cSrcweir                             //request the layout calculation
1077cdf0e10cSrcweir                             SwWrtShell& rWorkShell =
1078cdf0e10cSrcweir                                     static_cast< SwView* >(pWorkFrame->GetViewShell())->GetWrtShell();
1079cdf0e10cSrcweir                             rWorkShell.CalcLayout();
1080cdf0e10cSrcweir                             SwDoc* pWorkDoc = ((SwDocShell*)(&xWorkDocSh))->GetDoc();
1081cdf0e10cSrcweir                             SwNewDBMgr* pOldDBMgr = pWorkDoc->GetNewDBMgr();
1082cdf0e10cSrcweir                             pWorkDoc->SetNewDBMgr( this );
1083cdf0e10cSrcweir                             SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE), xWorkDocSh));
1084cdf0e10cSrcweir                             pWorkDoc->UpdateFlds(NULL, false);
1085cdf0e10cSrcweir                             SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE_FINISHED), xWorkDocSh));
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 							// alle versteckten Felder/Bereiche entfernen
1088cdf0e10cSrcweir                             pWorkDoc->RemoveInvisibleContent();
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir                             // launch MailMergeEvent if required
1091cdf0e10cSrcweir                             const SwXMailMerge *pEvtSrc = GetMailMergeEvtSrc();
1092cdf0e10cSrcweir                             if(pEvtSrc)
1093cdf0e10cSrcweir                             {
1094cdf0e10cSrcweir                                 uno::Reference< XInterface > xRef( (XMailMergeBroadcaster *) pEvtSrc );
1095cdf0e10cSrcweir                                 text::MailMergeEvent aEvt( xRef, xWorkDocSh->GetModel() );
1096cdf0e10cSrcweir                                 pEvtSrc->LaunchMailMergeEvent( aEvt );
1097cdf0e10cSrcweir                             }
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir                             if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile )
1100cdf0e10cSrcweir                             {
1101cdf0e10cSrcweir                                 DBG_ASSERT( pTargetShell, "no target shell available!" );
1102cdf0e10cSrcweir                                 // copy created file into the target document
1103cdf0e10cSrcweir                                 rWorkShell.ConvertFieldsToText();
1104cdf0e10cSrcweir                                 rWorkShell.SetNumberingRestart();
1105cdf0e10cSrcweir                                 if( bSynchronizedDoc )
1106cdf0e10cSrcweir                                 {
1107cdf0e10cSrcweir                                     lcl_RemoveSectionLinks( rWorkShell );
1108cdf0e10cSrcweir                                 }
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir                                 // insert the document into the target document
1111cdf0e10cSrcweir                                 rWorkShell.SttEndDoc(sal_False);
1112cdf0e10cSrcweir                                 rWorkShell.SttEndDoc(sal_True);
1113cdf0e10cSrcweir                                 rWorkShell.SelAll();
1114cdf0e10cSrcweir                                 pTargetShell->SwCrsrShell::SttEndDoc( sal_False );
1115cdf0e10cSrcweir                                 //#i72517# the headers and footers are still those from the source - update in case of fields inside header/footer
1116cdf0e10cSrcweir                                 if( !nDocNo && bPageStylesWithHeaderFooter )
1117cdf0e10cSrcweir                                     pTargetShell->GetView().GetDocShell()->_LoadStyles( *rWorkShell.GetView().GetDocShell(), sal_True );
1118cdf0e10cSrcweir                                 //#i72517# put the styles to the target document
1119cdf0e10cSrcweir                                 //if the source uses headers or footers each new copy need to copy a new page styles
1120cdf0e10cSrcweir                                 if(bPageStylesWithHeaderFooter)
1121cdf0e10cSrcweir                                 {
1122cdf0e10cSrcweir                                     //create a new pagestyle
1123cdf0e10cSrcweir                                     //copy the pagedesc from the current document to the new document and change the name of the to-be-applied style
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir                                     SwDoc* pTargetDoc = pTargetShell->GetDoc();
1126cdf0e10cSrcweir                                     SwPageDesc* pSourcePageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
1127cdf0e10cSrcweir                                     String sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
1128cdf0e10cSrcweir                                     pTargetDoc->MakePageDesc( sNewPageDescName );
1129cdf0e10cSrcweir                                     SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
1130cdf0e10cSrcweir                                     if(pSourcePageDesc && pTargetPageDesc)
1131cdf0e10cSrcweir                                     {
1132cdf0e10cSrcweir                                         pTargetDoc->CopyPageDesc( *pSourcePageDesc, *pTargetPageDesc, sal_False );
1133cdf0e10cSrcweir                                         sModifiedStartingPageDesc = sNewPageDescName;
1134cdf0e10cSrcweir                                         lcl_CopyFollowPageDesc( *pTargetShell, *pSourcePageDesc, *pTargetPageDesc, nDocNo );
1135cdf0e10cSrcweir                                     }
1136cdf0e10cSrcweir                                 }
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir                                 if(nDocNo > 1)
1139cdf0e10cSrcweir                                     pTargetShell->InsertPageBreak( &sModifiedStartingPageDesc, nStartingPageNo );
1140cdf0e10cSrcweir                                 else
1141cdf0e10cSrcweir                                     pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
1142cdf0e10cSrcweir                                 DBG_ASSERT(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
1143cdf0e10cSrcweir                                 //#i51359# add a second paragraph in case there's only one
1144cdf0e10cSrcweir                                 {
1145cdf0e10cSrcweir                                     SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
1146cdf0e10cSrcweir                                     SwPosition aTestPos( aIdx );
1147cdf0e10cSrcweir                                     SwCursor aTestCrsr(aTestPos,0,false);
1148cdf0e10cSrcweir                                     if(!aTestCrsr.MovePara(fnParaNext, fnParaStart))
1149cdf0e10cSrcweir                                     {
1150cdf0e10cSrcweir                                         //append a paragraph
1151cdf0e10cSrcweir                                         pWorkDoc->AppendTxtNode( aTestPos );
1152cdf0e10cSrcweir                                     }
1153cdf0e10cSrcweir                                 }
1154cdf0e10cSrcweir                                 pTargetShell->Paste( rWorkShell.GetDoc(), sal_True );
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir                                 //convert fields in page styles (header/footer - has to be done after the first document has been pasted
1157cdf0e10cSrcweir                                 if(1 == nDocNo)
1158cdf0e10cSrcweir                                 {
1159cdf0e10cSrcweir                                     pTargetShell->CalcLayout();
1160cdf0e10cSrcweir                                     pTargetShell->ConvertFieldsToText();
1161cdf0e10cSrcweir                                 }
1162cdf0e10cSrcweir                             }
1163cdf0e10cSrcweir                             else
1164cdf0e10cSrcweir                             {
1165cdf0e10cSrcweir                                 String sFileURL =  aTempFileURL.GetMainURL( INetURLObject::NO_DECODE );
1166cdf0e10cSrcweir                                 SfxMedium* pDstMed = new SfxMedium(
1167cdf0e10cSrcweir                                     sFileURL,
1168cdf0e10cSrcweir                                     STREAM_STD_READWRITE, sal_True );
1169cdf0e10cSrcweir                                 pDstMed->SetFilter( pStoreToFilter );
1170cdf0e10cSrcweir                                 if(pDstMed->GetItemSet())
1171cdf0e10cSrcweir                                 {
1172cdf0e10cSrcweir                                     if(pStoreToFilterOptions )
1173cdf0e10cSrcweir                                         pDstMed->GetItemSet()->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, *pStoreToFilterOptions));
1174cdf0e10cSrcweir                                     if(rMergeDescriptor.aSaveToFilterData.getLength())
1175cdf0e10cSrcweir                                         pDstMed->GetItemSet()->Put(SfxUsrAnyItem(SID_FILTER_DATA, makeAny(rMergeDescriptor.aSaveToFilterData)));
1176cdf0e10cSrcweir                                 }
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir                                 //convert fields to text if we are exporting to PDF
1179cdf0e10cSrcweir                                 //this prevents a second merge while updating the fields in SwXTextDocument::getRendererCount()
1180cdf0e10cSrcweir                                 if( pStoreToFilter && pStoreToFilter->GetFilterName().EqualsAscii("writer_pdf_Export"))
1181cdf0e10cSrcweir                                     rWorkShell.ConvertFieldsToText();
1182cdf0e10cSrcweir                                 xWorkDocSh->DoSaveAs(*pDstMed);
1183cdf0e10cSrcweir                                 xWorkDocSh->DoSaveCompleted(pDstMed);
1184cdf0e10cSrcweir                                 if( xWorkDocSh->GetError() )
1185cdf0e10cSrcweir                                 {
1186cdf0e10cSrcweir                                     // error message ??
1187cdf0e10cSrcweir                                     ErrorHandler::HandleError( xWorkDocSh->GetError() );
1188cdf0e10cSrcweir                                     bCancel = sal_True;
1189cdf0e10cSrcweir                                     bLoop = sal_False;
1190cdf0e10cSrcweir                                 }
1191cdf0e10cSrcweir                                 if( bEMail )
1192cdf0e10cSrcweir                                 {
1193cdf0e10cSrcweir                                     SwDBFormatData aDBFormat;
1194cdf0e10cSrcweir                                     aDBFormat.xFormatter = pImpl->pMergeData->xFormatter;
1195cdf0e10cSrcweir                                     aDBFormat.aNullDate = pImpl->pMergeData->aNullDate;
1196cdf0e10cSrcweir                                     String sMailAddress = GetDBField( xColumnProp, aDBFormat);
1197cdf0e10cSrcweir                                     if(!SwMailMergeHelper::CheckMailAddress( sMailAddress ))
1198cdf0e10cSrcweir                                     {
1199cdf0e10cSrcweir                                         DBG_ERROR("invalid e-Mail address in database column");
1200cdf0e10cSrcweir                                     }
1201cdf0e10cSrcweir                                     else
1202cdf0e10cSrcweir                                     {
1203cdf0e10cSrcweir                                         SwMailMessage* pMessage = 0;
1204cdf0e10cSrcweir                                         uno::Reference< mail::XMailMessage > xMessage =
1205cdf0e10cSrcweir                                                                 pMessage = new SwMailMessage;
1206cdf0e10cSrcweir                                         if(rMergeDescriptor.pMailMergeConfigItem->IsMailReplyTo())
1207cdf0e10cSrcweir                                             pMessage->setReplyToAddress(rMergeDescriptor.pMailMergeConfigItem->GetMailReplyTo());
1208cdf0e10cSrcweir                                         pMessage->addRecipient( sMailAddress );
1209cdf0e10cSrcweir                                         pMessage->SetSenderAddress( rMergeDescriptor.pMailMergeConfigItem->GetMailAddress() );
1210cdf0e10cSrcweir                                         ::rtl::OUString sBody;
1211cdf0e10cSrcweir                                         if(rMergeDescriptor.bSendAsAttachment)
1212cdf0e10cSrcweir                                         {
1213cdf0e10cSrcweir                                             sBody = rMergeDescriptor.sMailBody;
1214cdf0e10cSrcweir                                             mail::MailAttachment aAttach;
1215cdf0e10cSrcweir                                             aAttach.Data = new SwMailTransferable(
1216cdf0e10cSrcweir                                                     sFileURL,
1217cdf0e10cSrcweir                                                     rMergeDescriptor.sAttachmentName,
1218cdf0e10cSrcweir                                                     pStoreToFilter->GetMimeType());
1219cdf0e10cSrcweir                                             aAttach.ReadableName = rMergeDescriptor.sAttachmentName;
1220cdf0e10cSrcweir                                             pMessage->addAttachment( aAttach );
1221cdf0e10cSrcweir                                         }
1222cdf0e10cSrcweir                                         else
1223cdf0e10cSrcweir                                         {
1224cdf0e10cSrcweir                                             {
1225cdf0e10cSrcweir                                                 //read in the temporary file and use it as mail body
1226cdf0e10cSrcweir                                                 SfxMedium aMedium( sFileURL, STREAM_READ, sal_True);
1227cdf0e10cSrcweir                                                 SvStream* pInStream = aMedium.GetInStream();
1228cdf0e10cSrcweir                                                 DBG_ASSERT(pInStream, "no output file created?");
1229cdf0e10cSrcweir                                                 if(pInStream)
1230cdf0e10cSrcweir                                                 {
1231cdf0e10cSrcweir                                                     pInStream->SetStreamCharSet( eEncoding );
1232cdf0e10cSrcweir                                                     ByteString sLine;
1233cdf0e10cSrcweir                                                     sal_Bool bDone = pInStream->ReadLine( sLine );
1234cdf0e10cSrcweir                                                     while ( bDone )
1235cdf0e10cSrcweir                                                     {
1236cdf0e10cSrcweir                                                         sBody += String(sLine, eEncoding);
1237cdf0e10cSrcweir                                                         sBody += ::rtl::OUString('\n');
1238cdf0e10cSrcweir                                                         bDone = pInStream->ReadLine( sLine );
1239cdf0e10cSrcweir                                                     }
1240cdf0e10cSrcweir                                                 }
1241cdf0e10cSrcweir                                             }
1242cdf0e10cSrcweir                                         }
1243cdf0e10cSrcweir                                         pMessage->setSubject( rMergeDescriptor.sSubject );
1244cdf0e10cSrcweir                                         uno::Reference< datatransfer::XTransferable> xBody =
1245cdf0e10cSrcweir                                                     new SwMailTransferable(
1246cdf0e10cSrcweir                                                         sBody,
1247cdf0e10cSrcweir                                                         sBodyMimeType);
1248cdf0e10cSrcweir                                         pMessage->setBody( xBody );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir                                         if(rMergeDescriptor.aCopiesTo.getLength())
1251cdf0e10cSrcweir                                         {
1252cdf0e10cSrcweir                                             const ::rtl::OUString* pCopies = rMergeDescriptor.aCopiesTo.getConstArray();
1253cdf0e10cSrcweir                                             for( sal_Int32 nToken = 0; nToken < rMergeDescriptor.aCopiesTo.getLength(); ++nToken)
1254cdf0e10cSrcweir                                                 pMessage->addCcRecipient( pCopies[nToken] );
1255cdf0e10cSrcweir                                         }
1256cdf0e10cSrcweir                                         if(rMergeDescriptor.aBlindCopiesTo.getLength())
1257cdf0e10cSrcweir                                         {
1258cdf0e10cSrcweir                                             const ::rtl::OUString* pCopies = rMergeDescriptor.aBlindCopiesTo.getConstArray();
1259cdf0e10cSrcweir                                             for( sal_Int32 nToken = 0; nToken < rMergeDescriptor.aBlindCopiesTo.getLength(); ++nToken)
1260cdf0e10cSrcweir                                                 pMessage->addBccRecipient( pCopies[nToken] );
1261cdf0e10cSrcweir                                         }
1262cdf0e10cSrcweir                                         xMailDispatcher->enqueueMailMessage( xMessage );
1263cdf0e10cSrcweir                                         if(!xMailDispatcher->isStarted())
1264cdf0e10cSrcweir                                                 xMailDispatcher->start();
1265cdf0e10cSrcweir                                         //schedule for removal
1266cdf0e10cSrcweir                                         aFilesToRemove.push_back(sFileURL);
1267cdf0e10cSrcweir                                     }
1268cdf0e10cSrcweir                                 }
1269cdf0e10cSrcweir                             }
1270cdf0e10cSrcweir                             pWorkDoc->SetNewDBMgr( pOldDBMgr );
1271cdf0e10cSrcweir 						}
1272cdf0e10cSrcweir                         xWorkDocSh->DoClose();
1273cdf0e10cSrcweir 					}
1274cdf0e10cSrcweir 				}
1275cdf0e10cSrcweir                 nDocNo++;
1276cdf0e10cSrcweir                 nEndRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0;
1277cdf0e10cSrcweir             } while( !bCancel &&
1278cdf0e10cSrcweir                 (bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir             aPrtMonDlg.Show( sal_False );
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir             // save the single output document
1283cdf0e10cSrcweir             if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile)
1284cdf0e10cSrcweir             {
1285cdf0e10cSrcweir                 if( rMergeDescriptor.nMergeType != DBMGR_MERGE_MAILMERGE )
1286cdf0e10cSrcweir                 {
1287cdf0e10cSrcweir                     DBG_ASSERT( aTempFile.get(), "Temporary file not available" );
1288cdf0e10cSrcweir                     INetURLObject aTempFileURL(bAsSingleFile ? sSubject : aTempFile->GetURL());
1289cdf0e10cSrcweir                     SfxMedium* pDstMed = new SfxMedium(
1290cdf0e10cSrcweir                         aTempFileURL.GetMainURL( INetURLObject::NO_DECODE ),
1291cdf0e10cSrcweir                         STREAM_STD_READWRITE, sal_True );
1292cdf0e10cSrcweir                     pDstMed->SetFilter( pStoreToFilter );
1293cdf0e10cSrcweir                     if(pDstMed->GetItemSet())
1294cdf0e10cSrcweir                     {
1295cdf0e10cSrcweir                         if(pStoreToFilterOptions )
1296cdf0e10cSrcweir                             pDstMed->GetItemSet()->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, *pStoreToFilterOptions));
1297cdf0e10cSrcweir                         if(rMergeDescriptor.aSaveToFilterData.getLength())
1298cdf0e10cSrcweir                             pDstMed->GetItemSet()->Put(SfxUsrAnyItem(SID_FILTER_DATA, makeAny(rMergeDescriptor.aSaveToFilterData)));
1299cdf0e10cSrcweir                     }
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir                     xTargetDocShell->DoSaveAs(*pDstMed);
1302cdf0e10cSrcweir                     xTargetDocShell->DoSaveCompleted(pDstMed);
1303cdf0e10cSrcweir                     if( xTargetDocShell->GetError() )
1304cdf0e10cSrcweir                     {
1305cdf0e10cSrcweir                         // error message ??
1306cdf0e10cSrcweir                         ErrorHandler::HandleError( xTargetDocShell->GetError() );
1307cdf0e10cSrcweir                         bLoop = sal_False;
1308cdf0e10cSrcweir                     }
1309cdf0e10cSrcweir                 }
1310cdf0e10cSrcweir                 else if( pTargetView ) // must be available!
1311cdf0e10cSrcweir                 {
1312cdf0e10cSrcweir                     //print the target document
1313cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 1
1314cdf0e10cSrcweir                     sal_Bool  _bVal;
1315cdf0e10cSrcweir                     sal_Int16 _nVal;
1316cdf0e10cSrcweir                     rtl::OUString  _sVal;
1317cdf0e10cSrcweir                     const beans::PropertyValue* pDbgPrintOptions = rMergeDescriptor.aPrintOptions.getConstArray();
1318cdf0e10cSrcweir                     for( sal_Int32 nOption = 0; nOption < rMergeDescriptor.aPrintOptions.getLength(); ++nOption)
1319cdf0e10cSrcweir                     {
1320cdf0e10cSrcweir                         rtl::OUString aName( pDbgPrintOptions[nOption].Name );
1321cdf0e10cSrcweir                         uno::Any aVal( pDbgPrintOptions[nOption].Value );
1322cdf0e10cSrcweir                         aVal >>= _bVal;
1323cdf0e10cSrcweir                         aVal >>= _nVal;
1324cdf0e10cSrcweir                         aVal >>= _sVal;
1325cdf0e10cSrcweir                     }
1326cdf0e10cSrcweir         #endif
1327cdf0e10cSrcweir                     // printing should be done synchronously otherwise the document
1328cdf0e10cSrcweir                     // might already become invalid during the process
1329cdf0e10cSrcweir                     uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.aPrintOptions );
1330cdf0e10cSrcweir                     const sal_Int32 nOpts = aOptions.getLength();
1331cdf0e10cSrcweir                     aOptions.realloc( nOpts + 1 );
1332cdf0e10cSrcweir                     aOptions[ nOpts ].Name = rtl::OUString::createFromAscii( "Wait" );
1333cdf0e10cSrcweir                     aOptions[ nOpts ].Value <<= sal_True ;
1334cdf0e10cSrcweir //                    aPrintArgs.Put(SfxBoolItem(FN_QRY_MERGE, sal_True) );
1335cdf0e10cSrcweir //                    // #i52629# aynchronous printing should only be done in silent mode - otherwise
1336cdf0e10cSrcweir //                    // the printer dialog does not come up
1337cdf0e10cSrcweir //                    aPrintArgs.Put( SfxBoolItem( SID_ASYNCHRON, rMergeDescriptor.bPrintAsync ));
1338cdf0e10cSrcweir                     // move print options
1339cdf0e10cSrcweir                     const beans::PropertyValue* pPrintOptions = rMergeDescriptor.aPrintOptions.getConstArray();
1340cdf0e10cSrcweir                     for( sal_Int32 nOption = 0; nOption < rMergeDescriptor.aPrintOptions.getLength(); ++nOption)
1341cdf0e10cSrcweir                     {
1342cdf0e10cSrcweir                         if( pPrintOptions[nOption].Name.equalsAscii( "CopyCount" )
1343cdf0e10cSrcweir                             ||( pPrintOptions[nOption].Name.equalsAscii( "FileName" ))
1344cdf0e10cSrcweir                             ||( pPrintOptions[nOption].Name.equalsAscii( "Collate" ))
1345cdf0e10cSrcweir                             ||( pPrintOptions[nOption].Name.equalsAscii( "Pages" ))
1346cdf0e10cSrcweir                             ||( pPrintOptions[nOption].Name.equalsAscii( "Wait" )))
1347cdf0e10cSrcweir                         {
1348cdf0e10cSrcweir                             aOptions.realloc( nOpts + 1 );
1349cdf0e10cSrcweir                             aOptions[ nOpts ].Name = pPrintOptions[nOption].Name;
1350cdf0e10cSrcweir                             aOptions[ nOpts ].Value = pPrintOptions[nOption].Value ;
1351cdf0e10cSrcweir                         }
1352cdf0e10cSrcweir                     }
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir //                    const SwModuleOptions * pModOpt = SW_MOD()->GetModuleConfig();
1355cdf0e10cSrcweir //                    if (pModOpt->IsSinglePrintJob())
1356cdf0e10cSrcweir //                    {
1357cdf0e10cSrcweir //                    }
1358cdf0e10cSrcweir //                    else
1359cdf0e10cSrcweir //                    {
1360cdf0e10cSrcweir                         pTargetView->ExecPrint( aOptions, IsMergeSilent(), rMergeDescriptor.bPrintAsync );
1361cdf0e10cSrcweir //                    }
1362cdf0e10cSrcweir                 }
1363cdf0e10cSrcweir                 xTargetDocShell->DoClose();
1364cdf0e10cSrcweir             }
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir             //remove the temporary files
1367cdf0e10cSrcweir             ::std::vector<String>::iterator aFileIter;
1368cdf0e10cSrcweir             for(aFileIter = aFilesToRemove.begin();
1369cdf0e10cSrcweir                         aFileIter != aFilesToRemove.end(); aFileIter++)
1370cdf0e10cSrcweir                 SWUnoHelper::UCB_DeleteFile( *aFileIter );
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir             // Alle Dispatcher freigeben
1373cdf0e10cSrcweir             pViewFrm = SfxViewFrame::GetFirst(pSourrceDocSh);
1374cdf0e10cSrcweir 			while (pViewFrm)
1375cdf0e10cSrcweir 			{
1376cdf0e10cSrcweir 				pViewFrm->GetDispatcher()->Lock(sal_False);
1377cdf0e10cSrcweir                 pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pSourrceDocSh);
1378cdf0e10cSrcweir 			}
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir             SW_MOD()->SetView(&pSourceShell->GetView());
1381cdf0e10cSrcweir 		}
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir 		nMergeType = DBMGR_INSERT;
1384cdf0e10cSrcweir 	}
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir     if(bEMail)
1387cdf0e10cSrcweir     {
1388cdf0e10cSrcweir         xMailDispatcher->stop();
1389cdf0e10cSrcweir         xMailDispatcher->shutdown();
1390cdf0e10cSrcweir 
1391cdf0e10cSrcweir     }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir     return bLoop;
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir /*--------------------------------------------------------------------
1397cdf0e10cSrcweir 	Beschreibung:
1398cdf0e10cSrcweir   --------------------------------------------------------------------*/
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir IMPL_LINK_INLINE_START( SwNewDBMgr, PrtCancelHdl, Button *, pButton )
1401cdf0e10cSrcweir {
1402cdf0e10cSrcweir 	pButton->GetParent()->Hide();
1403cdf0e10cSrcweir 	bCancel = sal_True;
1404cdf0e10cSrcweir 	return 0;
1405cdf0e10cSrcweir }
1406cdf0e10cSrcweir IMPL_LINK_INLINE_END( SwNewDBMgr, PrtCancelHdl, Button *, pButton )
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir /*--------------------------------------------------------------------
1410cdf0e10cSrcweir 	Beschreibung: Numberformat der Spalte ermitteln und ggfs. in
1411cdf0e10cSrcweir 					den uebergebenen Formatter uebertragen
1412cdf0e10cSrcweir   --------------------------------------------------------------------*/
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir sal_uLong SwNewDBMgr::GetColumnFmt( const String& rDBName,
1415cdf0e10cSrcweir 								const String& rTableName,
1416cdf0e10cSrcweir 								const String& rColNm,
1417cdf0e10cSrcweir 								SvNumberFormatter* pNFmtr,
1418cdf0e10cSrcweir 								long nLanguage )
1419cdf0e10cSrcweir {
1420cdf0e10cSrcweir 	sal_uLong nRet = 0;
1421cdf0e10cSrcweir 	if(pNFmtr)
1422cdf0e10cSrcweir 	{
1423cdf0e10cSrcweir         uno::Reference< XDataSource> xSource;
1424cdf0e10cSrcweir         uno::Reference< XConnection> xConnection;
1425cdf0e10cSrcweir         sal_Bool bUseMergeData = sal_False;
1426cdf0e10cSrcweir         uno::Reference< XColumnsSupplier> xColsSupp;
1427cdf0e10cSrcweir         bool bDisposeConnection = false;
1428cdf0e10cSrcweir         if(pImpl->pMergeData &&
1429cdf0e10cSrcweir             pImpl->pMergeData->sDataSource.equals(rDBName) && pImpl->pMergeData->sCommand.equals(rTableName))
1430cdf0e10cSrcweir 		{
1431cdf0e10cSrcweir             xConnection = pImpl->pMergeData->xConnection;
1432cdf0e10cSrcweir             xSource = SwNewDBMgr::getDataSourceAsParent(xConnection,rDBName);
1433cdf0e10cSrcweir             bUseMergeData = sal_True;
1434cdf0e10cSrcweir             xColsSupp = xColsSupp.query( pImpl->pMergeData->xResultSet );
1435cdf0e10cSrcweir 		}
1436cdf0e10cSrcweir         if(!xConnection.is())
1437cdf0e10cSrcweir         {
1438cdf0e10cSrcweir             SwDBData aData;
1439cdf0e10cSrcweir             aData.sDataSource = rDBName;
1440cdf0e10cSrcweir             aData.sCommand = rTableName;
1441cdf0e10cSrcweir             aData.nCommandType = -1;
1442cdf0e10cSrcweir             SwDSParam* pParam = FindDSData(aData, sal_False);
1443cdf0e10cSrcweir             if(pParam && pParam->xConnection.is())
1444cdf0e10cSrcweir             {
1445cdf0e10cSrcweir                 xConnection = pParam->xConnection;
1446cdf0e10cSrcweir                 xColsSupp = xColsSupp.query( pParam->xResultSet );
1447cdf0e10cSrcweir             }
1448cdf0e10cSrcweir             else
1449cdf0e10cSrcweir             {
1450cdf0e10cSrcweir                 rtl::OUString sDBName(rDBName);
1451cdf0e10cSrcweir                 xConnection = RegisterConnection( sDBName );
1452cdf0e10cSrcweir                 bDisposeConnection = true;
1453cdf0e10cSrcweir             }
1454cdf0e10cSrcweir             if(bUseMergeData)
1455cdf0e10cSrcweir                 pImpl->pMergeData->xConnection = xConnection;
1456cdf0e10cSrcweir         }
1457cdf0e10cSrcweir         bool bDispose = !xColsSupp.is();
1458cdf0e10cSrcweir         if(bDispose)
1459cdf0e10cSrcweir         {
1460cdf0e10cSrcweir             xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
1461cdf0e10cSrcweir         }
1462cdf0e10cSrcweir 		if(xColsSupp.is())
1463cdf0e10cSrcweir 		{
1464cdf0e10cSrcweir             uno::Reference<XNameAccess> xCols;
1465cdf0e10cSrcweir             try
1466cdf0e10cSrcweir             {
1467cdf0e10cSrcweir                 xCols = xColsSupp->getColumns();
1468cdf0e10cSrcweir             }
1469cdf0e10cSrcweir             catch(Exception&)
1470cdf0e10cSrcweir             {
1471cdf0e10cSrcweir                 DBG_ERROR("Exception in getColumns()");
1472cdf0e10cSrcweir             }
1473cdf0e10cSrcweir             if(!xCols.is() || !xCols->hasByName(rColNm))
1474cdf0e10cSrcweir 				return nRet;
1475cdf0e10cSrcweir 			Any aCol = xCols->getByName(rColNm);
1476cdf0e10cSrcweir             uno::Reference< XPropertySet > xColumn;
1477cdf0e10cSrcweir             aCol >>= xColumn;
1478cdf0e10cSrcweir             nRet = GetColumnFmt(xSource, xConnection, xColumn, pNFmtr, nLanguage);
1479cdf0e10cSrcweir             if(bDispose)
1480cdf0e10cSrcweir             {
1481cdf0e10cSrcweir                 ::comphelper::disposeComponent( xColsSupp );
1482cdf0e10cSrcweir             }
1483cdf0e10cSrcweir             if(bDisposeConnection)
1484cdf0e10cSrcweir             {
1485cdf0e10cSrcweir                 ::comphelper::disposeComponent( xConnection );
1486cdf0e10cSrcweir             }
1487cdf0e10cSrcweir         }
1488cdf0e10cSrcweir         else
1489cdf0e10cSrcweir 			nRet = pNFmtr->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM );
1490cdf0e10cSrcweir 	}
1491cdf0e10cSrcweir 	return nRet;
1492cdf0e10cSrcweir }
1493cdf0e10cSrcweir /* -----------------------------07.06.01 15:43--------------------------------
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1496cdf0e10cSrcweir sal_uLong SwNewDBMgr::GetColumnFmt( uno::Reference< XDataSource> xSource,
1497cdf0e10cSrcweir                         uno::Reference< XConnection> xConnection,
1498cdf0e10cSrcweir                         uno::Reference< XPropertySet> xColumn,
1499cdf0e10cSrcweir 						SvNumberFormatter* pNFmtr,
1500cdf0e10cSrcweir                         long nLanguage )
1501cdf0e10cSrcweir {
1502cdf0e10cSrcweir 	//JP 12.01.99: ggfs. das NumberFormat im Doc setzen
1503cdf0e10cSrcweir 	sal_uLong nRet = 0;
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir     if(!xSource.is())
1506cdf0e10cSrcweir     {
1507cdf0e10cSrcweir         uno::Reference<XChild> xChild(xConnection, UNO_QUERY);
1508cdf0e10cSrcweir         if ( xChild.is() )
1509cdf0e10cSrcweir             xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
1510cdf0e10cSrcweir     }
1511cdf0e10cSrcweir     if(xSource.is() && xConnection.is() && xColumn.is() && pNFmtr)
1512cdf0e10cSrcweir 	{
1513cdf0e10cSrcweir 		SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNFmtr );
1514cdf0e10cSrcweir         uno::Reference< util::XNumberFormatsSupplier >  xDocNumFmtsSupplier = pNumFmt;
1515cdf0e10cSrcweir         uno::Reference< XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
1516cdf0e10cSrcweir         uno::Reference< XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir 		Locale aLocale( MsLangId::convertLanguageToLocale( (LanguageType)nLanguage ));
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir 		//get the number formatter of the data source
1521cdf0e10cSrcweir         uno::Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1522cdf0e10cSrcweir         uno::Reference< XNumberFormats > xNumberFormats;
1523cdf0e10cSrcweir 		if(xSourceProps.is())
1524cdf0e10cSrcweir 		{
1525cdf0e10cSrcweir 			Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
1526cdf0e10cSrcweir 			if(aFormats.hasValue())
1527cdf0e10cSrcweir 			{
1528cdf0e10cSrcweir                 uno::Reference<XNumberFormatsSupplier> xSuppl;
1529cdf0e10cSrcweir                 aFormats >>= xSuppl;
1530cdf0e10cSrcweir 				if(xSuppl.is())
1531cdf0e10cSrcweir 				{
1532cdf0e10cSrcweir 					xNumberFormats = xSuppl->getNumberFormats();
1533cdf0e10cSrcweir 				}
1534cdf0e10cSrcweir 			}
1535cdf0e10cSrcweir 		}
1536cdf0e10cSrcweir         bool bUseDefault = true;
1537cdf0e10cSrcweir         try
1538cdf0e10cSrcweir         {
1539cdf0e10cSrcweir             Any aFormatKey = xColumn->getPropertyValue(C2U("FormatKey"));
1540cdf0e10cSrcweir             if(aFormatKey.hasValue())
1541cdf0e10cSrcweir             {
1542cdf0e10cSrcweir                 sal_Int32 nFmt = 0;
1543cdf0e10cSrcweir                 aFormatKey >>= nFmt;
1544cdf0e10cSrcweir                 if(xNumberFormats.is())
1545cdf0e10cSrcweir                 {
1546cdf0e10cSrcweir                     try
1547cdf0e10cSrcweir                     {
1548cdf0e10cSrcweir                         uno::Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
1549cdf0e10cSrcweir                         Any aFormatString = xNumProps->getPropertyValue(C2U("FormatString"));
1550cdf0e10cSrcweir                         Any aLocaleVal = xNumProps->getPropertyValue(C2U("Locale"));
1551cdf0e10cSrcweir                         rtl::OUString sFormat;
1552cdf0e10cSrcweir                         aFormatString >>= sFormat;
1553cdf0e10cSrcweir                         lang::Locale aLoc;
1554cdf0e10cSrcweir                         aLocaleVal >>= aLoc;
1555cdf0e10cSrcweir                         nFmt = xDocNumberFormats->queryKey( sFormat, aLoc, sal_False );
1556cdf0e10cSrcweir                         if(NUMBERFORMAT_ENTRY_NOT_FOUND == sal::static_int_cast< sal_uInt32, sal_Int32>(nFmt))
1557cdf0e10cSrcweir                             nFmt = xDocNumberFormats->addNew( sFormat, aLoc );
1558cdf0e10cSrcweir                         nRet = nFmt;
1559cdf0e10cSrcweir                         bUseDefault = false;
1560cdf0e10cSrcweir                     }
1561cdf0e10cSrcweir                     catch(const Exception&)
1562cdf0e10cSrcweir                     {
1563cdf0e10cSrcweir                         DBG_ERROR("illegal number format key");
1564cdf0e10cSrcweir                     }
1565cdf0e10cSrcweir                 }
1566cdf0e10cSrcweir             }
1567cdf0e10cSrcweir         }
1568cdf0e10cSrcweir         catch( const Exception& )
1569cdf0e10cSrcweir         {
1570cdf0e10cSrcweir             DBG_ERROR("no FormatKey property found");
1571cdf0e10cSrcweir         }
1572cdf0e10cSrcweir         if(bUseDefault)
1573cdf0e10cSrcweir             nRet = SwNewDBMgr::GetDbtoolsClient().getDefaultNumberFormat(xColumn, xDocNumberFormatTypes,  aLocale);
1574cdf0e10cSrcweir 	}
1575cdf0e10cSrcweir 	return nRet;
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir /* -----------------------------17.07.00 09:47--------------------------------
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1581cdf0e10cSrcweir sal_Int32 SwNewDBMgr::GetColumnType( const String& rDBName,
1582cdf0e10cSrcweir 						  const String& rTableName,
1583cdf0e10cSrcweir 						  const String& rColNm )
1584cdf0e10cSrcweir {
1585cdf0e10cSrcweir 	sal_Int32 nRet = DataType::SQLNULL;
1586cdf0e10cSrcweir     SwDBData aData;
1587cdf0e10cSrcweir     aData.sDataSource = rDBName;
1588cdf0e10cSrcweir     aData.sCommand = rTableName;
1589cdf0e10cSrcweir     aData.nCommandType = -1;
1590cdf0e10cSrcweir     SwDSParam* pParam = FindDSData(aData, sal_False);
1591cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
1592cdf0e10cSrcweir     uno::Reference< XColumnsSupplier > xColsSupp;
1593cdf0e10cSrcweir     bool bDispose = false;
1594cdf0e10cSrcweir     if(pParam && pParam->xConnection.is())
1595cdf0e10cSrcweir     {
1596cdf0e10cSrcweir         xConnection = pParam->xConnection;
1597cdf0e10cSrcweir         xColsSupp = uno::Reference< XColumnsSupplier >( pParam->xResultSet, UNO_QUERY );
1598cdf0e10cSrcweir     }
1599cdf0e10cSrcweir     else
1600cdf0e10cSrcweir     {
1601cdf0e10cSrcweir         rtl::OUString sDBName(rDBName);
1602cdf0e10cSrcweir         xConnection = RegisterConnection( sDBName );
1603cdf0e10cSrcweir     }
1604cdf0e10cSrcweir     if( !xColsSupp.is() )
1605cdf0e10cSrcweir     {
1606cdf0e10cSrcweir         xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
1607cdf0e10cSrcweir         bDispose = true;
1608cdf0e10cSrcweir     }
1609cdf0e10cSrcweir 	if(xColsSupp.is())
1610cdf0e10cSrcweir 	{
1611cdf0e10cSrcweir         uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
1612cdf0e10cSrcweir 		if(xCols->hasByName(rColNm))
1613cdf0e10cSrcweir 		{
1614cdf0e10cSrcweir 			Any aCol = xCols->getByName(rColNm);
1615cdf0e10cSrcweir             uno::Reference<XPropertySet> xCol;
1616cdf0e10cSrcweir             aCol >>= xCol;
1617cdf0e10cSrcweir 			Any aType = xCol->getPropertyValue(C2S("Type"));
1618cdf0e10cSrcweir 			aType >>= nRet;
1619cdf0e10cSrcweir 		}
1620cdf0e10cSrcweir         if(bDispose)
1621cdf0e10cSrcweir             ::comphelper::disposeComponent( xColsSupp );
1622cdf0e10cSrcweir     }
1623cdf0e10cSrcweir 	return nRet;
1624cdf0e10cSrcweir }
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir /* -----------------------------03.07.00 17:12--------------------------------
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1629cdf0e10cSrcweir uno::Reference< sdbc::XConnection> SwNewDBMgr::GetConnection(const String& rDataSource,
1630cdf0e10cSrcweir                                                     uno::Reference<XDataSource>& rxSource)
1631cdf0e10cSrcweir {
1632cdf0e10cSrcweir 	Reference< sdbc::XConnection> xConnection;
1633cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1634cdf0e10cSrcweir 	try
1635cdf0e10cSrcweir 	{
1636cdf0e10cSrcweir 		Reference<XCompletedConnection> xComplConnection(SwNewDBMgr::GetDbtoolsClient().getDataSource(rDataSource, xMgr),UNO_QUERY);
1637cdf0e10cSrcweir 		if ( xComplConnection.is() )
1638cdf0e10cSrcweir 		{
1639cdf0e10cSrcweir 			rxSource.set(xComplConnection,UNO_QUERY);
1640cdf0e10cSrcweir 			Reference< XInteractionHandler > xHandler(
1641cdf0e10cSrcweir 					xMgr->createInstance( C2U( "com.sun.star.task.InteractionHandler" )), UNO_QUERY);
1642cdf0e10cSrcweir 				xConnection = xComplConnection->connectWithCompletion( xHandler );
1643cdf0e10cSrcweir 		}
1644cdf0e10cSrcweir 	}
1645cdf0e10cSrcweir 	catch(Exception&) {}
1646cdf0e10cSrcweir 
1647cdf0e10cSrcweir 	return xConnection;
1648cdf0e10cSrcweir }
1649cdf0e10cSrcweir /* -----------------------------03.07.00 17:12--------------------------------
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1652cdf0e10cSrcweir uno::Reference< sdbcx::XColumnsSupplier> SwNewDBMgr::GetColumnSupplier(uno::Reference<sdbc::XConnection> xConnection,
1653cdf0e10cSrcweir 									const String& rTableOrQuery,
1654cdf0e10cSrcweir 									sal_uInt8	eTableOrQuery)
1655cdf0e10cSrcweir {
1656cdf0e10cSrcweir     Reference< sdbcx::XColumnsSupplier> xRet;
1657cdf0e10cSrcweir     try
1658cdf0e10cSrcweir     {
1659cdf0e10cSrcweir         if(eTableOrQuery == SW_DB_SELECT_UNKNOWN)
1660cdf0e10cSrcweir         {
1661cdf0e10cSrcweir             //search for a table with the given command name
1662cdf0e10cSrcweir             Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
1663cdf0e10cSrcweir             if(xTSupplier.is())
1664cdf0e10cSrcweir             {
1665cdf0e10cSrcweir                 Reference<XNameAccess> xTbls = xTSupplier->getTables();
1666cdf0e10cSrcweir                 eTableOrQuery = xTbls->hasByName(rTableOrQuery) ?
1667cdf0e10cSrcweir                             SW_DB_SELECT_TABLE : SW_DB_SELECT_QUERY;
1668cdf0e10cSrcweir             }
1669cdf0e10cSrcweir         }
1670cdf0e10cSrcweir         sal_Int32 nCommandType = SW_DB_SELECT_TABLE == eTableOrQuery ?
1671cdf0e10cSrcweir                 CommandType::TABLE : CommandType::QUERY;
1672cdf0e10cSrcweir         Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1673cdf0e10cSrcweir         Reference<XRowSet> xRowSet(
1674cdf0e10cSrcweir                 xMgr->createInstance(C2U("com.sun.star.sdb.RowSet")), UNO_QUERY);
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir         ::rtl::OUString sDataSource;
1677cdf0e10cSrcweir         Reference<XDataSource> xSource = SwNewDBMgr::getDataSourceAsParent(xConnection, sDataSource);
1678cdf0e10cSrcweir         Reference<XPropertySet> xSourceProperties(xSource, UNO_QUERY);
1679cdf0e10cSrcweir         if(xSourceProperties.is())
1680cdf0e10cSrcweir         {
1681cdf0e10cSrcweir             xSourceProperties->getPropertyValue(C2U("Name")) >>= sDataSource;
1682cdf0e10cSrcweir         }
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir         Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
1685cdf0e10cSrcweir         xRowProperties->setPropertyValue(C2U("DataSourceName"), makeAny(sDataSource));
1686cdf0e10cSrcweir         xRowProperties->setPropertyValue(C2U("Command"), makeAny(::rtl::OUString(rTableOrQuery)));
1687cdf0e10cSrcweir         xRowProperties->setPropertyValue(C2U("CommandType"), makeAny(nCommandType));
1688cdf0e10cSrcweir         xRowProperties->setPropertyValue(C2U("FetchSize"), makeAny((sal_Int32)10));
1689cdf0e10cSrcweir         xRowProperties->setPropertyValue(C2U("ActiveConnection"), makeAny(xConnection));
1690cdf0e10cSrcweir         xRowSet->execute();
1691cdf0e10cSrcweir         xRet = Reference<XColumnsSupplier>( xRowSet, UNO_QUERY );
1692cdf0e10cSrcweir     }
1693cdf0e10cSrcweir     catch( const uno::Exception& )
1694cdf0e10cSrcweir     {
1695cdf0e10cSrcweir         DBG_ERROR("Exception in SwDBMgr::GetColumnSupplier");
1696cdf0e10cSrcweir     }
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     return xRet;
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir /* -----------------------------05.07.00 13:44--------------------------------
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1703cdf0e10cSrcweir String SwNewDBMgr::GetDBField(uno::Reference<XPropertySet> xColumnProps,
1704cdf0e10cSrcweir 						const SwDBFormatData& rDBFormatData,
1705cdf0e10cSrcweir 						double* pNumber)
1706cdf0e10cSrcweir {
1707cdf0e10cSrcweir     uno::Reference< XColumn > xColumn(xColumnProps, UNO_QUERY);
1708cdf0e10cSrcweir 	String sRet;
1709cdf0e10cSrcweir 	DBG_ASSERT(xColumn.is(), "SwNewDBMgr::::ImportDBField: illegal arguments");
1710cdf0e10cSrcweir 	if(!xColumn.is())
1711cdf0e10cSrcweir 		return sRet;
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir 	Any aType = xColumnProps->getPropertyValue(C2U("Type"));
1714cdf0e10cSrcweir 	sal_Int32 eDataType = 0;
1715cdf0e10cSrcweir 	aType >>= eDataType;
1716cdf0e10cSrcweir 	switch(eDataType)
1717cdf0e10cSrcweir 	{
1718cdf0e10cSrcweir 		case DataType::CHAR:
1719cdf0e10cSrcweir 		case DataType::VARCHAR:
1720cdf0e10cSrcweir 		case DataType::LONGVARCHAR:
1721cdf0e10cSrcweir             try
1722cdf0e10cSrcweir             {
1723cdf0e10cSrcweir 			    sRet = xColumn->getString();
1724cdf0e10cSrcweir             }
1725cdf0e10cSrcweir             catch( SQLException& )
1726cdf0e10cSrcweir             {
1727cdf0e10cSrcweir             }
1728cdf0e10cSrcweir 		break;
1729cdf0e10cSrcweir 		case DataType::BIT:
1730cdf0e10cSrcweir 		case DataType::BOOLEAN:
1731cdf0e10cSrcweir 		case DataType::TINYINT:
1732cdf0e10cSrcweir 		case DataType::SMALLINT:
1733cdf0e10cSrcweir 		case DataType::INTEGER:
1734cdf0e10cSrcweir 		case DataType::BIGINT:
1735cdf0e10cSrcweir 		case DataType::FLOAT:
1736cdf0e10cSrcweir 		case DataType::REAL:
1737cdf0e10cSrcweir 		case DataType::DOUBLE:
1738cdf0e10cSrcweir 		case DataType::NUMERIC:
1739cdf0e10cSrcweir 		case DataType::DECIMAL:
1740cdf0e10cSrcweir 		case DataType::DATE:
1741cdf0e10cSrcweir 		case DataType::TIME:
1742cdf0e10cSrcweir 		case DataType::TIMESTAMP:
1743cdf0e10cSrcweir 		{
1744cdf0e10cSrcweir //			::Date aTempDate(rDBFormatData.aNullDate.Day,
1745cdf0e10cSrcweir //				rDBFormatData.aNullDate.Month, rDBFormatData.aNullDate.Year);
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir 			try
1748cdf0e10cSrcweir 			{
1749cdf0e10cSrcweir                 SwDbtoolsClient& aClient = SwNewDBMgr::GetDbtoolsClient();
1750cdf0e10cSrcweir                 sRet = aClient.getFormattedValue(
1751cdf0e10cSrcweir 					xColumnProps,
1752cdf0e10cSrcweir 					rDBFormatData.xFormatter,
1753cdf0e10cSrcweir 					rDBFormatData.aLocale,
1754cdf0e10cSrcweir 					rDBFormatData.aNullDate);
1755cdf0e10cSrcweir 				if (pNumber)
1756cdf0e10cSrcweir                 {
1757cdf0e10cSrcweir 				    double fVal = xColumn->getDouble();
1758cdf0e10cSrcweir                     if(!xColumn->wasNull())
1759cdf0e10cSrcweir                     {
1760cdf0e10cSrcweir                         *pNumber = fVal;
1761cdf0e10cSrcweir                     }
1762cdf0e10cSrcweir                 }
1763cdf0e10cSrcweir 			}
1764cdf0e10cSrcweir             catch(Exception& )
1765cdf0e10cSrcweir 			{
1766cdf0e10cSrcweir 				DBG_ERROR("exception caught");
1767cdf0e10cSrcweir 			}
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir 		}
1770cdf0e10cSrcweir 		break;
1771cdf0e10cSrcweir 
1772cdf0e10cSrcweir //		case DataType::BINARY:
1773cdf0e10cSrcweir //		case DataType::VARBINARY:
1774cdf0e10cSrcweir //		case DataType::LONGVARBINARY:
1775cdf0e10cSrcweir //		case DataType::SQLNULL:
1776cdf0e10cSrcweir //		case DataType::OTHER:
1777cdf0e10cSrcweir //		case DataType::OBJECT:
1778cdf0e10cSrcweir //		case DataType::DISTINCT:
1779cdf0e10cSrcweir //		case DataType::STRUCT:
1780cdf0e10cSrcweir //		case DataType::ARRAY:
1781cdf0e10cSrcweir //		case DataType::BLOB:
1782cdf0e10cSrcweir //		case DataType::CLOB:
1783cdf0e10cSrcweir //		case DataType::REF:
1784cdf0e10cSrcweir //		default:
1785cdf0e10cSrcweir 	}
1786cdf0e10cSrcweir //	if (pFormat)
1787cdf0e10cSrcweir //	{
1788cdf0e10cSrcweir //		SFX_ITEMSET_GET(*pCol, pFormatItem, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
1789cdf0e10cSrcweir //		*pFormat = pFormatItem->GetValue();
1790cdf0e10cSrcweir //	}
1791cdf0e10cSrcweir 
1792cdf0e10cSrcweir 	return sRet;
1793cdf0e10cSrcweir }
1794cdf0e10cSrcweir /* -----------------------------06.07.00 14:28--------------------------------
1795cdf0e10cSrcweir 	releases the merge data source table or query after merge is completed
1796cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1797cdf0e10cSrcweir void	SwNewDBMgr::EndMerge()
1798cdf0e10cSrcweir {
1799cdf0e10cSrcweir 	DBG_ASSERT(bInMerge, "merge is not active");
1800cdf0e10cSrcweir 	bInMerge = sal_False;
1801cdf0e10cSrcweir     delete pImpl->pMergeData;
1802cdf0e10cSrcweir     pImpl->pMergeData = 0;
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir /* -----------------------------06.07.00 14:28--------------------------------
1805cdf0e10cSrcweir 	checks if a desired data source table or query is open
1806cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1807cdf0e10cSrcweir sal_Bool    SwNewDBMgr::IsDataSourceOpen(const String& rDataSource,
1808cdf0e10cSrcweir             const String& rTableOrQuery, sal_Bool bMergeOnly)
1809cdf0e10cSrcweir {
1810cdf0e10cSrcweir     if(pImpl->pMergeData)
1811cdf0e10cSrcweir 	{
1812cdf0e10cSrcweir         return !bMergeLock &&
1813cdf0e10cSrcweir                 ((rDataSource == (String)pImpl->pMergeData->sDataSource &&
1814cdf0e10cSrcweir                     rTableOrQuery == (String)pImpl->pMergeData->sCommand)
1815cdf0e10cSrcweir                     ||(!rDataSource.Len() && !rTableOrQuery.Len()))
1816cdf0e10cSrcweir                     &&
1817cdf0e10cSrcweir                     pImpl->pMergeData->xResultSet.is();
1818cdf0e10cSrcweir 	}
1819cdf0e10cSrcweir     else if(!bMergeOnly)
1820cdf0e10cSrcweir     {
1821cdf0e10cSrcweir         SwDBData aData;
1822cdf0e10cSrcweir         aData.sDataSource = rDataSource;
1823cdf0e10cSrcweir         aData.sCommand = rTableOrQuery;
1824cdf0e10cSrcweir         aData.nCommandType = -1;
1825cdf0e10cSrcweir         SwDSParam* pFound = FindDSData(aData, sal_False);
1826cdf0e10cSrcweir         return (pFound && pFound->xResultSet.is());
1827cdf0e10cSrcweir     }
1828cdf0e10cSrcweir     return sal_False;
1829cdf0e10cSrcweir }
1830cdf0e10cSrcweir /* -----------------------------17.07.00 16:44--------------------------------
1831cdf0e10cSrcweir 	read column data a a specified position
1832cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1833cdf0e10cSrcweir sal_Bool SwNewDBMgr::GetColumnCnt(const String& rSourceName, const String& rTableName,
1834cdf0e10cSrcweir 							const String& rColumnName, sal_uInt32 nAbsRecordId,
1835cdf0e10cSrcweir 							long nLanguage,
1836cdf0e10cSrcweir 							String& rResult, double* pNumber)
1837cdf0e10cSrcweir {
1838cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1839cdf0e10cSrcweir     SwDSParam* pFound = 0;
1840cdf0e10cSrcweir     //check if it's the merge data source
1841cdf0e10cSrcweir     if(pImpl->pMergeData &&
1842cdf0e10cSrcweir         rSourceName == (String)pImpl->pMergeData->sDataSource &&
1843cdf0e10cSrcweir         rTableName == (String)pImpl->pMergeData->sCommand)
1844cdf0e10cSrcweir 	{
1845cdf0e10cSrcweir         pFound = pImpl->pMergeData;
1846cdf0e10cSrcweir     }
1847cdf0e10cSrcweir     else
1848cdf0e10cSrcweir 	{
1849cdf0e10cSrcweir         SwDBData aData;
1850cdf0e10cSrcweir         aData.sDataSource = rSourceName;
1851cdf0e10cSrcweir         aData.sCommand = rTableName;
1852cdf0e10cSrcweir         aData.nCommandType = -1;
1853cdf0e10cSrcweir         pFound = FindDSData(aData, sal_False);
1854cdf0e10cSrcweir     }
1855cdf0e10cSrcweir     //check validity of supplied record Id
1856cdf0e10cSrcweir     if(pFound->aSelection.getLength())
1857cdf0e10cSrcweir     {
1858cdf0e10cSrcweir         //the destination has to be an element of the selection
1859cdf0e10cSrcweir         const Any* pSelection = pFound->aSelection.getConstArray();
1860cdf0e10cSrcweir         sal_Bool bFound = sal_False;
1861cdf0e10cSrcweir         for(sal_Int32 nPos = 0; !bFound && nPos < pFound->aSelection.getLength(); nPos++)
1862cdf0e10cSrcweir         {
1863cdf0e10cSrcweir             sal_Int32 nSelection = 0;
1864cdf0e10cSrcweir             pSelection[nPos] >>= nSelection;
1865cdf0e10cSrcweir             if(nSelection == static_cast<sal_Int32>(nAbsRecordId))
1866cdf0e10cSrcweir                 bFound = sal_True;
1867cdf0e10cSrcweir         }
1868cdf0e10cSrcweir         if(!bFound)
1869cdf0e10cSrcweir             return sal_False;
1870cdf0e10cSrcweir     }
1871cdf0e10cSrcweir     if(pFound && pFound->xResultSet.is() && !pFound->bAfterSelection)
1872cdf0e10cSrcweir     {
1873cdf0e10cSrcweir         sal_Int32 nOldRow = 0;
1874cdf0e10cSrcweir         try
1875cdf0e10cSrcweir         {
1876cdf0e10cSrcweir             nOldRow = pFound->xResultSet->getRow();
1877cdf0e10cSrcweir         }
1878cdf0e10cSrcweir         catch(const Exception& )
1879cdf0e10cSrcweir         {
1880cdf0e10cSrcweir 			return sal_False;
1881cdf0e10cSrcweir         }
1882cdf0e10cSrcweir         //position to the desired index
1883cdf0e10cSrcweir         sal_Bool bMove = sal_True;
1884cdf0e10cSrcweir         if ( nOldRow != static_cast<sal_Int32>(nAbsRecordId) )
1885cdf0e10cSrcweir             bMove = lcl_MoveAbsolute(pFound, nAbsRecordId);
1886cdf0e10cSrcweir         if(bMove)
1887cdf0e10cSrcweir         {
1888cdf0e10cSrcweir             bRet = lcl_GetColumnCnt(pFound, rColumnName, nLanguage, rResult, pNumber);
1889cdf0e10cSrcweir         }
1890cdf0e10cSrcweir         if ( nOldRow != static_cast<sal_Int32>(nAbsRecordId) )
1891cdf0e10cSrcweir             bMove = lcl_MoveAbsolute(pFound, nOldRow);
1892cdf0e10cSrcweir     }
1893cdf0e10cSrcweir 	return bRet;
1894cdf0e10cSrcweir }
1895cdf0e10cSrcweir /* -----------------------------06.07.00 16:47--------------------------------
1896cdf0e10cSrcweir 	reads the column data at the current position
1897cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1898cdf0e10cSrcweir sal_Bool	SwNewDBMgr::GetMergeColumnCnt(const String& rColumnName, sal_uInt16 nLanguage,
1899cdf0e10cSrcweir                                 String &rResult, double *pNumber, sal_uInt32 * /*pFormat*/)
1900cdf0e10cSrcweir {
1901cdf0e10cSrcweir     if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is() || pImpl->pMergeData->bAfterSelection )
1902cdf0e10cSrcweir 	{
1903cdf0e10cSrcweir 		rResult.Erase();
1904cdf0e10cSrcweir 		return sal_False;
1905cdf0e10cSrcweir 	}
1906cdf0e10cSrcweir 
1907cdf0e10cSrcweir     sal_Bool bRet = lcl_GetColumnCnt(pImpl->pMergeData, rColumnName, nLanguage, rResult, pNumber);
1908cdf0e10cSrcweir 	return bRet;
1909cdf0e10cSrcweir }
1910cdf0e10cSrcweir /* -----------------------------07.07.00 14:28--------------------------------
1911cdf0e10cSrcweir 
1912cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1913cdf0e10cSrcweir sal_Bool SwNewDBMgr::ToNextMergeRecord()
1914cdf0e10cSrcweir {
1915cdf0e10cSrcweir     DBG_ASSERT(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is(), "no data source in merge");
1916cdf0e10cSrcweir     return ToNextRecord(pImpl->pMergeData);
1917cdf0e10cSrcweir }
1918cdf0e10cSrcweir /* -----------------------------10.07.01 14:28--------------------------------
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1921cdf0e10cSrcweir sal_Bool SwNewDBMgr::ToNextRecord(
1922cdf0e10cSrcweir     const String& rDataSource, const String& rCommand, sal_Int32 /*nCommandType*/)
1923cdf0e10cSrcweir {
1924cdf0e10cSrcweir     SwDSParam* pFound = 0;
1925cdf0e10cSrcweir     if(pImpl->pMergeData &&
1926cdf0e10cSrcweir         rDataSource == (String)pImpl->pMergeData->sDataSource &&
1927cdf0e10cSrcweir         rCommand == (String)pImpl->pMergeData->sCommand)
1928cdf0e10cSrcweir         pFound = pImpl->pMergeData;
1929cdf0e10cSrcweir     else
1930cdf0e10cSrcweir     {
1931cdf0e10cSrcweir         SwDBData aData;
1932cdf0e10cSrcweir         aData.sDataSource = rDataSource;
1933cdf0e10cSrcweir         aData.sCommand = rCommand;
1934cdf0e10cSrcweir         aData.nCommandType = -1;
1935cdf0e10cSrcweir         pFound = FindDSData(aData, sal_False);
1936cdf0e10cSrcweir     }
1937cdf0e10cSrcweir     return ToNextRecord(pFound);
1938cdf0e10cSrcweir }
1939cdf0e10cSrcweir /* -----------------------------10.07.01 14:38--------------------------------
1940cdf0e10cSrcweir 
1941cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1942cdf0e10cSrcweir sal_Bool SwNewDBMgr::ToNextRecord(SwDSParam* pParam)
1943cdf0e10cSrcweir {
1944cdf0e10cSrcweir     sal_Bool bRet = sal_True;
1945cdf0e10cSrcweir     if(!pParam || !pParam->xResultSet.is() || pParam->bEndOfDB ||
1946cdf0e10cSrcweir 			(pParam->aSelection.getLength() && pParam->aSelection.getLength() <= pParam->nSelectionIndex))
1947cdf0e10cSrcweir 	{
1948cdf0e10cSrcweir         if(pParam)
1949cdf0e10cSrcweir             pParam->CheckEndOfDB();
1950cdf0e10cSrcweir 		return sal_False;
1951cdf0e10cSrcweir 	}
1952cdf0e10cSrcweir 	try
1953cdf0e10cSrcweir 	{
1954cdf0e10cSrcweir         if(pParam->aSelection.getLength())
1955cdf0e10cSrcweir 		{
1956cdf0e10cSrcweir 			sal_Int32 nPos = 0;
1957cdf0e10cSrcweir 			pParam->aSelection.getConstArray()[ pParam->nSelectionIndex++ ] >>= nPos;
1958cdf0e10cSrcweir             pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos );
1959cdf0e10cSrcweir             pParam->CheckEndOfDB();
1960cdf0e10cSrcweir             bRet = !pParam->bEndOfDB;
1961cdf0e10cSrcweir             if(pParam->nSelectionIndex >= pParam->aSelection.getLength())
1962cdf0e10cSrcweir                 pParam->bEndOfDB = sal_True;
1963cdf0e10cSrcweir 		}
1964cdf0e10cSrcweir 		else
1965cdf0e10cSrcweir 		{
1966cdf0e10cSrcweir             sal_Int32 nBefore = pParam->xResultSet->getRow();
1967cdf0e10cSrcweir             pParam->bEndOfDB = !pParam->xResultSet->next();
1968cdf0e10cSrcweir             if( !pParam->bEndOfDB && nBefore == pParam->xResultSet->getRow())
1969cdf0e10cSrcweir             {
1970cdf0e10cSrcweir                 //next returned true but it didn't move
1971cdf0e10cSrcweir                 pParam->bEndOfDB = sal_True;
1972cdf0e10cSrcweir             }
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir             pParam->CheckEndOfDB();
1975cdf0e10cSrcweir             bRet = !pParam->bEndOfDB;
1976cdf0e10cSrcweir             ++pParam->nSelectionIndex;
1977cdf0e10cSrcweir 		}
1978cdf0e10cSrcweir 	}
1979cdf0e10cSrcweir     catch(Exception&)
1980cdf0e10cSrcweir 	{
1981cdf0e10cSrcweir 	}
1982cdf0e10cSrcweir     return bRet;
1983cdf0e10cSrcweir }
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir /* -----------------------------13.07.00 17:23--------------------------------
1986cdf0e10cSrcweir 	synchronized labels contain a next record field at their end
1987cdf0e10cSrcweir 	to assure that the next page can be created in mail merge
1988cdf0e10cSrcweir 	the cursor position must be validated
1989cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1990cdf0e10cSrcweir sal_Bool SwNewDBMgr::ExistsNextRecord() const
1991cdf0e10cSrcweir {
1992cdf0e10cSrcweir     return pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB;
1993cdf0e10cSrcweir }
1994cdf0e10cSrcweir /* -----------------------------13.07.00 10:41--------------------------------
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1997cdf0e10cSrcweir sal_uInt32 	SwNewDBMgr::GetSelectedRecordId()
1998cdf0e10cSrcweir {
1999cdf0e10cSrcweir 	sal_uInt32 	nRet = 0;
2000cdf0e10cSrcweir     DBG_ASSERT(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is(), "no data source in merge");
2001cdf0e10cSrcweir     if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is())
2002cdf0e10cSrcweir 		return sal_False;
2003cdf0e10cSrcweir 	try
2004cdf0e10cSrcweir 	{
2005cdf0e10cSrcweir         nRet = pImpl->pMergeData->xResultSet->getRow();
2006cdf0e10cSrcweir 	}
2007cdf0e10cSrcweir     catch(Exception& )
2008cdf0e10cSrcweir 	{
2009cdf0e10cSrcweir 	}
2010cdf0e10cSrcweir 	return nRet;
2011cdf0e10cSrcweir }
2012cdf0e10cSrcweir /* -----------------------------13.07.00 10:58--------------------------------
2013cdf0e10cSrcweir 
2014cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2015cdf0e10cSrcweir sal_Bool SwNewDBMgr::ToRecordId(sal_Int32 nSet)
2016cdf0e10cSrcweir {
2017cdf0e10cSrcweir     DBG_ASSERT(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is(), "no data source in merge");
2018cdf0e10cSrcweir     if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is()|| nSet < 0)
2019cdf0e10cSrcweir 		return sal_False;
2020cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
2021cdf0e10cSrcweir     sal_Int32 nAbsPos = nSet;
2022cdf0e10cSrcweir 
2023cdf0e10cSrcweir 	if(nAbsPos >= 0)
2024cdf0e10cSrcweir 	{
2025cdf0e10cSrcweir         bRet = lcl_MoveAbsolute(pImpl->pMergeData, nAbsPos);
2026cdf0e10cSrcweir         pImpl->pMergeData->bEndOfDB = !bRet;
2027cdf0e10cSrcweir         pImpl->pMergeData->CheckEndOfDB();
2028cdf0e10cSrcweir 	}
2029cdf0e10cSrcweir 	return bRet;
2030cdf0e10cSrcweir }
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir /* -----------------------------17.07.00 14:17--------------------------------
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2035cdf0e10cSrcweir sal_Bool SwNewDBMgr::OpenDataSource(const String& rDataSource, const String& rTableOrQuery,
2036cdf0e10cSrcweir             sal_Int32 nCommandType, bool bCreate)
2037cdf0e10cSrcweir {
2038cdf0e10cSrcweir     SwDBData aData;
2039cdf0e10cSrcweir     aData.sDataSource = rDataSource;
2040cdf0e10cSrcweir     aData.sCommand = rTableOrQuery;
2041cdf0e10cSrcweir     aData.nCommandType = nCommandType;
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir     SwDSParam* pFound = FindDSData(aData, sal_True);
2044cdf0e10cSrcweir     uno::Reference< XDataSource> xSource;
2045cdf0e10cSrcweir 	if(pFound->xResultSet.is())
2046cdf0e10cSrcweir 		return sal_True;
2047cdf0e10cSrcweir     SwDSParam* pParam = FindDSConnection(rDataSource, sal_False);
2048cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
2049cdf0e10cSrcweir     if(pParam && pParam->xConnection.is())
2050cdf0e10cSrcweir         pFound->xConnection = pParam->xConnection;
2051cdf0e10cSrcweir     else if(bCreate)
2052cdf0e10cSrcweir     {
2053cdf0e10cSrcweir         rtl::OUString sDataSource(rDataSource);
2054cdf0e10cSrcweir         pFound->xConnection = RegisterConnection( sDataSource );
2055cdf0e10cSrcweir     }
2056cdf0e10cSrcweir 	if(pFound->xConnection.is())
2057cdf0e10cSrcweir 	{
2058cdf0e10cSrcweir 		try
2059cdf0e10cSrcweir 		{
2060cdf0e10cSrcweir             uno::Reference< sdbc::XDatabaseMetaData >  xMetaData = pFound->xConnection->getMetaData();
2061cdf0e10cSrcweir             try
2062cdf0e10cSrcweir             {
2063cdf0e10cSrcweir                 pFound->bScrollable = xMetaData
2064cdf0e10cSrcweir 						->supportsResultSetType((sal_Int32)ResultSetType::SCROLL_INSENSITIVE);
2065cdf0e10cSrcweir             }
2066cdf0e10cSrcweir             catch(Exception&)
2067cdf0e10cSrcweir             {
2068cdf0e10cSrcweir                 //#98373# DB driver may not be ODBC 3.0 compliant
2069cdf0e10cSrcweir                 pFound->bScrollable = sal_True;
2070cdf0e10cSrcweir             }
2071cdf0e10cSrcweir 			pFound->xStatement = pFound->xConnection->createStatement();
2072cdf0e10cSrcweir             rtl::OUString aQuoteChar = xMetaData->getIdentifierQuoteString();
2073cdf0e10cSrcweir             rtl::OUString sStatement(C2U("SELECT * FROM "));
2074cdf0e10cSrcweir             sStatement = C2U("SELECT * FROM ");
2075cdf0e10cSrcweir             sStatement += aQuoteChar;
2076cdf0e10cSrcweir             sStatement += rTableOrQuery;
2077cdf0e10cSrcweir             sStatement += aQuoteChar;
2078cdf0e10cSrcweir             pFound->xResultSet = pFound->xStatement->executeQuery( sStatement );
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir 			//after executeQuery the cursor must be positioned
2081cdf0e10cSrcweir             pFound->bEndOfDB = !pFound->xResultSet->next();
2082cdf0e10cSrcweir             pFound->bAfterSelection = sal_False;
2083cdf0e10cSrcweir             pFound->CheckEndOfDB();
2084cdf0e10cSrcweir             ++pFound->nSelectionIndex;
2085cdf0e10cSrcweir 		}
2086cdf0e10cSrcweir 		catch (Exception&)
2087cdf0e10cSrcweir 		{
2088cdf0e10cSrcweir 			pFound->xResultSet = 0;
2089cdf0e10cSrcweir 			pFound->xStatement = 0;
2090cdf0e10cSrcweir 			pFound->xConnection = 0;
2091cdf0e10cSrcweir 		}
2092cdf0e10cSrcweir 	}
2093cdf0e10cSrcweir 	return pFound->xResultSet.is();
2094cdf0e10cSrcweir }
2095cdf0e10cSrcweir /* -----------------------------14.08.2001 10:26------------------------------
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2098cdf0e10cSrcweir uno::Reference< XConnection> SwNewDBMgr::RegisterConnection(rtl::OUString& rDataSource)
2099cdf0e10cSrcweir {
2100cdf0e10cSrcweir     SwDSParam* pFound = SwNewDBMgr::FindDSConnection(rDataSource, sal_True);
2101cdf0e10cSrcweir     uno::Reference< XDataSource> xSource;
2102cdf0e10cSrcweir     if(!pFound->xConnection.is())
2103cdf0e10cSrcweir 	{
2104cdf0e10cSrcweir         pFound->xConnection = SwNewDBMgr::GetConnection(rDataSource, xSource );
2105cdf0e10cSrcweir         try
2106cdf0e10cSrcweir         {
2107cdf0e10cSrcweir             uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
2108cdf0e10cSrcweir             if(xComponent.is())
2109cdf0e10cSrcweir                 xComponent->addEventListener(pImpl->xDisposeListener);
2110cdf0e10cSrcweir         }
2111cdf0e10cSrcweir         catch(Exception&)
2112cdf0e10cSrcweir         {
2113cdf0e10cSrcweir         }
2114cdf0e10cSrcweir 	}
2115cdf0e10cSrcweir     return pFound->xConnection;
2116cdf0e10cSrcweir }
2117cdf0e10cSrcweir /* -----------------------------17.07.00 15:55--------------------------------
2118cdf0e10cSrcweir 
2119cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2120cdf0e10cSrcweir sal_uInt32      SwNewDBMgr::GetSelectedRecordId(
2121cdf0e10cSrcweir     const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType)
2122cdf0e10cSrcweir {
2123cdf0e10cSrcweir     sal_uInt32 nRet = 0xffffffff;
2124cdf0e10cSrcweir 	//check for merge data source first
2125cdf0e10cSrcweir     if(pImpl->pMergeData && rDataSource == (String)pImpl->pMergeData->sDataSource &&
2126cdf0e10cSrcweir                     rTableOrQuery == (String)pImpl->pMergeData->sCommand &&
2127cdf0e10cSrcweir                     (nCommandType == -1 || nCommandType == pImpl->pMergeData->nCommandType) &&
2128cdf0e10cSrcweir                     pImpl->pMergeData->xResultSet.is())
2129cdf0e10cSrcweir 		nRet = GetSelectedRecordId();
2130cdf0e10cSrcweir 	else
2131cdf0e10cSrcweir 	{
2132cdf0e10cSrcweir         SwDBData aData;
2133cdf0e10cSrcweir         aData.sDataSource = rDataSource;
2134cdf0e10cSrcweir         aData.sCommand = rTableOrQuery;
2135cdf0e10cSrcweir         aData.nCommandType = nCommandType;
2136cdf0e10cSrcweir         SwDSParam* pFound = FindDSData(aData, sal_False);
2137cdf0e10cSrcweir 		if(pFound && pFound->xResultSet.is())
2138cdf0e10cSrcweir 		{
2139cdf0e10cSrcweir 			try
2140cdf0e10cSrcweir 			{	//if a selection array is set the current row at the result set may not be set yet
2141cdf0e10cSrcweir 				if(pFound->aSelection.getLength())
2142cdf0e10cSrcweir 				{
2143cdf0e10cSrcweir 					sal_Int32 nSelIndex = pFound->nSelectionIndex;
2144cdf0e10cSrcweir                     if(nSelIndex >= pFound->aSelection.getLength())
2145cdf0e10cSrcweir 						nSelIndex = pFound->aSelection.getLength() -1;
2146cdf0e10cSrcweir 					pFound->aSelection.getConstArray()[nSelIndex] >>= nRet;
2147cdf0e10cSrcweir 
2148cdf0e10cSrcweir 				}
2149cdf0e10cSrcweir 				else
2150cdf0e10cSrcweir 					nRet = pFound->xResultSet->getRow();
2151cdf0e10cSrcweir 			}
2152cdf0e10cSrcweir 			catch(Exception&){}
2153cdf0e10cSrcweir 		}
2154cdf0e10cSrcweir 	}
2155cdf0e10cSrcweir 	return nRet;
2156cdf0e10cSrcweir }
2157cdf0e10cSrcweir 
2158cdf0e10cSrcweir /* -----------------------------17.07.00 14:18--------------------------------
2159cdf0e10cSrcweir 	close all data sources - after fields were updated
2160cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2161cdf0e10cSrcweir void	SwNewDBMgr::CloseAll(sal_Bool bIncludingMerge)
2162cdf0e10cSrcweir {
2163cdf0e10cSrcweir     //the only thing done here is to reset the selection index
2164cdf0e10cSrcweir 	//all connections stay open
2165cdf0e10cSrcweir     for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.Count(); nPos++)
2166cdf0e10cSrcweir     {
2167cdf0e10cSrcweir         SwDSParam* pParam = aDataSourceParams[nPos];
2168cdf0e10cSrcweir         if(bIncludingMerge || pParam != pImpl->pMergeData)
2169cdf0e10cSrcweir         {
2170cdf0e10cSrcweir 			pParam->nSelectionIndex = 0;
2171cdf0e10cSrcweir 			pParam->bAfterSelection = sal_False;
2172cdf0e10cSrcweir             pParam->bEndOfDB = sal_False;
2173cdf0e10cSrcweir             try
2174cdf0e10cSrcweir             {
2175cdf0e10cSrcweir                 if(!bInMerge && pParam->xResultSet.is())
2176cdf0e10cSrcweir                     pParam->xResultSet->first();
2177cdf0e10cSrcweir             }
2178cdf0e10cSrcweir             catch(Exception& )
2179cdf0e10cSrcweir             {}
2180cdf0e10cSrcweir         }
2181cdf0e10cSrcweir     }
2182cdf0e10cSrcweir }
2183cdf0e10cSrcweir /* -----------------------------17.07.00 14:54--------------------------------
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2186cdf0e10cSrcweir SwDSParam* SwNewDBMgr::FindDSData(const SwDBData& rData, sal_Bool bCreate)
2187cdf0e10cSrcweir {
2188cdf0e10cSrcweir     //prefer merge data if available
2189cdf0e10cSrcweir     if(pImpl->pMergeData && rData.sDataSource == pImpl->pMergeData->sDataSource &&
2190cdf0e10cSrcweir         rData.sCommand == pImpl->pMergeData->sCommand &&
2191cdf0e10cSrcweir         (rData.nCommandType == -1 || rData.nCommandType == pImpl->pMergeData->nCommandType ||
2192cdf0e10cSrcweir         (bCreate && pImpl->pMergeData->nCommandType == -1)))
2193cdf0e10cSrcweir     {
2194cdf0e10cSrcweir          return pImpl->pMergeData;
2195cdf0e10cSrcweir     }
2196cdf0e10cSrcweir 
2197cdf0e10cSrcweir     SwDSParam* pFound = 0;
2198cdf0e10cSrcweir 	for(sal_uInt16 nPos = aDataSourceParams.Count(); nPos; nPos--)
2199cdf0e10cSrcweir 	{
2200cdf0e10cSrcweir 		SwDSParam* pParam = aDataSourceParams[nPos - 1];
2201cdf0e10cSrcweir         if(rData.sDataSource == pParam->sDataSource &&
2202cdf0e10cSrcweir             rData.sCommand == pParam->sCommand &&
2203cdf0e10cSrcweir             (rData.nCommandType == -1 || rData.nCommandType == pParam->nCommandType ||
2204cdf0e10cSrcweir             (bCreate && pParam->nCommandType == -1)))
2205cdf0e10cSrcweir 			{
2206cdf0e10cSrcweir                 //#94779# calls from the calculator may add a connection with an invalid commandtype
2207cdf0e10cSrcweir                 //later added "real" data base connections have to re-use the already available
2208cdf0e10cSrcweir                 //DSData and set the correct CommandType
2209cdf0e10cSrcweir                 if(bCreate && pParam->nCommandType == -1)
2210cdf0e10cSrcweir                     pParam->nCommandType = rData.nCommandType;
2211cdf0e10cSrcweir 				pFound = pParam;
2212cdf0e10cSrcweir 				break;
2213cdf0e10cSrcweir 			}
2214cdf0e10cSrcweir 	}
2215cdf0e10cSrcweir 	if(bCreate)
2216cdf0e10cSrcweir 	{
2217cdf0e10cSrcweir 		if(!pFound)
2218cdf0e10cSrcweir 		{
2219cdf0e10cSrcweir             pFound = new SwDSParam(rData);
2220cdf0e10cSrcweir             aDataSourceParams.Insert(pFound, aDataSourceParams.Count());
2221cdf0e10cSrcweir             try
2222cdf0e10cSrcweir             {
2223cdf0e10cSrcweir                 uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
2224cdf0e10cSrcweir                 if(xComponent.is())
2225cdf0e10cSrcweir                     xComponent->addEventListener(pImpl->xDisposeListener);
2226cdf0e10cSrcweir             }
2227cdf0e10cSrcweir             catch(Exception&)
2228cdf0e10cSrcweir             {
2229cdf0e10cSrcweir             }
2230cdf0e10cSrcweir         }
2231cdf0e10cSrcweir 	}
2232cdf0e10cSrcweir 	return pFound;
2233cdf0e10cSrcweir }
2234cdf0e10cSrcweir /* -----------------------------14.08.2001 10:27------------------------------
2235cdf0e10cSrcweir 
2236cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2237cdf0e10cSrcweir 
2238cdf0e10cSrcweir SwDSParam*  SwNewDBMgr::FindDSConnection(const rtl::OUString& rDataSource, sal_Bool bCreate)
2239cdf0e10cSrcweir {
2240cdf0e10cSrcweir     //prefer merge data if available
2241cdf0e10cSrcweir     if(pImpl->pMergeData && rDataSource == pImpl->pMergeData->sDataSource )
2242cdf0e10cSrcweir     {
2243cdf0e10cSrcweir          return pImpl->pMergeData;
2244cdf0e10cSrcweir     }
2245cdf0e10cSrcweir 	SwDSParam* pFound = 0;
2246cdf0e10cSrcweir 	for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.Count(); nPos++)
2247cdf0e10cSrcweir 	{
2248cdf0e10cSrcweir 		SwDSParam* pParam = aDataSourceParams[nPos];
2249cdf0e10cSrcweir         if(rDataSource == pParam->sDataSource)
2250cdf0e10cSrcweir         {
2251cdf0e10cSrcweir             pFound = pParam;
2252cdf0e10cSrcweir             break;
2253cdf0e10cSrcweir         }
2254cdf0e10cSrcweir 	}
2255cdf0e10cSrcweir 	if(bCreate && !pFound)
2256cdf0e10cSrcweir 	{
2257cdf0e10cSrcweir         SwDBData aData;
2258cdf0e10cSrcweir         aData.sDataSource = rDataSource;
2259cdf0e10cSrcweir         pFound = new SwDSParam(aData);
2260cdf0e10cSrcweir 		aDataSourceParams.Insert(pFound, aDataSourceParams.Count());
2261cdf0e10cSrcweir         try
2262cdf0e10cSrcweir         {
2263cdf0e10cSrcweir             uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
2264cdf0e10cSrcweir             if(xComponent.is())
2265cdf0e10cSrcweir                 xComponent->addEventListener(pImpl->xDisposeListener);
2266cdf0e10cSrcweir         }
2267cdf0e10cSrcweir         catch(Exception&)
2268cdf0e10cSrcweir         {
2269cdf0e10cSrcweir         }
2270cdf0e10cSrcweir     }
2271cdf0e10cSrcweir 	return pFound;
2272cdf0e10cSrcweir }
2273cdf0e10cSrcweir 
2274cdf0e10cSrcweir /* -----------------------------17.07.00 14:34--------------------------------
2275cdf0e10cSrcweir 
2276cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2277cdf0e10cSrcweir const SwDBData&	SwNewDBMgr::GetAddressDBName()
2278cdf0e10cSrcweir {
2279cdf0e10cSrcweir 	return SW_MOD()->GetDBConfig()->GetAddressSource();
2280cdf0e10cSrcweir }
2281cdf0e10cSrcweir /* -----------------------------18.07.00 13:13--------------------------------
2282cdf0e10cSrcweir 
2283cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2284cdf0e10cSrcweir Sequence<rtl::OUString> SwNewDBMgr::GetExistingDatabaseNames()
2285cdf0e10cSrcweir {
2286cdf0e10cSrcweir     uno::Reference<XNameAccess> xDBContext;
2287cdf0e10cSrcweir     uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
2288cdf0e10cSrcweir 	if( xMgr.is() )
2289cdf0e10cSrcweir 	{
2290cdf0e10cSrcweir         uno::Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" ));
2291cdf0e10cSrcweir         xDBContext = uno::Reference<XNameAccess>(xInstance, UNO_QUERY) ;
2292cdf0e10cSrcweir 	}
2293cdf0e10cSrcweir 	if(xDBContext.is())
2294cdf0e10cSrcweir 	{
2295cdf0e10cSrcweir 		return xDBContext->getElementNames();
2296cdf0e10cSrcweir 	}
2297cdf0e10cSrcweir     return Sequence<rtl::OUString>();
2298cdf0e10cSrcweir }
2299cdf0e10cSrcweir /*-- 26.05.2004 14:33:13---------------------------------------------------
2300cdf0e10cSrcweir 
2301cdf0e10cSrcweir   -----------------------------------------------------------------------*/
2302cdf0e10cSrcweir String SwNewDBMgr::LoadAndRegisterDataSource()
2303cdf0e10cSrcweir {
2304cdf0e10cSrcweir     sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
2305cdf0e10cSrcweir     Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
2306cdf0e10cSrcweir 
2307cdf0e10cSrcweir     String sHomePath(SvtPathOptions().GetWorkPath());
2308cdf0e10cSrcweir     aDlgHelper.SetDisplayDirectory( sHomePath );
2309cdf0e10cSrcweir 
2310cdf0e10cSrcweir     Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir     String sFilterAll(SW_RES(STR_FILTER_ALL));
2313cdf0e10cSrcweir     String sFilterAllData(SW_RES(STR_FILTER_ALL_DATA));
2314cdf0e10cSrcweir     String sFilterSXB(SW_RES(STR_FILTER_SXB));
2315cdf0e10cSrcweir     String sFilterSXC(SW_RES(STR_FILTER_SXC));
2316cdf0e10cSrcweir     String sFilterDBF(SW_RES(STR_FILTER_DBF));
2317cdf0e10cSrcweir     String sFilterXLS(SW_RES(STR_FILTER_XLS));
2318cdf0e10cSrcweir     String sFilterTXT(SW_RES(STR_FILTER_TXT));
2319cdf0e10cSrcweir     String sFilterCSV(SW_RES(STR_FILTER_CSV));
2320cdf0e10cSrcweir #ifdef WNT
2321cdf0e10cSrcweir     String sFilterMDB(SW_RES(STR_FILTER_MDB));
2322cdf0e10cSrcweir     String sFilterACCDB(SW_RES(STR_FILTER_ACCDB));
2323cdf0e10cSrcweir #endif
2324cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterAll, C2U("*") );
2325cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterAllData, C2U("*.ods;*.sxc;*.dbf;*.xls;*.txt;*.csv"));
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterSXB, C2U("*.odb") );
2328cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterSXC, C2U("*.ods;*.sxc") );
2329cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterDBF, C2U("*.dbf") );
2330cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterXLS, C2U("*.xls") );
2331cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterTXT, C2U("*.txt") );
2332cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterCSV, C2U("*.csv") );
2333cdf0e10cSrcweir #ifdef WNT
2334cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterMDB, C2U("*.mdb") );
2335cdf0e10cSrcweir     xFltMgr->appendFilter( sFilterACCDB, C2U("*.accdb") );
2336cdf0e10cSrcweir #endif
2337cdf0e10cSrcweir 
2338cdf0e10cSrcweir     xFltMgr->setCurrentFilter( sFilterAll ) ;
2339cdf0e10cSrcweir     String sFind;
2340cdf0e10cSrcweir     bool bTextConnection = false;
2341cdf0e10cSrcweir     if( ERRCODE_NONE == aDlgHelper.Execute() )
2342cdf0e10cSrcweir     {
2343cdf0e10cSrcweir         String sURL = xFP->getFiles().getConstArray()[0];
2344cdf0e10cSrcweir         //data sources have to be registered depending on their extensions
2345cdf0e10cSrcweir         INetURLObject aURL( sURL );
2346cdf0e10cSrcweir         String sExt( aURL.GetExtension() );
2347cdf0e10cSrcweir         Any aURLAny;
2348cdf0e10cSrcweir         Any aTableFilterAny;
2349cdf0e10cSrcweir         Any aSuppressVersionsAny;
2350cdf0e10cSrcweir         Any aInfoAny;
2351cdf0e10cSrcweir         INetURLObject aTempURL(aURL);
2352cdf0e10cSrcweir         bool bStore = true;
2353cdf0e10cSrcweir         if(sExt.EqualsAscii("odb"))
2354cdf0e10cSrcweir         {
2355cdf0e10cSrcweir             bStore = false;
2356cdf0e10cSrcweir         }
2357cdf0e10cSrcweir         else if(sExt.EqualsIgnoreCaseAscii("sxc")
2358cdf0e10cSrcweir             || sExt.EqualsIgnoreCaseAscii("ods")
2359cdf0e10cSrcweir                 || sExt.EqualsIgnoreCaseAscii("xls"))
2360cdf0e10cSrcweir         {
2361cdf0e10cSrcweir             rtl::OUString sDBURL(C2U("sdbc:calc:"));
2362cdf0e10cSrcweir             sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
2363cdf0e10cSrcweir             aURLAny <<= sDBURL;
2364cdf0e10cSrcweir         }
2365cdf0e10cSrcweir         else if(sExt.EqualsIgnoreCaseAscii("dbf"))
2366cdf0e10cSrcweir         {
2367cdf0e10cSrcweir             aTempURL.removeSegment();
2368cdf0e10cSrcweir             aTempURL.removeFinalSlash();
2369cdf0e10cSrcweir             rtl::OUString sDBURL(C2U("sdbc:dbase:"));
2370cdf0e10cSrcweir             sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
2371cdf0e10cSrcweir             aURLAny <<= sDBURL;
2372cdf0e10cSrcweir             //set the filter to the file name without extension
2373cdf0e10cSrcweir             Sequence<rtl::OUString> aFilters(1);
2374cdf0e10cSrcweir             rtl::OUString sTmp(aURL.getBase());
2375cdf0e10cSrcweir             aFilters[0] = aURL.getBase();
2376cdf0e10cSrcweir             aTableFilterAny <<= aFilters;
2377cdf0e10cSrcweir         }
2378cdf0e10cSrcweir         else if(sExt.EqualsIgnoreCaseAscii("csv") || sExt.EqualsIgnoreCaseAscii("txt"))
2379cdf0e10cSrcweir         {
2380cdf0e10cSrcweir             aTempURL.removeSegment();
2381cdf0e10cSrcweir             aTempURL.removeFinalSlash();
2382cdf0e10cSrcweir             rtl::OUString sDBURL(C2U("sdbc:flat:"));
2383cdf0e10cSrcweir             //only the 'path' has to be added
2384cdf0e10cSrcweir             sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
2385cdf0e10cSrcweir             aURLAny <<= sDBURL;
2386cdf0e10cSrcweir 
2387cdf0e10cSrcweir             bTextConnection = true;
2388cdf0e10cSrcweir             //set the filter to the file name without extension
2389cdf0e10cSrcweir             Sequence<rtl::OUString> aFilters(1);
2390cdf0e10cSrcweir             rtl::OUString sTmp(aURL.getBase());
2391cdf0e10cSrcweir             aFilters[0] = aURL.getBase();
2392cdf0e10cSrcweir             aTableFilterAny <<= aFilters;
2393cdf0e10cSrcweir         }
2394cdf0e10cSrcweir #ifdef WNT
2395cdf0e10cSrcweir         else if(sExt.EqualsIgnoreCaseAscii("mdb"))
2396cdf0e10cSrcweir         {
2397cdf0e10cSrcweir             rtl::OUString sDBURL(C2U("sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="));
2398cdf0e10cSrcweir             sDBURL += aTempURL.PathToFileName();
2399cdf0e10cSrcweir             aURLAny <<= sDBURL;
2400cdf0e10cSrcweir             aSuppressVersionsAny <<= makeAny(true);
2401cdf0e10cSrcweir         }
2402cdf0e10cSrcweir         else if(sExt.EqualsIgnoreCaseAscii("accdb"))
2403cdf0e10cSrcweir         {
2404cdf0e10cSrcweir             rtl::OUString sDBURL(C2U("sdbc:ado:PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE="));
2405cdf0e10cSrcweir             sDBURL += aTempURL.PathToFileName();
2406cdf0e10cSrcweir             aURLAny <<= sDBURL;
2407cdf0e10cSrcweir             aSuppressVersionsAny <<= makeAny(true);
2408cdf0e10cSrcweir         }
2409cdf0e10cSrcweir #endif
2410cdf0e10cSrcweir         try
2411cdf0e10cSrcweir         {
2412cdf0e10cSrcweir             Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
2413cdf0e10cSrcweir             Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" ));
2414cdf0e10cSrcweir             Reference<XNameAccess> xDBContext(xInstance, UNO_QUERY_THROW);
2415cdf0e10cSrcweir             Reference<XSingleServiceFactory> xFact( xDBContext, UNO_QUERY);
2416cdf0e10cSrcweir 
2417cdf0e10cSrcweir 			String sNewName = INetURLObject::decode( aURL.getName(),
2418cdf0e10cSrcweir 													 INET_HEX_ESCAPE,
2419cdf0e10cSrcweir 													 INetURLObject::DECODE_UNAMBIGUOUS,
2420cdf0e10cSrcweir 													 RTL_TEXTENCODING_UTF8 );
2421cdf0e10cSrcweir             xub_StrLen nExtLen = static_cast< xub_StrLen >(aURL.GetExtension().getLength());
2422cdf0e10cSrcweir             sNewName.Erase( sNewName.Len() - nExtLen - 1, nExtLen + 1 );
2423cdf0e10cSrcweir 
2424cdf0e10cSrcweir             //find a unique name if sNewName already exists
2425cdf0e10cSrcweir             sFind = sNewName;
2426cdf0e10cSrcweir             sal_Int32 nIndex = 0;
2427cdf0e10cSrcweir             while(xDBContext->hasByName(sFind))
2428cdf0e10cSrcweir             {
2429cdf0e10cSrcweir                 sFind = sNewName;
2430cdf0e10cSrcweir                 sFind += String::CreateFromInt32(++nIndex);
2431cdf0e10cSrcweir             }
2432cdf0e10cSrcweir 
2433cdf0e10cSrcweir             Reference<XInterface> xNewInstance;
2434cdf0e10cSrcweir             if(!bStore)
2435cdf0e10cSrcweir             {
2436cdf0e10cSrcweir                 //odb-file
2437cdf0e10cSrcweir                 Any aDataSource = xDBContext->getByName(aTempURL.GetMainURL(INetURLObject::NO_DECODE));
2438cdf0e10cSrcweir                 aDataSource >>= xNewInstance;
2439cdf0e10cSrcweir             }
2440cdf0e10cSrcweir             else
2441cdf0e10cSrcweir             {
2442cdf0e10cSrcweir                 xNewInstance = xFact->createInstance();
2443cdf0e10cSrcweir                 Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY);
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir                 if(aURLAny.hasValue())
2446cdf0e10cSrcweir                     xDataProperties->setPropertyValue(C2U("URL"), aURLAny);
2447cdf0e10cSrcweir                 if(aTableFilterAny.hasValue())
2448cdf0e10cSrcweir                     xDataProperties->setPropertyValue(C2U("TableFilter"), aTableFilterAny);
2449cdf0e10cSrcweir                 if(aSuppressVersionsAny.hasValue())
2450cdf0e10cSrcweir                     xDataProperties->setPropertyValue(C2U("SuppressVersionColumns"), aSuppressVersionsAny);
2451cdf0e10cSrcweir                 if(aInfoAny.hasValue())
2452cdf0e10cSrcweir                     xDataProperties->setPropertyValue(C2U("Info"), aInfoAny);
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir                 if( bTextConnection )
2455cdf0e10cSrcweir                 {
2456cdf0e10cSrcweir                     uno::Reference < ui::dialogs::XExecutableDialog > xSettingsDlg(
2457cdf0e10cSrcweir                                 xMgr->createInstance( C2U( "com.sun.star.sdb.TextConnectionSettings" ) ), uno::UNO_QUERY);
2458cdf0e10cSrcweir                     if( xSettingsDlg->execute() )
2459cdf0e10cSrcweir                     {
2460cdf0e10cSrcweir                         uno::Any aSettings = xDataProperties->getPropertyValue( C2U( "Settings" ) );
2461cdf0e10cSrcweir                         uno::Reference < beans::XPropertySet > xDSSettings;
2462cdf0e10cSrcweir                         aSettings >>= xDSSettings;
2463cdf0e10cSrcweir                         ::comphelper::copyProperties(
2464cdf0e10cSrcweir                             uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY ),
2465cdf0e10cSrcweir                             xDSSettings );
2466cdf0e10cSrcweir                         xDSSettings->setPropertyValue( C2U("Extension"), uno::makeAny( ::rtl::OUString( sExt )));
2467cdf0e10cSrcweir                     }
2468cdf0e10cSrcweir                 }
2469cdf0e10cSrcweir 
2470cdf0e10cSrcweir                 Reference<XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
2471cdf0e10cSrcweir                 Reference<XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
2472cdf0e10cSrcweir                 String sOutputExt = String::CreateFromAscii(".odb");
2473cdf0e10cSrcweir                 String sTmpName;
2474cdf0e10cSrcweir                 {
2475cdf0e10cSrcweir                     utl::TempFile aTempFile(sNewName , &sOutputExt, &sHomePath);
2476cdf0e10cSrcweir                     aTempFile.EnableKillingFile(sal_True);
2477cdf0e10cSrcweir                     sTmpName = aTempFile.GetURL();
2478cdf0e10cSrcweir                 }
2479cdf0e10cSrcweir                 xStore->storeAsURL(sTmpName, Sequence< PropertyValue >());
2480cdf0e10cSrcweir             }
2481cdf0e10cSrcweir             Reference<XNamingService> xNaming(xDBContext, UNO_QUERY);
2482cdf0e10cSrcweir             xNaming->registerObject( sFind, xNewInstance );
2483cdf0e10cSrcweir 
2484cdf0e10cSrcweir         }
2485cdf0e10cSrcweir         catch(Exception&)
2486cdf0e10cSrcweir         {
2487cdf0e10cSrcweir         }
2488cdf0e10cSrcweir     }
2489cdf0e10cSrcweir     return sFind;
2490cdf0e10cSrcweir 
2491cdf0e10cSrcweir }
2492cdf0e10cSrcweir /* -----------------------------10.11.00 17:10--------------------------------
2493cdf0e10cSrcweir 
2494cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2495cdf0e10cSrcweir void SwNewDBMgr::ExecuteFormLetter(	SwWrtShell& rSh,
2496cdf0e10cSrcweir                         const Sequence<PropertyValue>& rProperties,
2497cdf0e10cSrcweir                         sal_Bool bWithDataSourceBrowser)
2498cdf0e10cSrcweir {
2499cdf0e10cSrcweir 	//prevent second call
2500cdf0e10cSrcweir     if(pImpl->pMergeDialog)
2501cdf0e10cSrcweir 		return ;
2502cdf0e10cSrcweir     rtl::OUString sDataSource, sDataTableOrQuery;
2503cdf0e10cSrcweir     Sequence<Any> aSelection;
2504cdf0e10cSrcweir 
2505*60e513e9SAriel Constenla-Haile 	sal_Int32 nCmdType = CommandType::TABLE;
2506cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
2507cdf0e10cSrcweir 
2508cdf0e10cSrcweir 	ODataAccessDescriptor aDescriptor(rProperties);
2509cdf0e10cSrcweir 	sDataSource = aDescriptor.getDataSource();
2510cdf0e10cSrcweir 	aDescriptor[daCommand]		>>= sDataTableOrQuery;
2511cdf0e10cSrcweir 	aDescriptor[daCommandType]	>>= nCmdType;
2512cdf0e10cSrcweir 
2513cdf0e10cSrcweir 	if ( aDescriptor.has(daSelection) )
2514cdf0e10cSrcweir 		aDescriptor[daSelection] >>= aSelection;
2515cdf0e10cSrcweir 	if ( aDescriptor.has(daConnection) )
2516cdf0e10cSrcweir 		aDescriptor[daConnection] >>= xConnection;
2517cdf0e10cSrcweir 
2518cdf0e10cSrcweir     if(!sDataSource.getLength() || !sDataTableOrQuery.getLength())
2519cdf0e10cSrcweir 	{
2520cdf0e10cSrcweir 		DBG_ERROR("PropertyValues missing or unset");
2521cdf0e10cSrcweir 		return;
2522cdf0e10cSrcweir 	}
2523cdf0e10cSrcweir 
2524cdf0e10cSrcweir     //always create a connection for the dialog and dispose it after the dialog has been closed
2525cdf0e10cSrcweir     SwDSParam* pFound = 0;
2526cdf0e10cSrcweir     if(!xConnection.is())
2527cdf0e10cSrcweir     {
2528cdf0e10cSrcweir         xConnection = SwNewDBMgr::RegisterConnection(sDataSource);
2529cdf0e10cSrcweir         pFound = FindDSConnection(sDataSource, sal_True);
2530cdf0e10cSrcweir     }
2531cdf0e10cSrcweir 	SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2532cdf0e10cSrcweir     DBG_ASSERT(pFact, "Dialogdiet fail!");
2533cdf0e10cSrcweir     pImpl->pMergeDialog = pFact->CreateMailMergeDlg( DLG_MAILMERGE,
2534cdf0e10cSrcweir 														&rSh.GetView().GetViewFrame()->GetWindow(), rSh,
2535cdf0e10cSrcweir 														sDataSource,
2536cdf0e10cSrcweir 														sDataTableOrQuery,
2537cdf0e10cSrcweir 														nCmdType,
2538cdf0e10cSrcweir 														xConnection,
2539cdf0e10cSrcweir 														bWithDataSourceBrowser ? 0 : &aSelection);
2540cdf0e10cSrcweir     DBG_ASSERT(pImpl->pMergeDialog, "Dialogdiet fail!");
2541cdf0e10cSrcweir     if(pImpl->pMergeDialog->Execute() == RET_OK)
2542cdf0e10cSrcweir 	{
2543cdf0e10cSrcweir 		aDescriptor[daSelection] <<= pImpl->pMergeDialog->GetSelection();
2544cdf0e10cSrcweir 
2545cdf0e10cSrcweir         uno::Reference<XResultSet> xResSet = pImpl->pMergeDialog->GetResultSet();
2546cdf0e10cSrcweir         if(xResSet.is())
2547cdf0e10cSrcweir 			aDescriptor[daCursor] <<= xResSet;
2548cdf0e10cSrcweir 
2549cdf0e10cSrcweir         // SfxObjectShellRef is ok, since there should be no control over the document lifetime here
2550cdf0e10cSrcweir         SfxObjectShellRef xDocShell = rSh.GetView().GetViewFrame()->GetObjectShell();
2551cdf0e10cSrcweir         SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), xDocShell));
2552cdf0e10cSrcweir         {
2553cdf0e10cSrcweir             //copy rSh to aTempFile
2554cdf0e10cSrcweir             ::rtl::OUString sTempURL;
2555cdf0e10cSrcweir             const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
2556cdf0e10cSrcweir                         String::CreateFromAscii( FILTER_XML ),
2557cdf0e10cSrcweir                         SwDocShell::Factory().GetFilterContainer() );
2558cdf0e10cSrcweir             try
2559cdf0e10cSrcweir             {
2560cdf0e10cSrcweir 
2561cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aValues(1);
2562cdf0e10cSrcweir                 beans::PropertyValue* pValues = aValues.getArray();
2563cdf0e10cSrcweir                 pValues[0].Name = C2U("FilterName");
2564cdf0e10cSrcweir                 pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
2565cdf0e10cSrcweir                 uno::Reference< frame::XStorable > xStore( xDocShell->GetModel(), uno::UNO_QUERY);
2566cdf0e10cSrcweir                 sTempURL = URIHelper::SmartRel2Abs( INetURLObject(), utl::TempFile::CreateTempName() );
2567cdf0e10cSrcweir                 xStore->storeToURL( sTempURL, aValues );
2568cdf0e10cSrcweir             }
2569cdf0e10cSrcweir             catch( const uno::Exception& rEx )
2570cdf0e10cSrcweir             {
2571cdf0e10cSrcweir                 (void) rEx;
2572cdf0e10cSrcweir             }
2573cdf0e10cSrcweir             if( xDocShell->GetError() )
2574cdf0e10cSrcweir             {
2575cdf0e10cSrcweir                 // error message ??
2576cdf0e10cSrcweir                 ErrorHandler::HandleError( xDocShell->GetError() );
2577cdf0e10cSrcweir             }
2578cdf0e10cSrcweir             else
2579cdf0e10cSrcweir             {
2580cdf0e10cSrcweir                 // the shell will be explicitly closed, but it is more safe to use SfxObjectShellLock here
2581cdf0e10cSrcweir                 // especially for the case that the loading has failed
2582cdf0e10cSrcweir                 SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
2583cdf0e10cSrcweir                 SfxMedium* pWorkMed = new SfxMedium( sTempURL, STREAM_STD_READ, sal_True );
2584cdf0e10cSrcweir                 pWorkMed->SetFilter( pSfxFlt );
2585cdf0e10cSrcweir                 if( xWorkDocSh->DoLoad(pWorkMed) )
2586cdf0e10cSrcweir                 {
2587cdf0e10cSrcweir                     SfxViewFrame *pFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 );
2588cdf0e10cSrcweir                     SwView *pView = (SwView*) pFrame->GetViewShell();
2589cdf0e10cSrcweir                     pView->AttrChangedNotify( &pView->GetWrtShell() );//Damit SelectShell gerufen wird.
2590cdf0e10cSrcweir                     //set the current DBMgr
2591cdf0e10cSrcweir                     SwDoc* pWorkDoc = pView->GetWrtShell().GetDoc();
2592cdf0e10cSrcweir                     SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr();
2593cdf0e10cSrcweir                     pWorkDoc->SetNewDBMgr( this );
2594cdf0e10cSrcweir 
2595cdf0e10cSrcweir                     SwMergeDescriptor aMergeDesc( pImpl->pMergeDialog->GetMergeType(), pView->GetWrtShell(), aDescriptor );
2596cdf0e10cSrcweir                     aMergeDesc.sSaveToFilter = pImpl->pMergeDialog->GetSaveFilter();
2597cdf0e10cSrcweir                     aMergeDesc.bCreateSingleFile = !pImpl->pMergeDialog->IsSaveIndividualDocs();
2598cdf0e10cSrcweir                     if( !aMergeDesc.bCreateSingleFile && pImpl->pMergeDialog->IsGenerateFromDataBase() )
2599cdf0e10cSrcweir                     {
2600cdf0e10cSrcweir                         aMergeDesc.sAddressFromColumn = pImpl->pMergeDialog->GetColumnName();
2601cdf0e10cSrcweir                         aMergeDesc.sSubject = pImpl->pMergeDialog->GetPath();
2602cdf0e10cSrcweir                     }
2603cdf0e10cSrcweir 
2604cdf0e10cSrcweir                     MergeNew(aMergeDesc);
2605cdf0e10cSrcweir 
2606cdf0e10cSrcweir                     pWorkDoc->SetNewDBMgr( pWorkDBMgr );
2607cdf0e10cSrcweir                     //close the temporary file
2608cdf0e10cSrcweir                     uno::Reference< util::XCloseable > xClose( xWorkDocSh->GetModel(), uno::UNO_QUERY );
2609cdf0e10cSrcweir                     if (xClose.is())
2610cdf0e10cSrcweir                     {
2611cdf0e10cSrcweir                         try
2612cdf0e10cSrcweir                         {
2613cdf0e10cSrcweir                             //! 'sal_True' -> transfer ownership to vetoing object if vetoed!
2614cdf0e10cSrcweir                             //! I.e. now that object is responsible for closing the model and doc shell.
2615cdf0e10cSrcweir                             xClose->close( sal_True );
2616cdf0e10cSrcweir                         }
2617cdf0e10cSrcweir                         catch ( const uno::Exception& )
2618cdf0e10cSrcweir                         {
2619cdf0e10cSrcweir                         }
2620cdf0e10cSrcweir                     }
2621cdf0e10cSrcweir                 }
2622cdf0e10cSrcweir             }
2623cdf0e10cSrcweir             //remove the temporary file
2624cdf0e10cSrcweir             SWUnoHelper::UCB_DeleteFile( sTempURL );
2625cdf0e10cSrcweir         }
2626cdf0e10cSrcweir         SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), rSh.GetView().GetViewFrame()->GetObjectShell()));
2627cdf0e10cSrcweir 
2628cdf0e10cSrcweir 		// reset the cursor inside
2629cdf0e10cSrcweir 		xResSet = NULL;
2630cdf0e10cSrcweir 		aDescriptor[daCursor] <<= xResSet;
2631cdf0e10cSrcweir 	}
2632cdf0e10cSrcweir     if(pFound)
2633cdf0e10cSrcweir     {
2634cdf0e10cSrcweir         for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.Count(); nPos++)
2635cdf0e10cSrcweir         {
2636cdf0e10cSrcweir             SwDSParam* pParam = aDataSourceParams[nPos];
2637cdf0e10cSrcweir             if(pParam == pFound)
2638cdf0e10cSrcweir             {
2639cdf0e10cSrcweir                 try
2640cdf0e10cSrcweir                 {
2641cdf0e10cSrcweir                     uno::Reference<XComponent> xComp(pParam->xConnection, UNO_QUERY);
2642cdf0e10cSrcweir                     if(xComp.is())
2643cdf0e10cSrcweir                         xComp->dispose();
2644cdf0e10cSrcweir                 }
2645cdf0e10cSrcweir                 catch(const RuntimeException& )
2646cdf0e10cSrcweir                 {
2647cdf0e10cSrcweir                     //may be disposed already since multiple entries may have used the same connection
2648cdf0e10cSrcweir                 }
2649cdf0e10cSrcweir                 break;
2650cdf0e10cSrcweir             }
2651cdf0e10cSrcweir             //pFound doesn't need to be removed/deleted -
2652cdf0e10cSrcweir             //this has been done by the SwConnectionDisposedListener_Impl already
2653cdf0e10cSrcweir         }
2654cdf0e10cSrcweir     }
2655cdf0e10cSrcweir     DELETEZ(pImpl->pMergeDialog);
2656cdf0e10cSrcweir }
2657cdf0e10cSrcweir /* -----------------------------13.11.00 08:20--------------------------------
2658cdf0e10cSrcweir 
2659cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2660cdf0e10cSrcweir void SwNewDBMgr::InsertText(SwWrtShell& rSh,
2661cdf0e10cSrcweir 						const Sequence< PropertyValue>& rProperties)
2662cdf0e10cSrcweir {
2663cdf0e10cSrcweir     rtl::OUString sDataSource, sDataTableOrQuery;
2664cdf0e10cSrcweir     uno::Reference<XResultSet>  xResSet;
2665cdf0e10cSrcweir     Sequence<Any> aSelection;
2666cdf0e10cSrcweir 	sal_Bool bHasSelectionProperty = sal_False;
2667cdf0e10cSrcweir 	sal_Int32 nSelectionPos = 0;
2668cdf0e10cSrcweir 	sal_Int16 nCmdType = CommandType::TABLE;
2669cdf0e10cSrcweir 	const PropertyValue* pValues = rProperties.getConstArray();
2670cdf0e10cSrcweir     uno::Reference< XConnection> xConnection;
2671cdf0e10cSrcweir     for(sal_Int32 nPos = 0; nPos < rProperties.getLength(); nPos++)
2672cdf0e10cSrcweir 	{
2673cdf0e10cSrcweir         if(pValues[nPos].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cDataSourceName)))
2674cdf0e10cSrcweir 			pValues[nPos].Value >>= sDataSource;
2675cdf0e10cSrcweir         else if(pValues[nPos].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cCommand)))
2676cdf0e10cSrcweir 			pValues[nPos].Value >>= sDataTableOrQuery;
2677cdf0e10cSrcweir         else if(pValues[nPos].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cCursor)))
2678cdf0e10cSrcweir 			pValues[nPos].Value >>= xResSet;
2679cdf0e10cSrcweir         else if(pValues[nPos].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cSelection)))
2680cdf0e10cSrcweir 		{
2681cdf0e10cSrcweir 			bHasSelectionProperty = sal_True;
2682cdf0e10cSrcweir 			nSelectionPos = nPos;
2683cdf0e10cSrcweir 			pValues[nPos].Value >>= aSelection;
2684cdf0e10cSrcweir 		}
2685cdf0e10cSrcweir         else if(pValues[nPos].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cCommandType)))
2686cdf0e10cSrcweir 			pValues[nPos].Value >>= nCmdType;
2687cdf0e10cSrcweir         else if(pValues[nPos].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(cActiveConnection)))
2688cdf0e10cSrcweir             pValues[nPos].Value >>= xConnection;
2689cdf0e10cSrcweir     }
2690cdf0e10cSrcweir 	if(!sDataSource.getLength() || !sDataTableOrQuery.getLength() || !xResSet.is())
2691cdf0e10cSrcweir 	{
2692cdf0e10cSrcweir 		DBG_ERROR("PropertyValues missing or unset");
2693cdf0e10cSrcweir 		return;
2694cdf0e10cSrcweir 	}
2695cdf0e10cSrcweir     uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
2696cdf0e10cSrcweir     uno::Reference<XDataSource> xSource;
2697cdf0e10cSrcweir     uno::Reference<XChild> xChild(xConnection, UNO_QUERY);
2698cdf0e10cSrcweir     if(xChild.is())
2699cdf0e10cSrcweir         xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
2700cdf0e10cSrcweir     if(!xSource.is())
2701cdf0e10cSrcweir         xSource = SwNewDBMgr::GetDbtoolsClient().getDataSource(sDataSource, xMgr);
2702cdf0e10cSrcweir     uno::Reference< XColumnsSupplier > xColSupp( xResSet, UNO_QUERY );
2703cdf0e10cSrcweir 	SwDBData aDBData;
2704cdf0e10cSrcweir 	aDBData.sDataSource = sDataSource;
2705cdf0e10cSrcweir 	aDBData.sCommand = sDataTableOrQuery;
2706cdf0e10cSrcweir 	aDBData.nCommandType = nCmdType;
2707cdf0e10cSrcweir 
2708cdf0e10cSrcweir     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2709cdf0e10cSrcweir     DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
2710cdf0e10cSrcweir 
2711cdf0e10cSrcweir 	AbstractSwInsertDBColAutoPilot* pDlg = pFact->CreateSwInsertDBColAutoPilot( rSh.GetView(),
2712cdf0e10cSrcweir 																				xSource,
2713cdf0e10cSrcweir 																				xColSupp,
2714cdf0e10cSrcweir 																				aDBData,
2715cdf0e10cSrcweir                                                                                 DLG_AP_INSERT_DB_SEL );
2716cdf0e10cSrcweir     DBG_ASSERT(pDlg, "Dialogdiet fail!");
2717cdf0e10cSrcweir 	if( RET_OK == pDlg->Execute() )
2718cdf0e10cSrcweir 	{
2719cdf0e10cSrcweir         rtl::OUString sDummy;
2720cdf0e10cSrcweir         if(!xConnection.is())
2721cdf0e10cSrcweir             xConnection = xSource->getConnection(sDummy, sDummy);
2722cdf0e10cSrcweir         try
2723cdf0e10cSrcweir         {
2724cdf0e10cSrcweir             pDlg->DataToDoc( aSelection , xSource, xConnection, xResSet);
2725cdf0e10cSrcweir         }
2726cdf0e10cSrcweir         catch(Exception& )
2727cdf0e10cSrcweir         {
2728cdf0e10cSrcweir             DBG_ERROR("exception caught");
2729cdf0e10cSrcweir         }
2730cdf0e10cSrcweir     }
2731cdf0e10cSrcweir 	delete pDlg;
2732cdf0e10cSrcweir 
2733cdf0e10cSrcweir }
2734cdf0e10cSrcweir /* -----------------------------30.08.2001 12:00------------------------------
2735cdf0e10cSrcweir 
2736cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2737cdf0e10cSrcweir SwDbtoolsClient* SwNewDBMgr::pDbtoolsClient = NULL;
2738cdf0e10cSrcweir 
2739cdf0e10cSrcweir SwDbtoolsClient& SwNewDBMgr::GetDbtoolsClient()
2740cdf0e10cSrcweir {
2741cdf0e10cSrcweir     if ( !pDbtoolsClient )
2742cdf0e10cSrcweir         pDbtoolsClient = new SwDbtoolsClient;
2743cdf0e10cSrcweir     return *pDbtoolsClient;
2744cdf0e10cSrcweir }
2745cdf0e10cSrcweir /* -----------------13.05.2003 15:34-----------------
2746cdf0e10cSrcweir 
2747cdf0e10cSrcweir  --------------------------------------------------*/
2748cdf0e10cSrcweir void SwNewDBMgr::RemoveDbtoolsClient()
2749cdf0e10cSrcweir {
2750cdf0e10cSrcweir     delete pDbtoolsClient;
2751cdf0e10cSrcweir     pDbtoolsClient = 0;
2752cdf0e10cSrcweir }
2753cdf0e10cSrcweir /* -----------------------------20.08.2002 12:00------------------------------
2754cdf0e10cSrcweir 
2755cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2756cdf0e10cSrcweir uno::Reference<XDataSource> SwNewDBMgr::getDataSourceAsParent(const uno::Reference< XConnection>& _xConnection,const ::rtl::OUString& _sDataSourceName)
2757cdf0e10cSrcweir {
2758cdf0e10cSrcweir     uno::Reference<XDataSource> xSource;
2759cdf0e10cSrcweir 	try
2760cdf0e10cSrcweir 	{
2761cdf0e10cSrcweir         uno::Reference<XChild> xChild(_xConnection, UNO_QUERY);
2762cdf0e10cSrcweir 		if ( xChild.is() )
2763cdf0e10cSrcweir             xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
2764cdf0e10cSrcweir 		if ( !xSource.is() )
2765cdf0e10cSrcweir 			xSource = SwNewDBMgr::GetDbtoolsClient().getDataSource(_sDataSourceName, ::comphelper::getProcessServiceFactory());
2766cdf0e10cSrcweir 	}
2767cdf0e10cSrcweir 	catch(const Exception&)
2768cdf0e10cSrcweir 	{
2769cdf0e10cSrcweir 		DBG_ERROR("exception in getDataSourceAsParent caught");
2770cdf0e10cSrcweir 	}
2771cdf0e10cSrcweir 	return xSource;
2772cdf0e10cSrcweir }
2773cdf0e10cSrcweir /* -----------------------------20.08.2002 12:00------------------------------
2774cdf0e10cSrcweir 
2775cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
2776cdf0e10cSrcweir uno::Reference<XResultSet> SwNewDBMgr::createCursor(const ::rtl::OUString& _sDataSourceName,
2777cdf0e10cSrcweir 									   const ::rtl::OUString& _sCommand,
2778cdf0e10cSrcweir 									   sal_Int32 _nCommandType,
2779cdf0e10cSrcweir                                        const uno::Reference<XConnection>& _xConnection
2780cdf0e10cSrcweir 									  )
2781cdf0e10cSrcweir {
2782cdf0e10cSrcweir     uno::Reference<XResultSet> xResultSet;
2783cdf0e10cSrcweir 	try
2784cdf0e10cSrcweir 	{
2785cdf0e10cSrcweir         uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
2786cdf0e10cSrcweir 		if( xMgr.is() )
2787cdf0e10cSrcweir 		{
2788cdf0e10cSrcweir             uno::Reference<XInterface> xInstance = xMgr->createInstance(
2789cdf0e10cSrcweir 				C2U( "com.sun.star.sdb.RowSet" ));
2790cdf0e10cSrcweir             uno::Reference<XPropertySet> xRowSetPropSet(xInstance, UNO_QUERY);
2791cdf0e10cSrcweir 			if(xRowSetPropSet.is())
2792cdf0e10cSrcweir 			{
2793cdf0e10cSrcweir 				xRowSetPropSet->setPropertyValue(C2U("DataSourceName"), makeAny(_sDataSourceName));
2794cdf0e10cSrcweir 				xRowSetPropSet->setPropertyValue(C2U("ActiveConnection"), makeAny(_xConnection));
2795cdf0e10cSrcweir 				xRowSetPropSet->setPropertyValue(C2U("Command"), makeAny(_sCommand));
2796cdf0e10cSrcweir 				xRowSetPropSet->setPropertyValue(C2U("CommandType"), makeAny(_nCommandType));
2797cdf0e10cSrcweir 
2798cdf0e10cSrcweir                 uno::Reference< XCompletedExecution > xRowSet(xInstance, UNO_QUERY);
2799cdf0e10cSrcweir 
2800cdf0e10cSrcweir 				if ( xRowSet.is() )
2801cdf0e10cSrcweir 				{
2802cdf0e10cSrcweir                     uno::Reference< XInteractionHandler > xHandler(xMgr->createInstance(C2U("com.sun.star.task.InteractionHandler")), UNO_QUERY);
2803cdf0e10cSrcweir 					xRowSet->executeWithCompletion(xHandler);
2804cdf0e10cSrcweir 				}
2805cdf0e10cSrcweir                 xResultSet = uno::Reference<XResultSet>(xRowSet, UNO_QUERY);
2806cdf0e10cSrcweir 			}
2807cdf0e10cSrcweir 		}
2808cdf0e10cSrcweir 	}
2809cdf0e10cSrcweir 	catch(const Exception&)
2810cdf0e10cSrcweir 	{
2811cdf0e10cSrcweir 		DBG_ASSERT(0,"Caught exception while creating a new RowSet!");
2812cdf0e10cSrcweir 	}
2813cdf0e10cSrcweir 	return xResultSet;
2814cdf0e10cSrcweir }
2815cdf0e10cSrcweir /*-- 13.05.2004 16:14:15---------------------------------------------------
2816cdf0e10cSrcweir     merge all data into one resulting document and return the number of
2817cdf0e10cSrcweir     merged documents
2818cdf0e10cSrcweir   -----------------------------------------------------------------------*/
2819cdf0e10cSrcweir 
2820cdf0e10cSrcweir sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
2821cdf0e10cSrcweir                             SwView& rSourceView )
2822cdf0e10cSrcweir {
2823cdf0e10cSrcweir     // check the availability of all data in the config item
2824cdf0e10cSrcweir     uno::Reference< XResultSet> xResultSet = rMMConfig.GetResultSet();
2825cdf0e10cSrcweir     if(!xResultSet.is())
2826cdf0e10cSrcweir         return false;
2827cdf0e10cSrcweir     bInMerge = sal_True;
2828cdf0e10cSrcweir     sal_Int32 nRet  = 0;
2829cdf0e10cSrcweir     pImpl->pMergeData = new SwDSParam(
2830cdf0e10cSrcweir                 rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection());
2831cdf0e10cSrcweir 
2832cdf0e10cSrcweir     try{
2833cdf0e10cSrcweir         //set to start position
2834cdf0e10cSrcweir         if(pImpl->pMergeData->aSelection.getLength())
2835cdf0e10cSrcweir         {
2836cdf0e10cSrcweir             sal_Int32 nPos = 0;
2837cdf0e10cSrcweir             pImpl->pMergeData->aSelection.getConstArray()[ pImpl->pMergeData->nSelectionIndex++ ] >>= nPos;
2838cdf0e10cSrcweir             pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->absolute( nPos );
2839cdf0e10cSrcweir             pImpl->pMergeData->CheckEndOfDB();
2840cdf0e10cSrcweir             if(pImpl->pMergeData->nSelectionIndex >= pImpl->pMergeData->aSelection.getLength())
2841cdf0e10cSrcweir                 pImpl->pMergeData->bEndOfDB = sal_True;
2842cdf0e10cSrcweir         }
2843cdf0e10cSrcweir         else
2844cdf0e10cSrcweir         {
2845cdf0e10cSrcweir             pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->first();
2846cdf0e10cSrcweir             pImpl->pMergeData->CheckEndOfDB();
2847cdf0e10cSrcweir         }
2848cdf0e10cSrcweir     }
2849cdf0e10cSrcweir     catch(Exception&)
2850cdf0e10cSrcweir     {
2851cdf0e10cSrcweir         pImpl->pMergeData->bEndOfDB = sal_True;
2852cdf0e10cSrcweir         pImpl->pMergeData->CheckEndOfDB();
2853cdf0e10cSrcweir         DBG_ERROR("exception in MergeNew()");
2854cdf0e10cSrcweir     }
2855cdf0e10cSrcweir 
2856cdf0e10cSrcweir     //bCancel is set from the PrintMonitor
2857cdf0e10cSrcweir     bCancel = sal_False;
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir     CreateMonitor aMonitorDlg(&rSourceView.GetEditWin());
2860cdf0e10cSrcweir     aMonitorDlg.SetCancelHdl(LINK(this, SwNewDBMgr, PrtCancelHdl));
2861cdf0e10cSrcweir     if (!IsMergeSilent())
2862cdf0e10cSrcweir     {
2863cdf0e10cSrcweir         aMonitorDlg.Show();
2864cdf0e10cSrcweir         aMonitorDlg.Invalidate();
2865cdf0e10cSrcweir         aMonitorDlg.Update();
2866cdf0e10cSrcweir         // the print monitor needs some time to act
2867cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < 25; i++)
2868cdf0e10cSrcweir             Application::Reschedule();
2869cdf0e10cSrcweir     }
2870cdf0e10cSrcweir 
2871cdf0e10cSrcweir     SwWrtShell& rSourceShell = rSourceView.GetWrtShell();
2872cdf0e10cSrcweir     sal_Bool bSynchronizedDoc = rSourceShell.IsLabelDoc() && rSourceShell.GetSectionFmtCount() > 1;
2873cdf0e10cSrcweir     //save the settings of the first
2874cdf0e10cSrcweir     rSourceShell.SttEndDoc(sal_True);
2875cdf0e10cSrcweir     sal_uInt16 nStartingPageNo = rSourceShell.GetVirtPageNum();
2876cdf0e10cSrcweir     String sModifiedStartingPageDesc;
2877cdf0e10cSrcweir     String sStartingPageDesc = sModifiedStartingPageDesc = rSourceShell.GetPageDesc(
2878cdf0e10cSrcweir                                 rSourceShell.GetCurPageDesc()).GetName();
2879cdf0e10cSrcweir 
2880cdf0e10cSrcweir     try
2881cdf0e10cSrcweir     {
2882cdf0e10cSrcweir         // create a target docshell to put the merged document into
2883cdf0e10cSrcweir         SfxObjectShellRef xTargetDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
2884cdf0e10cSrcweir         xTargetDocShell->DoInitNew( 0 );
2885cdf0e10cSrcweir         SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 );
2886cdf0e10cSrcweir 
2887cdf0e10cSrcweir         //the created window has to be located at the same position as the source window
2888cdf0e10cSrcweir         Window& rTargetWindow = pTargetFrame->GetFrame().GetWindow();
2889cdf0e10cSrcweir         Window& rSourceWindow = rSourceView.GetViewFrame()->GetFrame().GetWindow();
2890cdf0e10cSrcweir         rTargetWindow.SetPosPixel(rSourceWindow.GetPosPixel());
2891cdf0e10cSrcweir 
2892cdf0e10cSrcweir //        pTargetFrame->GetFrame().Appear();
2893cdf0e10cSrcweir         SwView* pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() );
2894cdf0e10cSrcweir         rMMConfig.SetTargetView(pTargetView);
2895cdf0e10cSrcweir         //initiate SelectShell() to create sub shells
2896cdf0e10cSrcweir         pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
2897cdf0e10cSrcweir         SwWrtShell* pTargetShell = pTargetView->GetWrtShellPtr();
2898cdf0e10cSrcweir         // #i63806#
2899cdf0e10cSrcweir         const SwPageDesc* pSourcePageDesc = rSourceShell.FindPageDescByName( sStartingPageDesc );
2900cdf0e10cSrcweir         const SwFrmFmt& rMaster = pSourcePageDesc->GetMaster();
2901cdf0e10cSrcweir         bool bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive()  ||
2902cdf0e10cSrcweir                                         rMaster.GetFooter().IsActive();
2903cdf0e10cSrcweir 
2904cdf0e10cSrcweir 
2905cdf0e10cSrcweir         // #122799# copy compatibility options
2906cdf0e10cSrcweir         lcl_CopyCompatibilityOptions( rSourceShell, *pTargetShell);
2907cdf0e10cSrcweir         // #72821# copy dynamic defaults
2908cdf0e10cSrcweir         lcl_CopyDynamicDefaults( *rSourceShell.GetDoc(), *pTargetShell->GetDoc() );
2909cdf0e10cSrcweir 
2910cdf0e10cSrcweir 
2911cdf0e10cSrcweir         long nStartRow, nEndRow;
2912cdf0e10cSrcweir         sal_uLong nDocNo = 1;
2913cdf0e10cSrcweir         sal_Int32 nDocCount = 0;
2914cdf0e10cSrcweir         if( !IsMergeSilent() && lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) )
2915cdf0e10cSrcweir             aMonitorDlg.SetTotalCount( nDocCount );
2916cdf0e10cSrcweir 
2917cdf0e10cSrcweir         do
2918cdf0e10cSrcweir         {
2919cdf0e10cSrcweir             nStartRow = pImpl->pMergeData->xResultSet->getRow();
2920cdf0e10cSrcweir             if (!IsMergeSilent())
2921cdf0e10cSrcweir             {
2922cdf0e10cSrcweir                 aMonitorDlg.SetCurrentPosition( nDocNo );
2923cdf0e10cSrcweir                 aMonitorDlg.Invalidate();
2924cdf0e10cSrcweir                 aMonitorDlg.Update();
2925cdf0e10cSrcweir                 // the print monitor needs some time to act
2926cdf0e10cSrcweir                 for( sal_uInt16 i = 0; i < 25; i++)
2927cdf0e10cSrcweir                     Application::Reschedule();
2928cdf0e10cSrcweir             }
2929cdf0e10cSrcweir 
2930cdf0e10cSrcweir             // copy the source document
2931cdf0e10cSrcweir             // the copy will be closed later, but it is more safe to use SfxObjectShellLock here
2932cdf0e10cSrcweir             SfxObjectShellLock xWorkDocSh;
2933cdf0e10cSrcweir             if(nDocNo == 1 )
2934cdf0e10cSrcweir             {
2935cdf0e10cSrcweir                 uno::Reference< util::XCloneable > xClone( rSourceView.GetDocShell()->GetModel(), uno::UNO_QUERY);
2936cdf0e10cSrcweir                 uno::Reference< lang::XUnoTunnel > xWorkDocShell( xClone->createClone(), uno::UNO_QUERY);
2937cdf0e10cSrcweir                 SwXTextDocument* pWorkModel = reinterpret_cast<SwXTextDocument*>(xWorkDocShell->getSomething(SwXTextDocument::getUnoTunnelId()));
2938cdf0e10cSrcweir                 xWorkDocSh = pWorkModel->GetDocShell();
2939cdf0e10cSrcweir             }
2940cdf0e10cSrcweir             else
2941cdf0e10cSrcweir             {
2942cdf0e10cSrcweir                 xWorkDocSh = rSourceView.GetDocShell()->GetDoc()->CreateCopy(true);
2943cdf0e10cSrcweir             }
2944cdf0e10cSrcweir             //create a ViewFrame
2945cdf0e10cSrcweir             SwView* pWorkView = static_cast< SwView* >( SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 )->GetViewShell() );
2946cdf0e10cSrcweir             SwWrtShell& rWorkShell = pWorkView->GetWrtShell();
2947cdf0e10cSrcweir             pWorkView->AttrChangedNotify( &rWorkShell );//Damit SelectShell gerufen wird.
2948cdf0e10cSrcweir 
2949cdf0e10cSrcweir                 // merge the data
2950cdf0e10cSrcweir                 SwDoc* pWorkDoc = rWorkShell.GetDoc();
2951cdf0e10cSrcweir                 SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr();
2952cdf0e10cSrcweir                 pWorkDoc->SetNewDBMgr( this );
2953cdf0e10cSrcweir                 pWorkDoc->EmbedAllLinks();
2954cdf0e10cSrcweir                 SwUndoId nLastUndoId(UNDO_EMPTY);
2955cdf0e10cSrcweir                 if (rWorkShell.GetLastUndoInfo(0, & nLastUndoId))
2956cdf0e10cSrcweir                 {
2957cdf0e10cSrcweir                     if (UNDO_UI_DELETE_INVISIBLECNTNT == nLastUndoId)
2958cdf0e10cSrcweir                     {
2959cdf0e10cSrcweir                         rWorkShell.Undo();
2960cdf0e10cSrcweir                     }
2961cdf0e10cSrcweir                 }
2962cdf0e10cSrcweir                 // #i69485# lock fields to prevent access to the result set while calculating layout
2963cdf0e10cSrcweir 	            rWorkShell.LockExpFlds();
2964cdf0e10cSrcweir                 // create a layout
2965cdf0e10cSrcweir                 rWorkShell.CalcLayout();
2966cdf0e10cSrcweir                 rWorkShell.UnlockExpFlds();
2967cdf0e10cSrcweir                 SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE), rWorkShell.GetView().GetViewFrame()->GetObjectShell()));
2968cdf0e10cSrcweir             rWorkShell.ViewShell::UpdateFlds();
2969cdf0e10cSrcweir                 SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE_FINISHED), rWorkShell.GetView().GetViewFrame()->GetObjectShell()));
2970cdf0e10cSrcweir 
2971cdf0e10cSrcweir             // strip invisible content and convert fields to text
2972cdf0e10cSrcweir             rWorkShell.RemoveInvisibleContent();
2973cdf0e10cSrcweir             rWorkShell.ConvertFieldsToText();
2974cdf0e10cSrcweir             rWorkShell.SetNumberingRestart();
2975cdf0e10cSrcweir             if( bSynchronizedDoc )
2976cdf0e10cSrcweir             {
2977cdf0e10cSrcweir                 lcl_RemoveSectionLinks( rWorkShell );
2978cdf0e10cSrcweir             }
2979cdf0e10cSrcweir 
2980cdf0e10cSrcweir             // insert the document into the target document
2981cdf0e10cSrcweir             rWorkShell.SttEndDoc(sal_False);
2982cdf0e10cSrcweir             rWorkShell.SttEndDoc(sal_True);
2983cdf0e10cSrcweir             rWorkShell.SelAll();
2984cdf0e10cSrcweir             pTargetShell->SttEndDoc(sal_False);
2985cdf0e10cSrcweir 
2986cdf0e10cSrcweir             //#i63806# put the styles to the target document
2987cdf0e10cSrcweir             //if the source uses headers or footers each new copy need to copy a new page styles
2988cdf0e10cSrcweir             if(bPageStylesWithHeaderFooter)
2989cdf0e10cSrcweir             {
2990cdf0e10cSrcweir                 //create a new pagestyle
2991cdf0e10cSrcweir                 //copy the pagedesc from the current document to the new document and change the name of the to-be-applied style
2992cdf0e10cSrcweir 
2993cdf0e10cSrcweir                 SwDoc* pTargetDoc = pTargetShell->GetDoc();
2994cdf0e10cSrcweir                 String sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
2995cdf0e10cSrcweir                 pTargetShell->GetDoc()->MakePageDesc( sNewPageDescName );
2996cdf0e10cSrcweir                 SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
2997cdf0e10cSrcweir                 const SwPageDesc* pWorkPageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
2998cdf0e10cSrcweir 
2999cdf0e10cSrcweir                 if(pWorkPageDesc && pTargetPageDesc)
3000cdf0e10cSrcweir                 {
3001cdf0e10cSrcweir                     pTargetDoc->CopyPageDesc( *pWorkPageDesc, *pTargetPageDesc, sal_False );
3002cdf0e10cSrcweir                     sModifiedStartingPageDesc = sNewPageDescName;
3003cdf0e10cSrcweir                     lcl_CopyFollowPageDesc( *pTargetShell, *pWorkPageDesc, *pTargetPageDesc, nDocNo );
3004cdf0e10cSrcweir                 }
3005cdf0e10cSrcweir             }
3006cdf0e10cSrcweir             if(nDocNo == 1 || bPageStylesWithHeaderFooter)
3007cdf0e10cSrcweir             {
3008cdf0e10cSrcweir                 pTargetView->GetDocShell()->_LoadStyles( *rSourceView.GetDocShell(), sal_True );
3009cdf0e10cSrcweir             }
3010cdf0e10cSrcweir             if(nDocNo > 1)
3011cdf0e10cSrcweir             {
3012cdf0e10cSrcweir                 pTargetShell->InsertPageBreak( &sModifiedStartingPageDesc, nStartingPageNo );
3013cdf0e10cSrcweir             }
3014cdf0e10cSrcweir             else
3015cdf0e10cSrcweir             {
3016cdf0e10cSrcweir                 pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
3017cdf0e10cSrcweir             }
3018cdf0e10cSrcweir             sal_uInt16 nPageCountBefore = pTargetShell->GetPageCnt();
3019cdf0e10cSrcweir             DBG_ASSERT(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
3020cdf0e10cSrcweir             //#i51359# add a second paragraph in case there's only one
3021cdf0e10cSrcweir             {
3022cdf0e10cSrcweir                 SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
3023cdf0e10cSrcweir               SwPosition aTestPos( aIdx );
3024cdf0e10cSrcweir               SwCursor aTestCrsr(aTestPos,0,false);
3025cdf0e10cSrcweir                 if(!aTestCrsr.MovePara(fnParaNext, fnParaStart))
3026cdf0e10cSrcweir                 {
3027cdf0e10cSrcweir                     //append a paragraph
3028cdf0e10cSrcweir                     pWorkDoc->AppendTxtNode( aTestPos );
3029cdf0e10cSrcweir                 }
3030cdf0e10cSrcweir             }
3031cdf0e10cSrcweir             pTargetShell->Paste( rWorkShell.GetDoc(), sal_True );
3032cdf0e10cSrcweir             //convert fields in page styles (header/footer - has to be done after the first document has been pasted
3033cdf0e10cSrcweir             if(1 == nDocNo)
3034cdf0e10cSrcweir             {
3035cdf0e10cSrcweir                 pTargetShell->CalcLayout();
3036cdf0e10cSrcweir                 pTargetShell->ConvertFieldsToText();
3037cdf0e10cSrcweir             }
3038cdf0e10cSrcweir             //add the document info to the config item
3039cdf0e10cSrcweir             SwDocMergeInfo aMergeInfo;
3040cdf0e10cSrcweir             aMergeInfo.nStartPageInTarget = nPageCountBefore;
3041cdf0e10cSrcweir             //#i72820# calculate layout to be able to find the correct page index
3042cdf0e10cSrcweir             pTargetShell->CalcLayout();
3043cdf0e10cSrcweir             aMergeInfo.nEndPageInTarget = pTargetShell->GetPageCnt();
3044cdf0e10cSrcweir             aMergeInfo.nDBRow = nStartRow;
3045cdf0e10cSrcweir             rMMConfig.AddMergedDocument( aMergeInfo );
3046cdf0e10cSrcweir             ++nRet;
3047cdf0e10cSrcweir 
3048cdf0e10cSrcweir             // the print monitor needs some time to act
3049cdf0e10cSrcweir             for( sal_uInt16 i = 0; i < 25; i++)
3050cdf0e10cSrcweir                 Application::Reschedule();
3051cdf0e10cSrcweir 
3052cdf0e10cSrcweir             //restore the ole DBMgr
3053cdf0e10cSrcweir             pWorkDoc->SetNewDBMgr( pWorkDBMgr );
3054cdf0e10cSrcweir             //now the temporary document should be closed
3055cdf0e10cSrcweir             SfxObjectShellRef xDocSh(pWorkView->GetDocShell());
3056cdf0e10cSrcweir             xDocSh->DoClose();
3057cdf0e10cSrcweir             nEndRow = pImpl->pMergeData->xResultSet->getRow();
3058cdf0e10cSrcweir             ++nDocNo;
3059cdf0e10cSrcweir         } while( !bCancel &&
3060cdf0e10cSrcweir                 (bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
3061cdf0e10cSrcweir 
3062cdf0e10cSrcweir         //deselect all, go out of the frame and go to the beginning of the document
3063cdf0e10cSrcweir         Point aPt(LONG_MIN, LONG_MIN);
3064cdf0e10cSrcweir         pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME);
3065cdf0e10cSrcweir         if (pTargetShell->IsSelFrmMode())
3066cdf0e10cSrcweir         {
3067cdf0e10cSrcweir             pTargetShell->UnSelectFrm();
3068cdf0e10cSrcweir             pTargetShell->LeaveSelFrmMode();
3069cdf0e10cSrcweir         }
3070cdf0e10cSrcweir         pTargetShell->EnterStdMode();
3071cdf0e10cSrcweir         pTargetShell->SttDoc();
3072cdf0e10cSrcweir         //
3073cdf0e10cSrcweir     }
3074cdf0e10cSrcweir     catch( Exception& rEx)
3075cdf0e10cSrcweir     {
3076cdf0e10cSrcweir         (void)rEx;
3077cdf0e10cSrcweir         DBG_ERROR("exception caught in SwNewDBMgr::MergeDocuments");
3078cdf0e10cSrcweir     }
3079cdf0e10cSrcweir     DELETEZ(pImpl->pMergeData);
3080cdf0e10cSrcweir     bInMerge = sal_False;
3081cdf0e10cSrcweir     return nRet;
3082cdf0e10cSrcweir }
3083cdf0e10cSrcweir /* -----------------09.12.2002 12:38-----------------
3084cdf0e10cSrcweir  *
3085cdf0e10cSrcweir  * --------------------------------------------------*/
3086cdf0e10cSrcweir SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwNewDBMgr& rMgr) :
3087cdf0e10cSrcweir     rDBMgr(rMgr)
3088cdf0e10cSrcweir {};
3089cdf0e10cSrcweir /* -----------------09.12.2002 12:39-----------------
3090cdf0e10cSrcweir  *
3091cdf0e10cSrcweir  * --------------------------------------------------*/
3092cdf0e10cSrcweir SwConnectionDisposedListener_Impl::~SwConnectionDisposedListener_Impl()
3093cdf0e10cSrcweir {};
3094cdf0e10cSrcweir /* -----------------09.12.2002 12:39-----------------
3095cdf0e10cSrcweir  *
3096cdf0e10cSrcweir  * --------------------------------------------------*/
3097cdf0e10cSrcweir void SwConnectionDisposedListener_Impl::disposing( const EventObject& rSource )
3098cdf0e10cSrcweir         throw (RuntimeException)
3099cdf0e10cSrcweir {
3100cdf0e10cSrcweir     ::vos::OGuard aGuard(Application::GetSolarMutex());
3101cdf0e10cSrcweir     uno::Reference<XConnection> xSource(rSource.Source, UNO_QUERY);
3102cdf0e10cSrcweir     for(sal_uInt16 nPos = rDBMgr.aDataSourceParams.Count(); nPos; nPos--)
3103cdf0e10cSrcweir     {
3104cdf0e10cSrcweir         SwDSParam* pParam = rDBMgr.aDataSourceParams[nPos - 1];
3105cdf0e10cSrcweir         if(pParam->xConnection.is() &&
3106cdf0e10cSrcweir                 (xSource == pParam->xConnection))
3107cdf0e10cSrcweir         {
3108cdf0e10cSrcweir             rDBMgr.aDataSourceParams.DeleteAndDestroy(nPos - 1);
3109cdf0e10cSrcweir         }
3110cdf0e10cSrcweir     }
3111cdf0e10cSrcweir }
3112