Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <editsh.hxx>
30 : : #include <dbfld.hxx>
31 : : #include <dbmgr.hxx>
32 : : #include <com/sun/star/container/XNameAccess.hpp>
33 : : #include <comphelper/processfactory.hxx>
34 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : : #include <doc.hxx>
36 : : #include <docary.hxx>
37 : : #include <ndtxt.hxx> // GetCurFld
38 : : #include <txtfld.hxx>
39 : : #include <fmtfld.hxx>
40 : : #include <edimp.hxx>
41 : : #include <flddat.hxx>
42 : : #include <switerator.hxx>
43 : :
44 : : using namespace com::sun::star;
45 : : using ::rtl::OUString;
46 : :
47 : 0 : sal_Bool SwEditShell::IsFieldDataSourceAvailable(String& rUsedDataSource) const
48 : : {
49 [ # # ]: 0 : const SwFldTypes * pFldTypes = GetDoc()->GetFldTypes();
50 : 0 : const sal_uInt16 nSize = pFldTypes->size();
51 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
52 [ # # ]: 0 : if( !xMgr.is() )
53 : 0 : return sal_False;
54 [ # # ][ # # ]: 0 : uno::Reference<uno::XInterface> xInstance = xMgr->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatabaseContext")));
[ # # ]
55 [ # # ]: 0 : uno::Reference<container::XNameAccess> xDBContext(xInstance, uno::UNO_QUERY) ;
56 [ # # ]: 0 : if(!xDBContext.is())
57 : 0 : return sal_False;
58 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nSize; ++i)
59 : : {
60 [ # # ]: 0 : SwFieldType& rFldType = *((*pFldTypes)[i]);
61 : 0 : sal_uInt16 nWhich = rFldType.Which();
62 [ # # ][ # # ]: 0 : if(IsUsed(rFldType))
63 : : {
64 [ # # ]: 0 : switch(nWhich)
65 : : {
66 : : case RES_DBFLD:
67 : : {
68 [ # # ]: 0 : SwIterator<SwFmtFld,SwFieldType> aIter( rFldType );
69 [ # # ]: 0 : SwFmtFld* pFld = aIter.First();
70 [ # # ]: 0 : while(pFld)
71 : : {
72 [ # # ][ # # ]: 0 : if(pFld->IsFldInDoc())
73 : : {
74 : : const SwDBData& rData =
75 : 0 : ((SwDBFieldType*)pFld->GetFld()->GetTyp())->GetDBData();
76 : : try
77 : : {
78 [ # # ][ # # ]: 0 : return xDBContext->getByName(rData.sDataSource).hasValue();
79 : : }
80 [ # # # # ]: 0 : catch(uno::Exception const &)
81 : : {
82 [ # # ]: 0 : rUsedDataSource = rData.sDataSource;
83 : 0 : return sal_False;
84 : : }
85 : : }
86 [ # # ]: 0 : pFld = aIter.Next();
87 [ # # ][ # # ]: 0 : }
88 : : }
89 : 0 : break;
90 : : }
91 : : }
92 : : }
93 : 0 : return sal_True;
94 : : }
95 : :
96 : :
97 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|