2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:15:01 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 17:23:11 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 17:23:11 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 17:23:11 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 17:23:11 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 17:23:11 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
2008-04-10 17:23:11 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:15:01 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 21:43:40 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-07-28 13:59:44 +00:00
|
|
|
#include <unotxdoc.hxx>
|
2003-06-10 08:15:14 +00:00
|
|
|
#include <com/sun/star/text/NotePrintMode.hpp>
|
2006-05-02 14:20:53 +00:00
|
|
|
#include <sfx2/app.hxx>
|
2000-11-13 07:32:00 +00:00
|
|
|
#include <com/sun/star/sdb/CommandType.hpp>
|
2005-03-30 09:55:07 +00:00
|
|
|
#include <com/sun/star/sdb/XDocumentDataSource.hpp>
|
2000-10-27 10:26:20 +00:00
|
|
|
#include <com/sun/star/frame/XComponentLoader.hpp>
|
2005-10-19 07:25:32 +00:00
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
2004-08-02 13:20:28 +00:00
|
|
|
#include <com/sun/star/lang/XEventListener.hpp>
|
2012-08-29 09:32:55 +02:00
|
|
|
#include <com/sun/star/util/NumberFormatter.hpp>
|
2012-09-18 09:46:34 +02:00
|
|
|
#include <com/sun/star/sdb/DatabaseContext.hpp>
|
2000-12-01 10:45:55 +00:00
|
|
|
#include <com/sun/star/sdb/XCompletedConnection.hpp>
|
2002-08-21 11:23:43 +00:00
|
|
|
#include <com/sun/star/sdb/XCompletedExecution.hpp>
|
2001-06-08 12:47:33 +00:00
|
|
|
#include <com/sun/star/container/XChild.hpp>
|
2003-03-27 14:45:43 +00:00
|
|
|
#include <com/sun/star/text/MailMergeEvent.hpp>
|
2004-08-02 13:20:28 +00:00
|
|
|
#include <com/sun/star/frame/XStorable.hpp>
|
2012-10-02 15:03:12 +02:00
|
|
|
#include <com/sun/star/task/InteractionHandler.hpp>
|
2009-07-28 13:59:44 +00:00
|
|
|
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
|
2004-08-02 13:20:28 +00:00
|
|
|
#include <com/sun/star/ui/dialogs/XFilePicker.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
|
|
|
|
#include <com/sun/star/uno/XNamingService.hpp>
|
2007-11-06 15:25:40 +00:00
|
|
|
#include <com/sun/star/util/XCloseable.hpp>
|
2008-03-07 10:16:55 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2005-01-28 14:47:46 +00:00
|
|
|
#include <sfx2/fcontnr.hxx>
|
2004-08-02 13:20:28 +00:00
|
|
|
#include <sfx2/filedlghelper.hxx>
|
2000-10-27 10:26:20 +00:00
|
|
|
#include <sfx2/viewfrm.hxx>
|
2001-02-21 11:27:37 +00:00
|
|
|
#include <dbconfig.hxx>
|
2001-08-30 12:56:46 +00:00
|
|
|
#include <swdbtoolsclient.hxx>
|
2004-09-20 12:11:33 +00:00
|
|
|
#include <pagedesc.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <vcl/lstbox.hxx>
|
2000-11-06 08:30:33 +00:00
|
|
|
#include <unotools/tempfile.hxx>
|
2009-10-06 07:38:24 +02:00
|
|
|
#include <unotools/pathoptions.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/urihelper.hxx>
|
|
|
|
#include <svl/zforlist.hxx>
|
|
|
|
#include <svl/zformat.hxx>
|
|
|
|
#include <svl/stritem.hxx>
|
|
|
|
#include <svl/eitem.hxx>
|
2009-08-14 13:56:56 +00:00
|
|
|
#include <vcl/oldprintadaptor.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <sfx2/docfile.hxx>
|
|
|
|
#include <sfx2/progress.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
2009-12-15 21:55:40 +01:00
|
|
|
#include <svl/mailenum.hxx>
|
2002-11-29 11:14:12 +00:00
|
|
|
#include <cmdid.h>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <swmodule.hxx>
|
|
|
|
#include <view.hxx>
|
|
|
|
#include <docsh.hxx>
|
|
|
|
#include <edtwin.hxx>
|
|
|
|
#include <wrtsh.hxx>
|
|
|
|
#include <fldbas.hxx>
|
|
|
|
#include <initui.hxx>
|
|
|
|
#include <swundo.hxx>
|
|
|
|
#include <flddat.hxx>
|
|
|
|
#include <modcfg.hxx>
|
|
|
|
#include <shellio.hxx>
|
|
|
|
#include <dbui.hxx>
|
|
|
|
#include <dbmgr.hxx>
|
|
|
|
#include <doc.hxx>
|
|
|
|
#include <swwait.hxx>
|
2001-10-19 14:33:53 +00:00
|
|
|
#include <swunohelper.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <dbui.hrc>
|
|
|
|
#include <globals.hrc>
|
|
|
|
#include <statstr.hrc>
|
2004-09-20 12:11:33 +00:00
|
|
|
#include <mmconfigitem.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <sfx2/request.hxx>
|
|
|
|
#include <hintids.hxx>
|
2008-03-07 10:16:55 +00:00
|
|
|
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
|
2002-08-21 11:23:43 +00:00
|
|
|
#include <com/sun/star/sdbc/XRowSet.hpp>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
|
|
|
|
#include <com/sun/star/sdb/XColumn.hpp>
|
|
|
|
#include <com/sun/star/sdbc/DataType.hpp>
|
|
|
|
#include <com/sun/star/sdbc/ResultSetType.hpp>
|
2005-01-28 14:47:46 +00:00
|
|
|
#include <com/sun/star/mail/MailAttachment.hpp>
|
2012-10-02 15:03:12 +02:00
|
|
|
#include <comphelper/componentcontext.hxx>
|
2000-10-20 13:18:07 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2008-03-07 10:16:55 +00:00
|
|
|
#include <comphelper/property.hxx>
|
2012-06-11 13:15:18 +01:00
|
|
|
#include <comphelper/string.hxx>
|
|
|
|
#include <comphelper/types.hxx>
|
2005-01-28 14:47:46 +00:00
|
|
|
#include <mailmergehelper.hxx>
|
|
|
|
#include <maildispatcher.hxx>
|
2010-01-13 22:25:07 +01:00
|
|
|
#include <svtools/htmlcfg.hxx>
|
2006-04-07 14:17:54 +00:00
|
|
|
#include <i18npool/mslangid.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
#include <com/sun/star/util/XNumberFormatTypes.hpp>
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/langitem.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/numuno.hxx>
|
2000-11-13 07:32:00 +00:00
|
|
|
|
2003-03-27 14:45:43 +00:00
|
|
|
#include <unomailmerge.hxx>
|
2000-11-13 07:32:00 +00:00
|
|
|
#include <sfx2/event.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
2002-08-21 11:23:43 +00:00
|
|
|
#include <svx/dataaccessdescriptor.hxx>
|
2010-10-16 03:22:02 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2004-09-20 12:11:33 +00:00
|
|
|
#include <rtl/textenc.h>
|
2005-10-19 07:25:32 +00:00
|
|
|
#include <ndindex.hxx>
|
|
|
|
#include <pam.hxx>
|
|
|
|
#include <swcrsr.hxx>
|
2005-03-11 09:48:02 +00:00
|
|
|
#include <swevent.hxx>
|
2004-09-20 12:11:33 +00:00
|
|
|
#include <osl/file.hxx>
|
2007-09-27 10:31:02 +00:00
|
|
|
#include <swabstdlg.hxx>
|
2006-08-14 16:30:22 +00:00
|
|
|
#include <fmthdft.hxx>
|
2007-09-27 10:31:02 +00:00
|
|
|
#include <envelp.hrc>
|
2005-01-28 14:47:46 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2007-09-27 10:31:02 +00:00
|
|
|
#include <unomid.h>
|
2010-07-29 14:58:17 +02:00
|
|
|
#include <section.hxx>
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::svx;
|
2000-10-27 10:26:20 +00:00
|
|
|
using namespace ::com::sun::star;
|
2007-09-27 10:31:02 +00:00
|
|
|
using namespace ::com::sun::star::text;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::frame;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::sdb;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::sdbcx;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
using namespace ::com::sun::star::task;
|
|
|
|
using namespace ::com::sun::star::ui::dialogs;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
#define DB_SEP_SPACE 0
|
|
|
|
#define DB_SEP_TAB 1
|
|
|
|
#define DB_SEP_RETURN 2
|
|
|
|
#define DB_SEP_NEWLINE 3
|
|
|
|
|
2001-06-06 05:20:21 +00:00
|
|
|
const sal_Char cCursor[] = "Cursor";
|
|
|
|
const sal_Char cCommand[] = "Command";
|
|
|
|
const sal_Char cCommandType[] = "CommandType";
|
|
|
|
const sal_Char cDataSourceName[] = "DataSourceName";
|
|
|
|
const sal_Char cSelection[] = "Selection";
|
2001-06-08 12:47:33 +00:00
|
|
|
const sal_Char cActiveConnection[] = "ActiveConnection";
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2002-08-21 11:23:43 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Use nameless namespace to avoid to rubbish the global namespace
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2004-11-16 15:57:21 +00:00
|
|
|
bool lcl_getCountFromResultSet( sal_Int32& rCount, const uno::Reference<XResultSet>& xResultSet )
|
|
|
|
{
|
|
|
|
uno::Reference<XPropertySet> xPrSet(xResultSet, UNO_QUERY);
|
|
|
|
if(xPrSet.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2007-11-12 15:30:55 +00:00
|
|
|
sal_Bool bFinal = sal_False;
|
2004-11-16 15:57:21 +00:00
|
|
|
Any aFinal = xPrSet->getPropertyValue(C2U("IsRowCountFinal"));
|
|
|
|
aFinal >>= bFinal;
|
|
|
|
if(!bFinal)
|
|
|
|
{
|
|
|
|
xResultSet->last();
|
|
|
|
xResultSet->first();
|
|
|
|
}
|
|
|
|
Any aCount = xPrSet->getPropertyValue(C2U("RowCount"));
|
|
|
|
if( aCount >>= rCount )
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2004-11-16 15:57:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-25 22:33:34 +01:00
|
|
|
// copy compatibility options
|
2005-10-18 12:49:13 +00:00
|
|
|
void lcl_CopyCompatibilityOptions( SwWrtShell& rSourceShell, SwWrtShell& rTargetShell)
|
|
|
|
{
|
2006-08-14 16:30:22 +00:00
|
|
|
IDocumentSettingAccess* pIDsa = rSourceShell.getIDocumentSettingAccess();
|
|
|
|
|
|
|
|
rTargetShell.SetParaSpaceMax( pIDsa->get(IDocumentSettingAccess::PARA_SPACE_MAX));
|
|
|
|
rTargetShell.SetParaSpaceMaxAtPages(pIDsa->get(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES));
|
|
|
|
rTargetShell.SetTabCompat( pIDsa->get(IDocumentSettingAccess::TAB_COMPAT));
|
|
|
|
rTargetShell.SetAddExtLeading( pIDsa->get(IDocumentSettingAccess::ADD_EXT_LEADING));
|
|
|
|
rTargetShell.SetUseVirDev( pIDsa->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE));
|
|
|
|
rTargetShell.SetAddParaSpacingToTableCells( pIDsa->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS));
|
|
|
|
rTargetShell.SetUseFormerLineSpacing( pIDsa->get(IDocumentSettingAccess::OLD_LINE_SPACING));
|
|
|
|
rTargetShell.SetUseFormerObjectPositioning( pIDsa->get(IDocumentSettingAccess::USE_FORMER_OBJECT_POS));
|
|
|
|
rTargetShell.SetConsiderWrapOnObjPos( pIDsa->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION));
|
|
|
|
rTargetShell.SetUseFormerTextWrapping( pIDsa->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING));
|
2005-10-18 12:49:13 +00:00
|
|
|
}
|
2002-08-21 11:23:43 +00:00
|
|
|
}
|
2002-12-09 12:58:30 +00:00
|
|
|
|
|
|
|
class SwConnectionDisposedListener_Impl : public cppu::WeakImplHelper1
|
2007-09-27 10:31:02 +00:00
|
|
|
< lang::XEventListener >
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
|
|
|
SwNewDBMgr& rDBMgr;
|
|
|
|
|
|
|
|
virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
|
|
|
|
public:
|
|
|
|
SwConnectionDisposedListener_Impl(SwNewDBMgr& rMgr);
|
|
|
|
~SwConnectionDisposedListener_Impl();
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2002-12-09 12:58:30 +00:00
|
|
|
};
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2002-12-09 12:58:30 +00:00
|
|
|
struct SwNewDBMgr_Impl
|
|
|
|
{
|
|
|
|
SwDSParam* pMergeData;
|
2004-05-10 15:20:29 +00:00
|
|
|
AbstractMailMergeDlg* pMergeDialog;
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<lang::XEventListener> xDisposeListener;
|
2002-12-09 12:58:30 +00:00
|
|
|
|
|
|
|
SwNewDBMgr_Impl(SwNewDBMgr& rDBMgr)
|
|
|
|
:pMergeData(0)
|
|
|
|
,pMergeDialog(0)
|
|
|
|
,xDisposeListener(new SwConnectionDisposedListener_Impl(rDBMgr))
|
|
|
|
{}
|
|
|
|
};
|
2003-11-25 09:48:37 +00:00
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static void lcl_InitNumberFormatter(SwDSParam& rParam, uno::Reference<XDataSource> xSource)
|
2003-11-25 09:48:37 +00:00
|
|
|
{
|
2012-08-29 09:32:55 +02:00
|
|
|
uno::Reference<XComponentContext> xContext = ::comphelper::getProcessComponentContext();
|
|
|
|
rParam.xFormatter = uno::Reference<util::XNumberFormatter>(util::NumberFormatter::create(xContext), UNO_QUERY);
|
2003-11-25 09:48:37 +00:00
|
|
|
if(!xSource.is())
|
|
|
|
xSource = SwNewDBMgr::getDataSourceAsParent(rParam.xConnection, rParam.sDataSource);
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
|
2003-11-25 09:48:37 +00:00
|
|
|
if(xSourceProps.is())
|
|
|
|
{
|
|
|
|
Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
|
|
|
|
if(aFormats.hasValue())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNumberFormatsSupplier> xSuppl;
|
2003-11-25 09:48:37 +00:00
|
|
|
aFormats >>= xSuppl;
|
|
|
|
if(xSuppl.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
|
2003-11-25 09:48:37 +00:00
|
|
|
Any aNull = xSettings->getPropertyValue(C2U("NullDate"));
|
|
|
|
aNull >>= rParam.aNullDate;
|
|
|
|
if(rParam.xFormatter.is())
|
|
|
|
rParam.xFormatter->attachNumberFormatsSupplier(xSuppl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static sal_Bool lcl_MoveAbsolute(SwDSParam* pParam, long nAbsPos)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRet = sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(pParam->bScrollable)
|
|
|
|
{
|
|
|
|
bRet = pParam->xResultSet->absolute( nAbsPos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("no absolute positioning available");
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static sal_Bool lcl_GetColumnCnt(SwDSParam* pParam,
|
2012-03-07 16:52:06 +00:00
|
|
|
const String& rColumnName, long nLanguage, rtl::OUString& rResult, double* pNumber)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumnsSupplier > xColsSupp( pParam->xResultSet, UNO_QUERY );
|
2005-10-19 07:25:32 +00:00
|
|
|
uno::Reference<XNameAccess> xCols;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
xCols = xColsSupp->getColumns();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const lang::DisposedException&)
|
2005-10-19 07:25:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
if(!xCols.is() || !xCols->hasByName(rColumnName))
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
Any aCol = xCols->getByName(rColumnName);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XPropertySet > xColumnProps;
|
2001-09-06 12:36:15 +00:00
|
|
|
aCol >>= xColumnProps;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
SwDBFormatData aFormatData;
|
2003-11-25 09:48:37 +00:00
|
|
|
if(!pParam->xFormatter.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XDataSource> xSource = SwNewDBMgr::getDataSourceAsParent(
|
2003-11-25 09:48:37 +00:00
|
|
|
pParam->xConnection,pParam->sDataSource);
|
|
|
|
lcl_InitNumberFormatter(*pParam, xSource );
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
aFormatData.aNullDate = pParam->aNullDate;
|
|
|
|
aFormatData.xFormatter = pParam->xFormatter;
|
|
|
|
|
2006-04-07 14:17:54 +00:00
|
|
|
MsLangId::convertLanguageToLocale( (LanguageType)nLanguage, aFormatData.aLocale );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
rResult = SwNewDBMgr::GetDBField( xColumnProps, aFormatData, pNumber);
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_True;
|
2000-09-18 16:15:01 +00:00
|
|
|
};
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: import data
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::MergeNew(const SwMergeDescriptor& rMergeDesc )
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2005-01-28 14:47:46 +00:00
|
|
|
SetMergeType( rMergeDesc.nMergeType );
|
2000-11-13 07:32:00 +00:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(!bInMerge && !pImpl->pMergeData, "merge already activated!");
|
2000-11-13 07:32:00 +00:00
|
|
|
|
2001-03-30 11:05:13 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.nCommandType = CommandType::TABLE;
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XResultSet> xResSet;
|
2001-06-26 13:35:16 +00:00
|
|
|
Sequence<Any> aSelection;
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
aData.sDataSource = rMergeDesc.rDescriptor.getDataSource();
|
|
|
|
rMergeDesc.rDescriptor[daCommand] >>= aData.sCommand;
|
|
|
|
rMergeDesc.rDescriptor[daCommandType] >>= aData.nCommandType;
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
if ( rMergeDesc.rDescriptor.has(daCursor) )
|
|
|
|
rMergeDesc.rDescriptor[daCursor] >>= xResSet;
|
|
|
|
if ( rMergeDesc.rDescriptor.has(daSelection) )
|
|
|
|
rMergeDesc.rDescriptor[daSelection] >>= aSelection;
|
|
|
|
if ( rMergeDesc.rDescriptor.has(daConnection) )
|
|
|
|
rMergeDesc.rDescriptor[daConnection] >>= xConnection;
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2012-01-17 17:47:34 -02:00
|
|
|
if(aData.sDataSource.isEmpty() || aData.sCommand.isEmpty() || !xResSet.is())
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
2002-08-21 11:23:43 +00:00
|
|
|
|
|
|
|
pImpl->pMergeData = new SwDSParam(aData, xResSet, aSelection);
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pTemp = FindDSData(aData, sal_False);
|
2001-03-30 11:05:13 +00:00
|
|
|
if(pTemp)
|
2001-08-30 12:56:46 +00:00
|
|
|
*pTemp = *pImpl->pMergeData;
|
2001-03-30 11:05:13 +00:00
|
|
|
else
|
2001-11-26 14:07:28 +00:00
|
|
|
{
|
2011-02-25 22:33:34 +01:00
|
|
|
// calls from the calculator may have added a connection with an invalid commandtype
|
2001-11-26 14:07:28 +00:00
|
|
|
//"real" data base connections added here have to re-use the already available
|
|
|
|
//DSData and set the correct CommandType
|
|
|
|
SwDBData aTempData(aData);
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
pTemp = FindDSData(aData, sal_False);
|
2001-11-26 14:07:28 +00:00
|
|
|
if(pTemp)
|
|
|
|
*pTemp = *pImpl->pMergeData;
|
|
|
|
else
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
|
|
|
SwDSParam* pInsert = new SwDSParam(*pImpl->pMergeData);
|
2012-05-23 13:49:36 +02:00
|
|
|
aDataSourceParams.push_back(pInsert);
|
2002-12-09 12:58:30 +00:00
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XComponent> xComponent(pInsert->xConnection, UNO_QUERY);
|
2002-12-09 12:58:30 +00:00
|
|
|
if(xComponent.is())
|
|
|
|
xComponent->addEventListener(pImpl->xDisposeListener);
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2001-11-26 14:07:28 +00:00
|
|
|
}
|
2001-08-30 12:56:46 +00:00
|
|
|
if(!pImpl->pMergeData->xConnection.is())
|
|
|
|
pImpl->pMergeData->xConnection = xConnection;
|
2002-12-09 12:58:30 +00:00
|
|
|
// add an XEventListener
|
2001-01-26 14:51:55 +00:00
|
|
|
|
|
|
|
try{
|
|
|
|
//set to start position
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData->aSelection.getLength())
|
2001-01-26 14:51:55 +00:00
|
|
|
{
|
2002-08-21 11:23:43 +00:00
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
pImpl->pMergeData->aSelection.getConstArray()[ pImpl->pMergeData->nSelectionIndex++ ] >>= nPos;
|
|
|
|
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->absolute( nPos );
|
2001-08-30 12:56:46 +00:00
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
|
|
|
if(pImpl->pMergeData->nSelectionIndex >= pImpl->pMergeData->aSelection.getLength())
|
2011-01-17 15:06:54 +01:00
|
|
|
pImpl->pMergeData->bEndOfDB = sal_True;
|
2001-01-26 14:51:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->first();
|
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
2001-01-26 14:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2001-01-26 14:51:55 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
pImpl->pMergeData->bEndOfDB = sal_True;
|
2001-08-30 12:56:46 +00:00
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("exception in MergeNew()");
|
2001-01-26 14:51:55 +00:00
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XDataSource> xSource = SwNewDBMgr::getDataSourceAsParent(xConnection,aData.sDataSource);
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2003-11-25 09:48:37 +00:00
|
|
|
lcl_InitNumberFormatter(*pImpl->pMergeData, xSource);
|
2000-11-13 07:32:00 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
rMergeDesc.rSh.ChgDBData(aData);
|
2011-01-17 15:06:54 +01:00
|
|
|
bInMerge = sal_True;
|
2000-11-13 07:32:00 +00:00
|
|
|
|
|
|
|
if (IsInitDBFields())
|
|
|
|
{
|
2011-02-25 22:21:36 +01:00
|
|
|
// with database fields without DB-Name, use DB-Name from Doc
|
2012-01-13 00:20:39 -05:00
|
|
|
std::vector<String> aDBNames;
|
|
|
|
aDBNames.push_back(String());
|
2007-09-27 10:31:02 +00:00
|
|
|
SwDBData aInsertData = rMergeDesc.rSh.GetDBData();
|
|
|
|
String sDBName = aInsertData.sDataSource;
|
2001-02-21 11:27:37 +00:00
|
|
|
sDBName += DB_DELIM;
|
2007-09-27 10:31:02 +00:00
|
|
|
sDBName += (String)aInsertData.sCommand;
|
2001-02-21 11:27:37 +00:00
|
|
|
sDBName += DB_DELIM;
|
2007-09-27 10:31:02 +00:00
|
|
|
sDBName += String::CreateFromInt32(aInsertData.nCommandType);
|
2005-01-28 14:47:46 +00:00
|
|
|
rMergeDesc.rSh.ChangeDBFields( aDBNames, sDBName);
|
2011-01-17 15:06:54 +01:00
|
|
|
SetInitDBFields(sal_False);
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRet = sal_True;
|
2005-01-28 14:47:46 +00:00
|
|
|
switch(rMergeDesc.nMergeType)
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
|
|
|
case DBMGR_MERGE:
|
2011-02-25 22:21:36 +01:00
|
|
|
bRet = Merge(&rMergeDesc.rSh);
|
2000-11-13 07:32:00 +00:00
|
|
|
break;
|
|
|
|
|
2009-09-01 08:22:04 +00:00
|
|
|
case DBMGR_MERGE_MAILMERGE: // printing merge from 'old' merge dialog or from UNO-component
|
2000-11-13 07:32:00 +00:00
|
|
|
case DBMGR_MERGE_MAILING:
|
|
|
|
case DBMGR_MERGE_MAILFILES:
|
2007-07-05 06:38:34 +00:00
|
|
|
case DBMGR_MERGE_SINGLE_FILE:
|
2005-01-28 14:47:46 +00:00
|
|
|
// save files and send them as e-Mail if required
|
|
|
|
bRet = MergeMailFiles(&rMergeDesc.rSh,
|
|
|
|
rMergeDesc);
|
2000-11-13 07:32:00 +00:00
|
|
|
break;
|
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
default:
|
|
|
|
// insert selected entries
|
|
|
|
// (was: InsertRecord)
|
2005-01-28 14:47:46 +00:00
|
|
|
ImportFromConnection(&rMergeDesc.rSh);
|
2000-11-13 07:32:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndMerge();
|
|
|
|
return bRet;
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: import data
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::Merge(SwWrtShell* pSh)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
pSh->StartAllAction();
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
pSh->ViewShell::UpdateFlds(sal_True);
|
2000-09-18 16:15:01 +00:00
|
|
|
pSh->SetModified();
|
|
|
|
|
|
|
|
pSh->EndAllAction();
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_True;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SwNewDBMgr::ImportFromConnection( SwWrtShell* pSh )
|
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
pSh->StartAllAction();
|
2007-09-27 10:31:02 +00:00
|
|
|
pSh->StartUndo(UNDO_EMPTY);
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bGroupUndo(pSh->DoesGroupUndo());
|
|
|
|
pSh->DoGroupUndo(sal_False);
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
if( pSh->HasSelection() )
|
|
|
|
pSh->DelRight();
|
|
|
|
|
|
|
|
SwWait *pWait = 0;
|
|
|
|
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong i = 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
do {
|
|
|
|
|
|
|
|
ImportDBEntry(pSh);
|
|
|
|
if( 10 == ++i )
|
2011-01-17 15:06:54 +01:00
|
|
|
pWait = new SwWait( *pSh->GetView().GetDocShell(), sal_True);
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
} while(ToNextMergeRecord());
|
|
|
|
}
|
|
|
|
|
|
|
|
pSh->DoGroupUndo(bGroupUndo);
|
2007-09-27 10:31:02 +00:00
|
|
|
pSh->EndUndo(UNDO_EMPTY);
|
2000-09-18 16:15:01 +00:00
|
|
|
pSh->EndAllAction();
|
|
|
|
delete pWait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static String lcl_FindColumn(const String& sFormatStr,sal_uInt16 &nUsedPos, sal_uInt8 &nSeparator)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
String sReturn;
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nLen = sFormatStr.Len();
|
2000-09-18 16:15:01 +00:00
|
|
|
nSeparator = 0xff;
|
|
|
|
while(nUsedPos < nLen && nSeparator == 0xff)
|
|
|
|
{
|
|
|
|
sal_Unicode cAkt = sFormatStr.GetChar(nUsedPos);
|
|
|
|
switch(cAkt)
|
|
|
|
{
|
|
|
|
case ',':
|
|
|
|
nSeparator = DB_SEP_SPACE;
|
|
|
|
break;
|
|
|
|
case ';':
|
|
|
|
nSeparator = DB_SEP_RETURN;
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
nSeparator = DB_SEP_TAB;
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
nSeparator = DB_SEP_NEWLINE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sReturn += cAkt;
|
|
|
|
}
|
|
|
|
nUsedPos++;
|
|
|
|
|
|
|
|
}
|
|
|
|
return sReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwNewDBMgr::ImportDBEntry(SwWrtShell* pSh)
|
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, UNO_QUERY );
|
|
|
|
uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
|
2007-09-27 10:31:02 +00:00
|
|
|
String sFormatStr;
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nFmtLen = sFormatStr.Len();
|
2000-09-18 16:15:01 +00:00
|
|
|
if( nFmtLen )
|
|
|
|
{
|
|
|
|
const char cSpace = ' ';
|
|
|
|
const char cTab = '\t';
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nUsedPos = 0;
|
|
|
|
sal_uInt8 nSeparator;
|
2000-09-18 16:15:01 +00:00
|
|
|
String sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
|
|
|
|
while( sColumn.Len() )
|
|
|
|
{
|
|
|
|
if(!xCols->hasByName(sColumn))
|
|
|
|
return;
|
|
|
|
Any aCol = xCols->getByName(sColumn);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XPropertySet > xColumnProp;
|
2001-09-06 12:36:15 +00:00
|
|
|
aCol >>= xColumnProp;
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xColumnProp.is())
|
|
|
|
{
|
|
|
|
SwDBFormatData aDBFormat;
|
|
|
|
String sInsert = GetDBField( xColumnProp, aDBFormat);
|
|
|
|
if( DB_SEP_SPACE == nSeparator )
|
|
|
|
sInsert += cSpace;
|
|
|
|
else if( DB_SEP_TAB == nSeparator)
|
|
|
|
sInsert += cTab;
|
|
|
|
pSh->Insert(sInsert);
|
|
|
|
if( DB_SEP_RETURN == nSeparator)
|
|
|
|
pSh->SplitNode();
|
|
|
|
else if(DB_SEP_NEWLINE == nSeparator)
|
|
|
|
pSh->InsertLineBreak();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-25 22:21:36 +01:00
|
|
|
// column not found -> show error
|
2012-07-04 23:58:05 +01:00
|
|
|
rtl::OUStringBuffer sInsert;
|
|
|
|
sInsert.append('?').append(sColumn).append('?');
|
|
|
|
pSh->Insert(sInsert.makeStringAndClear());
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
|
|
|
|
}
|
|
|
|
pSh->SplitNode();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String sStr;
|
2001-09-04 11:40:59 +00:00
|
|
|
Sequence<rtl::OUString> aColNames = xCols->getElementNames();
|
|
|
|
const rtl::OUString* pColNames = aColNames.getConstArray();
|
2000-09-18 16:15:01 +00:00
|
|
|
long nLength = aColNames.getLength();
|
|
|
|
for(long i = 0; i < nLength; i++)
|
|
|
|
{
|
|
|
|
Any aCol = xCols->getByName(pColNames[i]);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XPropertySet > xColumnProp;
|
2001-09-06 12:36:15 +00:00
|
|
|
aCol >>= xColumnProp;
|
2000-09-18 16:15:01 +00:00
|
|
|
SwDBFormatData aDBFormat;
|
|
|
|
sStr += GetDBField( xColumnProp, aDBFormat);
|
|
|
|
if (i < nLength - 1)
|
|
|
|
sStr += '\t';
|
|
|
|
}
|
CWS-TOOLING: integrate CWS odfmetadata3
2009-09-11 Michael Stahl merge DEV300_m58
2009-09-07 Michael Stahl SwFmtFld::Modify(): do nothing on RES_OBJECTDYING
2009-08-27 Michael Stahl #i91565#, #i91566#: TextPortionEnumerationTest.java: add test document
2009-08-27 Michael Stahl #i91565#, #i91566#: add complex test: TextPortionEnumerationTest.java
2009-08-27 Michael Stahl CLiteral::initialize(): zero-length literals probably not an error
2009-08-27 Michael Stahl #i91565#, #i91566#: offapi: new InContentMetadata and MetadataField services
adapt TextPortion for InContentMetadata
2009-08-27 Michael Stahl #i91564#: xmloff: load/store xml:id and RDFa for text:bookmark(-start).
2009-08-27 Michael Stahl #i91564#: sw core: add support for xml:id at bookmarks:
sw::mark::Bookmark: derive from Metadatable.
SwHistoryBookmark, SaveBookmark: store a MetadatableUndo.
ndcopy.cxx: lcl_CopyBookmarks(): copy the xml:id.
SwXBookmark: derive from MetadatableMixin.
2009-08-27 Michael Stahl #i91565#, #i91566#: xmloff: refactor ruby import so nested meta(-field) works:
remove XMLRubyHint_Impl.
XMLImpRubyContext_Impl::~XMLImpRubyContext_Impl(): insert ruby directly.
2009-08-27 Michael Stahl #i91565#, #i91566#: xmloff: fix text:meta(-field) import/export:
new XMLTextParagraphExport::exportTextField() overload for XTextField.
CreateAndInsertMark(): set xml:id after insertion.
fix meta(-field) service names, bugs etc.
2009-08-27 Michael Stahl #i91565#, #i91566#: sw text formatting: paint background of meta(-field) body:
SwFont: add member m_nMetaCount.
txttypes.hxx: add POR_META.
atrstck.cxx: handle RES_TXTATR_META(FIELD).
itrform2.cxx: SwTxtFormatter::WhichTxtPor(): create new class SwMetaPortion.
2009-08-27 Michael Stahl #i91566#: sw text formatting: display meta-field prefix and suffix:
SwAttrIter::GetAttr(): replace with call to GetTxtAttrForCharAt().
SwTxtFormatter::NewExtraPortion(): handle meta-field prefix.
SwTxtFormatter: new member m_nHintEndIndex.
SwTxtFormatter::WhichFirstPortion(): call TryNewNoLengthPortion().
SwTxtFormatter::TryNewNoLengthPortion(): new; handle suffix of meta-field.
SwTxtFormatter::UnderFlow(): UGLY HACK: decrement m_nHintEndIndex.
SwFldPortion: add flag m_bNoLength: portion has zero length (for suffix).
2009-08-27 Michael Stahl #i91565#, #i91566#: extend text:meta(-field) uno wrapper with XText interface:
unoobj.hxx: new CursorType CURSOR_META.
unoobj2.cxx: refactor SwXText implementation to ensure that when the SwXText
belongs to a SwXMeta, content is always inserted inside the meta(-field).
unoobj.cxx: new SwXTextCursor::ForceIntoMeta(): cursor stays in meta(-field).
unometa.hxx: SwXMeta implements XText, forwarding to a member SwXMetaText.
DocInsertStringSplitCR(), SwX*::attachToRange(), SwX*::DeleteAndInsert():
use FORCEHINTEXPAND hack to ensure insert into the meta(-field) at the end.
2009-08-27 Michael Stahl #i91565#, #i91566#: add text:meta(-field) uno wrapper to sw:
fmtmeta.hxx, fmtatr2.cxx: new class sw::MetaField, new sw::MetaFieldManager.
doc.hxx, docnew.cxx: new SwDoc::GetMetaFieldManager().
unocoll.hxx,.cxx: new SW_SERVICE_FIELDTYPE_METAFIELD, SW_SERVICE_TYPE_META.
unomap.hxx,.cxx: new PROPERTY_MAP_METAFIELD.
unoprnms.hxx: new UNO_NAME_META.
unoport.hxx: new PORTION_META; add "InContentMetadata" prop to SwXTextPortion.
new unometa.hxx: new class SwXMeta and SwXMetaField.
unofield.cxx: SwXFieldEnumeration: include meta-fields.
unoportenum.cxx: handle RES_TXTATR_META(FIELD) by using a portion list stack.
unotext.cxx: SwXText::insertTextContent(): handle meta(-field) as attribute.
2009-08-27 Michael Stahl #i91565#, #i91566#: ndhints.cxx: remove sort number from SwTxtAttrNesting
2009-08-27 Michael Stahl #i91565#, #i91566#: add support for hints with end and CH_TXTATR to sw core:
doc.hxx, docedt.cxx: replace SwDoc::Delete(), DeleteAndJoin(), ReplaceRange()
with wrappers that split at left-overlapped end+CH_TXTATR hints.
txatbase.hxx: new member SwTxtAttr::m_bHasDummyChar.
ndtxt.hxx: rename SwTxtNode::GetTxtAttr() to GetTxtAttrForCharAt().
ndtxt.cxx: SwTxtNode::CopyText(): copy end+CH_TXTATR hints iff copy CH_TXTATR.
txtatr2.cxx, thints.cxx: SwTxtMeta gets a CH_TXTATR.
2009-08-27 Michael Stahl #i91565#, #i91566#: add text:meta(-field) to sw core:
txatbase.hxx: new member SwTxtAttr::m_bNesting.
hintids.hxx: new ids RES_TXTATR_META, RES_TXTATR_METAFIELD.
txtatr.hxx: new base class SwTxtAttrNesting.
new hint SwTxtMeta.
SwTxtRuby derives from SwTxtAttrNesting.
txtinet.hxx: SwTxtINetFmt derives from SwTxtAttrNesting.
new header fmtmeta.hxx: new pool item SwFmtMeta. new class sw::Meta.
ndhints.hxx, thints.cxx: new method SwpHints::TryInsertNesting().
thints.cxx: refactoring: BuildPortions() no longer handles Ruby/Hyperlink,
but TryInsertNesting(), which also handles meta(-field).
SwTxtNode::InsertItem(): check if the hint is actually inserted.
ndhints.cxx: sort nesting hints based on sort number.
ndtxt.cxx: lcl_CopyHint(): handle copy of meta/meta-field.
2009-08-27 Michael Stahl enable expanding hints with m_bLockExpandFlag set:
add new InsertFlag: INS_FORCEHINTEXPAND.
add new SetAttrMode: SETATTR_FORCEHINTEXPAND.
rename SwEditShell::Insert() to Insert2() because changed signature fails
to compile when SwWrtShell tries to overwrite these non-virtual members...
SwWrtShell::Insert() sets FOCEHINTEXPAND if range was selected/deleted.
adapt SwUndoInsert to store flags.
2009-08-27 Michael Stahl change formal parameters of item insertion methods to type SetAttrMode
2009-08-27 Michael Stahl fix incorrect resetting of text attributes in SwUndoInsSection, SwUndoInserts
2009-08-27 Michael Stahl clean up SwTxtNode::CutImpl() and lcl_CopyHint()
2009-08-27 Michael Stahl rename SwDoc::Copy() to CopyRange(), and _Copy() to CopyImpl()
2009-08-27 Michael Stahl rename SwNodes::Move() to MoveRange(), and remove unused parameter
2009-08-27 Michael Stahl rename SwDoc::Move() to MoveRange()/MoveNodeRange()
2009-08-27 Michael Stahl rename SwDoc::Insert() to InsertString(), and remove sal_Unicode variant
2009-08-27 Michael Stahl rename SwDoc::Insert() to InsertPoolItem()/InsertItemSet()/InsertSwSection()
2009-08-27 Michael Stahl rename SwDoc::Replace() to ReplaceRange()
2009-08-27 Michael Stahl remove SwDoc::Overwrite() sal_Unicode variant
2009-08-27 Michael Stahl split up SwDoc::DeleteAndJoin(): factor out DeleteAndJoinWithRedline()
2009-08-27 Michael Stahl rename overloaded SwDoc::Delete() to DeleteRange()/DeleteTOXMark()
2009-08-27 Michael Stahl rename SwTxtNode::Copy() to CopyText()
2009-08-27 Michael Stahl rename SwTxtNode::Cut() to CutText(), and _Cut() to CutImpl()
2009-08-27 Michael Stahl rename SwTxtNode::Delete() to DeleteAttribute()/DeleteAttributes()
2009-08-27 Michael Stahl rename SwTxtNode::Replace() to ReplaceText(), and remove the xub_Unicode variant
2009-08-27 Michael Stahl rename SwTxtNode::Erase() to EraseText()
2009-08-27 Michael Stahl rename SwTxtNode::Insert() to InsertText(), and remove the xub_Unicode variant
2009-08-27 Michael Stahl clean up SwTxtNode::Update()
2009-08-27 Michael Stahl remove SwTxtAttr::RemoveFromPool() and make destructor non-public,
to be invoked by new method SwTxtAttr::Destroy()
2009-08-27 Michael Stahl ensure that SwDoc::Insert() for item (set) returns success indicator:
replace SwRegHistory constructor with method InsertItems(), returning bool.
refactor InsAttr() so that it checks if InsertItems() succeeds.
2009-08-27 Michael Stahl move SwXTextPortionEnumeration from unoobj.hxx to unoport.hxx
2009-08-27 Michael Stahl add missing SolarMutex in SwXTextPortion methods
2009-08-27 Michael Stahl SwXTextPortion: new member m_xTextField (so the TextField property need not
be returned indirectly via SwUnoCursorHelper).
factor out function CreateSwXTextField().
2009-08-27 Michael Stahl SwXTextPortion: remove PORTION_CONTROL_CHAR and implementation of XTextField
2009-08-27 Michael Stahl remove obsolete hint SwTxtHardBlank and formats SwFmtHardBlank/SwFmtSoftHyph
2009-08-27 Michael Stahl clean up SwTxtAttr and friends:
remove many accessor methods for obsolete (due to autofmt) char format items.
remove unused flag SwTxtAttr::m_bDontMergeAttr.
MakeRedlineTxtAttr() now dedicated function, no longer calls MakeTxtAttr().
2009-08-27 Michael Stahl remove obsolete attribute SwTxt2Lines
2009-08-27 Michael Stahl SwXTextPortionEnumeration: finish refactoring CreatePortions
change ExportHints so it always returns a text portion for hint w/ CH_TXTATR.
remove special case for handling end of paragraph.
unfortunately had to refactor the fieldmarks export as well (got in the way).
2009-08-27 Michael Stahl SwXTextPortionEnumeration: refactor CreatePortions: frames export
extract function ExportFrames() from CreatePortions().
remove (un)dead code that calls evil MovePara(fnParaCurr, fnParaEnd)
2009-08-27 Michael Stahl clean up SwXParaFrameEnumeration
2009-08-27 Michael Stahl CollectFrameAtNode: replace SwDependArr with STL based FrameDependList_t
2009-08-27 Michael Stahl SwXTextPortionEnumeration: tweak refmark/toxmark export
so ExportHints returns the portion for point marks
2009-08-27 Michael Stahl clean up SwXTextPortionEnumeration:
prefix members, remove casts, replace SvWeirdArray with STL, etc.
make CreatePortions() method a function, and remove lots of members.
extract fieldmarks function from CreatePortions.
2009-08-27 Michael Stahl remove FOREACHUNOPAM_START/END macros
2009-08-27 Michael Stahl clean up SwXTextPortion:
prefix members, remove casts, etc.
remove SwXRubyPortion: replace it with another SwXTextPortion constructor
2009-08-27 Michael Stahl #i102541# SwXReferenceMark::InsertRefMark(): use flag SETATTR_DONTEXPAND
2009-08-27 Michael Stahl rename SwTxtNode::Insert to SwTxtNode::InsertHint, and
fix constness in SwTxtNode::InsertItem
2009-08-27 Michael Stahl turn SwTxtNode::MakeTxtAttr() methods into global functions in ndhints.hxx
2009-08-27 Michael Stahl remove obsolete sw/inc/bookmrk.hxx
2009-08-27 Michael Stahl pam.cxx: fix ComparePosition functions (returned wrong result in one case)
2009-08-27 Michael Stahl #i103613# only import RDF metadata on normal open of a document
2009-09-11 kz CWS-TOOLING: integrate CWS impress176
2009-09-08 20:18:24 +0200 sj r275957 : fixed warning (shadowed variable)
2009-09-08 18:02:05 +0200 cl r275948 : #i104315# added missing tab pages
2009-09-08 17:35:18 +0200 cl r275947 : #i104866# fixed angle import
2009-09-08 17:32:53 +0200 cl r275946 : #i104841# fixed angle import
2009-09-08 17:01:25 +0200 cl r275943 : #i103935# fixed the SID_EVENTCONFIG mess
2009-09-08 14:32:57 +0200 sj r275928 : #i104685# only comments
2009-09-07 12:37:36 +0200 sj r275886 : #i104683# fixed import of bold/italic attributes for normal text shapes
2009-09-04 15:07:46 +0200 sj r275808 : #104689# fixed bullet color problem
2009-09-03 15:25:07 +0200 sj r275753 : #160200# added vertical alignment of table cells
2009-09-11 kz CWS-TOOLING: integrate CWS dv14
2009-09-10 15:16:32 +0200 sg r276035 : #160513# updated wfs scheme to accept ports
2009-09-10 07:41:47 +0200 dv r276019 : #i104942# Better renaming algorithmen
2009-08-31 13:41:11 +0200 dv r275604 : #160505# Setting APP1PRODUCTNAME must not overwrite APP1PRODUCTDEF
2009-09-11 kz CWS-TOOLING: integrate CWS jl131
2009-09-02 16:42:40 +0200 jl r275720 : #i97896#
2009-08-31 13:01:53 +0200 jl r275599 : CWS-TOOLING: rebase CWS jl131 to trunk@275331 (milestone: DEV300:m56)
2009-07-31 14:35:30 +0200 jl r274531 : CWS-TOOLING: rebase CWS jl131 to trunk@274203 (milestone: DEV300:m53)
2009-07-23 14:20:32 +0200 jl r274272 : #i79839# better error text when trying to modify shared layer without having write permission, eg. unopkg add --shared, unopkg remove --shared, unopkg reinstall --shared
2009-07-22 16:38:02 +0200 jl r274252 : #i97896# localize error message for lock file
2009-07-22 16:37:22 +0200 jl r274251 : #i80462# unprecise wording in updatedialog
2009-07-22 16:36:06 +0200 jl r274250 : #i97896# localize error message for lock file
2009-07-22 16:35:20 +0200 jl r274249 : #i97896# localize error message for lock file
2009-07-22 15:07:30 +0200 jl r274242 : #i98873# minimum java version is 1.5 since OOo 3.0
2009-09-11 kz CWS-TOOLING: integrate CWS changehc
2009-08-31 19:38:50 +0200 pl r275633 : remove dbug printf
2009-08-31 17:41:50 +0200 pl r275623 : CWS-TOOLING: rebase CWS changehc to trunk@275331 (milestone: DEV300:m56)
2009-07-15 19:45:46 +0200 pl r274028 : #i35482# use HC flag to decide high contrast mode
2009-07-15 17:40:52 +0200 pl r274020 : #i35482# use HC flag to decide high contrast mode
2009-07-15 17:39:50 +0200 pl r274019 : #i35482# update autohc correctly in MergeSystemSettings
2009-07-15 17:38:57 +0200 pl r274018 : #i35482# update autohc correctly in MergeSystemSettings
2009-09-11 kz CWS-TOOLING: integrate CWS notes10
2009-08-24 07:25:57 +0200 mod r275287 : 2009-07-26 02:38:32 +0200 mod r274343 : #i#i103645#
2009-07-26 02:01:53 +0200 mod r274342 : #i103645#
2009-07-26 01:52:42 +0200 mod r274341 : #i103490#
2009-07-22 08:31:48 +0200 mod r274215 : #i103373#
2009-07-15 00:55:11 +0200 mod r273987 : #i101419#
2009-07-14 07:07:55 +0200 mod r273956 : #i101419#
2009-07-14 07:07:43 +0200 mod r273955 : #i101419#
2009-07-14 07:02:10 +0200 mod r273954 : changes from notes9
2009-07-14 06:14:25 +0200 mod r273953 : #i103476#
2009-09-11 kz CWS-TOOLING: integrate CWS ab70
2009-09-10 15:12:54 +0200 jsk r276034 : #i85434# - mandatory automatic update test
2009-09-10 15:11:06 +0200 jsk r276033 : #i85434# - mandatory automatic update test
2009-09-02 09:49:24 +0200 ab r275698 : #i85434# Dialog Import
2009-09-11 kz CWS-TOOLING: integrate CWS hb32bugs02
2009-09-02 Henning Brinkmann #i102420# revert changes
2009-08-26 Henning Brinkmann merged DEV300_m56
2009-08-19 Henning Brinkmann merged DEV300_m55
2009-08-14 Henning Brinkmann merged changes from wntmsci12
2009-08-12 Henning Brinkmann Implemented NoSpaceEdit constructor and destructor in .cxx to allow compile with debug on wntmsci12.
2009-08-12 Henning Brinkmann Added some SW_DLLPUBLIC to make compilable on wntmsci12.
2009-08-11 Henning Brinkmann #i102420# dbg_out: surround output for SwNodes with <nodes-array>.
2009-08-10 Henning Brinkmann #i102420# rewritten debug output for SwNodes.
2009-08-07 Henning Brinkmann #i102420# debug _MoveNodes: output the destination, too. Break after two iterations.
2009-08-07 Henning Brinkmann #i102420# _MoveNodes: Additionally check if destination index is inside source => false
Check if current range was already handled => loop
Debug output current range
2009-08-06 Henning Brinkmann merged DEV300_m54
2009-08-06 Henning Brinkmann added master fix
2009-08-06 Henning Brinkmann debug output for SwNodeRange
2009-08-04 Henning Brinkmann #i102844# robustness: check for NULL pointer to prevent crash
2009-08-03 Henning Brinkmann #i103475# applied patch and verified
2009-08-03 Henning Brinkmann Removed code preventing build of sw with DEBUG.
2009-09-11 convert-repo update tags
2009-09-10 kz CWS-TOOLING: integrate CWS os2port06dev300
2009-09-05 22:49:00 +0200 ydario r275858 : #i99588# applied os2port06 diff to DEV300 tree.
2009-09-10 kz CWS-TOOLING: integrate CWS mingwport23
2009-08-29 07:07:53 +0200 tono r275555 : i#104522: mingw port graphite
2009-08-29 07:07:26 +0200 tono r275554 : i#104522: mingw port printf format fix
2009-09-10 kz CWS-TOOLING: integrate CWS mh232
2009-08-26 03:52:57 +0200 mh r275385 : #i102182# FreeBSD patch
2009-08-26 03:43:20 +0200 mh r275384 : #i101333# patch for FreeBSD
2009-08-26 03:11:20 +0200 mh r275383 : #i39230
2009-08-26 03:07:51 +0200 mh r275382 : #i39230# more space for initials field
2009-08-26 02:41:19 +0200 mh r275380 : #i39230# use vos::osecurity for reading the user name
2009-08-18 22:06:00 +0200 mh r275130 : #i104243#, line ending problem with newer perl
2009-08-18 21:53:21 +0200 mh r275129 : #i39230# read initials via getpwnam
2009-08-18 21:34:05 +0200 mh r275128 : enable CAIROCANVAS for Linux and Mac, #i88613#
2009-08-17 18:02:59 +0200 mh r275067 : #i95498# make compile with gcc3
2009-09-10 kz CWS-TOOLING: integrate CWS tkr24
2009-09-07 14:31:06 +0200 is r275898 : #160081# adding NO_LICENSE_INTO_COPYRIGHT
2009-09-10 releng #i10000# change KeyMapping to SingletonRef<framework::KeyMapping>
2009-09-11 convert-repo update tags
2009-09-10 kz CWS-TOOLING: integrate CWS os2port06dev300
2009-09-05 22:49:00 +0200 ydario r275858 : #i99588# applied os2port06 diff to DEV300 tree.
2009-09-10 kz CWS-TOOLING: integrate CWS mingwport23
2009-08-29 07:07:53 +0200 tono r275555 : i#104522: mingw port graphite
2009-08-29 07:07:26 +0200 tono r275554 : i#104522: mingw port printf format fix
2009-09-10 kz CWS-TOOLING: integrate CWS mh232
2009-08-26 03:52:57 +0200 mh r275385 : #i102182# FreeBSD patch
2009-08-26 03:43:20 +0200 mh r275384 : #i101333# patch for FreeBSD
2009-08-26 03:11:20 +0200 mh r275383 : #i39230
2009-08-26 03:07:51 +0200 mh r275382 : #i39230# more space for initials field
2009-08-26 02:41:19 +0200 mh r275380 : #i39230# use vos::osecurity for reading the user name
2009-08-18 22:06:00 +0200 mh r275130 : #i104243#, line ending problem with newer perl
2009-08-18 21:53:21 +0200 mh r275129 : #i39230# read initials via getpwnam
2009-08-18 21:34:05 +0200 mh r275128 : enable CAIROCANVAS for Linux and Mac, #i88613#
2009-08-17 18:02:59 +0200 mh r275067 : #i95498# make compile with gcc3
2009-09-10 kz CWS-TOOLING: integrate CWS tkr24
2009-09-07 14:31:06 +0200 is r275898 : #160081# adding NO_LICENSE_INTO_COPYRIGHT
2009-09-10 releng #i10000# change KeyMapping to SingletonRef<framework::KeyMapping>
2009-09-11 14:29:45 +00:00
|
|
|
pSh->SwEditShell::Insert2(sStr);
|
2011-02-25 22:21:36 +01:00
|
|
|
pSh->SwFEShell::SplitNode(); // line feed
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: fill Listbox with tablelist
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::GetTableNames(ListBox* pListBox, const String& rDBName)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRet = sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
String sOldTableName(pListBox->GetSelectEntry());
|
|
|
|
pListBox->Clear();
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pParam = FindDSConnection(rDBName, sal_False);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2001-08-15 07:20:44 +00:00
|
|
|
if(pParam && pParam->xConnection.is())
|
|
|
|
xConnection = pParam->xConnection;
|
|
|
|
else
|
2002-10-24 12:48:08 +00:00
|
|
|
{
|
|
|
|
rtl::OUString sDBName(rDBName);
|
2012-01-17 17:47:34 -02:00
|
|
|
if ( !sDBName.isEmpty() )
|
2010-11-23 10:29:28 +01:00
|
|
|
xConnection = RegisterConnection( sDBName );
|
2002-10-24 12:48:08 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xConnection.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XTablesSupplier> xTSupplier = uno::Reference<XTablesSupplier>(xConnection, UNO_QUERY);
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xTSupplier.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNameAccess> xTbls = xTSupplier->getTables();
|
2001-09-04 11:40:59 +00:00
|
|
|
Sequence<rtl::OUString> aTbls = xTbls->getElementNames();
|
|
|
|
const rtl::OUString* pTbls = aTbls.getConstArray();
|
2000-09-18 16:15:01 +00:00
|
|
|
for(long i = 0; i < aTbls.getLength(); i++)
|
2001-07-20 11:49:57 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nEntry = pListBox->InsertEntry(pTbls[i]);
|
2001-07-20 11:49:57 +00:00
|
|
|
pListBox->SetEntryData(nEntry, (void*)0);
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XQueriesSupplier> xQSupplier = uno::Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xQSupplier.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNameAccess> xQueries = xQSupplier->getQueries();
|
2001-09-04 11:40:59 +00:00
|
|
|
Sequence<rtl::OUString> aQueries = xQueries->getElementNames();
|
|
|
|
const rtl::OUString* pQueries = aQueries.getConstArray();
|
2000-09-18 16:15:01 +00:00
|
|
|
for(long i = 0; i < aQueries.getLength(); i++)
|
2001-07-20 11:49:57 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nEntry = pListBox->InsertEntry(pQueries[i]);
|
2001-07-20 11:49:57 +00:00
|
|
|
pListBox->SetEntryData(nEntry, (void*)1);
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
if (sOldTableName.Len())
|
|
|
|
pListBox->SelectEntry(sOldTableName);
|
2011-01-17 15:06:54 +01:00
|
|
|
bRet = sal_True;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: fill Listbox with column names of a database
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::GetColumnNames(ListBox* pListBox,
|
|
|
|
const String& rDBName, const String& rTableName, sal_Bool bAppend)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
if (!bAppend)
|
|
|
|
pListBox->Clear();
|
2007-07-12 09:49:57 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDBName;
|
|
|
|
aData.sCommand = rTableName;
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pParam = FindDSData(aData, sal_False);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2001-08-15 07:20:44 +00:00
|
|
|
if(pParam && pParam->xConnection.is())
|
|
|
|
xConnection = pParam->xConnection;
|
|
|
|
else
|
2002-10-24 12:48:08 +00:00
|
|
|
{
|
|
|
|
rtl::OUString sDBName(rDBName);
|
|
|
|
xConnection = RegisterConnection( sDBName );
|
|
|
|
}
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xColsSupp.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
|
2001-09-04 11:40:59 +00:00
|
|
|
const Sequence<rtl::OUString> aColNames = xCols->getElementNames();
|
|
|
|
const rtl::OUString* pColNames = aColNames.getConstArray();
|
2000-09-18 16:15:01 +00:00
|
|
|
for(int nCol = 0; nCol < aColNames.getLength(); nCol++)
|
|
|
|
{
|
|
|
|
pListBox->InsertEntry(pColNames[nCol]);
|
|
|
|
}
|
2004-11-09 11:56:07 +00:00
|
|
|
::comphelper::disposeComponent( xColsSupp );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
return(sal_True);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2001-06-08 12:47:33 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::GetColumnNames(ListBox* pListBox,
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection,
|
2011-01-17 15:06:54 +01:00
|
|
|
const String& rTableName, sal_Bool bAppend)
|
2001-06-08 12:47:33 +00:00
|
|
|
{
|
|
|
|
if (!bAppend)
|
|
|
|
pListBox->Clear();
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
|
2001-06-08 12:47:33 +00:00
|
|
|
if(xColsSupp.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
|
2001-09-04 11:40:59 +00:00
|
|
|
const Sequence<rtl::OUString> aColNames = xCols->getElementNames();
|
|
|
|
const rtl::OUString* pColNames = aColNames.getConstArray();
|
2001-06-08 12:47:33 +00:00
|
|
|
for(int nCol = 0; nCol < aColNames.getLength(); nCol++)
|
|
|
|
{
|
|
|
|
pListBox->InsertEntry(pColNames[nCol]);
|
|
|
|
}
|
2004-11-09 11:56:07 +00:00
|
|
|
::comphelper::disposeComponent( xColsSupp );
|
2001-06-08 12:47:33 +00:00
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
return(sal_True);
|
2001-06-08 12:47:33 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: CTOR
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
|
|
|
SwNewDBMgr::SwNewDBMgr() :
|
2007-09-27 10:31:02 +00:00
|
|
|
nMergeType(DBMGR_INSERT),
|
2011-01-17 15:06:54 +01:00
|
|
|
bInitDBFields(sal_False),
|
|
|
|
bInMerge(sal_False),
|
|
|
|
bMergeSilent(sal_False),
|
|
|
|
bMergeLock(sal_False),
|
2007-09-27 10:31:02 +00:00
|
|
|
pImpl(new SwNewDBMgr_Impl(*this)),
|
|
|
|
pMergeEvtSrc(NULL)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwNewDBMgr::~SwNewDBMgr()
|
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.size(); nPos++)
|
2001-08-15 07:20:44 +00:00
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
SwDSParam* pParam = &aDataSourceParams[nPos];
|
2001-08-15 07:20:44 +00:00
|
|
|
if(pParam->xConnection.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XComponent> xComp(pParam->xConnection, UNO_QUERY);
|
2001-08-15 07:20:44 +00:00
|
|
|
if(xComp.is())
|
|
|
|
xComp->dispose();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const RuntimeException&)
|
2001-08-15 07:20:44 +00:00
|
|
|
{
|
|
|
|
//may be disposed already since multiple entries may have used the same connection
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-08-30 12:56:46 +00:00
|
|
|
delete pImpl;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: save bulk letters as single documents
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
2012-10-12 16:49:40 +02:00
|
|
|
static String lcl_FindUniqueName(SwWrtShell* pTargetShell, const String& rStartingPageDesc, sal_uLong nDocNo )
|
2007-04-04 14:17:58 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
String sTest = rStartingPageDesc;
|
|
|
|
sTest += String::CreateFromInt32( nDocNo );
|
|
|
|
if( !pTargetShell->FindPageDescByName( sTest ) )
|
|
|
|
return sTest;
|
|
|
|
++nDocNo;
|
|
|
|
}while(true);
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static void lcl_CopyDynamicDefaults( const SwDoc& rSource, SwDoc& rTarget )
|
2007-04-04 14:17:58 +00:00
|
|
|
{
|
2011-03-14 16:51:14 +00:00
|
|
|
sal_uInt16 aRangeOfDefaults[] = {
|
2007-04-04 14:17:58 +00:00
|
|
|
RES_FRMATR_BEGIN, RES_FRMATR_END-1,
|
|
|
|
RES_CHRATR_BEGIN, RES_CHRATR_END-1,
|
|
|
|
RES_PARATR_BEGIN, RES_PARATR_END-1,
|
2008-06-13 10:14:02 +00:00
|
|
|
RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
|
2007-04-04 14:17:58 +00:00
|
|
|
RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
SfxItemSet aNewDefaults( rTarget.GetAttrPool(), aRangeOfDefaults );
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nWhich;
|
|
|
|
sal_uInt16 nRange = 0;
|
2007-04-04 14:17:58 +00:00
|
|
|
while( aRangeOfDefaults[nRange] != 0)
|
|
|
|
{
|
|
|
|
for( nWhich = aRangeOfDefaults[nRange]; nWhich < aRangeOfDefaults[nRange + 1]; ++nWhich )
|
|
|
|
{
|
|
|
|
const SfxPoolItem& rSourceAttr = rSource.GetDefault( nWhich );
|
|
|
|
if( rSourceAttr != rTarget.GetDefault( nWhich ) )
|
|
|
|
aNewDefaults.Put( rSourceAttr );
|
|
|
|
}
|
|
|
|
nRange += 2;
|
|
|
|
}
|
|
|
|
if( aNewDefaults.Count() )
|
|
|
|
rTarget.SetDefault( aNewDefaults );
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static void lcl_CopyFollowPageDesc(
|
2007-04-04 14:17:58 +00:00
|
|
|
SwWrtShell& rTargetShell,
|
|
|
|
const SwPageDesc& rSourcePageDesc,
|
|
|
|
const SwPageDesc& rTargetPageDesc,
|
2011-01-17 15:06:54 +01:00
|
|
|
const sal_uLong nDocNo )
|
2007-04-04 14:17:58 +00:00
|
|
|
{
|
|
|
|
//now copy the follow page desc, too
|
|
|
|
const SwPageDesc* pFollowPageDesc = rSourcePageDesc.GetFollow();
|
|
|
|
String sFollowPageDesc = pFollowPageDesc->GetName();
|
|
|
|
if( sFollowPageDesc != rSourcePageDesc.GetName() )
|
|
|
|
{
|
|
|
|
SwDoc* pTargetDoc = rTargetShell.GetDoc();
|
|
|
|
String sNewFollowPageDesc = lcl_FindUniqueName(&rTargetShell, sFollowPageDesc, nDocNo );
|
|
|
|
sal_uInt16 nNewDesc = pTargetDoc->MakePageDesc( sNewFollowPageDesc );
|
2012-06-21 13:40:06 +02:00
|
|
|
SwPageDesc& rTargetFollowPageDesc = pTargetDoc->GetPageDesc( nNewDesc );
|
2007-04-04 14:17:58 +00:00
|
|
|
|
2012-10-25 17:01:26 +09:00
|
|
|
pTargetDoc->CopyPageDesc( *pFollowPageDesc, rTargetFollowPageDesc, false );
|
2007-04-04 14:17:58 +00:00
|
|
|
SwPageDesc aDesc( rTargetPageDesc );
|
|
|
|
aDesc.SetFollow( &rTargetFollowPageDesc );
|
|
|
|
pTargetDoc->ChgPageDesc( rTargetPageDesc.GetName(), aDesc );
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell )
|
2010-07-29 14:58:17 +02:00
|
|
|
{
|
|
|
|
//reset all links of the sections of synchronized labels
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nSections = rWorkShell.GetSectionFmtCount();
|
|
|
|
for( sal_uInt16 nSection = 0; nSection < nSections; ++nSection )
|
2010-07-29 14:58:17 +02:00
|
|
|
{
|
|
|
|
SwSectionData aSectionData( *rWorkShell.GetSectionFmt( nSection ).GetSection() );
|
|
|
|
if( aSectionData.GetType() == FILE_LINK_SECTION )
|
|
|
|
{
|
|
|
|
aSectionData.SetType( CONTENT_SECTION );
|
|
|
|
aSectionData.SetLinkFileName( String() );
|
|
|
|
rWorkShell.UpdateSection( nSection, aSectionData );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rWorkShell.SetLabelDoc( sal_False );
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
|
2005-01-28 14:47:46 +00:00
|
|
|
const SwMergeDescriptor& rMergeDescriptor)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
//check if the doc is synchronized and contains at least one linked section
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bSynchronizedDoc = pSourceShell->IsLabelDoc() && pSourceShell->GetSectionFmtCount() > 1;
|
|
|
|
sal_Bool bLoop = sal_True;
|
|
|
|
sal_Bool bEMail = rMergeDescriptor.nMergeType == DBMGR_MERGE_MAILING;
|
2007-07-05 06:38:34 +00:00
|
|
|
const bool bAsSingleFile = rMergeDescriptor.nMergeType == DBMGR_MERGE_SINGLE_FILE;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
::rtl::Reference< MailDispatcher > xMailDispatcher;
|
|
|
|
::rtl::OUString sBodyMimeType;
|
2011-11-24 12:06:54 +01:00
|
|
|
rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
if(bEMail)
|
|
|
|
{
|
|
|
|
xMailDispatcher.set( new MailDispatcher(rMergeDescriptor.xSmtpServer));
|
|
|
|
if(!rMergeDescriptor.bSendAsAttachment && rMergeDescriptor.bSendAsHTML)
|
|
|
|
{
|
2010-10-27 11:38:46 +01:00
|
|
|
sBodyMimeType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("text/html; charset="));
|
2005-01-28 14:47:46 +00:00
|
|
|
sBodyMimeType += ::rtl::OUString::createFromAscii(
|
|
|
|
rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
|
2011-05-20 09:06:56 +01:00
|
|
|
SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
|
|
|
|
eEncoding = rHtmlOptions.GetTextEncoding();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
else
|
|
|
|
sBodyMimeType =
|
2010-10-27 11:38:46 +01:00
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("text/plain; charset=UTF-8; format=flowed"));
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XPropertySet > xColumnProp;
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bColumnName = sEMailAddrFld.Len() > 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
if (bColumnName)
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, UNO_QUERY );
|
|
|
|
uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
|
2000-09-18 16:15:01 +00:00
|
|
|
if(!xCols->hasByName(sEMailAddrFld))
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
Any aCol = xCols->getByName(sEMailAddrFld);
|
2001-09-06 12:36:15 +00:00
|
|
|
aCol >>= xColumnProp;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
SfxDispatcher* pSfxDispatcher = pSourceShell->GetView().GetViewFrame()->GetDispatcher();
|
2007-09-27 10:31:02 +00:00
|
|
|
SwDocShell* pSourrceDocSh = pSourceShell->GetView().GetDocShell();
|
|
|
|
pSfxDispatcher->Execute( pSourrceDocSh->HasName() ? SID_SAVEDOC : SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
|
2005-01-28 14:47:46 +00:00
|
|
|
// has document been saved successfully?
|
2007-09-27 10:31:02 +00:00
|
|
|
if( !pSourrceDocSh->IsModified() )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2005-01-28 14:47:46 +00:00
|
|
|
SfxMedium* pOrig = pSourceShell->GetView().GetDocShell()->GetMedium();
|
|
|
|
String sSourceDocumentURL(pOrig->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ));
|
2000-09-18 16:15:01 +00:00
|
|
|
const SfxFilter* pSfxFlt = SwIoSystem::GetFileFilter(
|
2005-01-28 14:47:46 +00:00
|
|
|
sSourceDocumentURL, ::aEmptyStr );
|
|
|
|
const SfxFilter* pStoreToFilter = pSfxFlt;
|
|
|
|
SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
|
2005-03-08 12:55:46 +00:00
|
|
|
const String* pStoreToFilterOptions = 0;
|
2005-01-28 14:47:46 +00:00
|
|
|
// if a save_to filter is set then use it - otherwise use the default
|
|
|
|
if( bEMail && !rMergeDescriptor.bSendAsAttachment )
|
|
|
|
{
|
2012-07-02 16:02:38 +01:00
|
|
|
rtl::OUString sExtension = rMergeDescriptor.bSendAsHTML ? rtl::OUString("html") : rtl::OUString("txt");
|
2005-01-28 14:47:46 +00:00
|
|
|
pStoreToFilter = pFilterContainer->GetFilter4Extension(sExtension, SFX_FILTER_EXPORT);
|
|
|
|
}
|
|
|
|
else if( rMergeDescriptor.sSaveToFilter.Len())
|
|
|
|
{
|
|
|
|
const SfxFilter* pFilter =
|
|
|
|
pFilterContainer->GetFilter4FilterName( rMergeDescriptor.sSaveToFilter );
|
|
|
|
if(pFilter)
|
2005-03-08 12:55:46 +00:00
|
|
|
{
|
2005-01-28 14:47:46 +00:00
|
|
|
pStoreToFilter = pFilter;
|
2005-03-08 12:55:46 +00:00
|
|
|
if(rMergeDescriptor.sSaveToFilterOptions.Len())
|
|
|
|
pStoreToFilterOptions = &rMergeDescriptor.sSaveToFilterOptions;
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
bCancel = sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
// in case of creating a single resulting file this has to be created here
|
|
|
|
SwWrtShell* pTargetShell = 0;
|
2011-01-03 13:40:23 +01:00
|
|
|
|
|
|
|
// the shell will be explicitly closed at the end of the method, but it is
|
|
|
|
// still more safe to use SfxObjectShellLock here
|
|
|
|
SfxObjectShellLock xTargetDocShell;
|
|
|
|
|
2009-09-01 08:22:04 +00:00
|
|
|
SwView* pTargetView = 0;
|
2005-01-28 14:47:46 +00:00
|
|
|
std::auto_ptr< utl::TempFile > aTempFile;
|
2007-04-04 14:17:58 +00:00
|
|
|
String sModifiedStartingPageDesc;
|
2005-01-28 14:47:46 +00:00
|
|
|
String sStartingPageDesc;
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nStartingPageNo = 0;
|
2007-04-04 14:17:58 +00:00
|
|
|
bool bPageStylesWithHeaderFooter = false;
|
2007-07-05 06:38:34 +00:00
|
|
|
if(bAsSingleFile || rMergeDescriptor.bCreateSingleFile)
|
2005-01-28 14:47:46 +00:00
|
|
|
{
|
|
|
|
// create a target docshell to put the merged document into
|
|
|
|
xTargetDocShell = new SwDocShell( SFX_CREATE_MODE_STANDARD );
|
|
|
|
xTargetDocShell->DoInitNew( 0 );
|
2009-12-09 10:11:48 +01:00
|
|
|
SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 );
|
2005-01-28 14:47:46 +00:00
|
|
|
|
2009-09-01 08:22:04 +00:00
|
|
|
pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() );
|
2005-01-28 14:47:46 +00:00
|
|
|
|
|
|
|
//initiate SelectShell() to create sub shells
|
|
|
|
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
|
|
|
|
pTargetShell = pTargetView->GetWrtShellPtr();
|
|
|
|
//copy the styles from the source to the target document
|
|
|
|
SwgReaderOption aOpt;
|
|
|
|
aOpt.SetTxtFmts( sal_True );
|
|
|
|
aOpt.SetFrmFmts( sal_True );
|
|
|
|
aOpt.SetPageDescs( sal_True );
|
|
|
|
aOpt.SetNumRules( sal_True );
|
|
|
|
aOpt.SetMerge( sal_False );
|
|
|
|
pTargetView->GetDocShell()->LoadStylesFromFile(
|
|
|
|
sSourceDocumentURL, aOpt, sal_True );
|
|
|
|
//determine the page style and number used at the start of the source document
|
2011-01-17 15:06:54 +01:00
|
|
|
pSourceShell->SttEndDoc(sal_True);
|
2005-01-28 14:47:46 +00:00
|
|
|
nStartingPageNo = pSourceShell->GetVirtPageNum();
|
2007-04-04 14:17:58 +00:00
|
|
|
sStartingPageDesc = sModifiedStartingPageDesc = pSourceShell->GetPageDesc(
|
2005-01-28 14:47:46 +00:00
|
|
|
pSourceShell->GetCurPageDesc()).GetName();
|
2011-02-25 22:33:34 +01:00
|
|
|
// copy compatibility options
|
2005-10-18 12:49:13 +00:00
|
|
|
lcl_CopyCompatibilityOptions( *pSourceShell, *pTargetShell);
|
2007-04-04 14:17:58 +00:00
|
|
|
// #72821# copy dynamic defaults
|
|
|
|
lcl_CopyDynamicDefaults( *pSourceShell->GetDoc(), *pTargetShell->GetDoc() );
|
|
|
|
// #i72517#
|
|
|
|
const SwPageDesc* pSourcePageDesc = pSourceShell->FindPageDescByName( sStartingPageDesc );
|
|
|
|
const SwFrmFmt& rMaster = pSourcePageDesc->GetMaster();
|
|
|
|
bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive() ||
|
|
|
|
rMaster.GetFooter().IsActive();
|
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
|
|
|
|
2008-10-01 06:46:01 +00:00
|
|
|
PrintMonitor aPrtMonDlg(&pSourceShell->GetView().GetEditWin(), PrintMonitor::MONITOR_TYPE_PRINT);
|
2005-01-28 14:47:46 +00:00
|
|
|
aPrtMonDlg.aDocName.SetText(pSourceShell->GetView().GetDocShell()->GetTitle(22));
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
aPrtMonDlg.aCancel.SetClickHdl(LINK(this, SwNewDBMgr, PrtCancelHdl));
|
2003-03-27 14:45:43 +00:00
|
|
|
if (!IsMergeSilent())
|
|
|
|
aPrtMonDlg.Show();
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-02-25 22:21:36 +01:00
|
|
|
// Progress, to prohibit KeyInputs
|
2007-09-27 10:31:02 +00:00
|
|
|
SfxProgress aProgress(pSourrceDocSh, ::aEmptyStr, 1);
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
// lock all dispatchers
|
2007-09-27 10:31:02 +00:00
|
|
|
SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst(pSourrceDocSh);
|
2000-09-18 16:15:01 +00:00
|
|
|
while (pViewFrm)
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
pViewFrm->GetDispatcher()->Lock(sal_True);
|
2007-09-27 10:31:02 +00:00
|
|
|
pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pSourrceDocSh);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nDocNo = 1;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2003-04-04 17:15:06 +00:00
|
|
|
long nStartRow, nEndRow;
|
2005-01-28 14:47:46 +00:00
|
|
|
// collect temporary files
|
|
|
|
::std::vector< String> aFilesToRemove;
|
2003-04-04 17:15:06 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
nStartRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
String sPath(sSubject);
|
|
|
|
|
2009-05-06 13:20:55 +00:00
|
|
|
String sAddress;
|
2005-01-28 14:47:46 +00:00
|
|
|
if( !bEMail && bColumnName )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
SwDBFormatData aDBFormat;
|
2003-11-25 09:48:37 +00:00
|
|
|
aDBFormat.xFormatter = pImpl->pMergeData->xFormatter;
|
|
|
|
aDBFormat.aNullDate = pImpl->pMergeData->aNullDate;
|
2000-09-18 16:15:01 +00:00
|
|
|
sAddress = GetDBField( xColumnProp, aDBFormat);
|
|
|
|
if (!sAddress.Len())
|
|
|
|
sAddress = '_';
|
|
|
|
sPath += sAddress;
|
|
|
|
}
|
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
// create a new temporary file name - only done once in case of bCreateSingleFile
|
2007-07-05 06:38:34 +00:00
|
|
|
if( 1 == nDocNo || (!rMergeDescriptor.bCreateSingleFile && !bAsSingleFile) )
|
2005-01-28 14:47:46 +00:00
|
|
|
{
|
|
|
|
INetURLObject aEntry(sPath);
|
2009-05-06 13:20:55 +00:00
|
|
|
String sLeading;
|
|
|
|
//#i97667# if the name is from a database field then it will be used _as is_
|
|
|
|
if( sAddress.Len() )
|
|
|
|
sLeading = sAddress;
|
|
|
|
else
|
|
|
|
sLeading = aEntry.GetBase();
|
2005-01-28 14:47:46 +00:00
|
|
|
aEntry.removeSegment();
|
|
|
|
sPath = aEntry.GetMainURL( INetURLObject::NO_DECODE );
|
2012-06-11 13:15:18 +01:00
|
|
|
String sExt(comphelper::string::stripStart(pStoreToFilter->GetDefaultExtension(), '*'));
|
2005-01-28 14:47:46 +00:00
|
|
|
aTempFile = std::auto_ptr< utl::TempFile >(
|
|
|
|
new utl::TempFile(sLeading,&sExt,&sPath ));
|
2007-07-05 06:38:34 +00:00
|
|
|
if( bAsSingleFile )
|
|
|
|
aTempFile->EnableKillingFile();
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
if( !aTempFile->IsValid() )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
ErrorHandler::HandleError( ERRCODE_IO_NOTSUPPORTED );
|
2011-01-17 15:06:54 +01:00
|
|
|
bLoop = sal_False;
|
|
|
|
bCancel = sal_True;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-01-28 14:47:46 +00:00
|
|
|
INetURLObject aTempFileURL(aTempFile->GetURL());
|
|
|
|
aPrtMonDlg.aPrinter.SetText( aTempFileURL.GetBase() );
|
2000-09-18 16:15:01 +00:00
|
|
|
String sStat(SW_RES(STR_STATSTR_LETTER)); // Brief
|
|
|
|
sStat += ' ';
|
2005-01-28 14:47:46 +00:00
|
|
|
sStat += String::CreateFromInt32( nDocNo );
|
2000-09-18 16:15:01 +00:00
|
|
|
aPrtMonDlg.aPrintInfo.SetText(sStat);
|
|
|
|
|
2011-02-25 22:21:36 +01:00
|
|
|
// computation time for Save-Monitor:
|
2011-01-17 15:06:54 +01:00
|
|
|
for (sal_uInt16 i = 0; i < 10; i++)
|
2000-09-18 16:15:01 +00:00
|
|
|
Application::Reschedule();
|
|
|
|
|
2011-01-03 13:40:23 +01:00
|
|
|
// Create and save new document
|
|
|
|
// The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
|
|
|
|
SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
|
2012-05-24 11:38:12 +02:00
|
|
|
SfxMedium* pWorkMed = new SfxMedium( sSourceDocumentURL, STREAM_STD_READ );
|
2005-01-28 14:47:46 +00:00
|
|
|
pWorkMed->SetFilter( pSfxFlt );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
if (xWorkDocSh->DoLoad(pWorkMed))
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2003-04-04 17:15:06 +00:00
|
|
|
//create a view frame for the document
|
2009-12-09 10:11:48 +01:00
|
|
|
SfxViewFrame* pWorkFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 );
|
2003-04-04 17:15:06 +00:00
|
|
|
//request the layout calculation
|
2005-01-28 14:47:46 +00:00
|
|
|
SwWrtShell& rWorkShell =
|
|
|
|
static_cast< SwView* >(pWorkFrame->GetViewShell())->GetWrtShell();
|
|
|
|
rWorkShell.CalcLayout();
|
|
|
|
SwDoc* pWorkDoc = ((SwDocShell*)(&xWorkDocSh))->GetDoc();
|
|
|
|
SwNewDBMgr* pOldDBMgr = pWorkDoc->GetNewDBMgr();
|
|
|
|
pWorkDoc->SetNewDBMgr( this );
|
2009-09-18 10:15:03 +00:00
|
|
|
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE), xWorkDocSh));
|
2006-08-14 16:30:22 +00:00
|
|
|
pWorkDoc->UpdateFlds(NULL, false);
|
2009-09-18 10:15:03 +00:00
|
|
|
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE_FINISHED), xWorkDocSh));
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
pWorkDoc->RemoveInvisibleContent();
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2003-03-27 14:45:43 +00:00
|
|
|
// launch MailMergeEvent if required
|
|
|
|
const SwXMailMerge *pEvtSrc = GetMailMergeEvtSrc();
|
2005-01-28 14:47:46 +00:00
|
|
|
if(pEvtSrc)
|
2003-03-27 14:45:43 +00:00
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XInterface > xRef( (XMailMergeBroadcaster *) pEvtSrc );
|
2005-01-28 14:47:46 +00:00
|
|
|
text::MailMergeEvent aEvt( xRef, xWorkDocSh->GetModel() );
|
2003-03-27 14:45:43 +00:00
|
|
|
pEvtSrc->LaunchMailMergeEvent( aEvt );
|
|
|
|
}
|
|
|
|
|
2007-07-05 06:38:34 +00:00
|
|
|
if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile )
|
2005-01-28 14:47:46 +00:00
|
|
|
{
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE( pTargetShell, "no target shell available!" );
|
2005-01-28 14:47:46 +00:00
|
|
|
// copy created file into the target document
|
|
|
|
rWorkShell.ConvertFieldsToText();
|
2005-11-04 15:01:40 +00:00
|
|
|
rWorkShell.SetNumberingRestart();
|
2010-07-29 14:58:17 +02:00
|
|
|
if( bSynchronizedDoc )
|
|
|
|
{
|
|
|
|
lcl_RemoveSectionLinks( rWorkShell );
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
|
|
|
|
// insert the document into the target document
|
2011-01-17 15:06:54 +01:00
|
|
|
rWorkShell.SttEndDoc(sal_False);
|
|
|
|
rWorkShell.SttEndDoc(sal_True);
|
2005-01-28 14:47:46 +00:00
|
|
|
rWorkShell.SelAll();
|
2011-01-17 15:06:54 +01:00
|
|
|
pTargetShell->SwCrsrShell::SttEndDoc( sal_False );
|
2007-04-04 14:17:58 +00:00
|
|
|
//#i72517# the headers and footers are still those from the source - update in case of fields inside header/footer
|
|
|
|
if( !nDocNo && bPageStylesWithHeaderFooter )
|
|
|
|
pTargetShell->GetView().GetDocShell()->_LoadStyles( *rWorkShell.GetView().GetDocShell(), sal_True );
|
|
|
|
//#i72517# put the styles to the target document
|
|
|
|
//if the source uses headers or footers each new copy need to copy a new page styles
|
|
|
|
if(bPageStylesWithHeaderFooter)
|
|
|
|
{
|
|
|
|
//create a new pagestyle
|
|
|
|
//copy the pagedesc from the current document to the new document and change the name of the to-be-applied style
|
|
|
|
|
|
|
|
SwDoc* pTargetDoc = pTargetShell->GetDoc();
|
|
|
|
SwPageDesc* pSourcePageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
|
|
|
|
String sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
|
|
|
|
pTargetDoc->MakePageDesc( sNewPageDescName );
|
|
|
|
SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
|
|
|
|
if(pSourcePageDesc && pTargetPageDesc)
|
|
|
|
{
|
2012-10-25 17:01:26 +09:00
|
|
|
pTargetDoc->CopyPageDesc( *pSourcePageDesc, *pTargetPageDesc, false );
|
2007-04-04 14:17:58 +00:00
|
|
|
sModifiedStartingPageDesc = sNewPageDescName;
|
2007-09-27 10:31:02 +00:00
|
|
|
lcl_CopyFollowPageDesc( *pTargetShell, *pSourcePageDesc, *pTargetPageDesc, nDocNo );
|
2007-04-04 14:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
if(nDocNo > 1)
|
2007-04-04 14:17:58 +00:00
|
|
|
pTargetShell->InsertPageBreak( &sModifiedStartingPageDesc, nStartingPageNo );
|
2005-01-28 14:47:46 +00:00
|
|
|
else
|
2007-04-04 14:17:58 +00:00
|
|
|
pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
|
2005-10-19 07:25:32 +00:00
|
|
|
//#i51359# add a second paragraph in case there's only one
|
|
|
|
{
|
|
|
|
SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
|
2007-04-04 14:17:58 +00:00
|
|
|
SwPosition aTestPos( aIdx );
|
2007-11-22 14:39:40 +00:00
|
|
|
SwCursor aTestCrsr(aTestPos,0,false);
|
2005-10-19 07:25:32 +00:00
|
|
|
if(!aTestCrsr.MovePara(fnParaNext, fnParaStart))
|
|
|
|
{
|
|
|
|
//append a paragraph
|
|
|
|
pWorkDoc->AppendTxtNode( aTestPos );
|
|
|
|
}
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True );
|
2007-04-04 14:17:58 +00:00
|
|
|
|
2005-11-10 14:57:22 +00:00
|
|
|
//convert fields in page styles (header/footer - has to be done after the first document has been pasted
|
|
|
|
if(1 == nDocNo)
|
|
|
|
{
|
|
|
|
pTargetShell->CalcLayout();
|
|
|
|
pTargetShell->ConvertFieldsToText();
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2005-01-28 14:47:46 +00:00
|
|
|
String sFileURL = aTempFileURL.GetMainURL( INetURLObject::NO_DECODE );
|
|
|
|
SfxMedium* pDstMed = new SfxMedium(
|
|
|
|
sFileURL,
|
2012-05-24 11:38:12 +02:00
|
|
|
STREAM_STD_READWRITE );
|
2005-01-28 14:47:46 +00:00
|
|
|
pDstMed->SetFilter( pStoreToFilter );
|
2005-03-08 12:55:46 +00:00
|
|
|
if(pDstMed->GetItemSet())
|
|
|
|
{
|
|
|
|
if(pStoreToFilterOptions )
|
|
|
|
pDstMed->GetItemSet()->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, *pStoreToFilterOptions));
|
|
|
|
if(rMergeDescriptor.aSaveToFilterData.getLength())
|
|
|
|
pDstMed->GetItemSet()->Put(SfxUsrAnyItem(SID_FILTER_DATA, makeAny(rMergeDescriptor.aSaveToFilterData)));
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
|
2008-12-09 07:49:49 +00:00
|
|
|
//convert fields to text if we are exporting to PDF
|
|
|
|
//this prevents a second merge while updating the fields in SwXTextDocument::getRendererCount()
|
|
|
|
if( pStoreToFilter && pStoreToFilter->GetFilterName().EqualsAscii("writer_pdf_Export"))
|
|
|
|
rWorkShell.ConvertFieldsToText();
|
2005-01-28 14:47:46 +00:00
|
|
|
xWorkDocSh->DoSaveAs(*pDstMed);
|
|
|
|
xWorkDocSh->DoSaveCompleted(pDstMed);
|
|
|
|
if( xWorkDocSh->GetError() )
|
|
|
|
{
|
|
|
|
// error message ??
|
|
|
|
ErrorHandler::HandleError( xWorkDocSh->GetError() );
|
2011-01-17 15:06:54 +01:00
|
|
|
bCancel = sal_True;
|
|
|
|
bLoop = sal_False;
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
|
|
|
if( bEMail )
|
|
|
|
{
|
|
|
|
SwDBFormatData aDBFormat;
|
|
|
|
aDBFormat.xFormatter = pImpl->pMergeData->xFormatter;
|
|
|
|
aDBFormat.aNullDate = pImpl->pMergeData->aNullDate;
|
|
|
|
String sMailAddress = GetDBField( xColumnProp, aDBFormat);
|
|
|
|
if(!SwMailMergeHelper::CheckMailAddress( sMailAddress ))
|
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("invalid e-Mail address in database column");
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-24 09:26:00 +00:00
|
|
|
SwMailMessage* pMessage = new SwMailMessage;
|
|
|
|
uno::Reference< mail::XMailMessage > xMessage = pMessage;
|
2005-01-28 14:47:46 +00:00
|
|
|
if(rMergeDescriptor.pMailMergeConfigItem->IsMailReplyTo())
|
|
|
|
pMessage->setReplyToAddress(rMergeDescriptor.pMailMergeConfigItem->GetMailReplyTo());
|
|
|
|
pMessage->addRecipient( sMailAddress );
|
|
|
|
pMessage->SetSenderAddress( rMergeDescriptor.pMailMergeConfigItem->GetMailAddress() );
|
|
|
|
::rtl::OUString sBody;
|
|
|
|
if(rMergeDescriptor.bSendAsAttachment)
|
|
|
|
{
|
|
|
|
sBody = rMergeDescriptor.sMailBody;
|
|
|
|
mail::MailAttachment aAttach;
|
|
|
|
aAttach.Data = new SwMailTransferable(
|
|
|
|
sFileURL,
|
|
|
|
rMergeDescriptor.sAttachmentName,
|
|
|
|
pStoreToFilter->GetMimeType());
|
|
|
|
aAttach.ReadableName = rMergeDescriptor.sAttachmentName;
|
|
|
|
pMessage->addAttachment( aAttach );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//read in the temporary file and use it as mail body
|
2012-05-24 11:38:12 +02:00
|
|
|
SfxMedium aMedium( sFileURL, STREAM_READ);
|
2005-01-28 14:47:46 +00:00
|
|
|
SvStream* pInStream = aMedium.GetInStream();
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pInStream, "no output file created?");
|
2005-01-28 14:47:46 +00:00
|
|
|
if(pInStream)
|
|
|
|
{
|
|
|
|
pInStream->SetStreamCharSet( eEncoding );
|
2011-11-01 22:38:51 +00:00
|
|
|
rtl::OString sLine;
|
2005-01-28 14:47:46 +00:00
|
|
|
sal_Bool bDone = pInStream->ReadLine( sLine );
|
|
|
|
while ( bDone )
|
|
|
|
{
|
2012-06-18 18:40:40 +01:00
|
|
|
sBody += rtl::OStringToOUString(sLine, eEncoding);
|
2005-01-28 14:47:46 +00:00
|
|
|
sBody += ::rtl::OUString('\n');
|
|
|
|
bDone = pInStream->ReadLine( sLine );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pMessage->setSubject( rMergeDescriptor.sSubject );
|
|
|
|
uno::Reference< datatransfer::XTransferable> xBody =
|
|
|
|
new SwMailTransferable(
|
|
|
|
sBody,
|
|
|
|
sBodyMimeType);
|
|
|
|
pMessage->setBody( xBody );
|
|
|
|
|
|
|
|
if(rMergeDescriptor.aCopiesTo.getLength())
|
|
|
|
{
|
|
|
|
const ::rtl::OUString* pCopies = rMergeDescriptor.aCopiesTo.getConstArray();
|
|
|
|
for( sal_Int32 nToken = 0; nToken < rMergeDescriptor.aCopiesTo.getLength(); ++nToken)
|
|
|
|
pMessage->addCcRecipient( pCopies[nToken] );
|
|
|
|
}
|
|
|
|
if(rMergeDescriptor.aBlindCopiesTo.getLength())
|
|
|
|
{
|
|
|
|
const ::rtl::OUString* pCopies = rMergeDescriptor.aBlindCopiesTo.getConstArray();
|
|
|
|
for( sal_Int32 nToken = 0; nToken < rMergeDescriptor.aBlindCopiesTo.getLength(); ++nToken)
|
|
|
|
pMessage->addBccRecipient( pCopies[nToken] );
|
|
|
|
}
|
|
|
|
xMailDispatcher->enqueueMailMessage( xMessage );
|
|
|
|
if(!xMailDispatcher->isStarted())
|
|
|
|
xMailDispatcher->start();
|
|
|
|
//schedule for removal
|
|
|
|
aFilesToRemove.push_back(sFileURL);
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
pWorkDoc->SetNewDBMgr( pOldDBMgr );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
xWorkDocSh->DoClose();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
nDocNo++;
|
2003-04-04 17:15:06 +00:00
|
|
|
nEndRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0;
|
|
|
|
} while( !bCancel &&
|
|
|
|
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
|
2010-03-01 13:36:19 +01:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
aPrtMonDlg.Show( sal_False );
|
2010-03-01 13:36:19 +01:00
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
// save the single output document
|
2007-07-05 06:38:34 +00:00
|
|
|
if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile)
|
2005-01-28 14:47:46 +00:00
|
|
|
{
|
2009-09-01 08:22:04 +00:00
|
|
|
if( rMergeDescriptor.nMergeType != DBMGR_MERGE_MAILMERGE )
|
2005-03-08 12:55:46 +00:00
|
|
|
{
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE( aTempFile.get(), "Temporary file not available" );
|
2009-09-01 08:22:04 +00:00
|
|
|
INetURLObject aTempFileURL(bAsSingleFile ? sSubject : aTempFile->GetURL());
|
|
|
|
SfxMedium* pDstMed = new SfxMedium(
|
|
|
|
aTempFileURL.GetMainURL( INetURLObject::NO_DECODE ),
|
2012-05-24 11:38:12 +02:00
|
|
|
STREAM_STD_READWRITE );
|
2009-09-01 08:22:04 +00:00
|
|
|
pDstMed->SetFilter( pStoreToFilter );
|
|
|
|
if(pDstMed->GetItemSet())
|
|
|
|
{
|
|
|
|
if(pStoreToFilterOptions )
|
|
|
|
pDstMed->GetItemSet()->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, *pStoreToFilterOptions));
|
|
|
|
if(rMergeDescriptor.aSaveToFilterData.getLength())
|
|
|
|
pDstMed->GetItemSet()->Put(SfxUsrAnyItem(SID_FILTER_DATA, makeAny(rMergeDescriptor.aSaveToFilterData)));
|
|
|
|
}
|
2005-01-28 14:47:46 +00:00
|
|
|
|
2009-09-01 08:22:04 +00:00
|
|
|
xTargetDocShell->DoSaveAs(*pDstMed);
|
|
|
|
xTargetDocShell->DoSaveCompleted(pDstMed);
|
|
|
|
if( xTargetDocShell->GetError() )
|
|
|
|
{
|
|
|
|
// error message ??
|
|
|
|
ErrorHandler::HandleError( xTargetDocShell->GetError() );
|
2011-01-17 15:06:54 +01:00
|
|
|
bLoop = sal_False;
|
2009-09-01 08:22:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( pTargetView ) // must be available!
|
2005-01-28 14:47:46 +00:00
|
|
|
{
|
2009-09-01 08:22:04 +00:00
|
|
|
//print the target document
|
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
sal_Bool _bVal;
|
|
|
|
sal_Int16 _nVal;
|
|
|
|
rtl::OUString _sVal;
|
|
|
|
const beans::PropertyValue* pDbgPrintOptions = rMergeDescriptor.aPrintOptions.getConstArray();
|
|
|
|
for( sal_Int32 nOption = 0; nOption < rMergeDescriptor.aPrintOptions.getLength(); ++nOption)
|
|
|
|
{
|
|
|
|
rtl::OUString aName( pDbgPrintOptions[nOption].Name );
|
|
|
|
uno::Any aVal( pDbgPrintOptions[nOption].Value );
|
|
|
|
aVal >>= _bVal;
|
|
|
|
aVal >>= _nVal;
|
|
|
|
aVal >>= _sVal;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// printing should be done synchronously otherwise the document
|
|
|
|
// might already become invalid during the process
|
|
|
|
uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.aPrintOptions );
|
|
|
|
const sal_Int32 nOpts = aOptions.getLength();
|
|
|
|
aOptions.realloc( nOpts + 1 );
|
2010-10-27 11:38:46 +01:00
|
|
|
aOptions[ nOpts ].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Wait"));
|
2009-09-01 08:22:04 +00:00
|
|
|
aOptions[ nOpts ].Value <<= sal_True ;
|
|
|
|
// move print options
|
|
|
|
const beans::PropertyValue* pPrintOptions = rMergeDescriptor.aPrintOptions.getConstArray();
|
|
|
|
for( sal_Int32 nOption = 0; nOption < rMergeDescriptor.aPrintOptions.getLength(); ++nOption)
|
|
|
|
{
|
2012-04-06 19:49:53 +02:00
|
|
|
if( pPrintOptions[nOption].Name == "CopyCount" || pPrintOptions[nOption].Name == "FileName"
|
|
|
|
|| pPrintOptions[nOption].Name == "Collate" || pPrintOptions[nOption].Name == "Pages"
|
|
|
|
|| pPrintOptions[nOption].Name == "Wait" )
|
2009-09-01 08:22:04 +00:00
|
|
|
{
|
|
|
|
aOptions.realloc( nOpts + 1 );
|
|
|
|
aOptions[ nOpts ].Name = pPrintOptions[nOption].Name;
|
|
|
|
aOptions[ nOpts ].Value = pPrintOptions[nOption].Value ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pTargetView->ExecPrint( aOptions, IsMergeSilent(), rMergeDescriptor.bPrintAsync );
|
2005-01-28 14:47:46 +00:00
|
|
|
}
|
|
|
|
xTargetDocShell->DoClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
//remove the temporary files
|
|
|
|
::std::vector<String>::iterator aFileIter;
|
|
|
|
for(aFileIter = aFilesToRemove.begin();
|
2011-05-16 19:45:52 +02:00
|
|
|
aFileIter != aFilesToRemove.end(); ++aFileIter)
|
2005-01-28 14:47:46 +00:00
|
|
|
SWUnoHelper::UCB_DeleteFile( *aFileIter );
|
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
// unlock all dispatchers
|
2007-09-27 10:31:02 +00:00
|
|
|
pViewFrm = SfxViewFrame::GetFirst(pSourrceDocSh);
|
2000-09-18 16:15:01 +00:00
|
|
|
while (pViewFrm)
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
pViewFrm->GetDispatcher()->Lock(sal_False);
|
2007-09-27 10:31:02 +00:00
|
|
|
pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pSourrceDocSh);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
SW_MOD()->SetView(&pSourceShell->GetView());
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nMergeType = DBMGR_INSERT;
|
|
|
|
}
|
|
|
|
|
2005-01-28 14:47:46 +00:00
|
|
|
if(bEMail)
|
|
|
|
{
|
|
|
|
xMailDispatcher->stop();
|
|
|
|
xMailDispatcher->shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
return bLoop;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK_INLINE_START( SwNewDBMgr, PrtCancelHdl, Button *, pButton )
|
|
|
|
{
|
|
|
|
pButton->GetParent()->Hide();
|
2011-01-17 15:06:54 +01:00
|
|
|
bCancel = sal_True;
|
2000-09-18 16:15:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
IMPL_LINK_INLINE_END( SwNewDBMgr, PrtCancelHdl, Button *, pButton )
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
2011-02-25 22:21:36 +01:00
|
|
|
Description: determine the column's Numberformat and transfer
|
|
|
|
to the forwarded Formatter, if applicable.
|
2000-09-18 16:15:01 +00:00
|
|
|
--------------------------------------------------------------------*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong SwNewDBMgr::GetColumnFmt( const String& rDBName,
|
2000-09-18 16:15:01 +00:00
|
|
|
const String& rTableName,
|
|
|
|
const String& rColNm,
|
|
|
|
SvNumberFormatter* pNFmtr,
|
|
|
|
long nLanguage )
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nRet = 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
if(pNFmtr)
|
2001-06-08 12:47:33 +00:00
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XDataSource> xSource;
|
|
|
|
uno::Reference< XConnection> xConnection;
|
2001-06-08 12:47:33 +00:00
|
|
|
sal_Bool bUseMergeData = sal_False;
|
2005-10-19 07:25:32 +00:00
|
|
|
uno::Reference< XColumnsSupplier> xColsSupp;
|
2009-08-06 12:44:16 +00:00
|
|
|
bool bDisposeConnection = false;
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData &&
|
|
|
|
pImpl->pMergeData->sDataSource.equals(rDBName) && pImpl->pMergeData->sCommand.equals(rTableName))
|
2001-06-08 12:47:33 +00:00
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
xConnection = pImpl->pMergeData->xConnection;
|
2007-09-27 10:31:02 +00:00
|
|
|
xSource = SwNewDBMgr::getDataSourceAsParent(xConnection,rDBName);
|
2001-06-08 12:47:33 +00:00
|
|
|
bUseMergeData = sal_True;
|
2005-10-19 07:25:32 +00:00
|
|
|
xColsSupp = xColsSupp.query( pImpl->pMergeData->xResultSet );
|
2001-06-08 12:47:33 +00:00
|
|
|
}
|
2005-10-19 07:25:32 +00:00
|
|
|
if(!xConnection.is())
|
2001-06-08 12:47:33 +00:00
|
|
|
{
|
2007-07-12 09:49:57 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDBName;
|
|
|
|
aData.sCommand = rTableName;
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pParam = FindDSData(aData, sal_False);
|
2001-08-15 07:20:44 +00:00
|
|
|
if(pParam && pParam->xConnection.is())
|
2005-10-19 07:25:32 +00:00
|
|
|
{
|
2001-08-15 07:20:44 +00:00
|
|
|
xConnection = pParam->xConnection;
|
2005-10-19 07:25:32 +00:00
|
|
|
xColsSupp = xColsSupp.query( pParam->xResultSet );
|
|
|
|
}
|
2001-08-15 07:20:44 +00:00
|
|
|
else
|
2002-10-24 12:48:08 +00:00
|
|
|
{
|
|
|
|
rtl::OUString sDBName(rDBName);
|
|
|
|
xConnection = RegisterConnection( sDBName );
|
2009-08-06 12:44:16 +00:00
|
|
|
bDisposeConnection = true;
|
2002-10-24 12:48:08 +00:00
|
|
|
}
|
2001-06-08 12:47:33 +00:00
|
|
|
if(bUseMergeData)
|
2001-08-30 12:56:46 +00:00
|
|
|
pImpl->pMergeData->xConnection = xConnection;
|
2001-06-08 12:47:33 +00:00
|
|
|
}
|
2005-10-19 07:25:32 +00:00
|
|
|
bool bDispose = !xColsSupp.is();
|
|
|
|
if(bDispose)
|
|
|
|
{
|
|
|
|
xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
|
|
|
|
}
|
2001-06-08 12:47:33 +00:00
|
|
|
if(xColsSupp.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNameAccess> xCols;
|
2001-07-18 12:25:54 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
xCols = xColsSupp->getColumns();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2001-07-18 12:25:54 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("Exception in getColumns()");
|
2001-07-18 12:25:54 +00:00
|
|
|
}
|
2001-07-20 09:07:05 +00:00
|
|
|
if(!xCols.is() || !xCols->hasByName(rColNm))
|
2001-06-08 12:47:33 +00:00
|
|
|
return nRet;
|
|
|
|
Any aCol = xCols->getByName(rColNm);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XPropertySet > xColumn;
|
2001-06-08 12:47:33 +00:00
|
|
|
aCol >>= xColumn;
|
|
|
|
nRet = GetColumnFmt(xSource, xConnection, xColumn, pNFmtr, nLanguage);
|
2005-10-19 07:25:32 +00:00
|
|
|
if(bDispose)
|
|
|
|
{
|
|
|
|
::comphelper::disposeComponent( xColsSupp );
|
|
|
|
}
|
2009-08-06 12:44:16 +00:00
|
|
|
if(bDisposeConnection)
|
|
|
|
{
|
|
|
|
::comphelper::disposeComponent( xConnection );
|
|
|
|
}
|
2001-06-08 12:47:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
nRet = pNFmtr->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM );
|
|
|
|
}
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong SwNewDBMgr::GetColumnFmt( uno::Reference< XDataSource> xSource,
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection,
|
|
|
|
uno::Reference< XPropertySet> xColumn,
|
2001-06-08 12:47:33 +00:00
|
|
|
SvNumberFormatter* pNFmtr,
|
|
|
|
long nLanguage )
|
|
|
|
{
|
2011-02-25 22:33:34 +01:00
|
|
|
// set the NumberFormat in the doc if applicable
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nRet = 0;
|
2001-06-08 12:47:33 +00:00
|
|
|
|
|
|
|
if(!xSource.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XChild> xChild(xConnection, UNO_QUERY);
|
2011-01-07 15:19:05 +01:00
|
|
|
if ( xChild.is() )
|
|
|
|
xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
|
2001-06-08 12:47:33 +00:00
|
|
|
}
|
|
|
|
if(xSource.is() && xConnection.is() && xColumn.is() && pNFmtr)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNFmtr );
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< util::XNumberFormatsSupplier > xDocNumFmtsSupplier = pNumFmt;
|
|
|
|
uno::Reference< XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
|
|
|
|
uno::Reference< XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-09-24 18:08:24 +02:00
|
|
|
com::sun::star::lang::Locale aLocale( MsLangId::convertLanguageToLocale( (LanguageType)nLanguage ));
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
//get the number formatter of the data source
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
|
|
|
|
uno::Reference< XNumberFormats > xNumberFormats;
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xSourceProps.is())
|
|
|
|
{
|
|
|
|
Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
|
|
|
|
if(aFormats.hasValue())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNumberFormatsSupplier> xSuppl;
|
2001-09-06 12:36:15 +00:00
|
|
|
aFormats >>= xSuppl;
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xSuppl.is())
|
|
|
|
{
|
|
|
|
xNumberFormats = xSuppl->getNumberFormats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-19 08:39:02 +00:00
|
|
|
bool bUseDefault = true;
|
|
|
|
try
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-09-27 10:31:02 +00:00
|
|
|
Any aFormatKey = xColumn->getPropertyValue(C2U("FormatKey"));
|
|
|
|
if(aFormatKey.hasValue())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-11-12 15:30:55 +00:00
|
|
|
sal_Int32 nFmt = 0;
|
2007-09-27 10:31:02 +00:00
|
|
|
aFormatKey >>= nFmt;
|
2006-07-19 08:39:02 +00:00
|
|
|
if(xNumberFormats.is())
|
2001-06-08 12:47:33 +00:00
|
|
|
{
|
2006-07-19 08:39:02 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
|
2007-09-27 10:31:02 +00:00
|
|
|
Any aFormatString = xNumProps->getPropertyValue(C2U("FormatString"));
|
|
|
|
Any aLocaleVal = xNumProps->getPropertyValue(C2U("Locale"));
|
2006-07-19 08:39:02 +00:00
|
|
|
rtl::OUString sFormat;
|
2007-09-27 10:31:02 +00:00
|
|
|
aFormatString >>= sFormat;
|
|
|
|
lang::Locale aLoc;
|
|
|
|
aLocaleVal >>= aLoc;
|
2006-07-19 08:39:02 +00:00
|
|
|
nFmt = xDocNumberFormats->queryKey( sFormat, aLoc, sal_False );
|
2007-09-27 10:31:02 +00:00
|
|
|
if(NUMBERFORMAT_ENTRY_NOT_FOUND == sal::static_int_cast< sal_uInt32, sal_Int32>(nFmt))
|
2006-07-19 08:39:02 +00:00
|
|
|
nFmt = xDocNumberFormats->addNew( sFormat, aLoc );
|
|
|
|
nRet = nFmt;
|
|
|
|
bUseDefault = false;
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("illegal number format key");
|
2006-07-19 08:39:02 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2006-07-19 08:39:02 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("no FormatKey property found");
|
2006-07-19 08:39:02 +00:00
|
|
|
}
|
|
|
|
if(bUseDefault)
|
2002-08-21 11:23:43 +00:00
|
|
|
nRet = SwNewDBMgr::GetDbtoolsClient().getDefaultNumberFormat(xColumn, xDocNumberFormatTypes, aLocale);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
return nRet;
|
|
|
|
}
|
2001-06-08 12:47:33 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
sal_Int32 SwNewDBMgr::GetColumnType( const String& rDBName,
|
|
|
|
const String& rTableName,
|
|
|
|
const String& rColNm )
|
|
|
|
{
|
|
|
|
sal_Int32 nRet = DataType::SQLNULL;
|
2007-07-12 09:49:57 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDBName;
|
|
|
|
aData.sCommand = rTableName;
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pParam = FindDSData(aData, sal_False);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2007-07-12 09:49:57 +00:00
|
|
|
uno::Reference< XColumnsSupplier > xColsSupp;
|
|
|
|
bool bDispose = false;
|
2001-08-15 07:20:44 +00:00
|
|
|
if(pParam && pParam->xConnection.is())
|
2007-07-12 09:49:57 +00:00
|
|
|
{
|
2001-08-15 07:20:44 +00:00
|
|
|
xConnection = pParam->xConnection;
|
2007-07-12 09:49:57 +00:00
|
|
|
xColsSupp = uno::Reference< XColumnsSupplier >( pParam->xResultSet, UNO_QUERY );
|
|
|
|
}
|
2001-08-15 07:20:44 +00:00
|
|
|
else
|
2002-10-24 12:48:08 +00:00
|
|
|
{
|
|
|
|
rtl::OUString sDBName(rDBName);
|
|
|
|
xConnection = RegisterConnection( sDBName );
|
|
|
|
}
|
2007-07-12 09:49:57 +00:00
|
|
|
if( !xColsSupp.is() )
|
|
|
|
{
|
|
|
|
xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
|
|
|
|
bDispose = true;
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xColsSupp.is())
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
|
2000-09-18 16:15:01 +00:00
|
|
|
if(xCols->hasByName(rColNm))
|
|
|
|
{
|
|
|
|
Any aCol = xCols->getByName(rColNm);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XPropertySet> xCol;
|
2001-09-06 12:36:15 +00:00
|
|
|
aCol >>= xCol;
|
2012-07-02 16:02:38 +01:00
|
|
|
Any aType = xCol->getPropertyValue(rtl::OUString("Type"));
|
2000-09-18 16:15:01 +00:00
|
|
|
aType >>= nRet;
|
|
|
|
}
|
2007-07-12 09:49:57 +00:00
|
|
|
if(bDispose)
|
|
|
|
::comphelper::disposeComponent( xColsSupp );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< sdbc::XConnection> SwNewDBMgr::GetConnection(const String& rDataSource,
|
|
|
|
uno::Reference<XDataSource>& rxSource)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
Reference< sdbc::XConnection> xConnection;
|
2012-09-18 09:46:34 +02:00
|
|
|
Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
|
2004-08-02 13:20:28 +00:00
|
|
|
try
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2012-09-18 09:46:34 +02:00
|
|
|
Reference<XCompletedConnection> xComplConnection(SwNewDBMgr::GetDbtoolsClient().getDataSource(rDataSource, xContext),UNO_QUERY);
|
2004-08-02 13:20:28 +00:00
|
|
|
if ( xComplConnection.is() )
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-08-02 13:20:28 +00:00
|
|
|
rxSource.set(xComplConnection,UNO_QUERY);
|
2012-10-04 14:36:34 +02:00
|
|
|
Reference< XInteractionHandler > xHandler( InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
|
2012-10-02 15:03:12 +02:00
|
|
|
xConnection = xComplConnection->connectWithCompletion( xHandler );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
|
|
|
{
|
|
|
|
}
|
2004-08-02 13:20:28 +00:00
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
return xConnection;
|
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< sdbcx::XColumnsSupplier> SwNewDBMgr::GetColumnSupplier(uno::Reference<sdbc::XConnection> xConnection,
|
2000-09-18 16:15:01 +00:00
|
|
|
const String& rTableOrQuery,
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt8 eTableOrQuery)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-11-09 11:56:07 +00:00
|
|
|
Reference< sdbcx::XColumnsSupplier> xRet;
|
|
|
|
try
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-11-09 11:56:07 +00:00
|
|
|
if(eTableOrQuery == SW_DB_SELECT_UNKNOWN)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-11-09 11:56:07 +00:00
|
|
|
//search for a table with the given command name
|
|
|
|
Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
|
|
|
|
if(xTSupplier.is())
|
|
|
|
{
|
|
|
|
Reference<XNameAccess> xTbls = xTSupplier->getTables();
|
|
|
|
eTableOrQuery = xTbls->hasByName(rTableOrQuery) ?
|
|
|
|
SW_DB_SELECT_TABLE : SW_DB_SELECT_QUERY;
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2004-11-09 11:56:07 +00:00
|
|
|
sal_Int32 nCommandType = SW_DB_SELECT_TABLE == eTableOrQuery ?
|
|
|
|
CommandType::TABLE : CommandType::QUERY;
|
|
|
|
Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
|
|
|
|
Reference<XRowSet> xRowSet(
|
|
|
|
xMgr->createInstance(C2U("com.sun.star.sdb.RowSet")), UNO_QUERY);
|
|
|
|
|
|
|
|
::rtl::OUString sDataSource;
|
|
|
|
Reference<XDataSource> xSource = SwNewDBMgr::getDataSourceAsParent(xConnection, sDataSource);
|
|
|
|
Reference<XPropertySet> xSourceProperties(xSource, UNO_QUERY);
|
|
|
|
if(xSourceProperties.is())
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2004-11-09 11:56:07 +00:00
|
|
|
xSourceProperties->getPropertyValue(C2U("Name")) >>= sDataSource;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2004-11-09 11:56:07 +00:00
|
|
|
|
|
|
|
Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
|
|
|
|
xRowProperties->setPropertyValue(C2U("DataSourceName"), makeAny(sDataSource));
|
|
|
|
xRowProperties->setPropertyValue(C2U("Command"), makeAny(::rtl::OUString(rTableOrQuery)));
|
|
|
|
xRowProperties->setPropertyValue(C2U("CommandType"), makeAny(nCommandType));
|
|
|
|
xRowProperties->setPropertyValue(C2U("FetchSize"), makeAny((sal_Int32)10));
|
|
|
|
xRowProperties->setPropertyValue(C2U("ActiveConnection"), makeAny(xConnection));
|
|
|
|
xRowSet->execute();
|
|
|
|
xRet = Reference<XColumnsSupplier>( xRowSet, UNO_QUERY );
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const uno::Exception&)
|
2004-11-09 11:56:07 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("Exception in SwDBMgr::GetColumnSupplier");
|
2004-11-09 11:56:07 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
return xRet;
|
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
String SwNewDBMgr::GetDBField(uno::Reference<XPropertySet> xColumnProps,
|
2000-09-18 16:15:01 +00:00
|
|
|
const SwDBFormatData& rDBFormatData,
|
|
|
|
double* pNumber)
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumn > xColumn(xColumnProps, UNO_QUERY);
|
2000-09-18 16:15:01 +00:00
|
|
|
String sRet;
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(xColumn.is(), "SwNewDBMgr::::ImportDBField: illegal arguments");
|
2000-09-18 16:15:01 +00:00
|
|
|
if(!xColumn.is())
|
|
|
|
return sRet;
|
|
|
|
|
|
|
|
Any aType = xColumnProps->getPropertyValue(C2U("Type"));
|
2007-11-12 15:30:55 +00:00
|
|
|
sal_Int32 eDataType = 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
aType >>= eDataType;
|
|
|
|
switch(eDataType)
|
|
|
|
{
|
|
|
|
case DataType::CHAR:
|
|
|
|
case DataType::VARCHAR:
|
|
|
|
case DataType::LONGVARCHAR:
|
2006-02-01 12:48:54 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
sRet = xColumn->getString();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const SQLException&)
|
2006-02-01 12:48:54 +00:00
|
|
|
{
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
break;
|
|
|
|
case DataType::BIT:
|
2005-02-17 09:37:55 +00:00
|
|
|
case DataType::BOOLEAN:
|
2000-09-18 16:15:01 +00:00
|
|
|
case DataType::TINYINT:
|
|
|
|
case DataType::SMALLINT:
|
|
|
|
case DataType::INTEGER:
|
|
|
|
case DataType::BIGINT:
|
|
|
|
case DataType::FLOAT:
|
|
|
|
case DataType::REAL:
|
|
|
|
case DataType::DOUBLE:
|
|
|
|
case DataType::NUMERIC:
|
|
|
|
case DataType::DECIMAL:
|
|
|
|
case DataType::DATE:
|
|
|
|
case DataType::TIME:
|
|
|
|
case DataType::TIMESTAMP:
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2002-08-21 11:23:43 +00:00
|
|
|
SwDbtoolsClient& aClient = SwNewDBMgr::GetDbtoolsClient();
|
2010-11-23 12:50:54 +01:00
|
|
|
sRet = aClient.getFormattedValue(
|
2000-09-18 16:15:01 +00:00
|
|
|
xColumnProps,
|
|
|
|
rDBFormatData.xFormatter,
|
|
|
|
rDBFormatData.aLocale,
|
2000-11-08 08:46:34 +00:00
|
|
|
rDBFormatData.aNullDate);
|
2000-09-18 16:15:01 +00:00
|
|
|
if (pNumber)
|
2005-03-01 14:25:36 +00:00
|
|
|
{
|
|
|
|
double fVal = xColumn->getDouble();
|
|
|
|
if(!xColumn->wasNull())
|
|
|
|
{
|
|
|
|
*pNumber = fVal;
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("exception caught");
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
2010-10-20 15:36:15 +01:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
return sRet;
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
// releases the merge data source table or query after merge is completed
|
2000-09-18 16:15:01 +00:00
|
|
|
void SwNewDBMgr::EndMerge()
|
|
|
|
{
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(bInMerge, "merge is not active");
|
2011-01-17 15:06:54 +01:00
|
|
|
bInMerge = sal_False;
|
2001-08-30 12:56:46 +00:00
|
|
|
delete pImpl->pMergeData;
|
|
|
|
pImpl->pMergeData = 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
// checks if a desired data source table or query is open
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::IsDataSourceOpen(const String& rDataSource,
|
2001-07-10 12:51:01 +00:00
|
|
|
const String& rTableOrQuery, sal_Bool bMergeOnly)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2003-04-04 17:15:06 +00:00
|
|
|
return !bMergeLock &&
|
2007-07-18 11:59:12 +00:00
|
|
|
((rDataSource == (String)pImpl->pMergeData->sDataSource &&
|
|
|
|
rTableOrQuery == (String)pImpl->pMergeData->sCommand)
|
|
|
|
||(!rDataSource.Len() && !rTableOrQuery.Len()))
|
|
|
|
&&
|
2001-08-30 12:56:46 +00:00
|
|
|
pImpl->pMergeData->xResultSet.is();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2001-07-10 12:51:01 +00:00
|
|
|
else if(!bMergeOnly)
|
|
|
|
{
|
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDataSource;
|
|
|
|
aData.sCommand = rTableOrQuery;
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pFound = FindDSData(aData, sal_False);
|
2001-07-10 12:51:01 +00:00
|
|
|
return (pFound && pFound->xResultSet.is());
|
|
|
|
}
|
|
|
|
return sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
// read column data at a specified position
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::GetColumnCnt(const String& rSourceName, const String& rTableName,
|
2000-09-18 16:15:01 +00:00
|
|
|
const String& rColumnName, sal_uInt32 nAbsRecordId,
|
|
|
|
long nLanguage,
|
2012-03-07 16:52:06 +00:00
|
|
|
rtl::OUString& rResult, double* pNumber)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRet = sal_False;
|
2001-07-10 12:51:01 +00:00
|
|
|
SwDSParam* pFound = 0;
|
2000-09-18 16:15:01 +00:00
|
|
|
//check if it's the merge data source
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData &&
|
|
|
|
rSourceName == (String)pImpl->pMergeData->sDataSource &&
|
|
|
|
rTableName == (String)pImpl->pMergeData->sCommand)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
pFound = pImpl->pMergeData;
|
2001-07-10 12:51:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rSourceName;
|
|
|
|
aData.sCommand = rTableName;
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
pFound = FindDSData(aData, sal_False);
|
2001-07-10 12:51:01 +00:00
|
|
|
}
|
2011-11-04 23:01:17 +04:00
|
|
|
if (!pFound)
|
|
|
|
return sal_False;
|
2003-04-04 17:15:06 +00:00
|
|
|
//check validity of supplied record Id
|
|
|
|
if(pFound->aSelection.getLength())
|
|
|
|
{
|
|
|
|
//the destination has to be an element of the selection
|
|
|
|
const Any* pSelection = pFound->aSelection.getConstArray();
|
|
|
|
sal_Bool bFound = sal_False;
|
|
|
|
for(sal_Int32 nPos = 0; !bFound && nPos < pFound->aSelection.getLength(); nPos++)
|
|
|
|
{
|
2007-11-12 15:30:55 +00:00
|
|
|
sal_Int32 nSelection = 0;
|
2003-04-04 17:15:06 +00:00
|
|
|
pSelection[nPos] >>= nSelection;
|
|
|
|
if(nSelection == static_cast<sal_Int32>(nAbsRecordId))
|
|
|
|
bFound = sal_True;
|
|
|
|
}
|
|
|
|
if(!bFound)
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2003-04-04 17:15:06 +00:00
|
|
|
}
|
2011-11-04 23:01:17 +04:00
|
|
|
if(pFound->xResultSet.is() && !pFound->bAfterSelection)
|
2001-07-10 12:51:01 +00:00
|
|
|
{
|
2001-12-11 10:24:42 +00:00
|
|
|
sal_Int32 nOldRow = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
nOldRow = pFound->xResultSet->getRow();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2001-12-11 10:24:42 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2001-12-11 10:24:42 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
//position to the desired index
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bMove = sal_True;
|
2002-08-21 11:23:43 +00:00
|
|
|
if ( nOldRow != static_cast<sal_Int32>(nAbsRecordId) )
|
2001-07-10 12:51:01 +00:00
|
|
|
bMove = lcl_MoveAbsolute(pFound, nAbsRecordId);
|
2000-09-18 16:15:01 +00:00
|
|
|
if(bMove)
|
|
|
|
{
|
2001-07-10 12:51:01 +00:00
|
|
|
bRet = lcl_GetColumnCnt(pFound, rColumnName, nLanguage, rResult, pNumber);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2002-08-21 11:23:43 +00:00
|
|
|
if ( nOldRow != static_cast<sal_Int32>(nAbsRecordId) )
|
2001-07-10 12:51:01 +00:00
|
|
|
bMove = lcl_MoveAbsolute(pFound, nOldRow);
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
|
|
|
|
// reads the column data at the current position
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::GetMergeColumnCnt(const String& rColumnName, sal_uInt16 nLanguage,
|
2012-03-07 16:52:06 +00:00
|
|
|
rtl::OUString &rResult, double *pNumber, sal_uInt32 * /*pFormat*/)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is() || pImpl->pMergeData->bAfterSelection )
|
2001-02-26 09:26:48 +00:00
|
|
|
{
|
2012-03-07 16:52:06 +00:00
|
|
|
rResult = rtl::OUString();
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2001-02-26 09:26:48 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRet = lcl_GetColumnCnt(pImpl->pMergeData, rColumnName, nLanguage, rResult, pNumber);
|
2000-09-18 16:15:01 +00:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::ToNextMergeRecord()
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is(), "no data source in merge");
|
2001-08-30 12:56:46 +00:00
|
|
|
return ToNextRecord(pImpl->pMergeData);
|
2001-07-10 12:51:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::ToNextRecord(
|
2007-09-27 10:31:02 +00:00
|
|
|
const String& rDataSource, const String& rCommand, sal_Int32 /*nCommandType*/)
|
2001-07-10 12:51:01 +00:00
|
|
|
{
|
|
|
|
SwDSParam* pFound = 0;
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData &&
|
|
|
|
rDataSource == (String)pImpl->pMergeData->sDataSource &&
|
|
|
|
rCommand == (String)pImpl->pMergeData->sCommand)
|
|
|
|
pFound = pImpl->pMergeData;
|
2001-07-10 12:51:01 +00:00
|
|
|
else
|
2001-02-26 09:26:48 +00:00
|
|
|
{
|
2001-07-10 12:51:01 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDataSource;
|
|
|
|
aData.sCommand = rCommand;
|
|
|
|
aData.nCommandType = -1;
|
2011-01-17 15:06:54 +01:00
|
|
|
pFound = FindDSData(aData, sal_False);
|
2001-07-10 12:51:01 +00:00
|
|
|
}
|
|
|
|
return ToNextRecord(pFound);
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::ToNextRecord(SwDSParam* pParam)
|
2001-07-10 12:51:01 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bRet = sal_True;
|
2001-10-16 10:10:55 +00:00
|
|
|
if(!pParam || !pParam->xResultSet.is() || pParam->bEndOfDB ||
|
|
|
|
(pParam->aSelection.getLength() && pParam->aSelection.getLength() <= pParam->nSelectionIndex))
|
2001-07-10 12:51:01 +00:00
|
|
|
{
|
|
|
|
if(pParam)
|
|
|
|
pParam->CheckEndOfDB();
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2001-02-26 09:26:48 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
try
|
|
|
|
{
|
2001-07-10 12:51:01 +00:00
|
|
|
if(pParam->aSelection.getLength())
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2002-08-21 11:23:43 +00:00
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
pParam->aSelection.getConstArray()[ pParam->nSelectionIndex++ ] >>= nPos;
|
|
|
|
pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos );
|
2001-07-10 12:51:01 +00:00
|
|
|
pParam->CheckEndOfDB();
|
|
|
|
bRet = !pParam->bEndOfDB;
|
|
|
|
if(pParam->nSelectionIndex >= pParam->aSelection.getLength())
|
2011-01-17 15:06:54 +01:00
|
|
|
pParam->bEndOfDB = sal_True;
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
else
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
sal_Int32 nBefore = pParam->xResultSet->getRow();
|
2001-07-10 12:51:01 +00:00
|
|
|
pParam->bEndOfDB = !pParam->xResultSet->next();
|
2004-09-20 12:11:33 +00:00
|
|
|
if( !pParam->bEndOfDB && nBefore == pParam->xResultSet->getRow())
|
|
|
|
{
|
|
|
|
//next returned true but it didn't move
|
|
|
|
pParam->bEndOfDB = sal_True;
|
|
|
|
}
|
|
|
|
|
2001-07-10 12:51:01 +00:00
|
|
|
pParam->CheckEndOfDB();
|
|
|
|
bRet = !pParam->bEndOfDB;
|
|
|
|
++pParam->nSelectionIndex;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
}
|
2001-05-07 09:05:52 +00:00
|
|
|
return bRet;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2001-07-10 12:51:01 +00:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
/* ------------------------------------------------------------------------
|
2000-09-18 16:15:01 +00:00
|
|
|
synchronized labels contain a next record field at their end
|
|
|
|
to assure that the next page can be created in mail merge
|
|
|
|
the cursor position must be validated
|
|
|
|
---------------------------------------------------------------------------*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::ExistsNextRecord() const
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
return pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt32 SwNewDBMgr::GetSelectedRecordId()
|
|
|
|
{
|
|
|
|
sal_uInt32 nRet = 0;
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is(), "no data source in merge");
|
2001-08-30 12:56:46 +00:00
|
|
|
if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is())
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
2000-09-18 16:15:01 +00:00
|
|
|
try
|
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
nRet = pImpl->pMergeData->xResultSet->getRow();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SwNewDBMgr::ToRecordId(sal_Int32 nSet)
|
|
|
|
{
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is(), "no data source in merge");
|
2001-08-30 12:56:46 +00:00
|
|
|
if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is()|| nSet < 0)
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_False;
|
|
|
|
sal_Bool bRet = sal_False;
|
2001-03-30 11:05:13 +00:00
|
|
|
sal_Int32 nAbsPos = nSet;
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
if(nAbsPos >= 0)
|
|
|
|
{
|
2001-08-30 12:56:46 +00:00
|
|
|
bRet = lcl_MoveAbsolute(pImpl->pMergeData, nAbsPos);
|
|
|
|
pImpl->pMergeData->bEndOfDB = !bRet;
|
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool SwNewDBMgr::OpenDataSource(const String& rDataSource, const String& rTableOrQuery,
|
2005-10-19 07:25:32 +00:00
|
|
|
sal_Int32 nCommandType, bool bCreate)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-03-30 11:05:13 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDataSource;
|
|
|
|
aData.sCommand = rTableOrQuery;
|
|
|
|
aData.nCommandType = nCommandType;
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pFound = FindDSData(aData, sal_True);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XDataSource> xSource;
|
2000-09-18 16:15:01 +00:00
|
|
|
if(pFound->xResultSet.is())
|
2011-01-17 15:06:54 +01:00
|
|
|
return sal_True;
|
|
|
|
SwDSParam* pParam = FindDSConnection(rDataSource, sal_False);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2001-08-15 07:20:44 +00:00
|
|
|
if(pParam && pParam->xConnection.is())
|
|
|
|
pFound->xConnection = pParam->xConnection;
|
2005-10-19 07:25:32 +00:00
|
|
|
else if(bCreate)
|
2002-10-24 12:48:08 +00:00
|
|
|
{
|
|
|
|
rtl::OUString sDataSource(rDataSource);
|
|
|
|
pFound->xConnection = RegisterConnection( sDataSource );
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
if(pFound->xConnection.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< sdbc::XDatabaseMetaData > xMetaData = pFound->xConnection->getMetaData();
|
2002-09-03 05:28:09 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
pFound->bScrollable = xMetaData
|
2000-09-18 16:15:01 +00:00
|
|
|
->supportsResultSetType((sal_Int32)ResultSetType::SCROLL_INSENSITIVE);
|
2002-09-03 05:28:09 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2002-09-03 05:28:09 +00:00
|
|
|
{
|
2011-02-25 22:33:34 +01:00
|
|
|
// DB driver may not be ODBC 3.0 compliant
|
2011-01-17 15:06:54 +01:00
|
|
|
pFound->bScrollable = sal_True;
|
2002-09-03 05:28:09 +00:00
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
pFound->xStatement = pFound->xConnection->createStatement();
|
2001-09-04 11:40:59 +00:00
|
|
|
rtl::OUString aQuoteChar = xMetaData->getIdentifierQuoteString();
|
|
|
|
rtl::OUString sStatement(C2U("SELECT * FROM "));
|
2001-03-30 11:05:13 +00:00
|
|
|
sStatement = C2U("SELECT * FROM ");
|
|
|
|
sStatement += aQuoteChar;
|
|
|
|
sStatement += rTableOrQuery;
|
|
|
|
sStatement += aQuoteChar;
|
|
|
|
pFound->xResultSet = pFound->xStatement->executeQuery( sStatement );
|
2000-09-18 16:15:01 +00:00
|
|
|
|
|
|
|
//after executeQuery the cursor must be positioned
|
2001-03-30 11:05:13 +00:00
|
|
|
pFound->bEndOfDB = !pFound->xResultSet->next();
|
2001-07-10 12:51:01 +00:00
|
|
|
pFound->bAfterSelection = sal_False;
|
2001-03-30 11:05:13 +00:00
|
|
|
pFound->CheckEndOfDB();
|
|
|
|
++pFound->nSelectionIndex;
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch (const Exception&)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
|
|
|
pFound->xResultSet = 0;
|
|
|
|
pFound->xStatement = 0;
|
|
|
|
pFound->xConnection = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pFound->xResultSet.is();
|
|
|
|
}
|
2001-08-15 07:20:44 +00:00
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> SwNewDBMgr::RegisterConnection(rtl::OUString& rDataSource)
|
2001-08-15 07:20:44 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pFound = SwNewDBMgr::FindDSConnection(rDataSource, sal_True);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XDataSource> xSource;
|
2001-08-15 07:20:44 +00:00
|
|
|
if(!pFound->xConnection.is())
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
2001-08-15 07:20:44 +00:00
|
|
|
pFound->xConnection = SwNewDBMgr::GetConnection(rDataSource, xSource );
|
2002-12-09 12:58:30 +00:00
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
|
2002-12-09 12:58:30 +00:00
|
|
|
if(xComponent.is())
|
|
|
|
xComponent->addEventListener(pImpl->xDisposeListener);
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2001-08-15 07:20:44 +00:00
|
|
|
return pFound->xConnection;
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
|
2001-03-30 11:05:13 +00:00
|
|
|
sal_uInt32 SwNewDBMgr::GetSelectedRecordId(
|
|
|
|
const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-09-27 10:31:02 +00:00
|
|
|
sal_uInt32 nRet = 0xffffffff;
|
2000-09-18 16:15:01 +00:00
|
|
|
//check for merge data source first
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeData && rDataSource == (String)pImpl->pMergeData->sDataSource &&
|
|
|
|
rTableOrQuery == (String)pImpl->pMergeData->sCommand &&
|
|
|
|
(nCommandType == -1 || nCommandType == pImpl->pMergeData->nCommandType) &&
|
|
|
|
pImpl->pMergeData->xResultSet.is())
|
2000-09-18 16:15:01 +00:00
|
|
|
nRet = GetSelectedRecordId();
|
|
|
|
else
|
|
|
|
{
|
2001-03-30 11:05:13 +00:00
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDataSource;
|
|
|
|
aData.sCommand = rTableOrQuery;
|
|
|
|
aData.nCommandType = nCommandType;
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* pFound = FindDSData(aData, sal_False);
|
2000-09-18 16:15:01 +00:00
|
|
|
if(pFound && pFound->xResultSet.is())
|
|
|
|
{
|
|
|
|
try
|
2003-04-04 17:15:06 +00:00
|
|
|
{ //if a selection array is set the current row at the result set may not be set yet
|
|
|
|
if(pFound->aSelection.getLength())
|
|
|
|
{
|
|
|
|
sal_Int32 nSelIndex = pFound->nSelectionIndex;
|
2003-07-21 10:22:42 +00:00
|
|
|
if(nSelIndex >= pFound->aSelection.getLength())
|
2003-04-04 17:15:06 +00:00
|
|
|
nSelIndex = pFound->aSelection.getLength() -1;
|
|
|
|
pFound->aSelection.getConstArray()[nSelIndex] >>= nRet;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nRet = pFound->xResultSet->getRow();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
|
|
|
{
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
|
|
|
|
// close all data sources - after fields were updated
|
2011-01-17 15:06:54 +01:00
|
|
|
void SwNewDBMgr::CloseAll(sal_Bool bIncludingMerge)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2003-04-04 17:15:06 +00:00
|
|
|
//the only thing done here is to reset the selection index
|
|
|
|
//all connections stay open
|
2012-05-23 13:49:36 +02:00
|
|
|
for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.size(); nPos++)
|
2003-04-04 17:15:06 +00:00
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
SwDSParam* pParam = &aDataSourceParams[nPos];
|
2003-04-04 17:15:06 +00:00
|
|
|
if(bIncludingMerge || pParam != pImpl->pMergeData)
|
|
|
|
{
|
|
|
|
pParam->nSelectionIndex = 0;
|
|
|
|
pParam->bAfterSelection = sal_False;
|
2003-12-01 08:43:52 +00:00
|
|
|
pParam->bEndOfDB = sal_False;
|
2003-07-21 10:22:42 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(!bInMerge && pParam->xResultSet.is())
|
|
|
|
pParam->xResultSet->first();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2003-07-21 10:22:42 +00:00
|
|
|
{}
|
2003-04-04 17:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* SwNewDBMgr::FindDSData(const SwDBData& rData, sal_Bool bCreate)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2007-07-12 09:49:57 +00:00
|
|
|
//prefer merge data if available
|
|
|
|
if(pImpl->pMergeData && rData.sDataSource == pImpl->pMergeData->sDataSource &&
|
|
|
|
rData.sCommand == pImpl->pMergeData->sCommand &&
|
|
|
|
(rData.nCommandType == -1 || rData.nCommandType == pImpl->pMergeData->nCommandType ||
|
|
|
|
(bCreate && pImpl->pMergeData->nCommandType == -1)))
|
|
|
|
{
|
|
|
|
return pImpl->pMergeData;
|
|
|
|
}
|
|
|
|
|
2000-09-18 16:15:01 +00:00
|
|
|
SwDSParam* pFound = 0;
|
2012-05-23 13:49:36 +02:00
|
|
|
for(sal_uInt16 nPos = aDataSourceParams.size(); nPos; nPos--)
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
SwDSParam* pParam = &aDataSourceParams[nPos - 1];
|
2001-03-30 11:05:13 +00:00
|
|
|
if(rData.sDataSource == pParam->sDataSource &&
|
|
|
|
rData.sCommand == pParam->sCommand &&
|
2001-11-26 14:07:28 +00:00
|
|
|
(rData.nCommandType == -1 || rData.nCommandType == pParam->nCommandType ||
|
|
|
|
(bCreate && pParam->nCommandType == -1)))
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2011-02-25 22:33:34 +01:00
|
|
|
// calls from the calculator may add a connection with an invalid commandtype
|
2001-11-26 14:07:28 +00:00
|
|
|
//later added "real" data base connections have to re-use the already available
|
|
|
|
//DSData and set the correct CommandType
|
|
|
|
if(bCreate && pParam->nCommandType == -1)
|
|
|
|
pParam->nCommandType = rData.nCommandType;
|
2000-09-18 16:15:01 +00:00
|
|
|
pFound = pParam;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bCreate)
|
|
|
|
{
|
|
|
|
if(!pFound)
|
|
|
|
{
|
2001-03-30 11:05:13 +00:00
|
|
|
pFound = new SwDSParam(rData);
|
2012-05-23 13:49:36 +02:00
|
|
|
aDataSourceParams.push_back(pFound);
|
2002-12-09 12:58:30 +00:00
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
|
2002-12-09 12:58:30 +00:00
|
|
|
if(xComponent.is())
|
|
|
|
xComponent->addEventListener(pImpl->xDisposeListener);
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
|
|
|
}
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return pFound;
|
|
|
|
}
|
2003-11-25 09:48:37 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
SwDSParam* SwNewDBMgr::FindDSConnection(const rtl::OUString& rDataSource, sal_Bool bCreate)
|
2001-08-15 07:20:44 +00:00
|
|
|
{
|
2007-07-12 09:49:57 +00:00
|
|
|
//prefer merge data if available
|
|
|
|
if(pImpl->pMergeData && rDataSource == pImpl->pMergeData->sDataSource )
|
|
|
|
{
|
|
|
|
return pImpl->pMergeData;
|
|
|
|
}
|
2001-08-15 07:20:44 +00:00
|
|
|
SwDSParam* pFound = 0;
|
2012-05-23 13:49:36 +02:00
|
|
|
for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.size(); nPos++)
|
2001-08-15 07:20:44 +00:00
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
SwDSParam* pParam = &aDataSourceParams[nPos];
|
2001-08-15 07:20:44 +00:00
|
|
|
if(rDataSource == pParam->sDataSource)
|
|
|
|
{
|
|
|
|
pFound = pParam;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bCreate && !pFound)
|
|
|
|
{
|
|
|
|
SwDBData aData;
|
|
|
|
aData.sDataSource = rDataSource;
|
|
|
|
pFound = new SwDSParam(aData);
|
2012-05-23 13:49:36 +02:00
|
|
|
aDataSourceParams.push_back(pFound);
|
2002-12-09 12:58:30 +00:00
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XComponent> xComponent(pFound->xConnection, UNO_QUERY);
|
2002-12-09 12:58:30 +00:00
|
|
|
if(xComponent.is())
|
|
|
|
xComponent->addEventListener(pImpl->xDisposeListener);
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
|
|
|
}
|
2001-08-15 07:20:44 +00:00
|
|
|
}
|
|
|
|
return pFound;
|
|
|
|
}
|
|
|
|
|
2001-02-21 11:27:37 +00:00
|
|
|
const SwDBData& SwNewDBMgr::GetAddressDBName()
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2001-02-21 11:27:37 +00:00
|
|
|
return SW_MOD()->GetDBConfig()->GetAddressSource();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 11:40:59 +00:00
|
|
|
Sequence<rtl::OUString> SwNewDBMgr::GetExistingDatabaseNames()
|
2000-09-18 16:15:01 +00:00
|
|
|
{
|
2012-09-18 09:46:34 +02:00
|
|
|
Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
|
|
|
|
Reference<XDatabaseContext> xDBContext = DatabaseContext::create(xContext);
|
|
|
|
return xDBContext->getElementNames();
|
2000-09-18 16:15:01 +00:00
|
|
|
}
|
2004-08-02 13:20:28 +00:00
|
|
|
|
|
|
|
String SwNewDBMgr::LoadAndRegisterDataSource()
|
|
|
|
{
|
|
|
|
sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
|
|
|
|
Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
|
|
|
|
|
|
|
|
String sHomePath(SvtPathOptions().GetWorkPath());
|
|
|
|
aDlgHelper.SetDisplayDirectory( sHomePath );
|
|
|
|
|
|
|
|
Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
|
|
|
|
|
|
|
|
String sFilterAll(SW_RES(STR_FILTER_ALL));
|
|
|
|
String sFilterAllData(SW_RES(STR_FILTER_ALL_DATA));
|
|
|
|
String sFilterSXB(SW_RES(STR_FILTER_SXB));
|
|
|
|
String sFilterSXC(SW_RES(STR_FILTER_SXC));
|
|
|
|
String sFilterDBF(SW_RES(STR_FILTER_DBF));
|
|
|
|
String sFilterXLS(SW_RES(STR_FILTER_XLS));
|
|
|
|
String sFilterTXT(SW_RES(STR_FILTER_TXT));
|
|
|
|
String sFilterCSV(SW_RES(STR_FILTER_CSV));
|
2008-06-06 09:06:54 +00:00
|
|
|
#ifdef WNT
|
|
|
|
String sFilterMDB(SW_RES(STR_FILTER_MDB));
|
2008-10-01 06:46:01 +00:00
|
|
|
String sFilterACCDB(SW_RES(STR_FILTER_ACCDB));
|
2008-06-06 09:06:54 +00:00
|
|
|
#endif
|
2004-08-02 13:20:28 +00:00
|
|
|
xFltMgr->appendFilter( sFilterAll, C2U("*") );
|
2005-01-28 14:47:46 +00:00
|
|
|
xFltMgr->appendFilter( sFilterAllData, C2U("*.ods;*.sxc;*.dbf;*.xls;*.txt;*.csv"));
|
2004-08-02 13:20:28 +00:00
|
|
|
|
|
|
|
xFltMgr->appendFilter( sFilterSXB, C2U("*.odb") );
|
2005-02-16 16:10:36 +00:00
|
|
|
xFltMgr->appendFilter( sFilterSXC, C2U("*.ods;*.sxc") );
|
2004-08-02 13:20:28 +00:00
|
|
|
xFltMgr->appendFilter( sFilterDBF, C2U("*.dbf") );
|
|
|
|
xFltMgr->appendFilter( sFilterXLS, C2U("*.xls") );
|
|
|
|
xFltMgr->appendFilter( sFilterTXT, C2U("*.txt") );
|
|
|
|
xFltMgr->appendFilter( sFilterCSV, C2U("*.csv") );
|
2008-06-06 09:06:54 +00:00
|
|
|
#ifdef WNT
|
|
|
|
xFltMgr->appendFilter( sFilterMDB, C2U("*.mdb") );
|
2008-10-01 06:46:01 +00:00
|
|
|
xFltMgr->appendFilter( sFilterACCDB, C2U("*.accdb") );
|
2008-06-06 09:06:54 +00:00
|
|
|
#endif
|
2004-08-02 13:20:28 +00:00
|
|
|
|
|
|
|
xFltMgr->setCurrentFilter( sFilterAll ) ;
|
|
|
|
String sFind;
|
2008-03-07 10:16:55 +00:00
|
|
|
bool bTextConnection = false;
|
2004-08-02 13:20:28 +00:00
|
|
|
if( ERRCODE_NONE == aDlgHelper.Execute() )
|
|
|
|
{
|
|
|
|
String sURL = xFP->getFiles().getConstArray()[0];
|
|
|
|
//data sources have to be registered depending on their extensions
|
|
|
|
INetURLObject aURL( sURL );
|
|
|
|
String sExt( aURL.GetExtension() );
|
|
|
|
Any aURLAny;
|
|
|
|
Any aTableFilterAny;
|
2008-06-06 09:06:54 +00:00
|
|
|
Any aSuppressVersionsAny;
|
2004-08-02 13:20:28 +00:00
|
|
|
Any aInfoAny;
|
|
|
|
INetURLObject aTempURL(aURL);
|
|
|
|
bool bStore = true;
|
2004-09-20 12:11:33 +00:00
|
|
|
if(sExt.EqualsAscii("odb"))
|
2004-08-02 13:20:28 +00:00
|
|
|
{
|
|
|
|
bStore = false;
|
|
|
|
}
|
2007-07-12 09:49:57 +00:00
|
|
|
else if(sExt.EqualsIgnoreCaseAscii("sxc")
|
|
|
|
|| sExt.EqualsIgnoreCaseAscii("ods")
|
|
|
|
|| sExt.EqualsIgnoreCaseAscii("xls"))
|
2004-08-02 13:20:28 +00:00
|
|
|
{
|
|
|
|
rtl::OUString sDBURL(C2U("sdbc:calc:"));
|
|
|
|
sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
|
|
|
|
aURLAny <<= sDBURL;
|
|
|
|
}
|
2007-07-12 09:49:57 +00:00
|
|
|
else if(sExt.EqualsIgnoreCaseAscii("dbf"))
|
2004-08-02 13:20:28 +00:00
|
|
|
{
|
|
|
|
aTempURL.removeSegment();
|
|
|
|
aTempURL.removeFinalSlash();
|
|
|
|
rtl::OUString sDBURL(C2U("sdbc:dbase:"));
|
|
|
|
sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
|
|
|
|
aURLAny <<= sDBURL;
|
|
|
|
//set the filter to the file name without extension
|
|
|
|
Sequence<rtl::OUString> aFilters(1);
|
|
|
|
rtl::OUString sTmp(aURL.getBase());
|
|
|
|
aFilters[0] = aURL.getBase();
|
|
|
|
aTableFilterAny <<= aFilters;
|
|
|
|
}
|
2007-07-12 09:49:57 +00:00
|
|
|
else if(sExt.EqualsIgnoreCaseAscii("csv") || sExt.EqualsIgnoreCaseAscii("txt"))
|
2004-08-02 13:20:28 +00:00
|
|
|
{
|
|
|
|
aTempURL.removeSegment();
|
|
|
|
aTempURL.removeFinalSlash();
|
|
|
|
rtl::OUString sDBURL(C2U("sdbc:flat:"));
|
|
|
|
//only the 'path' has to be added
|
|
|
|
sDBURL += aTempURL.GetMainURL(INetURLObject::NO_DECODE);
|
|
|
|
aURLAny <<= sDBURL;
|
|
|
|
|
2008-03-07 10:16:55 +00:00
|
|
|
bTextConnection = true;
|
2004-08-02 13:20:28 +00:00
|
|
|
//set the filter to the file name without extension
|
|
|
|
Sequence<rtl::OUString> aFilters(1);
|
|
|
|
rtl::OUString sTmp(aURL.getBase());
|
|
|
|
aFilters[0] = aURL.getBase();
|
|
|
|
aTableFilterAny <<= aFilters;
|
|
|
|
}
|
2008-06-06 09:06:54 +00:00
|
|
|
#ifdef WNT
|
|
|
|
else if(sExt.EqualsIgnoreCaseAscii("mdb"))
|
|
|
|
{
|
|
|
|
rtl::OUString sDBURL(C2U("sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="));
|
|
|
|
sDBURL += aTempURL.PathToFileName();
|
|
|
|
aURLAny <<= sDBURL;
|
|
|
|
aSuppressVersionsAny <<= makeAny(true);
|
|
|
|
}
|
2008-10-01 06:46:01 +00:00
|
|
|
else if(sExt.EqualsIgnoreCaseAscii("accdb"))
|
|
|
|
{
|
|
|
|
rtl::OUString sDBURL(C2U("sdbc:ado:PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE="));
|
|
|
|
sDBURL += aTempURL.PathToFileName();
|
|
|
|
aURLAny <<= sDBURL;
|
|
|
|
aSuppressVersionsAny <<= makeAny(true);
|
|
|
|
}
|
2008-06-06 09:06:54 +00:00
|
|
|
#endif
|
2004-08-02 13:20:28 +00:00
|
|
|
try
|
|
|
|
{
|
2012-09-18 09:46:34 +02:00
|
|
|
Reference<XMultiServiceFactory> xMgr( ::comphelper::getProcessServiceFactory() );
|
|
|
|
Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
|
|
|
|
Reference<XDatabaseContext> xDBContext = DatabaseContext::create(xContext);
|
2004-08-02 13:20:28 +00:00
|
|
|
Reference<XSingleServiceFactory> xFact( xDBContext, UNO_QUERY);
|
|
|
|
|
2005-01-18 13:39:03 +00:00
|
|
|
String sNewName = INetURLObject::decode( aURL.getName(),
|
|
|
|
INET_HEX_ESCAPE,
|
|
|
|
INetURLObject::DECODE_UNAMBIGUOUS,
|
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2007-09-27 10:31:02 +00:00
|
|
|
xub_StrLen nExtLen = static_cast< xub_StrLen >(aURL.GetExtension().getLength());
|
2004-08-02 13:20:28 +00:00
|
|
|
sNewName.Erase( sNewName.Len() - nExtLen - 1, nExtLen + 1 );
|
|
|
|
|
|
|
|
//find a unique name if sNewName already exists
|
|
|
|
sFind = sNewName;
|
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
while(xDBContext->hasByName(sFind))
|
|
|
|
{
|
|
|
|
sFind = sNewName;
|
|
|
|
sFind += String::CreateFromInt32(++nIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<XInterface> xNewInstance;
|
|
|
|
if(!bStore)
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
//odb-file
|
2004-08-02 13:20:28 +00:00
|
|
|
Any aDataSource = xDBContext->getByName(aTempURL.GetMainURL(INetURLObject::NO_DECODE));
|
|
|
|
aDataSource >>= xNewInstance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xNewInstance = xFact->createInstance();
|
|
|
|
Reference<XPropertySet> xDataProperties(xNewInstance, UNO_QUERY);
|
|
|
|
|
|
|
|
if(aURLAny.hasValue())
|
|
|
|
xDataProperties->setPropertyValue(C2U("URL"), aURLAny);
|
|
|
|
if(aTableFilterAny.hasValue())
|
|
|
|
xDataProperties->setPropertyValue(C2U("TableFilter"), aTableFilterAny);
|
2008-06-06 09:06:54 +00:00
|
|
|
if(aSuppressVersionsAny.hasValue())
|
|
|
|
xDataProperties->setPropertyValue(C2U("SuppressVersionColumns"), aSuppressVersionsAny);
|
2004-08-02 13:20:28 +00:00
|
|
|
if(aInfoAny.hasValue())
|
|
|
|
xDataProperties->setPropertyValue(C2U("Info"), aInfoAny);
|
|
|
|
|
2008-03-07 10:16:55 +00:00
|
|
|
if( bTextConnection )
|
|
|
|
{
|
|
|
|
uno::Reference < ui::dialogs::XExecutableDialog > xSettingsDlg(
|
|
|
|
xMgr->createInstance( C2U( "com.sun.star.sdb.TextConnectionSettings" ) ), uno::UNO_QUERY);
|
|
|
|
if( xSettingsDlg->execute() )
|
|
|
|
{
|
|
|
|
uno::Any aSettings = xDataProperties->getPropertyValue( C2U( "Settings" ) );
|
|
|
|
uno::Reference < beans::XPropertySet > xDSSettings;
|
|
|
|
aSettings >>= xDSSettings;
|
|
|
|
::comphelper::copyProperties(
|
|
|
|
uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY ),
|
|
|
|
xDSSettings );
|
|
|
|
xDSSettings->setPropertyValue( C2U("Extension"), uno::makeAny( ::rtl::OUString( sExt )));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-30 09:55:07 +00:00
|
|
|
Reference<XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
|
|
|
|
Reference<XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
|
2012-07-02 16:02:38 +01:00
|
|
|
String sOutputExt = rtl::OUString(".odb");
|
2004-08-02 13:20:28 +00:00
|
|
|
String sTmpName;
|
|
|
|
{
|
2007-09-27 10:31:02 +00:00
|
|
|
utl::TempFile aTempFile(sNewName , &sOutputExt, &sHomePath);
|
2004-08-02 13:20:28 +00:00
|
|
|
aTempFile.EnableKillingFile(sal_True);
|
|
|
|
sTmpName = aTempFile.GetURL();
|
|
|
|
}
|
|
|
|
xStore->storeAsURL(sTmpName, Sequence< PropertyValue >());
|
|
|
|
}
|
|
|
|
Reference<XNamingService> xNaming(xDBContext, UNO_QUERY);
|
|
|
|
xNaming->registerObject( sFind, xNewInstance );
|
|
|
|
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2004-08-02 13:20:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sFind;
|
|
|
|
|
|
|
|
}
|
2000-11-13 07:32:00 +00:00
|
|
|
|
|
|
|
void SwNewDBMgr::ExecuteFormLetter( SwWrtShell& rSh,
|
2002-09-18 09:39:28 +00:00
|
|
|
const Sequence<PropertyValue>& rProperties,
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bWithDataSourceBrowser)
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2001-02-16 13:58:11 +00:00
|
|
|
//prevent second call
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeDialog)
|
2001-02-16 13:58:11 +00:00
|
|
|
return ;
|
2001-09-04 11:40:59 +00:00
|
|
|
rtl::OUString sDataSource, sDataTableOrQuery;
|
2001-06-19 06:42:09 +00:00
|
|
|
Sequence<Any> aSelection;
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2012-09-30 08:35:03 +02:00
|
|
|
sal_Int32 nCmdType = CommandType::TABLE;
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2002-08-21 11:23:43 +00:00
|
|
|
|
|
|
|
ODataAccessDescriptor aDescriptor(rProperties);
|
2004-08-02 13:20:28 +00:00
|
|
|
sDataSource = aDescriptor.getDataSource();
|
2012-09-30 08:35:03 +02:00
|
|
|
OSL_VERIFY(aDescriptor[daCommand] >>= sDataTableOrQuery);
|
|
|
|
OSL_VERIFY(aDescriptor[daCommandType] >>= nCmdType);
|
2002-08-21 11:23:43 +00:00
|
|
|
|
|
|
|
if ( aDescriptor.has(daSelection) )
|
|
|
|
aDescriptor[daSelection] >>= aSelection;
|
|
|
|
if ( aDescriptor.has(daConnection) )
|
|
|
|
aDescriptor[daConnection] >>= xConnection;
|
|
|
|
|
2012-01-17 17:47:34 -02:00
|
|
|
if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty())
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("PropertyValues missing or unset");
|
2000-11-13 07:32:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-06-19 06:42:09 +00:00
|
|
|
|
2005-07-18 11:26:10 +00:00
|
|
|
//always create a connection for the dialog and dispose it after the dialog has been closed
|
|
|
|
SwDSParam* pFound = 0;
|
|
|
|
if(!xConnection.is())
|
|
|
|
{
|
|
|
|
xConnection = SwNewDBMgr::RegisterConnection(sDataSource);
|
2011-01-17 15:06:54 +01:00
|
|
|
pFound = FindDSConnection(sDataSource, sal_True);
|
2005-07-18 11:26:10 +00:00
|
|
|
}
|
2004-05-10 15:20:29 +00:00
|
|
|
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pFact, "Dialogdiet fail!");
|
2007-04-26 08:02:02 +00:00
|
|
|
pImpl->pMergeDialog = pFact->CreateMailMergeDlg( DLG_MAILMERGE,
|
2004-05-10 15:20:29 +00:00
|
|
|
&rSh.GetView().GetViewFrame()->GetWindow(), rSh,
|
|
|
|
sDataSource,
|
|
|
|
sDataTableOrQuery,
|
|
|
|
nCmdType,
|
|
|
|
xConnection,
|
|
|
|
bWithDataSourceBrowser ? 0 : &aSelection);
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pImpl->pMergeDialog, "Dialogdiet fail!");
|
2001-08-30 12:56:46 +00:00
|
|
|
if(pImpl->pMergeDialog->Execute() == RET_OK)
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2002-08-21 11:23:43 +00:00
|
|
|
aDescriptor[daSelection] <<= pImpl->pMergeDialog->GetSelection();
|
2001-06-06 05:20:21 +00:00
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XResultSet> xResSet = pImpl->pMergeDialog->GetResultSet();
|
2001-06-06 05:20:21 +00:00
|
|
|
if(xResSet.is())
|
2002-08-21 11:23:43 +00:00
|
|
|
aDescriptor[daCursor] <<= xResSet;
|
|
|
|
|
2011-01-03 13:40:23 +01:00
|
|
|
// SfxObjectShellRef is ok, since there should be no control over the document lifetime here
|
2007-11-06 15:25:40 +00:00
|
|
|
SfxObjectShellRef xDocShell = rSh.GetView().GetViewFrame()->GetObjectShell();
|
2009-09-18 10:15:03 +00:00
|
|
|
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), xDocShell));
|
2007-11-06 15:25:40 +00:00
|
|
|
{
|
|
|
|
//copy rSh to aTempFile
|
|
|
|
::rtl::OUString sTempURL;
|
|
|
|
const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
|
2012-07-02 16:02:38 +01:00
|
|
|
rtl::OUString(FILTER_XML),
|
2007-11-06 15:25:40 +00:00
|
|
|
SwDocShell::Factory().GetFilterContainer() );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
uno::Sequence< beans::PropertyValue > aValues(1);
|
|
|
|
beans::PropertyValue* pValues = aValues.getArray();
|
|
|
|
pValues[0].Name = C2U("FilterName");
|
|
|
|
pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
|
|
|
|
uno::Reference< frame::XStorable > xStore( xDocShell->GetModel(), uno::UNO_QUERY);
|
|
|
|
sTempURL = URIHelper::SmartRel2Abs( INetURLObject(), utl::TempFile::CreateTempName() );
|
|
|
|
xStore->storeToURL( sTempURL, aValues );
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const uno::Exception&)
|
2007-11-06 15:25:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
if( xDocShell->GetError() )
|
|
|
|
{
|
|
|
|
// error message ??
|
|
|
|
ErrorHandler::HandleError( xDocShell->GetError() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-03 13:40:23 +01:00
|
|
|
// the shell will be explicitly closed, but it is more safe to use SfxObjectShellLock here
|
|
|
|
// especially for the case that the loading has failed
|
|
|
|
SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
|
2012-05-24 11:38:12 +02:00
|
|
|
SfxMedium* pWorkMed = new SfxMedium( sTempURL, STREAM_STD_READ );
|
2007-11-06 15:25:40 +00:00
|
|
|
pWorkMed->SetFilter( pSfxFlt );
|
|
|
|
if( xWorkDocSh->DoLoad(pWorkMed) )
|
|
|
|
{
|
2009-12-09 10:11:48 +01:00
|
|
|
SfxViewFrame *pFrame = SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 );
|
2007-11-06 15:25:40 +00:00
|
|
|
SwView *pView = (SwView*) pFrame->GetViewShell();
|
2011-02-25 22:21:36 +01:00
|
|
|
pView->AttrChangedNotify( &pView->GetWrtShell() );// in order for SelectShell to be called
|
2008-03-10 12:48:39 +00:00
|
|
|
//set the current DBMgr
|
|
|
|
SwDoc* pWorkDoc = pView->GetWrtShell().GetDoc();
|
|
|
|
SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr();
|
|
|
|
pWorkDoc->SetNewDBMgr( this );
|
2007-11-06 15:25:40 +00:00
|
|
|
|
|
|
|
SwMergeDescriptor aMergeDesc( pImpl->pMergeDialog->GetMergeType(), pView->GetWrtShell(), aDescriptor );
|
|
|
|
aMergeDesc.sSaveToFilter = pImpl->pMergeDialog->GetSaveFilter();
|
2011-03-15 14:20:47 +01:00
|
|
|
aMergeDesc.bCreateSingleFile = !pImpl->pMergeDialog->IsSaveIndividualDocs();
|
|
|
|
if( !aMergeDesc.bCreateSingleFile && pImpl->pMergeDialog->IsGenerateFromDataBase() )
|
|
|
|
{
|
|
|
|
aMergeDesc.sAddressFromColumn = pImpl->pMergeDialog->GetColumnName();
|
|
|
|
aMergeDesc.sSubject = pImpl->pMergeDialog->GetPath();
|
|
|
|
}
|
|
|
|
|
2007-11-06 15:25:40 +00:00
|
|
|
MergeNew(aMergeDesc);
|
2008-03-10 12:48:39 +00:00
|
|
|
|
|
|
|
pWorkDoc->SetNewDBMgr( pWorkDBMgr );
|
2007-11-06 15:25:40 +00:00
|
|
|
//close the temporary file
|
|
|
|
uno::Reference< util::XCloseable > xClose( xWorkDocSh->GetModel(), uno::UNO_QUERY );
|
|
|
|
if (xClose.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//! 'sal_True' -> transfer ownership to vetoing object if vetoed!
|
|
|
|
//! I.e. now that object is responsible for closing the model and doc shell.
|
|
|
|
xClose->close( sal_True );
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch (const uno::Exception&)
|
2007-11-06 15:25:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//remove the temporary file
|
|
|
|
SWUnoHelper::UCB_DeleteFile( sTempURL );
|
|
|
|
}
|
2009-09-18 10:15:03 +00:00
|
|
|
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), rSh.GetView().GetViewFrame()->GetObjectShell()));
|
2003-06-27 08:08:38 +00:00
|
|
|
|
2002-08-21 11:23:43 +00:00
|
|
|
// reset the cursor inside
|
|
|
|
xResSet = NULL;
|
|
|
|
aDescriptor[daCursor] <<= xResSet;
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
2005-07-18 11:26:10 +00:00
|
|
|
if(pFound)
|
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
for(sal_uInt16 nPos = 0; nPos < aDataSourceParams.size(); nPos++)
|
2005-07-18 11:26:10 +00:00
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
SwDSParam* pParam = &aDataSourceParams[nPos];
|
2005-07-18 11:26:10 +00:00
|
|
|
if(pParam == pFound)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference<XComponent> xComp(pParam->xConnection, UNO_QUERY);
|
|
|
|
if(xComp.is())
|
|
|
|
xComp->dispose();
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const RuntimeException&)
|
2005-07-18 11:26:10 +00:00
|
|
|
{
|
|
|
|
//may be disposed already since multiple entries may have used the same connection
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//pFound doesn't need to be removed/deleted -
|
|
|
|
//this has been done by the SwConnectionDisposedListener_Impl already
|
|
|
|
}
|
|
|
|
}
|
2001-08-30 12:56:46 +00:00
|
|
|
DELETEZ(pImpl->pMergeDialog);
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SwNewDBMgr::InsertText(SwWrtShell& rSh,
|
|
|
|
const Sequence< PropertyValue>& rProperties)
|
|
|
|
{
|
2001-09-04 11:40:59 +00:00
|
|
|
rtl::OUString sDataSource, sDataTableOrQuery;
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XResultSet> xResSet;
|
2001-06-06 11:01:40 +00:00
|
|
|
Sequence<Any> aSelection;
|
2000-11-13 07:32:00 +00:00
|
|
|
sal_Int16 nCmdType = CommandType::TABLE;
|
|
|
|
const PropertyValue* pValues = rProperties.getConstArray();
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XConnection> xConnection;
|
2000-11-13 07:32:00 +00:00
|
|
|
for(sal_Int32 nPos = 0; nPos < rProperties.getLength(); nPos++)
|
|
|
|
{
|
2012-04-06 15:05:52 +02:00
|
|
|
if ( pValues[nPos].Name == cDataSourceName )
|
2000-11-13 07:32:00 +00:00
|
|
|
pValues[nPos].Value >>= sDataSource;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( pValues[nPos].Name == cCommand )
|
2000-11-13 07:32:00 +00:00
|
|
|
pValues[nPos].Value >>= sDataTableOrQuery;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( pValues[nPos].Name == cCursor )
|
2000-11-13 07:32:00 +00:00
|
|
|
pValues[nPos].Value >>= xResSet;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( pValues[nPos].Name == cSelection )
|
2000-11-13 07:32:00 +00:00
|
|
|
pValues[nPos].Value >>= aSelection;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( pValues[nPos].Name == cCommandType )
|
2000-11-13 07:32:00 +00:00
|
|
|
pValues[nPos].Value >>= nCmdType;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( pValues[nPos].Name == cActiveConnection )
|
2001-06-08 12:47:33 +00:00
|
|
|
pValues[nPos].Value >>= xConnection;
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
2012-01-17 17:47:34 -02:00
|
|
|
if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty() || !xResSet.is())
|
2000-11-13 07:32:00 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("PropertyValues missing or unset");
|
2000-11-13 07:32:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-18 09:46:34 +02:00
|
|
|
Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XDataSource> xSource;
|
|
|
|
uno::Reference<XChild> xChild(xConnection, UNO_QUERY);
|
2001-06-08 12:47:33 +00:00
|
|
|
if(xChild.is())
|
2004-09-20 12:11:33 +00:00
|
|
|
xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
|
2001-06-08 12:47:33 +00:00
|
|
|
if(!xSource.is())
|
2012-09-18 09:46:34 +02:00
|
|
|
xSource = SwNewDBMgr::GetDbtoolsClient().getDataSource(sDataSource, xContext);
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XColumnsSupplier > xColSupp( xResSet, UNO_QUERY );
|
2001-02-21 11:27:37 +00:00
|
|
|
SwDBData aDBData;
|
|
|
|
aDBData.sDataSource = sDataSource;
|
|
|
|
aDBData.sCommand = sDataTableOrQuery;
|
|
|
|
aDBData.nCommandType = nCmdType;
|
2000-11-13 07:32:00 +00:00
|
|
|
|
2007-09-27 10:31:02 +00:00
|
|
|
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
|
2004-05-10 15:20:29 +00:00
|
|
|
|
|
|
|
AbstractSwInsertDBColAutoPilot* pDlg = pFact->CreateSwInsertDBColAutoPilot( rSh.GetView(),
|
|
|
|
xSource,
|
|
|
|
xColSupp,
|
|
|
|
aDBData,
|
2007-04-26 08:02:02 +00:00
|
|
|
DLG_AP_INSERT_DB_SEL );
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(pDlg, "Dialogdiet fail!");
|
2000-11-13 07:32:00 +00:00
|
|
|
if( RET_OK == pDlg->Execute() )
|
|
|
|
{
|
2001-09-04 11:40:59 +00:00
|
|
|
rtl::OUString sDummy;
|
2001-06-08 12:47:33 +00:00
|
|
|
if(!xConnection.is())
|
|
|
|
xConnection = xSource->getConnection(sDummy, sDummy);
|
2001-05-21 12:45:09 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
pDlg->DataToDoc( aSelection , xSource, xConnection, xResSet);
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2001-05-21 12:45:09 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("exception caught");
|
2001-05-21 12:45:09 +00:00
|
|
|
}
|
2000-11-13 07:32:00 +00:00
|
|
|
}
|
|
|
|
delete pDlg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-05-26 07:14:51 +00:00
|
|
|
SwDbtoolsClient* SwNewDBMgr::pDbtoolsClient = NULL;
|
|
|
|
|
2001-08-30 12:56:46 +00:00
|
|
|
SwDbtoolsClient& SwNewDBMgr::GetDbtoolsClient()
|
|
|
|
{
|
2002-08-21 11:23:43 +00:00
|
|
|
if ( !pDbtoolsClient )
|
2003-05-26 07:14:51 +00:00
|
|
|
pDbtoolsClient = new SwDbtoolsClient;
|
2002-08-21 11:23:43 +00:00
|
|
|
return *pDbtoolsClient;
|
2001-08-30 12:56:46 +00:00
|
|
|
}
|
2003-05-26 07:14:51 +00:00
|
|
|
|
|
|
|
void SwNewDBMgr::RemoveDbtoolsClient()
|
|
|
|
{
|
|
|
|
delete pDbtoolsClient;
|
|
|
|
pDbtoolsClient = 0;
|
|
|
|
}
|
2002-08-21 11:23:43 +00:00
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XDataSource> SwNewDBMgr::getDataSourceAsParent(const uno::Reference< XConnection>& _xConnection,const ::rtl::OUString& _sDataSourceName)
|
2002-08-21 11:23:43 +00:00
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XDataSource> xSource;
|
2003-09-11 08:41:01 +00:00
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XChild> xChild(_xConnection, UNO_QUERY);
|
2003-09-11 08:41:01 +00:00
|
|
|
if ( xChild.is() )
|
2004-09-20 12:11:33 +00:00
|
|
|
xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
|
2003-09-11 08:41:01 +00:00
|
|
|
if ( !xSource.is() )
|
2012-09-18 09:46:34 +02:00
|
|
|
xSource = SwNewDBMgr::GetDbtoolsClient().getDataSource(_sDataSourceName, ::comphelper::getProcessComponentContext());
|
2003-09-11 08:41:01 +00:00
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("exception in getDataSourceAsParent caught");
|
2003-09-11 08:41:01 +00:00
|
|
|
}
|
2002-08-21 11:23:43 +00:00
|
|
|
return xSource;
|
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XResultSet> SwNewDBMgr::createCursor(const ::rtl::OUString& _sDataSourceName,
|
2002-08-21 11:23:43 +00:00
|
|
|
const ::rtl::OUString& _sCommand,
|
|
|
|
sal_Int32 _nCommandType,
|
2004-09-20 12:11:33 +00:00
|
|
|
const uno::Reference<XConnection>& _xConnection
|
2002-08-21 11:23:43 +00:00
|
|
|
)
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XResultSet> xResultSet;
|
2002-08-21 11:23:43 +00:00
|
|
|
try
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
|
2002-08-21 11:23:43 +00:00
|
|
|
if( xMgr.is() )
|
|
|
|
{
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XInterface> xInstance = xMgr->createInstance(
|
2002-08-21 11:23:43 +00:00
|
|
|
C2U( "com.sun.star.sdb.RowSet" ));
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XPropertySet> xRowSetPropSet(xInstance, UNO_QUERY);
|
2002-08-21 11:23:43 +00:00
|
|
|
if(xRowSetPropSet.is())
|
|
|
|
{
|
|
|
|
xRowSetPropSet->setPropertyValue(C2U("DataSourceName"), makeAny(_sDataSourceName));
|
|
|
|
xRowSetPropSet->setPropertyValue(C2U("ActiveConnection"), makeAny(_xConnection));
|
|
|
|
xRowSetPropSet->setPropertyValue(C2U("Command"), makeAny(_sCommand));
|
|
|
|
xRowSetPropSet->setPropertyValue(C2U("CommandType"), makeAny(_nCommandType));
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference< XCompletedExecution > xRowSet(xInstance, UNO_QUERY);
|
2002-08-21 11:23:43 +00:00
|
|
|
|
|
|
|
if ( xRowSet.is() )
|
|
|
|
{
|
2012-10-04 14:36:34 +02:00
|
|
|
uno::Reference< XInteractionHandler > xHandler( InteractionHandler::createWithParent(comphelper::getComponentContext(xMgr), 0), UNO_QUERY_THROW );
|
2002-08-21 11:23:43 +00:00
|
|
|
xRowSet->executeWithCompletion(xHandler);
|
|
|
|
}
|
2004-09-20 12:11:33 +00:00
|
|
|
xResultSet = uno::Reference<XResultSet>(xRowSet, UNO_QUERY);
|
2002-08-21 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("Caught exception while creating a new RowSet!");
|
2002-08-21 11:23:43 +00:00
|
|
|
}
|
|
|
|
return xResultSet;
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2010-10-20 15:36:15 +01:00
|
|
|
|
|
|
|
// merge all data into one resulting document and return the number of merged documents
|
2004-09-20 12:11:33 +00:00
|
|
|
sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
|
|
|
|
SwView& rSourceView )
|
|
|
|
{
|
|
|
|
// check the availability of all data in the config item
|
|
|
|
uno::Reference< XResultSet> xResultSet = rMMConfig.GetResultSet();
|
|
|
|
if(!xResultSet.is())
|
|
|
|
return false;
|
2011-01-17 15:06:54 +01:00
|
|
|
bInMerge = sal_True;
|
2004-09-20 12:11:33 +00:00
|
|
|
sal_Int32 nRet = 0;
|
|
|
|
pImpl->pMergeData = new SwDSParam(
|
|
|
|
rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection());
|
|
|
|
|
|
|
|
try{
|
|
|
|
//set to start position
|
|
|
|
if(pImpl->pMergeData->aSelection.getLength())
|
|
|
|
{
|
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
pImpl->pMergeData->aSelection.getConstArray()[ pImpl->pMergeData->nSelectionIndex++ ] >>= nPos;
|
|
|
|
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->absolute( nPos );
|
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
|
|
|
if(pImpl->pMergeData->nSelectionIndex >= pImpl->pMergeData->aSelection.getLength())
|
2011-01-17 15:06:54 +01:00
|
|
|
pImpl->pMergeData->bEndOfDB = sal_True;
|
2004-09-20 12:11:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pImpl->pMergeData->bEndOfDB = !pImpl->pMergeData->xResultSet->first();
|
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2004-09-20 12:11:33 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
pImpl->pMergeData->bEndOfDB = sal_True;
|
2004-09-20 12:11:33 +00:00
|
|
|
pImpl->pMergeData->CheckEndOfDB();
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("exception in MergeNew()");
|
2004-09-20 12:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//bCancel is set from the PrintMonitor
|
2011-01-17 15:06:54 +01:00
|
|
|
bCancel = sal_False;
|
2004-09-20 12:11:33 +00:00
|
|
|
|
2004-11-16 15:57:21 +00:00
|
|
|
CreateMonitor aMonitorDlg(&rSourceView.GetEditWin());
|
|
|
|
aMonitorDlg.SetCancelHdl(LINK(this, SwNewDBMgr, PrtCancelHdl));
|
2004-09-20 12:11:33 +00:00
|
|
|
if (!IsMergeSilent())
|
2004-11-16 15:57:21 +00:00
|
|
|
{
|
|
|
|
aMonitorDlg.Show();
|
|
|
|
aMonitorDlg.Invalidate();
|
|
|
|
aMonitorDlg.Update();
|
|
|
|
// the print monitor needs some time to act
|
2011-01-17 15:06:54 +01:00
|
|
|
for( sal_uInt16 i = 0; i < 25; i++)
|
2004-11-16 15:57:21 +00:00
|
|
|
Application::Reschedule();
|
|
|
|
}
|
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
SwWrtShell& rSourceShell = rSourceView.GetWrtShell();
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_Bool bSynchronizedDoc = rSourceShell.IsLabelDoc() && rSourceShell.GetSectionFmtCount() > 1;
|
2004-09-20 12:11:33 +00:00
|
|
|
//save the settings of the first
|
2011-01-17 15:06:54 +01:00
|
|
|
rSourceShell.SttEndDoc(sal_True);
|
|
|
|
sal_uInt16 nStartingPageNo = rSourceShell.GetVirtPageNum();
|
2006-07-13 14:55:52 +00:00
|
|
|
String sModifiedStartingPageDesc;
|
|
|
|
String sStartingPageDesc = sModifiedStartingPageDesc = rSourceShell.GetPageDesc(
|
2004-09-20 12:11:33 +00:00
|
|
|
rSourceShell.GetCurPageDesc()).GetName();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// create a target docshell to put the merged document into
|
|
|
|
SfxObjectShellRef xTargetDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
|
|
|
|
xTargetDocShell->DoInitNew( 0 );
|
2009-12-09 10:11:48 +01:00
|
|
|
SfxViewFrame* pTargetFrame = SfxViewFrame::LoadHiddenDocument( *xTargetDocShell, 0 );
|
2004-09-20 12:11:33 +00:00
|
|
|
|
|
|
|
//the created window has to be located at the same position as the source window
|
2009-12-15 23:07:57 +01:00
|
|
|
Window& rTargetWindow = pTargetFrame->GetFrame().GetWindow();
|
|
|
|
Window& rSourceWindow = rSourceView.GetViewFrame()->GetFrame().GetWindow();
|
2004-09-20 12:11:33 +00:00
|
|
|
rTargetWindow.SetPosPixel(rSourceWindow.GetPosPixel());
|
|
|
|
|
|
|
|
SwView* pTargetView = static_cast<SwView*>( pTargetFrame->GetViewShell() );
|
|
|
|
rMMConfig.SetTargetView(pTargetView);
|
|
|
|
//initiate SelectShell() to create sub shells
|
|
|
|
pTargetView->AttrChangedNotify( &pTargetView->GetWrtShell() );
|
|
|
|
SwWrtShell* pTargetShell = pTargetView->GetWrtShellPtr();
|
2006-07-13 14:55:52 +00:00
|
|
|
// #i63806#
|
|
|
|
const SwPageDesc* pSourcePageDesc = rSourceShell.FindPageDescByName( sStartingPageDesc );
|
|
|
|
const SwFrmFmt& rMaster = pSourcePageDesc->GetMaster();
|
|
|
|
bool bPageStylesWithHeaderFooter = rMaster.GetHeader().IsActive() ||
|
|
|
|
rMaster.GetFooter().IsActive();
|
|
|
|
|
|
|
|
|
2011-02-25 22:33:34 +01:00
|
|
|
// copy compatibility options
|
2005-10-18 12:49:13 +00:00
|
|
|
lcl_CopyCompatibilityOptions( rSourceShell, *pTargetShell);
|
2007-04-04 14:17:58 +00:00
|
|
|
// #72821# copy dynamic defaults
|
|
|
|
lcl_CopyDynamicDefaults( *rSourceShell.GetDoc(), *pTargetShell->GetDoc() );
|
2004-09-20 12:11:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
long nStartRow, nEndRow;
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uLong nDocNo = 1;
|
2004-11-16 15:57:21 +00:00
|
|
|
sal_Int32 nDocCount = 0;
|
|
|
|
if( !IsMergeSilent() && lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) )
|
|
|
|
aMonitorDlg.SetTotalCount( nDocCount );
|
2004-09-20 12:11:33 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nStartRow = pImpl->pMergeData->xResultSet->getRow();
|
2004-11-16 15:57:21 +00:00
|
|
|
if (!IsMergeSilent())
|
|
|
|
{
|
|
|
|
aMonitorDlg.SetCurrentPosition( nDocNo );
|
|
|
|
aMonitorDlg.Invalidate();
|
|
|
|
aMonitorDlg.Update();
|
|
|
|
// the print monitor needs some time to act
|
2011-01-17 15:06:54 +01:00
|
|
|
for( sal_uInt16 i = 0; i < 25; i++)
|
2004-11-16 15:57:21 +00:00
|
|
|
Application::Reschedule();
|
|
|
|
}
|
2004-09-20 12:11:33 +00:00
|
|
|
|
2009-07-28 13:59:44 +00:00
|
|
|
// copy the source document
|
2011-01-03 13:40:23 +01:00
|
|
|
// the copy will be closed later, but it is more safe to use SfxObjectShellLock here
|
|
|
|
SfxObjectShellLock xWorkDocSh;
|
2009-07-28 13:59:44 +00:00
|
|
|
if(nDocNo == 1 )
|
2004-09-20 12:11:33 +00:00
|
|
|
{
|
2009-07-28 13:59:44 +00:00
|
|
|
uno::Reference< util::XCloneable > xClone( rSourceView.GetDocShell()->GetModel(), uno::UNO_QUERY);
|
|
|
|
uno::Reference< lang::XUnoTunnel > xWorkDocShell( xClone->createClone(), uno::UNO_QUERY);
|
|
|
|
SwXTextDocument* pWorkModel = reinterpret_cast<SwXTextDocument*>(xWorkDocShell->getSomething(SwXTextDocument::getUnoTunnelId()));
|
|
|
|
xWorkDocSh = pWorkModel->GetDocShell();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-20 15:50:24 +01:00
|
|
|
xWorkDocSh = rSourceView.GetDocShell()->GetDoc()->CreateCopy(true);
|
2009-07-28 13:59:44 +00:00
|
|
|
}
|
|
|
|
//create a ViewFrame
|
2009-12-09 10:11:48 +01:00
|
|
|
SwView* pWorkView = static_cast< SwView* >( SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 )->GetViewShell() );
|
2009-07-28 13:59:44 +00:00
|
|
|
SwWrtShell& rWorkShell = pWorkView->GetWrtShell();
|
2011-02-25 22:21:36 +01:00
|
|
|
pWorkView->AttrChangedNotify( &rWorkShell );// in order for SelectShell to be called
|
2009-07-28 13:59:44 +00:00
|
|
|
|
2009-08-26 11:47:12 +00:00
|
|
|
// merge the data
|
|
|
|
SwDoc* pWorkDoc = rWorkShell.GetDoc();
|
|
|
|
SwNewDBMgr* pWorkDBMgr = pWorkDoc->GetNewDBMgr();
|
|
|
|
pWorkDoc->SetNewDBMgr( this );
|
|
|
|
pWorkDoc->EmbedAllLinks();
|
2010-12-15 09:14:08 +01:00
|
|
|
SwUndoId nLastUndoId(UNDO_EMPTY);
|
|
|
|
if (rWorkShell.GetLastUndoInfo(0, & nLastUndoId))
|
2010-12-15 09:14:02 +01:00
|
|
|
{
|
2010-12-15 09:14:08 +01:00
|
|
|
if (UNDO_UI_DELETE_INVISIBLECNTNT == nLastUndoId)
|
|
|
|
{
|
|
|
|
rWorkShell.Undo();
|
|
|
|
}
|
2010-12-15 09:14:02 +01:00
|
|
|
}
|
2009-10-09 15:11:54 +02:00
|
|
|
// #i69485# lock fields to prevent access to the result set while calculating layout
|
|
|
|
rWorkShell.LockExpFlds();
|
2009-08-26 11:47:12 +00:00
|
|
|
// create a layout
|
|
|
|
rWorkShell.CalcLayout();
|
|
|
|
rWorkShell.UnlockExpFlds();
|
2009-09-18 10:15:03 +00:00
|
|
|
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE), rWorkShell.GetView().GetViewFrame()->GetObjectShell()));
|
|
|
|
rWorkShell.ViewShell::UpdateFlds();
|
|
|
|
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_FIELD_MERGE_FINISHED, SwDocShell::GetEventName(STR_SW_EVENT_FIELD_MERGE_FINISHED), rWorkShell.GetView().GetViewFrame()->GetObjectShell()));
|
2009-07-28 13:59:44 +00:00
|
|
|
|
|
|
|
// strip invisible content and convert fields to text
|
|
|
|
rWorkShell.RemoveInvisibleContent();
|
|
|
|
rWorkShell.ConvertFieldsToText();
|
|
|
|
rWorkShell.SetNumberingRestart();
|
2010-07-29 14:58:17 +02:00
|
|
|
if( bSynchronizedDoc )
|
|
|
|
{
|
|
|
|
lcl_RemoveSectionLinks( rWorkShell );
|
|
|
|
}
|
2009-07-28 13:59:44 +00:00
|
|
|
|
|
|
|
// insert the document into the target document
|
2011-01-17 15:06:54 +01:00
|
|
|
rWorkShell.SttEndDoc(sal_False);
|
|
|
|
rWorkShell.SttEndDoc(sal_True);
|
2009-07-28 13:59:44 +00:00
|
|
|
rWorkShell.SelAll();
|
2011-01-17 15:06:54 +01:00
|
|
|
pTargetShell->SttEndDoc(sal_False);
|
2009-07-28 13:59:44 +00:00
|
|
|
|
|
|
|
//#i63806# put the styles to the target document
|
|
|
|
//if the source uses headers or footers each new copy need to copy a new page styles
|
|
|
|
if(bPageStylesWithHeaderFooter)
|
|
|
|
{
|
|
|
|
//create a new pagestyle
|
|
|
|
//copy the pagedesc from the current document to the new document and change the name of the to-be-applied style
|
|
|
|
|
2009-09-01 03:54:53 +00:00
|
|
|
SwDoc* pTargetDoc = pTargetShell->GetDoc();
|
|
|
|
String sNewPageDescName = lcl_FindUniqueName(pTargetShell, sStartingPageDesc, nDocNo );
|
|
|
|
pTargetShell->GetDoc()->MakePageDesc( sNewPageDescName );
|
|
|
|
SwPageDesc* pTargetPageDesc = pTargetShell->FindPageDescByName( sNewPageDescName );
|
|
|
|
const SwPageDesc* pWorkPageDesc = rWorkShell.FindPageDescByName( sStartingPageDesc );
|
2009-08-26 11:47:12 +00:00
|
|
|
|
2009-09-01 03:54:53 +00:00
|
|
|
if(pWorkPageDesc && pTargetPageDesc)
|
2005-10-19 07:25:32 +00:00
|
|
|
{
|
2012-10-25 17:01:26 +09:00
|
|
|
pTargetDoc->CopyPageDesc( *pWorkPageDesc, *pTargetPageDesc, false );
|
2009-07-28 13:59:44 +00:00
|
|
|
sModifiedStartingPageDesc = sNewPageDescName;
|
2009-09-01 03:54:53 +00:00
|
|
|
lcl_CopyFollowPageDesc( *pTargetShell, *pWorkPageDesc, *pTargetPageDesc, nDocNo );
|
2005-10-19 07:25:32 +00:00
|
|
|
}
|
2009-07-28 13:59:44 +00:00
|
|
|
}
|
|
|
|
if(nDocNo == 1 || bPageStylesWithHeaderFooter)
|
|
|
|
{
|
2009-11-13 08:30:06 +00:00
|
|
|
pTargetView->GetDocShell()->_LoadStyles( *rSourceView.GetDocShell(), sal_True );
|
2009-07-28 13:59:44 +00:00
|
|
|
}
|
|
|
|
if(nDocNo > 1)
|
|
|
|
{
|
|
|
|
pTargetShell->InsertPageBreak( &sModifiedStartingPageDesc, nStartingPageNo );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pTargetShell->SetPageStyle(sModifiedStartingPageDesc);
|
|
|
|
}
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nPageCountBefore = pTargetShell->GetPageCnt();
|
2010-10-20 15:36:15 +01:00
|
|
|
OSL_ENSURE(!pTargetShell->GetTableFmt(),"target document ends with a table - paragraph should be appended");
|
2009-07-28 13:59:44 +00:00
|
|
|
//#i51359# add a second paragraph in case there's only one
|
|
|
|
{
|
|
|
|
SwNodeIndex aIdx( pWorkDoc->GetNodes().GetEndOfExtras(), 2 );
|
|
|
|
SwPosition aTestPos( aIdx );
|
|
|
|
SwCursor aTestCrsr(aTestPos,0,false);
|
|
|
|
if(!aTestCrsr.MovePara(fnParaNext, fnParaStart))
|
2005-11-10 14:57:22 +00:00
|
|
|
{
|
2009-07-28 13:59:44 +00:00
|
|
|
//append a paragraph
|
|
|
|
pWorkDoc->AppendTxtNode( aTestPos );
|
2005-11-10 14:57:22 +00:00
|
|
|
}
|
2009-07-28 13:59:44 +00:00
|
|
|
}
|
|
|
|
pTargetShell->Paste( rWorkShell.GetDoc(), sal_True );
|
|
|
|
//convert fields in page styles (header/footer - has to be done after the first document has been pasted
|
|
|
|
if(1 == nDocNo)
|
|
|
|
{
|
2007-07-12 09:49:57 +00:00
|
|
|
pTargetShell->CalcLayout();
|
2009-07-28 13:59:44 +00:00
|
|
|
pTargetShell->ConvertFieldsToText();
|
2004-09-20 12:11:33 +00:00
|
|
|
}
|
2009-07-28 13:59:44 +00:00
|
|
|
//add the document info to the config item
|
|
|
|
SwDocMergeInfo aMergeInfo;
|
|
|
|
aMergeInfo.nStartPageInTarget = nPageCountBefore;
|
|
|
|
//#i72820# calculate layout to be able to find the correct page index
|
|
|
|
pTargetShell->CalcLayout();
|
|
|
|
aMergeInfo.nEndPageInTarget = pTargetShell->GetPageCnt();
|
|
|
|
aMergeInfo.nDBRow = nStartRow;
|
|
|
|
rMMConfig.AddMergedDocument( aMergeInfo );
|
|
|
|
++nRet;
|
|
|
|
|
|
|
|
// the print monitor needs some time to act
|
2011-01-17 15:06:54 +01:00
|
|
|
for( sal_uInt16 i = 0; i < 25; i++)
|
2009-07-28 13:59:44 +00:00
|
|
|
Application::Reschedule();
|
|
|
|
|
|
|
|
//restore the ole DBMgr
|
|
|
|
pWorkDoc->SetNewDBMgr( pWorkDBMgr );
|
|
|
|
//now the temporary document should be closed
|
|
|
|
SfxObjectShellRef xDocSh(pWorkView->GetDocShell());
|
|
|
|
xDocSh->DoClose();
|
2004-09-20 12:11:33 +00:00
|
|
|
nEndRow = pImpl->pMergeData->xResultSet->getRow();
|
|
|
|
++nDocNo;
|
|
|
|
} while( !bCancel &&
|
|
|
|
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
|
2004-11-16 15:57:21 +00:00
|
|
|
|
|
|
|
//deselect all, go out of the frame and go to the beginning of the document
|
|
|
|
Point aPt(LONG_MIN, LONG_MIN);
|
|
|
|
pTargetShell->SelectObj(aPt, SW_LEAVE_FRAME);
|
|
|
|
if (pTargetShell->IsSelFrmMode())
|
|
|
|
{
|
|
|
|
pTargetShell->UnSelectFrm();
|
|
|
|
pTargetShell->LeaveSelFrmMode();
|
|
|
|
}
|
|
|
|
pTargetShell->EnterStdMode();
|
|
|
|
pTargetShell->SttDoc();
|
2010-10-20 15:36:15 +01:00
|
|
|
|
2004-09-20 12:11:33 +00:00
|
|
|
}
|
2011-06-15 23:56:45 +01:00
|
|
|
catch(const Exception&)
|
2004-09-20 12:11:33 +00:00
|
|
|
{
|
2011-03-12 11:51:35 +01:00
|
|
|
OSL_FAIL("exception caught in SwNewDBMgr::MergeDocuments");
|
2004-09-20 12:11:33 +00:00
|
|
|
}
|
|
|
|
DELETEZ(pImpl->pMergeData);
|
2011-01-17 15:06:54 +01:00
|
|
|
bInMerge = sal_False;
|
2004-09-20 12:11:33 +00:00
|
|
|
return nRet;
|
|
|
|
}
|
2010-10-11 17:38:56 -05:00
|
|
|
|
2002-12-09 12:58:30 +00:00
|
|
|
SwConnectionDisposedListener_Impl::SwConnectionDisposedListener_Impl(SwNewDBMgr& rMgr) :
|
|
|
|
rDBMgr(rMgr)
|
2010-10-11 17:38:56 -05:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2002-12-09 12:58:30 +00:00
|
|
|
SwConnectionDisposedListener_Impl::~SwConnectionDisposedListener_Impl()
|
2010-10-11 17:38:56 -05:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2002-12-09 12:58:30 +00:00
|
|
|
void SwConnectionDisposedListener_Impl::disposing( const EventObject& rSource )
|
|
|
|
throw (RuntimeException)
|
|
|
|
{
|
2010-10-16 03:22:02 -05:00
|
|
|
::SolarMutexGuard aGuard;
|
2004-09-20 12:11:33 +00:00
|
|
|
uno::Reference<XConnection> xSource(rSource.Source, UNO_QUERY);
|
2012-05-23 13:49:36 +02:00
|
|
|
for(sal_uInt16 nPos = rDBMgr.aDataSourceParams.size(); nPos; nPos--)
|
2002-12-09 12:58:30 +00:00
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
SwDSParam* pParam = &rDBMgr.aDataSourceParams[nPos - 1];
|
2002-12-09 12:58:30 +00:00
|
|
|
if(pParam->xConnection.is() &&
|
|
|
|
(xSource == pParam->xConnection))
|
|
|
|
{
|
2012-05-23 13:49:36 +02:00
|
|
|
rDBMgr.aDataSourceParams.erase(rDBMgr.aDataSourceParams.begin() + nPos - 1);
|
2002-12-09 12:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|