2004-08-02 13:18:47 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 12:45:36 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
2008-04-10 12:45:36 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
2008-04-10 12:45:36 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
2008-04-10 12:45:36 +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.
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
2008-04-10 12:45:36 +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).
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
2008-04-10 12:45:36 +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.
|
2004-08-02 13:18:47 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 20:05:42 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sw.hxx"
|
2004-08-02 13:18:47 +00:00
|
|
|
#include <editsh.hxx>
|
|
|
|
#include <dbfld.hxx>
|
|
|
|
#include <dbmgr.hxx>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2006-08-14 15:08:30 +00:00
|
|
|
#include <doc.hxx>
|
2004-08-02 13:18:47 +00:00
|
|
|
#include <docary.hxx>
|
|
|
|
#include <ndtxt.hxx> // GetCurFld
|
|
|
|
#include <txtfld.hxx>
|
|
|
|
#include <fmtfld.hxx>
|
|
|
|
#include <edimp.hxx>
|
|
|
|
#include <flddat.hxx>
|
|
|
|
|
2007-06-05 16:29:12 +00:00
|
|
|
using namespace com::sun::star;
|
2008-03-12 11:18:22 +00:00
|
|
|
using ::rtl::OUString;
|
2004-08-02 13:18:47 +00:00
|
|
|
|
|
|
|
/* -----------------28.11.2002 17:53-----------------
|
|
|
|
*
|
|
|
|
* --------------------------------------------------*/
|
|
|
|
BOOL SwEditShell::IsFieldDataSourceAvailable(String& rUsedDataSource) const
|
|
|
|
{
|
|
|
|
const SwFldTypes * pFldTypes = GetDoc()->GetFldTypes();
|
|
|
|
const USHORT nSize = pFldTypes->Count();
|
2007-06-05 16:29:12 +00:00
|
|
|
uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
|
2004-08-02 13:18:47 +00:00
|
|
|
if( !xMgr.is() )
|
|
|
|
return FALSE;
|
2007-06-05 16:29:12 +00:00
|
|
|
uno::Reference<uno::XInterface> xInstance = xMgr->createInstance( OUString::createFromAscii( "com.sun.star.sdb.DatabaseContext" ));
|
|
|
|
uno::Reference<container::XNameAccess> xDBContext(xInstance, uno::UNO_QUERY) ;
|
2004-08-02 13:18:47 +00:00
|
|
|
if(!xDBContext.is())
|
|
|
|
return FALSE;
|
|
|
|
for(USHORT i = 0; i < nSize; ++i)
|
|
|
|
{
|
|
|
|
SwFieldType& rFldType = *((*pFldTypes)[i]);
|
|
|
|
USHORT nWhich = rFldType.Which();
|
|
|
|
if(IsUsed(rFldType))
|
|
|
|
{
|
|
|
|
switch(nWhich)
|
|
|
|
{
|
|
|
|
case RES_DBFLD:
|
|
|
|
{
|
|
|
|
SwClientIter aIter( rFldType );
|
|
|
|
SwFmtFld* pFld = (SwFmtFld*)aIter.First( TYPE( SwFmtFld ));
|
|
|
|
while(pFld)
|
|
|
|
{
|
|
|
|
if(pFld->IsFldInDoc())
|
|
|
|
{
|
|
|
|
const SwDBData& rData =
|
|
|
|
((SwDBFieldType*)pFld->GetFld()->GetTyp())->GetDBData();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return xDBContext->getByName(rData.sDataSource).hasValue();
|
|
|
|
}
|
2007-06-05 16:29:12 +00:00
|
|
|
catch(uno::Exception const &)
|
2004-08-02 13:18:47 +00:00
|
|
|
{
|
|
|
|
rUsedDataSource = rData.sDataSource;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pFld = (SwFmtFld*)aIter.Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|