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 "XMLCodeNameProvider.hxx"
30 : : #include "document.hxx"
31 : :
32 : : using namespace com::sun::star;
33 : :
34 : : using ::rtl::OUString;
35 : :
36 : 0 : sal_Bool XMLCodeNameProvider::_getCodeName( const uno::Any& aAny, String& rCodeName )
37 : : {
38 [ # # ]: 0 : uno::Sequence<beans::PropertyValue> aProps;
39 [ # # ][ # # ]: 0 : if( !(aAny >>= aProps) )
40 : 0 : return false;
41 : :
42 [ # # ]: 0 : OUString sCodeNameProp( RTL_CONSTASCII_USTRINGPARAM("CodeName") );
43 : 0 : sal_Int32 nPropCount = aProps.getLength();
44 [ # # ]: 0 : for( sal_Int32 i=0; i<nPropCount; i++ )
45 : : {
46 [ # # ][ # # ]: 0 : if( aProps[i].Name == sCodeNameProp )
47 : : {
48 : 0 : OUString sCodeName;
49 [ # # ][ # # ]: 0 : if( aProps[i].Value >>= sCodeName )
50 : : {
51 [ # # ]: 0 : rCodeName = sCodeName;
52 : 0 : return sal_True;
53 [ # # ]: 0 : }
54 : : }
55 : : }
56 : :
57 [ # # ]: 0 : return false;
58 : : }
59 : :
60 : :
61 : 0 : XMLCodeNameProvider::XMLCodeNameProvider( ScDocument* pDoc ) :
62 : : mpDoc( pDoc ),
63 : : msDocName( RTL_CONSTASCII_USTRINGPARAM("*doc*") ),
64 [ # # ][ # # ]: 0 : msCodeNameProp( RTL_CONSTASCII_USTRINGPARAM("CodeName") )
65 : : {
66 : 0 : }
67 : :
68 : 0 : XMLCodeNameProvider::~XMLCodeNameProvider()
69 : : {
70 [ # # ]: 0 : }
71 : :
72 : 0 : ::sal_Bool SAL_CALL XMLCodeNameProvider::hasByName( const OUString& aName )
73 : : throw (uno::RuntimeException )
74 : : {
75 [ # # ]: 0 : if( aName == msDocName )
76 : 0 : return !mpDoc->GetCodeName().isEmpty();
77 : :
78 [ # # ]: 0 : SCTAB nCount = mpDoc->GetTableCount();
79 : 0 : rtl::OUString sSheetName, sCodeName;
80 [ # # ]: 0 : for( SCTAB i = 0; i < nCount; i++ )
81 : : {
82 [ # # ][ # # ]: 0 : if( mpDoc->GetName( i, sSheetName ) && sSheetName.equals(aName) )
[ # # ][ # # ]
83 : : {
84 [ # # ]: 0 : mpDoc->GetCodeName( i, sCodeName );
85 : 0 : return !sCodeName.isEmpty();
86 : : }
87 : : }
88 : :
89 : 0 : return false;
90 : : }
91 : :
92 : 0 : uno::Any SAL_CALL XMLCodeNameProvider::getByName( const OUString& aName )
93 : : throw (container::NoSuchElementException,
94 : : lang::WrappedTargetException, uno::RuntimeException)
95 : : {
96 : 0 : uno::Any aRet;
97 [ # # ]: 0 : uno::Sequence<beans::PropertyValue> aProps(1);
98 [ # # ]: 0 : aProps[0].Name = msCodeNameProp;
99 [ # # ]: 0 : if( aName == msDocName )
100 : : {
101 : 0 : OUString sUCodeName( mpDoc->GetCodeName() );
102 [ # # ][ # # ]: 0 : aProps[0].Value <<= sUCodeName;
103 [ # # ]: 0 : aRet <<= aProps;
104 : 0 : return aRet;
105 : : }
106 : :
107 [ # # ]: 0 : SCTAB nCount = mpDoc->GetTableCount();
108 : 0 : rtl::OUString sSheetName, sCodeName;
109 [ # # ]: 0 : for( SCTAB i = 0; i < nCount; i++ )
110 : : {
111 [ # # ][ # # ]: 0 : if( mpDoc->GetName( i, sSheetName ) && sSheetName.equals(aName) )
[ # # ][ # # ]
112 : : {
113 [ # # ]: 0 : mpDoc->GetCodeName( i, sCodeName );
114 [ # # ][ # # ]: 0 : aProps[0].Value <<= sCodeName;
115 [ # # ]: 0 : aRet <<= aProps;
116 : : return aRet;
117 : : }
118 : : }
119 : :
120 [ # # ]: 0 : return aRet;
121 : : }
122 : :
123 : 0 : uno::Sequence< OUString > SAL_CALL XMLCodeNameProvider::getElementNames( )
124 : : throw (uno::RuntimeException)
125 : : {
126 [ # # ]: 0 : SCTAB nCount = mpDoc->GetTableCount() + 1;
127 [ # # ]: 0 : uno::Sequence< OUString > aNames( nCount );
128 : 0 : sal_Int32 nRealCount = 0;
129 : :
130 [ # # ]: 0 : if( !mpDoc->GetCodeName().isEmpty() )
131 [ # # ]: 0 : aNames[nRealCount++] = msDocName;
132 : :
133 : 0 : rtl::OUString sSheetName, sCodeName;
134 [ # # ]: 0 : for( SCTAB i = 0; i < nCount; i++ )
135 : : {
136 [ # # ]: 0 : mpDoc->GetCodeName( i, sCodeName );
137 [ # # ]: 0 : if (!sCodeName.isEmpty())
138 : : {
139 [ # # ][ # # ]: 0 : if( mpDoc->GetName( i, sSheetName ) )
140 [ # # ]: 0 : aNames[nRealCount++] = sSheetName;
141 : : }
142 : : }
143 : :
144 [ # # ]: 0 : if( nCount != nRealCount )
145 [ # # ]: 0 : aNames.realloc( nRealCount );
146 : :
147 : 0 : return aNames;
148 : : }
149 : :
150 : 0 : uno::Type SAL_CALL XMLCodeNameProvider::getElementType( )
151 : : throw (uno::RuntimeException)
152 : : {
153 : 0 : return getCppuType(static_cast<uno::Sequence<beans::PropertyValue>*>(0));
154 : : }
155 : :
156 : 0 : ::sal_Bool SAL_CALL XMLCodeNameProvider::hasElements()
157 : : throw (uno::RuntimeException )
158 : : {
159 [ # # ]: 0 : if( !mpDoc->GetCodeName().isEmpty() )
160 : 0 : return sal_True;
161 : :
162 [ # # ]: 0 : SCTAB nCount = mpDoc->GetTableCount();
163 : 0 : rtl::OUString sSheetName, sCodeName;
164 [ # # ]: 0 : for( SCTAB i = 0; i < nCount; i++ )
165 : : {
166 [ # # ]: 0 : mpDoc->GetCodeName( i, sCodeName );
167 [ # # ][ # # ]: 0 : if (!sCodeName.isEmpty() && mpDoc->GetName(i, sSheetName))
[ # # ][ # # ]
168 : 0 : return sal_True;
169 : : }
170 : :
171 : 0 : return false;
172 : : }
173 : :
174 : 0 : void XMLCodeNameProvider::set( const uno::Reference< container::XNameAccess>& xNameAccess, ScDocument *pDoc )
175 : : {
176 : 0 : uno::Any aAny;
177 [ # # ]: 0 : OUString sDocName( RTL_CONSTASCII_USTRINGPARAM("*doc*") );
178 [ # # ]: 0 : String sCodeName;
179 [ # # ][ # # ]: 0 : if( xNameAccess->hasByName( sDocName ) )
[ # # ]
180 : : {
181 [ # # ][ # # ]: 0 : aAny = xNameAccess->getByName( sDocName );
182 [ # # ][ # # ]: 0 : if( _getCodeName( aAny, sCodeName ) )
183 [ # # ]: 0 : pDoc->SetCodeName( sCodeName );
184 : : }
185 : :
186 [ # # ]: 0 : SCTAB nCount = pDoc->GetTableCount();
187 : 0 : rtl::OUString sSheetName;
188 [ # # ]: 0 : for( SCTAB i = 0; i < nCount; i++ )
189 : : {
190 [ # # ][ # # ]: 0 : if( pDoc->GetName( i, sSheetName ) &&
[ # # ][ # # ]
191 [ # # ][ # # ]: 0 : xNameAccess->hasByName( sSheetName ) )
192 : : {
193 [ # # ][ # # ]: 0 : aAny = xNameAccess->getByName( sSheetName );
194 [ # # ][ # # ]: 0 : if( _getCodeName( aAny, sCodeName ) )
195 [ # # ][ # # ]: 0 : pDoc->SetCodeName( i, sCodeName );
196 : : }
197 [ # # ]: 0 : }
198 : 0 : }
199 : :
200 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|