1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 // INCLUDE ---------------------------------------------------------------
30
31 #include "xmldrani.hxx"
32 #include "xmlimprt.hxx"
33 #include "xmlfilti.hxx"
34 #include "xmlsorti.hxx"
35 #include "document.hxx"
36 #include "globstr.hrc"
37 #include "docuno.hxx"
38 #include "dbcolect.hxx"
39 #include "datauno.hxx"
40 #include "attrib.hxx"
41 #include "unonames.hxx"
42 #include "convuno.hxx"
43 #include "XMLConverter.hxx"
44 #include "rangeutl.hxx"
45
46 #include <xmloff/xmltkmap.hxx>
47 #include <xmloff/nmspmap.hxx>
48 #include <xmloff/xmltoken.hxx>
49 #include <xmloff/xmlnmspe.hxx>
50 #include <xmloff/xmluconv.hxx>
51 #include <xmloff/xmlerror.hxx>
52 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
53 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
54 #include <com/sun/star/sheet/XDatabaseRange.hpp>
55 #include <com/sun/star/table/CellRangeAddress.hpp>
56 #include <comphelper/extract.hxx>
57 #include <com/sun/star/uno/RuntimeException.hpp>
58 #include <com/sun/star/xml/sax/XLocator.hpp>
59
60 #define SC_ENABLEUSERSORTLIST "EnableUserSortList"
61 #define SC_USERSORTLISTINDEX "UserSortListIndex"
62 #define SC_USERLIST "UserList"
63
64 using namespace com::sun::star;
65 using namespace xmloff::token;
66
67 //------------------------------------------------------------------
68
ScXMLDatabaseRangesContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)69 ScXMLDatabaseRangesContext::ScXMLDatabaseRangesContext( ScXMLImport& rImport,
70 sal_uInt16 nPrfx,
71 const ::rtl::OUString& rLName,
72 const ::com::sun::star::uno::Reference<
73 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
74 SvXMLImportContext( rImport, nPrfx, rLName )
75 {
76 // has no attributes
77 rImport.LockSolarMutex();
78 }
79
~ScXMLDatabaseRangesContext()80 ScXMLDatabaseRangesContext::~ScXMLDatabaseRangesContext()
81 {
82 GetScImport().UnlockSolarMutex();
83 }
84
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)85 SvXMLImportContext *ScXMLDatabaseRangesContext::CreateChildContext( sal_uInt16 nPrefix,
86 const ::rtl::OUString& rLName,
87 const ::com::sun::star::uno::Reference<
88 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
89 {
90 SvXMLImportContext *pContext = 0;
91
92 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangesElemTokenMap();
93 switch( rTokenMap.Get( nPrefix, rLName ) )
94 {
95 case XML_TOK_DATABASE_RANGE :
96 {
97 pContext = new ScXMLDatabaseRangeContext( GetScImport(), nPrefix,
98 rLName, xAttrList);
99 }
100 break;
101 }
102
103 if( !pContext )
104 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
105
106 return pContext;
107 }
108
EndElement()109 void ScXMLDatabaseRangesContext::EndElement()
110 {
111 }
112
ScXMLDatabaseRangeContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)113 ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport& rImport,
114 sal_uInt16 nPrfx,
115 const ::rtl::OUString& rLName,
116 const ::com::sun::star::uno::Reference<
117 ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
118 SvXMLImportContext( rImport, nPrfx, rLName ),
119 sDatabaseRangeName(ScGlobal::GetRscString(STR_DB_NONAME)),
120 aSortSequence(),
121 eOrientation(table::TableOrientation_ROWS),
122 nRefresh(0),
123 nSubTotalsUserListIndex(0),
124 bContainsSort(sal_False),
125 bContainsSubTotal(sal_False),
126 bNative(sal_True),
127 bIsSelection(sal_False),
128 bKeepFormats(sal_False),
129 bMoveCells(sal_False),
130 bStripData(sal_False),
131 bContainsHeader(sal_True),
132 bAutoFilter(sal_False),
133 bSubTotalsBindFormatsToContent(sal_False),
134 bSubTotalsIsCaseSensitive(sal_False),
135 bSubTotalsInsertPageBreaks(sal_False),
136 bSubTotalsSortGroups(sal_False),
137 bSubTotalsEnabledUserList(sal_False),
138 bSubTotalsAscending(sal_True),
139 bFilterCopyOutputData(sal_False),
140 bFilterIsCaseSensitive(sal_False),
141 bFilterSkipDuplicates(sal_False),
142 bFilterUseRegularExpressions(sal_False),
143 bFilterConditionSourceRange(sal_False)
144 {
145 nSourceType = sheet::DataImportMode_NONE;
146 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
147 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeAttrTokenMap();
148 for( sal_Int16 i=0; i < nAttrCount; ++i )
149 {
150 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
151 rtl::OUString aLocalName;
152 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
153 sAttrName, &aLocalName );
154 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
155
156 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
157 {
158 case XML_TOK_DATABASE_RANGE_ATTR_NAME :
159 {
160 sDatabaseRangeName = sValue;
161 }
162 break;
163 case XML_TOK_DATABASE_RANGE_ATTR_IS_SELECTION :
164 {
165 bIsSelection = IsXMLToken(sValue, XML_TRUE);
166 }
167 break;
168 case XML_TOK_DATABASE_RANGE_ATTR_ON_UPDATE_KEEP_STYLES :
169 {
170 bKeepFormats = IsXMLToken(sValue, XML_TRUE);
171 }
172 break;
173 case XML_TOK_DATABASE_RANGE_ATTR_ON_UPDATE_KEEP_SIZE :
174 {
175 bMoveCells = !IsXMLToken(sValue, XML_TRUE);
176 }
177 break;
178 case XML_TOK_DATABASE_RANGE_ATTR_HAS_PERSISTENT_DATA :
179 {
180 bStripData = !IsXMLToken(sValue, XML_TRUE);
181 }
182 break;
183 case XML_TOK_DATABASE_RANGE_ATTR_ORIENTATION :
184 {
185 if (IsXMLToken(sValue, XML_COLUMN))
186 eOrientation = table::TableOrientation_COLUMNS;
187 }
188 break;
189 case XML_TOK_DATABASE_RANGE_ATTR_CONTAINS_HEADER :
190 {
191 bContainsHeader = IsXMLToken(sValue, XML_TRUE);
192 }
193 break;
194 case XML_TOK_DATABASE_RANGE_ATTR_DISPLAY_FILTER_BUTTONS :
195 {
196 bAutoFilter = IsXMLToken(sValue, XML_TRUE);
197 }
198 break;
199 case XML_TOK_DATABASE_RANGE_ATTR_TARGET_RANGE_ADDRESS :
200 {
201 sRangeAddress = sValue;
202 }
203 break;
204 case XML_TOK_DATABASE_RANGE_ATTR_REFRESH_DELAY :
205 {
206 double fTime;
207 if( SvXMLUnitConverter::convertTime( fTime, sValue ) )
208 nRefresh = Max( (sal_Int32)(fTime * 86400.0), (sal_Int32)0 );
209 }
210 break;
211 }
212 }
213 }
214
~ScXMLDatabaseRangeContext()215 ScXMLDatabaseRangeContext::~ScXMLDatabaseRangeContext()
216 {
217 }
218
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)219 SvXMLImportContext *ScXMLDatabaseRangeContext::CreateChildContext( sal_uInt16 nPrefix,
220 const ::rtl::OUString& rLName,
221 const ::com::sun::star::uno::Reference<
222 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
223 {
224 SvXMLImportContext *pContext = 0;
225
226 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangeElemTokenMap();
227 switch( rTokenMap.Get( nPrefix, rLName ) )
228 {
229 case XML_TOK_DATABASE_RANGE_SOURCE_SQL :
230 {
231 pContext = new ScXMLSourceSQLContext( GetScImport(), nPrefix,
232 rLName, xAttrList, this);
233 }
234 break;
235 case XML_TOK_DATABASE_RANGE_SOURCE_TABLE :
236 {
237 pContext = new ScXMLSourceTableContext( GetScImport(), nPrefix,
238 rLName, xAttrList, this);
239 }
240 break;
241 case XML_TOK_DATABASE_RANGE_SOURCE_QUERY :
242 {
243 pContext = new ScXMLSourceQueryContext( GetScImport(), nPrefix,
244 rLName, xAttrList, this);
245 }
246 break;
247 case XML_TOK_FILTER :
248 {
249 pContext = new ScXMLFilterContext( GetScImport(), nPrefix,
250 rLName, xAttrList, this);
251 }
252 break;
253 case XML_TOK_SORT :
254 {
255 bContainsSort = sal_True;
256 pContext = new ScXMLSortContext( GetScImport(), nPrefix,
257 rLName, xAttrList, this);
258 }
259 break;
260 case XML_TOK_DATABASE_RANGE_SUBTOTAL_RULES :
261 {
262 bContainsSubTotal = sal_True;
263 pContext = new ScXMLSubTotalRulesContext( GetScImport(), nPrefix,
264 rLName, xAttrList, this);
265 }
266 break;
267 }
268
269 if( !pContext )
270 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
271
272 return pContext;
273 }
274
EndElement()275 void ScXMLDatabaseRangeContext::EndElement()
276 {
277 if (GetScImport().GetModel().is())
278 {
279 uno::Reference <beans::XPropertySet> xPropertySet( GetScImport().GetModel(), uno::UNO_QUERY );
280 ScDocument* pDoc = GetScImport().GetDocument();
281 if (pDoc && xPropertySet.is())
282 {
283 uno::Reference <sheet::XDatabaseRanges> xDatabaseRanges(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DATABASERNG))), uno::UNO_QUERY);
284 if (xDatabaseRanges.is())
285 {
286 table::CellRangeAddress aCellRangeAddress;
287 sal_Int32 nOffset(0);
288 if (ScRangeStringConverter::GetRangeFromString( aCellRangeAddress, sRangeAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
289 {
290 sal_Bool bInsert(sal_True);
291 try
292 {
293 xDatabaseRanges->addNewByName(sDatabaseRangeName, aCellRangeAddress);
294 }
295 catch ( uno::RuntimeException& rRuntimeException )
296 {
297 bInsert = sal_False;
298 rtl::OUString sErrorMessage(RTL_CONSTASCII_USTRINGPARAM("DatabaseRange "));
299 sErrorMessage += sDatabaseRangeName;
300 sErrorMessage += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" could not be created with the range "));
301 sErrorMessage += sRangeAddress;
302 uno::Sequence<rtl::OUString> aSeq(1);
303 aSeq[0] = sErrorMessage;
304 uno::Reference<xml::sax::XLocator> xLocator;
305 GetScImport().SetError(XMLERROR_API | XMLERROR_FLAG_ERROR, aSeq, rRuntimeException.Message, xLocator);
306 }
307 if (bInsert)
308 {
309 uno::Reference <sheet::XDatabaseRange> xDatabaseRange(xDatabaseRanges->getByName(sDatabaseRangeName), uno::UNO_QUERY);
310 if (xDatabaseRange.is())
311 {
312 uno::Reference <beans::XPropertySet> xDatabaseRangePropertySet (xDatabaseRange, uno::UNO_QUERY);
313 if (xDatabaseRangePropertySet.is())
314 {
315 xDatabaseRangePropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_KEEPFORM)), uno::makeAny(bKeepFormats));
316 xDatabaseRangePropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_MOVCELLS)), uno::makeAny(bMoveCells));
317 xDatabaseRangePropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_STRIPDAT)), uno::makeAny(bStripData));
318 }
319 uno::Sequence <beans::PropertyValue> aImportDescriptor(xDatabaseRange->getImportDescriptor());
320 sal_Int32 nImportProperties = aImportDescriptor.getLength();
321 for (sal_Int16 i = 0; i < nImportProperties; ++i)
322 {
323 if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_DBNAME)))
324 {
325 if (sDatabaseName.getLength())
326 {
327 aImportDescriptor[i].Value <<= sDatabaseName;
328 }
329 else
330 {
331 aImportDescriptor[i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONRES));
332 aImportDescriptor[i].Value <<= sConnectionRessource;
333 }
334 }
335 else if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SRCOBJ)))
336 aImportDescriptor[i].Value <<= sSourceObject;
337 else if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SRCTYPE)))
338 aImportDescriptor[i].Value <<= nSourceType;
339 else if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISNATIVE)))
340 aImportDescriptor[i].Value <<= bNative;
341 }
342 ScDBCollection* pDBCollection = pDoc->GetDBCollection();
343 sal_uInt16 nIndex;
344 pDBCollection->SearchName(sDatabaseRangeName, nIndex);
345 ScDBData* pDBData = (*pDBCollection)[nIndex];
346 pDBData->SetImportSelection(bIsSelection);
347 pDBData->SetAutoFilter(bAutoFilter);
348 if (bAutoFilter)
349 pDoc->ApplyFlagsTab( static_cast<SCCOL>(aCellRangeAddress.StartColumn), static_cast<SCROW>(aCellRangeAddress.StartRow),
350 static_cast<SCCOL>(aCellRangeAddress.EndColumn), static_cast<SCROW>(aCellRangeAddress.StartRow),
351 aCellRangeAddress.Sheet, SC_MF_AUTO );
352 ScImportParam aImportParam;
353 ScImportDescriptor::FillImportParam(aImportParam, aImportDescriptor);
354 pDBData->SetImportParam(aImportParam);
355 if (bContainsSort)
356 {
357 sal_uInt32 nOldSize(aSortSequence.getLength());
358 aSortSequence.realloc(nOldSize + 1);
359 beans::PropertyValue aProperty;
360 aProperty.Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ORIENT));
361 aProperty.Value <<= eOrientation;
362 aSortSequence[nOldSize] = aProperty;
363 ScSortParam aSortParam;
364 ScSortDescriptor::FillSortParam(aSortParam, aSortSequence);
365
366 //#98317#; until now the Fields are relative to the left top edge of the range, but the
367 // core wants to have the absolute position (column/row)
368 SCCOLROW nFieldStart = aSortParam.bByRow ? static_cast<SCCOLROW>(aCellRangeAddress.StartColumn) : static_cast<SCCOLROW>(aCellRangeAddress.StartRow);
369 for (sal_uInt16 i = 0; i < MAXSORT; ++i)
370 {
371 if (aSortParam.bDoSort[i])
372 aSortParam.nField[i] += nFieldStart;
373 }
374
375 pDBData->SetSortParam(aSortParam);
376 }
377 uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor(
378 xDatabaseRange->getFilterDescriptor(), uno::UNO_QUERY );
379 if (xSheetFilterDescriptor.is())
380 {
381 uno::Reference <beans::XPropertySet> xFilterPropertySet (xSheetFilterDescriptor, uno::UNO_QUERY);
382 if (xFilterPropertySet.is())
383 {
384 sal_Bool bOrientation(table::TableOrientation_COLUMNS == eOrientation);
385 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ORIENT)), uno::makeAny(bOrientation));
386 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONTHDR)), uno::makeAny(bContainsHeader));
387 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_COPYOUT)), uno::makeAny(bFilterCopyOutputData));
388 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE)), uno::makeAny(bFilterIsCaseSensitive));
389 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SKIPDUP)), uno::makeAny(bFilterSkipDuplicates));
390 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_USEREGEX)), uno::makeAny(bFilterUseRegularExpressions));
391 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_OUTPOS)), uno::makeAny(aFilterOutputPosition));
392 }
393 xSheetFilterDescriptor->setFilterFields2(aFilterFields);
394 if (bFilterConditionSourceRange)
395 {
396 ScRange aAdvSource;
397 ScUnoConversion::FillScRange( aAdvSource, aFilterConditionSourceRangeAddress );
398 pDBData->SetAdvancedQuerySource(&aAdvSource);
399 }
400 }
401 if (bContainsSubTotal)
402 {
403 uno::Reference <sheet::XSubTotalDescriptor> xSubTotalDescriptor(xDatabaseRange->getSubTotalDescriptor());
404 if (xSubTotalDescriptor.is())
405 {
406 uno::Reference <beans::XPropertySet> xSubTotalPropertySet (xSubTotalDescriptor, uno::UNO_QUERY);
407 if( xSubTotalPropertySet.is())
408 {
409 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_BINDFMT)), uno::makeAny(bSubTotalsBindFormatsToContent));
410 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ENABLEUSERSORTLIST)), uno::makeAny(bSubTotalsEnabledUserList));
411 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_USERSORTLISTINDEX)), uno::makeAny(nSubTotalsUserListIndex));
412 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INSBRK)), uno::makeAny(bSubTotalsInsertPageBreaks));
413 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE)), uno::makeAny(bSubTotalsIsCaseSensitive));
414 }
415 ScSubTotalParam aSubTotalParam;
416 aSubTotalParam.bDoSort = bSubTotalsSortGroups;
417 aSubTotalParam.bAscending = bSubTotalsAscending;
418 aSubTotalParam.bUserDef = bSubTotalsEnabledUserList;
419 aSubTotalParam.nUserIndex = nSubTotalsUserListIndex;
420 pDBData->SetSubTotalParam(aSubTotalParam);
421 std::vector < ScSubTotalRule >::iterator aItr(aSubTotalRules.begin());
422 while (!aSubTotalRules.empty())
423 {
424 xSubTotalDescriptor->addNew(aItr->aSubTotalColumns, aItr->nSubTotalRuleGroupFieldNumber);
425 aItr = aSubTotalRules.erase(aItr);
426 }
427 }
428 }
429 if ( pDBData->HasImportParam() && !pDBData->HasImportSelection() )
430 {
431 pDBData->SetRefreshDelay( nRefresh );
432 pDBData->SetRefreshHandler( pDBCollection->GetRefreshHandler() );
433 pDBData->SetRefreshControl( pDoc->GetRefreshTimerControlAddress() );
434 }
435 }
436 }
437 }
438 }
439 }
440 }
441 }
442
ScXMLSourceSQLContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)443 ScXMLSourceSQLContext::ScXMLSourceSQLContext( ScXMLImport& rImport,
444 sal_uInt16 nPrfx,
445 const ::rtl::OUString& rLName,
446 const ::com::sun::star::uno::Reference<
447 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
448 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
449 SvXMLImportContext( rImport, nPrfx, rLName ),
450 pDatabaseRangeContext(pTempDatabaseRangeContext)
451 {
452 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
453 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceSQLAttrTokenMap();
454 for( sal_Int16 i=0; i < nAttrCount; ++i )
455 {
456 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
457 rtl::OUString aLocalName;
458 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
459 sAttrName, &aLocalName );
460 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
461
462 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
463 {
464 case XML_TOK_SOURCE_SQL_ATTR_DATABASE_NAME :
465 {
466 sDBName = sValue;
467 }
468 break;
469 case XML_TOK_SOURCE_SQL_ATTR_SQL_STATEMENT :
470 {
471 pDatabaseRangeContext->SetSourceObject(sValue);
472 }
473 break;
474 case XML_TOK_SOURCE_SQL_ATTR_PARSE_SQL_STATEMENT :
475 {
476 pDatabaseRangeContext->SetNative(IsXMLToken(sValue, XML_TRUE));
477 }
478 break;
479 }
480 }
481 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_SQL);
482 }
483
~ScXMLSourceSQLContext()484 ScXMLSourceSQLContext::~ScXMLSourceSQLContext()
485 {
486 }
487
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)488 SvXMLImportContext *ScXMLSourceSQLContext::CreateChildContext( sal_uInt16 nPrefix,
489 const ::rtl::OUString& rLName,
490 const ::com::sun::star::uno::Reference<
491 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
492 {
493 SvXMLImportContext *pContext = 0;
494
495 if ( nPrefix == XML_NAMESPACE_FORM )
496 {
497 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
498 {
499 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
500 rLName, xAttrList, pDatabaseRangeContext);
501 }
502 }
503
504 if( !pContext )
505 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
506
507 return pContext;
508 }
509
EndElement()510 void ScXMLSourceSQLContext::EndElement()
511 {
512 if (sDBName.getLength())
513 pDatabaseRangeContext->SetDatabaseName(sDBName);
514 }
515
ScXMLSourceTableContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)516 ScXMLSourceTableContext::ScXMLSourceTableContext( ScXMLImport& rImport,
517 sal_uInt16 nPrfx,
518 const ::rtl::OUString& rLName,
519 const ::com::sun::star::uno::Reference<
520 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
521 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
522 SvXMLImportContext( rImport, nPrfx, rLName ),
523 pDatabaseRangeContext(pTempDatabaseRangeContext)
524 {
525 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
526 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceTableAttrTokenMap();
527 for( sal_Int16 i=0; i < nAttrCount; ++i )
528 {
529 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
530 rtl::OUString aLocalName;
531 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
532 sAttrName, &aLocalName );
533 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
534
535 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
536 {
537 case XML_TOK_SOURCE_TABLE_ATTR_DATABASE_NAME :
538 {
539 sDBName = sValue;
540 }
541 break;
542 case XML_TOK_SOURCE_TABLE_ATTR_TABLE_NAME :
543 {
544 pDatabaseRangeContext->SetSourceObject(sValue);
545 }
546 break;
547 }
548 }
549 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_TABLE);
550 }
551
~ScXMLSourceTableContext()552 ScXMLSourceTableContext::~ScXMLSourceTableContext()
553 {
554 }
555
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)556 SvXMLImportContext *ScXMLSourceTableContext::CreateChildContext( sal_uInt16 nPrefix,
557 const ::rtl::OUString& rLName,
558 const ::com::sun::star::uno::Reference<
559 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
560 {
561 SvXMLImportContext *pContext = 0;
562
563 if ( nPrefix == XML_NAMESPACE_FORM )
564 {
565 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
566 {
567 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
568 rLName, xAttrList, pDatabaseRangeContext);
569 }
570 }
571
572 if( !pContext )
573 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
574
575 return pContext;
576 }
577
EndElement()578 void ScXMLSourceTableContext::EndElement()
579 {
580 if (sDBName.getLength())
581 pDatabaseRangeContext->SetDatabaseName(sDBName);
582 }
583
ScXMLSourceQueryContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)584 ScXMLSourceQueryContext::ScXMLSourceQueryContext( ScXMLImport& rImport,
585 sal_uInt16 nPrfx,
586 const ::rtl::OUString& rLName,
587 const ::com::sun::star::uno::Reference<
588 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
589 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
590 SvXMLImportContext( rImport, nPrfx, rLName ),
591 pDatabaseRangeContext(pTempDatabaseRangeContext)
592 {
593 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
594 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceQueryAttrTokenMap();
595 for( sal_Int16 i=0; i < nAttrCount; ++i )
596 {
597 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
598 rtl::OUString aLocalName;
599 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
600 sAttrName, &aLocalName );
601 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
602
603 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
604 {
605 case XML_TOK_SOURCE_QUERY_ATTR_DATABASE_NAME :
606 {
607 sDBName = sValue;
608 }
609 break;
610 case XML_TOK_SOURCE_QUERY_ATTR_QUERY_NAME :
611 {
612 pDatabaseRangeContext->SetSourceObject(sValue);
613 }
614 break;
615 }
616 }
617 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_QUERY);
618 }
619
~ScXMLSourceQueryContext()620 ScXMLSourceQueryContext::~ScXMLSourceQueryContext()
621 {
622 }
623
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)624 SvXMLImportContext *ScXMLSourceQueryContext::CreateChildContext( sal_uInt16 nPrefix,
625 const ::rtl::OUString& rLName,
626 const ::com::sun::star::uno::Reference<
627 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
628 {
629 SvXMLImportContext *pContext = 0;
630
631 if ( nPrefix == XML_NAMESPACE_FORM )
632 {
633 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
634 {
635 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
636 rLName, xAttrList, pDatabaseRangeContext);
637 }
638 }
639
640 if( !pContext )
641 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
642
643 return pContext;
644 }
645
EndElement()646 void ScXMLSourceQueryContext::EndElement()
647 {
648 if (sDBName.getLength())
649 pDatabaseRangeContext->SetDatabaseName(sDBName);
650 }
651
ScXMLConResContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)652 ScXMLConResContext::ScXMLConResContext( ScXMLImport& rImport,
653 sal_uInt16 nPrfx,
654 const ::rtl::OUString& rLName,
655 const ::com::sun::star::uno::Reference<
656 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
657 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
658 SvXMLImportContext( rImport, nPrfx, rLName ),
659 pDatabaseRangeContext( pTempDatabaseRangeContext )
660 {
661 rtl::OUString sConRes;
662 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
663 for( sal_Int16 i=0; i < nAttrCount; i++ )
664 {
665 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
666 rtl::OUString aLocalName;
667 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
668 sAttrName, &aLocalName );
669 rtl::OUString sValue = xAttrList->getValueByIndex( i );
670
671 if (nPrefix == XML_NAMESPACE_XLINK)
672 {
673 if (IsXMLToken(aLocalName, XML_HREF))
674 sConRes = sValue;
675 }
676 }
677 if (sConRes.getLength())
678 pDatabaseRangeContext->SetConnectionRessource(sConRes);
679 }
680
~ScXMLConResContext()681 ScXMLConResContext::~ScXMLConResContext()
682 {
683 }
684
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)685 SvXMLImportContext *ScXMLConResContext::CreateChildContext( sal_uInt16 nPrefix,
686 const ::rtl::OUString& rLName,
687 const ::com::sun::star::uno::Reference<
688 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
689 {
690 SvXMLImportContext *pContext = 0;
691
692 if( !pContext )
693 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
694
695 return pContext;
696 }
697
EndElement()698 void ScXMLConResContext::EndElement()
699 {
700 }
701
ScXMLSubTotalRulesContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)702 ScXMLSubTotalRulesContext::ScXMLSubTotalRulesContext( ScXMLImport& rImport,
703 sal_uInt16 nPrfx,
704 const ::rtl::OUString& rLName,
705 const ::com::sun::star::uno::Reference<
706 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
707 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
708 SvXMLImportContext( rImport, nPrfx, rLName ),
709 pDatabaseRangeContext(pTempDatabaseRangeContext)
710 {
711 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
712 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesAttrTokenMap();
713 for( sal_Int16 i=0; i < nAttrCount; ++i )
714 {
715 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
716 rtl::OUString aLocalName;
717 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
718 sAttrName, &aLocalName );
719 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
720
721 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
722 {
723 case XML_TOK_SUBTOTAL_RULES_ATTR_BIND_STYLES_TO_CONTENT :
724 {
725 pDatabaseRangeContext->SetSubTotalsBindFormatsToContent(IsXMLToken(sValue, XML_TRUE));
726 }
727 break;
728 case XML_TOK_SUBTOTAL_RULES_ATTR_CASE_SENSITIVE :
729 {
730 pDatabaseRangeContext->SetSubTotalsIsCaseSensitive(IsXMLToken(sValue, XML_TRUE));
731 }
732 break;
733 case XML_TOK_SUBTOTAL_RULES_ATTR_PAGE_BREAKS_ON_GROUP_CHANGE :
734 {
735 pDatabaseRangeContext->SetSubTotalsInsertPageBreaks(IsXMLToken(sValue, XML_TRUE));
736 }
737 break;
738 }
739 }
740 }
741
~ScXMLSubTotalRulesContext()742 ScXMLSubTotalRulesContext::~ScXMLSubTotalRulesContext()
743 {
744 }
745
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)746 SvXMLImportContext *ScXMLSubTotalRulesContext::CreateChildContext( sal_uInt16 nPrefix,
747 const ::rtl::OUString& rLName,
748 const ::com::sun::star::uno::Reference<
749 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
750 {
751 SvXMLImportContext *pContext = 0;
752
753 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesElemTokenMap();
754 switch( rTokenMap.Get( nPrefix, rLName ) )
755 {
756 case XML_TOK_SUBTOTAL_RULES_SORT_GROUPS :
757 {
758 pContext = new ScXMLSortGroupsContext( GetScImport(), nPrefix,
759 rLName, xAttrList, pDatabaseRangeContext);
760 }
761 break;
762 case XML_TOK_SUBTOTAL_RULES_SUBTOTAL_RULE :
763 {
764 pContext = new ScXMLSubTotalRuleContext( GetScImport(), nPrefix,
765 rLName, xAttrList, pDatabaseRangeContext);
766 }
767 break;
768 }
769
770 if( !pContext )
771 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
772
773 return pContext;
774 }
775
EndElement()776 void ScXMLSubTotalRulesContext::EndElement()
777 {
778 }
779
ScXMLSortGroupsContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)780 ScXMLSortGroupsContext::ScXMLSortGroupsContext( ScXMLImport& rImport,
781 sal_uInt16 nPrfx,
782 const ::rtl::OUString& rLName,
783 const ::com::sun::star::uno::Reference<
784 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
785 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
786 SvXMLImportContext( rImport, nPrfx, rLName ),
787 pDatabaseRangeContext(pTempDatabaseRangeContext)
788 {
789 pDatabaseRangeContext->SetSubTotalsSortGroups(sal_True);
790 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
791 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSortGroupsAttrTokenMap();
792 for( sal_Int16 i=0; i < nAttrCount; ++i )
793 {
794 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
795 rtl::OUString aLocalName;
796 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
797 sAttrName, &aLocalName );
798 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
799
800 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
801 {
802 case XML_TOK_SORT_GROUPS_ATTR_DATA_TYPE :
803 {
804 if (sValue.getLength() > 8)
805 {
806 rtl::OUString sTemp = sValue.copy(0, 8);
807 if (sTemp.compareToAscii(SC_USERLIST) == 0)
808 {
809 pDatabaseRangeContext->SetSubTotalsEnabledUserList(sal_True);
810 sTemp = sValue.copy(8);
811 pDatabaseRangeContext->SetSubTotalsUserListIndex(static_cast<sal_Int16>(sTemp.toInt32()));
812 }
813 else
814 {
815 //if (IsXMLToken(sValue, XML_AUTOMATIC))
816 //aSortField.FieldType = util::SortFieldType_AUTOMATIC;
817 // is not supported by StarOffice
818 }
819 }
820 else
821 {
822 //if (IsXMLToken(sValue, XML_TEXT))
823 //aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
824 // is not supported by StarOffice
825 //else if (IsXMLToken(sValue, XML_NUMBER))
826 //aSortField.FieldType = util::SortFieldType_NUMERIC;
827 // is not supported by StarOffice
828 }
829 }
830 break;
831 case XML_TOK_SORT_GROUPS_ATTR_ORDER :
832 {
833 if (IsXMLToken(sValue, XML_ASCENDING))
834 pDatabaseRangeContext->SetSubTotalsAscending(sal_True);
835 else
836 pDatabaseRangeContext->SetSubTotalsAscending(sal_False);
837 }
838 break;
839 }
840 }
841 }
842
~ScXMLSortGroupsContext()843 ScXMLSortGroupsContext::~ScXMLSortGroupsContext()
844 {
845 }
846
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)847 SvXMLImportContext *ScXMLSortGroupsContext::CreateChildContext( sal_uInt16 nPrefix,
848 const ::rtl::OUString& rLName,
849 const ::com::sun::star::uno::Reference<
850 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
851 {
852 SvXMLImportContext *pContext = 0;
853
854 if( !pContext )
855 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
856
857 return pContext;
858 }
859
EndElement()860 void ScXMLSortGroupsContext::EndElement()
861 {
862 }
863
ScXMLSubTotalRuleContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)864 ScXMLSubTotalRuleContext::ScXMLSubTotalRuleContext( ScXMLImport& rImport,
865 sal_uInt16 nPrfx,
866 const ::rtl::OUString& rLName,
867 const ::com::sun::star::uno::Reference<
868 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
869 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
870 SvXMLImportContext( rImport, nPrfx, rLName ),
871 pDatabaseRangeContext(pTempDatabaseRangeContext)
872 {
873 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
874 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleAttrTokenMap();
875 for( sal_Int16 i=0; i < nAttrCount; ++i )
876 {
877 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
878 rtl::OUString aLocalName;
879 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
880 sAttrName, &aLocalName );
881 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
882
883 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
884 {
885 case XML_TOK_SUBTOTAL_RULE_ATTR_GROUP_BY_FIELD_NUMBER :
886 {
887 aSubTotalRule.nSubTotalRuleGroupFieldNumber = static_cast<sal_Int16>(sValue.toInt32());
888 }
889 break;
890 }
891 }
892 }
893
~ScXMLSubTotalRuleContext()894 ScXMLSubTotalRuleContext::~ScXMLSubTotalRuleContext()
895 {
896 }
897
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)898 SvXMLImportContext *ScXMLSubTotalRuleContext::CreateChildContext( sal_uInt16 nPrefix,
899 const ::rtl::OUString& rLName,
900 const ::com::sun::star::uno::Reference<
901 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
902 {
903 SvXMLImportContext *pContext = 0;
904
905 const SvXMLTokenMap& rTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleElemTokenMap();
906 switch( rTokenMap.Get( nPrefix, rLName ) )
907 {
908 case XML_TOK_SUBTOTAL_RULE_SUBTOTAL_FIELD :
909 {
910 pContext = new ScXMLSubTotalFieldContext( GetScImport(), nPrefix,
911 rLName, xAttrList, this);
912 }
913 break;
914 }
915
916 if( !pContext )
917 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
918
919 return pContext;
920 }
921
EndElement()922 void ScXMLSubTotalRuleContext::EndElement()
923 {
924 if (pDatabaseRangeContext)
925 pDatabaseRangeContext->AddSubTotalRule(aSubTotalRule);
926 }
927
ScXMLSubTotalFieldContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLSubTotalRuleContext * pTempSubTotalRuleContext)928 ScXMLSubTotalFieldContext::ScXMLSubTotalFieldContext( ScXMLImport& rImport,
929 sal_uInt16 nPrfx,
930 const ::rtl::OUString& rLName,
931 const ::com::sun::star::uno::Reference<
932 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
933 ScXMLSubTotalRuleContext* pTempSubTotalRuleContext) :
934 SvXMLImportContext( rImport, nPrfx, rLName ),
935 pSubTotalRuleContext(pTempSubTotalRuleContext)
936 {
937 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
938 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRuleSubTotalFieldAttrTokenMap();
939 for( sal_Int16 i=0; i < nAttrCount; ++i )
940 {
941 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
942 rtl::OUString aLocalName;
943 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
944 sAttrName, &aLocalName );
945 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
946
947 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
948 {
949 case XML_TOK_SUBTOTAL_FIELD_ATTR_FIELD_NUMBER :
950 {
951 sFieldNumber = sValue;
952 }
953 break;
954 case XML_TOK_SUBTOTAL_FIELD_ATTR_FUNCTION :
955 {
956 sFunction = sValue;
957 }
958 break;
959 }
960 }
961 }
962
~ScXMLSubTotalFieldContext()963 ScXMLSubTotalFieldContext::~ScXMLSubTotalFieldContext()
964 {
965 }
966
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)967 SvXMLImportContext *ScXMLSubTotalFieldContext::CreateChildContext( sal_uInt16 nPrefix,
968 const ::rtl::OUString& rLName,
969 const ::com::sun::star::uno::Reference<
970 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
971 {
972 SvXMLImportContext *pContext = 0;
973
974 if( !pContext )
975 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
976
977 return pContext;
978 }
979
EndElement()980 void ScXMLSubTotalFieldContext::EndElement()
981 {
982 sheet::SubTotalColumn aSubTotalColumn;
983 aSubTotalColumn.Column = sFieldNumber.toInt32();
984 aSubTotalColumn.Function = ScXMLConverter::GetFunctionFromString( sFunction );
985 pSubTotalRuleContext->AddSubTotalColumn(aSubTotalColumn);
986 }
987
988