Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "xmldpimp.hxx"
21 : #include "xmlimprt.hxx"
22 : #include "xmlfilti.hxx"
23 : #include "xmlsorti.hxx"
24 : #include "document.hxx"
25 : #include "docuno.hxx"
26 : #include "dpshttab.hxx"
27 : #include "dpsdbtab.hxx"
28 : #include "attrib.hxx"
29 : #include "XMLConverter.hxx"
30 : #include "dpgroup.hxx"
31 : #include "dpdimsave.hxx"
32 : #include "rangeutl.hxx"
33 : #include "dpoutputgeometry.hxx"
34 :
35 : #include <xmloff/xmltkmap.hxx>
36 : #include <xmloff/nmspmap.hxx>
37 : #include <xmloff/xmltoken.hxx>
38 : #include <xmloff/xmlnmspe.hxx>
39 : #include <xmloff/xmluconv.hxx>
40 : #include <sax/tools/converter.hxx>
41 :
42 : #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
43 : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
44 : #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
45 : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
46 : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
47 : #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
48 : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
49 :
50 : using namespace com::sun::star;
51 : using namespace xmloff::token;
52 : using ::com::sun::star::uno::Reference;
53 : using ::com::sun::star::xml::sax::XAttributeList;
54 : using ::rtl::OUString;
55 :
56 : using rtl::OUString;
57 :
58 : //------------------------------------------------------------------
59 :
60 1 : ScXMLDataPilotTablesContext::ScXMLDataPilotTablesContext( ScXMLImport& rImport,
61 : sal_uInt16 nPrfx,
62 : const ::rtl::OUString& rLName,
63 : const ::com::sun::star::uno::Reference<
64 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
65 1 : SvXMLImportContext( rImport, nPrfx, rLName )
66 : {
67 : // has no Attributes
68 1 : rImport.LockSolarMutex();
69 1 : }
70 :
71 3 : ScXMLDataPilotTablesContext::~ScXMLDataPilotTablesContext()
72 : {
73 1 : GetScImport().UnlockSolarMutex();
74 2 : }
75 :
76 1 : SvXMLImportContext *ScXMLDataPilotTablesContext::CreateChildContext( sal_uInt16 nPrefix,
77 : const ::rtl::OUString& rLName,
78 : const ::com::sun::star::uno::Reference<
79 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
80 : {
81 1 : SvXMLImportContext *pContext = 0;
82 :
83 1 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTablesElemTokenMap();
84 1 : switch( rTokenMap.Get( nPrefix, rLName ) )
85 : {
86 : case XML_TOK_DATA_PILOT_TABLE :
87 : {
88 : pContext = new ScXMLDataPilotTableContext( GetScImport(), nPrefix,
89 1 : rLName, xAttrList);
90 : }
91 1 : break;
92 : }
93 :
94 1 : if( !pContext )
95 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
96 :
97 1 : return pContext;
98 : }
99 :
100 1 : void ScXMLDataPilotTablesContext::EndElement()
101 : {
102 1 : }
103 :
104 2 : ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
105 2 : mbVisible(true) {}
106 :
107 1 : ScXMLDataPilotTableContext::ScXMLDataPilotTableContext( ScXMLImport& rImport,
108 : sal_uInt16 nPrfx,
109 : const ::rtl::OUString& rLName,
110 : const ::com::sun::star::uno::Reference<
111 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
112 : SvXMLImportContext( rImport, nPrfx, rLName ),
113 1 : pDoc(GetScImport().GetDocument()),
114 : pDPObject(NULL),
115 : pDPSave(NULL),
116 : pDPDimSaveData(NULL),
117 : sDataPilotTableName(),
118 : sApplicationData(),
119 : mnRowFieldCount(0),
120 : mnColFieldCount(0),
121 : mnPageFieldCount(0),
122 : mnDataFieldCount(0),
123 : mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN),
124 : bIsNative(true),
125 : bIgnoreEmptyRows(false),
126 : bIdentifyCategories(false),
127 : bTargetRangeAddress(false),
128 : bSourceCellRange(false),
129 : bShowFilter(true),
130 : bDrillDown(true),
131 2 : bHeaderGridLayout(false)
132 : {
133 1 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
134 1 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableAttrTokenMap();
135 5 : for( sal_Int16 i=0; i < nAttrCount; ++i )
136 : {
137 4 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
138 4 : rtl::OUString aLocalName;
139 4 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
140 4 : sAttrName, &aLocalName );
141 4 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
142 :
143 4 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
144 : {
145 : case XML_TOK_DATA_PILOT_TABLE_ATTR_NAME :
146 : {
147 1 : sDataPilotTableName = sValue;
148 : }
149 1 : break;
150 : case XML_TOK_DATA_PILOT_TABLE_ATTR_APPLICATION_DATA :
151 : {
152 1 : sApplicationData = sValue;
153 : }
154 1 : break;
155 : case XML_TOK_DATA_PILOT_TABLE_ATTR_GRAND_TOTAL :
156 : {
157 0 : if (IsXMLToken(sValue, XML_BOTH))
158 : {
159 0 : maRowGrandTotal.mbVisible = true;
160 0 : maColGrandTotal.mbVisible = true;
161 : }
162 0 : else if (IsXMLToken(sValue, XML_ROW))
163 : {
164 0 : maRowGrandTotal.mbVisible = true;
165 0 : maColGrandTotal.mbVisible = false;
166 : }
167 0 : else if (IsXMLToken(sValue, XML_COLUMN))
168 : {
169 0 : maRowGrandTotal.mbVisible = false;
170 0 : maColGrandTotal.mbVisible = true;
171 : }
172 : else
173 : {
174 0 : maRowGrandTotal.mbVisible = false;
175 0 : maColGrandTotal.mbVisible = false;
176 : }
177 : }
178 0 : break;
179 : case XML_TOK_DATA_PILOT_TABLE_ATTR_IGNORE_EMPTY_ROWS :
180 : {
181 0 : bIgnoreEmptyRows = IsXMLToken(sValue, XML_TRUE);
182 : }
183 0 : break;
184 : case XML_TOK_DATA_PILOT_TABLE_ATTR_IDENTIFY_CATEGORIES :
185 : {
186 0 : bIdentifyCategories = IsXMLToken(sValue, XML_TRUE);
187 : }
188 0 : break;
189 : case XML_TOK_DATA_PILOT_TABLE_ATTR_TARGET_RANGE_ADDRESS :
190 : {
191 1 : sal_Int32 nOffset(0);
192 1 : bTargetRangeAddress = ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
193 : }
194 1 : break;
195 : case XML_TOK_DATA_PILOT_TABLE_ATTR_BUTTONS :
196 : {
197 1 : sButtons = sValue;
198 : }
199 1 : break;
200 : case XML_TOK_DATA_PILOT_TABLE_ATTR_SHOW_FILTER_BUTTON :
201 : {
202 0 : bShowFilter = IsXMLToken(sValue, XML_TRUE);
203 : }
204 0 : break;
205 : case XML_TOK_DATA_PILOT_TABLE_ATTR_DRILL_DOWN :
206 : {
207 0 : bDrillDown = IsXMLToken(sValue, XML_TRUE);
208 : }
209 0 : break;
210 : case XML_TOK_DATA_PILOT_TABLE_ATTR_HEADER_GRID_LAYOUT :
211 : {
212 0 : bHeaderGridLayout = IsXMLToken(sValue, XML_TRUE);
213 : }
214 0 : break;
215 : }
216 4 : }
217 :
218 1 : pDPObject = new ScDPObject(pDoc);
219 1 : pDPSave = new ScDPSaveData();
220 1 : }
221 :
222 3 : ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
223 : {
224 1 : delete pDPDimSaveData;
225 2 : }
226 :
227 9 : SvXMLImportContext *ScXMLDataPilotTableContext::CreateChildContext( sal_uInt16 nPrefix,
228 : const ::rtl::OUString& rLName,
229 : const ::com::sun::star::uno::Reference<
230 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
231 : {
232 9 : SvXMLImportContext *pContext = 0;
233 :
234 9 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTableElemTokenMap();
235 9 : switch( rTokenMap.Get( nPrefix, rLName ) )
236 : {
237 : case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_SQL :
238 : {
239 0 : pContext = new ScXMLDPSourceSQLContext(GetScImport(), nPrefix, rLName, xAttrList, this);
240 0 : nSourceType = SQL;
241 : }
242 0 : break;
243 : case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_TABLE :
244 : {
245 0 : pContext = new ScXMLDPSourceTableContext(GetScImport(), nPrefix, rLName, xAttrList, this);
246 0 : nSourceType = TABLE;
247 : }
248 0 : break;
249 : case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_QUERY :
250 : {
251 0 : pContext = new ScXMLDPSourceQueryContext(GetScImport(), nPrefix, rLName, xAttrList, this);
252 0 : nSourceType = QUERY;
253 : }
254 0 : break;
255 : case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_SERVICE :
256 : {
257 0 : pContext = new ScXMLSourceServiceContext(GetScImport(), nPrefix, rLName, xAttrList, this);
258 0 : nSourceType = SERVICE;
259 : }
260 0 : break;
261 : case XML_TOK_DATA_PILOT_TABLE_ELEM_GRAND_TOTAL:
262 : case XML_TOK_DATA_PILOT_TABLE_ELEM_GRAND_TOTAL_EXT:
263 : {
264 0 : pContext = new ScXMLDataPilotGrandTotalContext(GetScImport(), nPrefix, rLName, xAttrList, this);
265 : }
266 0 : break;
267 : case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_CELL_RANGE :
268 : {
269 1 : pContext = new ScXMLSourceCellRangeContext(GetScImport(), nPrefix, rLName, xAttrList, this);
270 1 : nSourceType = CELLRANGE;
271 : }
272 1 : break;
273 : case XML_TOK_DATA_PILOT_TABLE_ELEM_DATA_PILOT_FIELD :
274 8 : pContext = new ScXMLDataPilotFieldContext(GetScImport(), nPrefix, rLName, xAttrList, this);
275 8 : break;
276 : }
277 :
278 9 : if( !pContext )
279 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
280 :
281 9 : return pContext;
282 : }
283 :
284 : namespace {
285 :
286 7 : const ScDPSaveDimension* getDimension(
287 : const std::vector<const ScDPSaveDimension*>& rRowDims,
288 : const std::vector<const ScDPSaveDimension*>& rColDims,
289 : const std::vector<const ScDPSaveDimension*>& rPageDims,
290 : ScDPOutputGeometry::FieldType eType, size_t nPos)
291 : {
292 7 : switch (eType)
293 : {
294 : case ScDPOutputGeometry::Column:
295 : {
296 2 : if (rColDims.size() <= nPos)
297 0 : return NULL;
298 :
299 2 : return rColDims[nPos];
300 : }
301 : case ScDPOutputGeometry::Row:
302 : {
303 2 : if (rRowDims.size() <= nPos)
304 0 : return NULL;
305 :
306 2 : return rRowDims[nPos];
307 : }
308 : case ScDPOutputGeometry::Page:
309 : {
310 2 : if (rPageDims.size() <= nPos)
311 0 : return NULL;
312 :
313 2 : return rPageDims[nPos];
314 : }
315 : break;
316 : case ScDPOutputGeometry::Data:
317 0 : break;
318 : case ScDPOutputGeometry::None:
319 1 : break;
320 : default:
321 : ;
322 : }
323 1 : return NULL;
324 : }
325 :
326 1 : ScDPOutputGeometry::FieldType toFieldType(sal_uInt16 nOrient)
327 : {
328 1 : switch (nOrient)
329 : {
330 : case sheet::DataPilotFieldOrientation_COLUMN:
331 0 : return ScDPOutputGeometry::Column;
332 : case sheet::DataPilotFieldOrientation_DATA:
333 0 : return ScDPOutputGeometry::Data;
334 : case sheet::DataPilotFieldOrientation_PAGE:
335 0 : return ScDPOutputGeometry::Page;
336 : case sheet::DataPilotFieldOrientation_ROW:
337 1 : return ScDPOutputGeometry::Row;
338 : case sheet::DataPilotFieldOrientation_HIDDEN:
339 : default:
340 : ;
341 : }
342 0 : return ScDPOutputGeometry::None;
343 : }
344 :
345 : }
346 :
347 1 : void ScXMLDataPilotTableContext::SetButtons()
348 : {
349 1 : ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter);
350 1 : aGeometry.setColumnFieldCount(mnColFieldCount);
351 1 : aGeometry.setRowFieldCount(mnRowFieldCount);
352 1 : aGeometry.setPageFieldCount(mnPageFieldCount);
353 1 : aGeometry.setDataFieldCount(mnDataFieldCount);
354 1 : aGeometry.setDataLayoutType(toFieldType(mnDataLayoutType));
355 :
356 1 : std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims;
357 1 : pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims);
358 1 : pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims);
359 1 : pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aPageDims);
360 :
361 1 : OUString sAddress;
362 1 : sal_Int32 nOffset = 0;
363 10 : while( nOffset >= 0 )
364 : {
365 8 : ScRangeStringConverter::GetTokenByOffset( sAddress, sButtons, nOffset );
366 8 : if( nOffset >= 0 )
367 : {
368 7 : ScAddress aScAddress;
369 7 : sal_Int32 nAddrOffset(0);
370 7 : if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset ))
371 : {
372 7 : std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress);
373 : const ScDPSaveDimension* pDim = getDimension(
374 7 : aRowDims, aColDims, aPageDims, aBtnType.first, aBtnType.second);
375 :
376 7 : bool bDimension = pDim != NULL;
377 7 : bool bDataLayout = pDim && pDim->IsDataLayout();
378 7 : bool bHasHidden = pDim && pDim->HasInvisibleMember();
379 7 : bool bPageDim = pDim && pDim->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE;
380 :
381 7 : if (bPageDim)
382 : {
383 : // Page dimension needs 2 buttons.
384 :
385 2 : pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), SC_MF_BUTTON);
386 :
387 2 : sal_Int16 nMFlag = SC_MF_BUTTON_POPUP;
388 2 : if (bHasHidden)
389 0 : nMFlag |= SC_MF_HIDDEN_MEMBER;
390 2 : pDoc->ApplyFlagsTab(aScAddress.Col()+1, aScAddress.Row(), aScAddress.Col()+1, aScAddress.Row(), aScAddress.Tab(), nMFlag);
391 : }
392 : else
393 : {
394 5 : sal_Int16 nMFlag = SC_MF_BUTTON;
395 5 : if (bDataLayout)
396 : {
397 : // Data layout dimension only has a plain button with no popup.
398 : }
399 5 : else if (bDimension)
400 : {
401 : // Normal dimension has a popup arrow button.
402 4 : if (bHasHidden)
403 0 : nMFlag |= SC_MF_HIDDEN_MEMBER;
404 :
405 4 : nMFlag |= SC_MF_BUTTON_POPUP;
406 : }
407 :
408 5 : pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag);
409 : }
410 : }
411 : }
412 : }
413 :
414 1 : if ( pDPObject )
415 1 : pDPObject->RefreshAfterLoad();
416 1 : }
417 :
418 8 : void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim)
419 : {
420 8 : if (pDPSave)
421 : {
422 8 : if (pDim->IsDataLayout())
423 1 : mnDataLayoutType = pDim->GetOrientation();
424 :
425 : // if a dimension with that name has already been inserted,
426 : // mark the new one as duplicate
427 15 : if ( !pDim->IsDataLayout() &&
428 7 : pDPSave->GetExistingDimensionByName(pDim->GetName()) )
429 0 : pDim->SetDupFlag(true);
430 :
431 8 : switch (pDim->GetOrientation())
432 : {
433 : case sheet::DataPilotFieldOrientation_ROW:
434 3 : ++mnRowFieldCount;
435 3 : break;
436 : case sheet::DataPilotFieldOrientation_COLUMN:
437 2 : ++mnColFieldCount;
438 2 : break;
439 : case sheet::DataPilotFieldOrientation_PAGE:
440 2 : ++mnPageFieldCount;
441 2 : break;
442 : case sheet::DataPilotFieldOrientation_DATA:
443 1 : ++mnDataFieldCount;
444 1 : break;
445 : case sheet::DataPilotFieldOrientation_HIDDEN:
446 : default:
447 : ;
448 : }
449 :
450 8 : pDPSave->AddDimension(pDim);
451 : }
452 8 : }
453 :
454 0 : void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim)
455 : {
456 0 : if (!pDPDimSaveData)
457 0 : pDPDimSaveData = new ScDPDimensionSaveData();
458 0 : pDPDimSaveData->AddNumGroupDimension(aNumGroupDim);
459 0 : }
460 :
461 0 : void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGroupDim)
462 : {
463 0 : if (!pDPDimSaveData)
464 0 : pDPDimSaveData = new ScDPDimensionSaveData();
465 0 : pDPDimSaveData->AddGroupDimension(aGroupDim);
466 0 : }
467 :
468 1 : void ScXMLDataPilotTableContext::EndElement()
469 : {
470 1 : if (!bTargetRangeAddress)
471 1 : return;
472 :
473 1 : pDPObject->SetName(sDataPilotTableName);
474 1 : pDPObject->SetTag(sApplicationData);
475 1 : pDPObject->SetOutRange(aTargetRangeAddress);
476 1 : pDPObject->SetHeaderLayout(bHeaderGridLayout);
477 1 : switch (nSourceType)
478 : {
479 : case SQL :
480 : {
481 0 : ScImportSourceDesc aImportDesc(pDoc);
482 0 : aImportDesc.aDBName = sDatabaseName;
483 0 : aImportDesc.aObject = sSourceObject;
484 0 : aImportDesc.nType = sheet::DataImportMode_SQL;
485 0 : aImportDesc.bNative = bIsNative;
486 0 : pDPObject->SetImportDesc(aImportDesc);
487 : }
488 0 : break;
489 : case TABLE :
490 : {
491 0 : ScImportSourceDesc aImportDesc(pDoc);
492 0 : aImportDesc.aDBName = sDatabaseName;
493 0 : aImportDesc.aObject = sSourceObject;
494 0 : aImportDesc.nType = sheet::DataImportMode_TABLE;
495 0 : pDPObject->SetImportDesc(aImportDesc);
496 : }
497 0 : break;
498 : case QUERY :
499 : {
500 0 : ScImportSourceDesc aImportDesc(pDoc);
501 0 : aImportDesc.aDBName = sDatabaseName;
502 0 : aImportDesc.aObject = sSourceObject;
503 0 : aImportDesc.nType = sheet::DataImportMode_QUERY;
504 0 : pDPObject->SetImportDesc(aImportDesc);
505 : }
506 0 : break;
507 : case SERVICE :
508 : {
509 : ScDPServiceDesc aServiceDesk(sServiceName, sServiceSourceName, sServiceSourceObject,
510 0 : sServiceUsername, sServicePassword);
511 0 : pDPObject->SetServiceData(aServiceDesk);
512 : }
513 0 : break;
514 : case CELLRANGE :
515 : {
516 1 : if (bSourceCellRange)
517 : {
518 1 : ScSheetSourceDesc aSheetDesc(pDoc);
519 1 : if (!sSourceRangeName.isEmpty())
520 : // Range name takes precedence.
521 0 : aSheetDesc.SetRangeName(sSourceRangeName);
522 : else
523 1 : aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
524 1 : aSheetDesc.SetQueryParam(aSourceQueryParam);
525 1 : pDPObject->SetSheetDesc(aSheetDesc);
526 : }
527 : }
528 1 : break;
529 : }
530 :
531 1 : pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
532 1 : pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
533 1 : if (!maRowGrandTotal.maDisplayName.isEmpty())
534 : // TODO: Right now, we only support one grand total name for both
535 : // column and row totals. Take the value from the row total for
536 : // now.
537 0 : pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
538 :
539 1 : pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
540 1 : pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
541 1 : pDPSave->SetFilterButton(bShowFilter);
542 1 : pDPSave->SetDrillDown(bDrillDown);
543 1 : if (pDPDimSaveData)
544 0 : pDPSave->SetDimensionData(pDPDimSaveData);
545 1 : pDPObject->SetSaveData(*pDPSave);
546 1 : if (pDoc)
547 : {
548 1 : ScDPCollection* pDPCollection = pDoc->GetDPCollection();
549 :
550 : // #i94570# Names have to be unique, or the tables can't be accessed by API.
551 1 : if ( pDPCollection->GetByName(pDPObject->GetName()) )
552 0 : pDPObject->SetName( String() ); // ignore the invalid name, create a new name in AfterXMLLoading
553 :
554 1 : pDPObject->SetAlive(sal_True);
555 1 : pDPCollection->InsertNewTable(pDPObject);
556 : }
557 1 : SetButtons();
558 : }
559 :
560 0 : void ScXMLDataPilotTableContext::SetGrandTotal(
561 : XMLTokenEnum eOrientation, bool bVisible, const OUString& rDisplayName)
562 : {
563 0 : switch (eOrientation)
564 : {
565 : case XML_BOTH:
566 0 : maRowGrandTotal.mbVisible = bVisible;
567 0 : maRowGrandTotal.maDisplayName = rDisplayName;
568 0 : maColGrandTotal.mbVisible = bVisible;
569 0 : maColGrandTotal.maDisplayName = rDisplayName;
570 0 : break;
571 : case XML_ROW:
572 0 : maRowGrandTotal.mbVisible = bVisible;
573 0 : maRowGrandTotal.maDisplayName = rDisplayName;
574 0 : break;
575 : case XML_COLUMN:
576 0 : maColGrandTotal.mbVisible = bVisible;
577 0 : maColGrandTotal.maDisplayName = rDisplayName;
578 0 : break;
579 : default:
580 : ;
581 : }
582 0 : }
583 :
584 0 : ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( 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 : ScXMLDataPilotTableContext* pTempDataPilotTable) :
590 : SvXMLImportContext( rImport, nPrfx, rLName ),
591 0 : pDataPilotTable(pTempDataPilotTable)
592 : {
593 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
594 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceSQLAttrTokenMap();
595 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
596 : {
597 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
598 0 : rtl::OUString aLocalName;
599 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
600 0 : sAttrName, &aLocalName );
601 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
602 :
603 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
604 : {
605 : case XML_TOK_SOURCE_SQL_ATTR_DATABASE_NAME :
606 : {
607 0 : pDataPilotTable->SetDatabaseName(sValue);
608 : }
609 0 : break;
610 : case XML_TOK_SOURCE_SQL_ATTR_SQL_STATEMENT :
611 : {
612 0 : pDataPilotTable->SetSourceObject(sValue);
613 : }
614 0 : break;
615 : case XML_TOK_SOURCE_SQL_ATTR_PARSE_SQL_STATEMENT :
616 : {
617 0 : pDataPilotTable->SetNative(!IsXMLToken(sValue, XML_TRUE));
618 : }
619 0 : break;
620 : }
621 0 : }
622 0 : }
623 :
624 0 : ScXMLDPSourceSQLContext::~ScXMLDPSourceSQLContext()
625 : {
626 0 : }
627 :
628 0 : SvXMLImportContext *ScXMLDPSourceSQLContext::CreateChildContext( sal_uInt16 nPrefix,
629 : const ::rtl::OUString& rLName,
630 : const ::com::sun::star::uno::Reference<
631 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
632 : {
633 0 : SvXMLImportContext *pContext = 0;
634 :
635 0 : if( !pContext )
636 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
637 :
638 0 : return pContext;
639 : }
640 :
641 0 : void ScXMLDPSourceSQLContext::EndElement()
642 : {
643 0 : }
644 :
645 0 : ScXMLDPSourceTableContext::ScXMLDPSourceTableContext( ScXMLImport& rImport,
646 : sal_uInt16 nPrfx,
647 : const ::rtl::OUString& rLName,
648 : const ::com::sun::star::uno::Reference<
649 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
650 : ScXMLDataPilotTableContext* pTempDataPilotTable) :
651 : SvXMLImportContext( rImport, nPrfx, rLName ),
652 0 : pDataPilotTable(pTempDataPilotTable)
653 : {
654 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
655 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceTableAttrTokenMap();
656 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
657 : {
658 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
659 0 : rtl::OUString aLocalName;
660 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
661 0 : sAttrName, &aLocalName );
662 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
663 :
664 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
665 : {
666 : case XML_TOK_SOURCE_TABLE_ATTR_DATABASE_NAME :
667 : {
668 0 : pDataPilotTable->SetDatabaseName(sValue);
669 : }
670 0 : break;
671 : case XML_TOK_SOURCE_TABLE_ATTR_TABLE_NAME :
672 : {
673 0 : pDataPilotTable->SetSourceObject(sValue);
674 : }
675 0 : break;
676 : }
677 0 : }
678 0 : }
679 :
680 0 : ScXMLDPSourceTableContext::~ScXMLDPSourceTableContext()
681 : {
682 0 : }
683 :
684 0 : SvXMLImportContext *ScXMLDPSourceTableContext::CreateChildContext( sal_uInt16 nPrefix,
685 : const ::rtl::OUString& rLName,
686 : const ::com::sun::star::uno::Reference<
687 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
688 : {
689 0 : SvXMLImportContext *pContext = 0;
690 :
691 0 : if( !pContext )
692 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
693 :
694 0 : return pContext;
695 : }
696 :
697 0 : void ScXMLDPSourceTableContext::EndElement()
698 : {
699 0 : }
700 :
701 0 : ScXMLDPSourceQueryContext::ScXMLDPSourceQueryContext( ScXMLImport& rImport,
702 : sal_uInt16 nPrfx,
703 : const ::rtl::OUString& rLName,
704 : const ::com::sun::star::uno::Reference<
705 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
706 : ScXMLDataPilotTableContext* pTempDataPilotTable) :
707 : SvXMLImportContext( rImport, nPrfx, rLName ),
708 0 : pDataPilotTable(pTempDataPilotTable)
709 : {
710 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
711 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceQueryAttrTokenMap();
712 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
713 : {
714 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
715 0 : rtl::OUString aLocalName;
716 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
717 0 : sAttrName, &aLocalName );
718 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
719 :
720 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
721 : {
722 : case XML_TOK_SOURCE_QUERY_ATTR_DATABASE_NAME :
723 : {
724 0 : pDataPilotTable->SetDatabaseName(sValue);
725 : }
726 0 : break;
727 : case XML_TOK_SOURCE_QUERY_ATTR_QUERY_NAME :
728 : {
729 0 : pDataPilotTable->SetSourceObject(sValue);
730 : }
731 0 : break;
732 : }
733 0 : }
734 0 : }
735 :
736 0 : ScXMLDPSourceQueryContext::~ScXMLDPSourceQueryContext()
737 : {
738 0 : }
739 :
740 0 : SvXMLImportContext *ScXMLDPSourceQueryContext::CreateChildContext( sal_uInt16 nPrefix,
741 : const ::rtl::OUString& rLName,
742 : const ::com::sun::star::uno::Reference<
743 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
744 : {
745 0 : SvXMLImportContext *pContext = 0;
746 :
747 0 : if( !pContext )
748 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
749 :
750 0 : return pContext;
751 : }
752 :
753 0 : void ScXMLDPSourceQueryContext::EndElement()
754 : {
755 0 : }
756 :
757 0 : ScXMLSourceServiceContext::ScXMLSourceServiceContext( ScXMLImport& rImport,
758 : sal_uInt16 nPrfx,
759 : const ::rtl::OUString& rLName,
760 : const ::com::sun::star::uno::Reference<
761 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
762 : ScXMLDataPilotTableContext* pTempDataPilotTable) :
763 : SvXMLImportContext( rImport, nPrfx, rLName ),
764 0 : pDataPilotTable(pTempDataPilotTable)
765 : {
766 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
767 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableSourceServiceAttrTokenMap();
768 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
769 : {
770 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
771 0 : rtl::OUString aLocalName;
772 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
773 0 : sAttrName, &aLocalName );
774 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
775 :
776 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
777 : {
778 : case XML_TOK_SOURCE_SERVICE_ATTR_NAME :
779 : {
780 0 : pDataPilotTable->SetServiceName(sValue);
781 : }
782 0 : break;
783 : case XML_TOK_SOURCE_SERVICE_ATTR_SOURCE_NAME :
784 : {
785 0 : pDataPilotTable->SetServiceSourceName(sValue);
786 : }
787 0 : break;
788 : case XML_TOK_SOURCE_SERVICE_ATTR_OBJECT_NAME :
789 : {
790 0 : pDataPilotTable->SetServiceSourceObject(sValue);
791 : }
792 0 : break;
793 : case XML_TOK_SOURCE_SERVICE_ATTR_USER_NAME :
794 : {
795 0 : pDataPilotTable->SetServiceUsername(sValue);
796 : }
797 0 : break;
798 : case XML_TOK_SOURCE_SERVICE_ATTR_PASSWORD :
799 : {
800 0 : pDataPilotTable->SetServicePassword(sValue);
801 : }
802 0 : break;
803 : }
804 0 : }
805 0 : }
806 :
807 0 : ScXMLSourceServiceContext::~ScXMLSourceServiceContext()
808 : {
809 0 : }
810 :
811 0 : SvXMLImportContext *ScXMLSourceServiceContext::CreateChildContext( sal_uInt16 nPrefix,
812 : const ::rtl::OUString& rLName,
813 : const ::com::sun::star::uno::Reference<
814 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
815 : {
816 0 : SvXMLImportContext *pContext = 0;
817 :
818 0 : if( !pContext )
819 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
820 :
821 0 : return pContext;
822 : }
823 :
824 0 : void ScXMLSourceServiceContext::EndElement()
825 : {
826 0 : }
827 :
828 0 : ScXMLImport& ScXMLDataPilotGrandTotalContext::GetScImport()
829 : {
830 0 : return static_cast<ScXMLImport&>(GetImport());
831 : }
832 :
833 0 : ScXMLDataPilotGrandTotalContext::ScXMLDataPilotGrandTotalContext(
834 : ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, const Reference<XAttributeList>& xAttrList,
835 : ScXMLDataPilotTableContext* pTableContext ) :
836 : SvXMLImportContext( rImport, nPrefix, rLName ),
837 : mpTableContext(pTableContext),
838 : meOrientation(NONE),
839 0 : mbVisible(false)
840 : {
841 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
842 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotGrandTotalAttrTokenMap();
843 0 : for (sal_Int16 i = 0; i < nAttrCount; ++i)
844 : {
845 0 : const OUString& rAttrName = xAttrList->getNameByIndex(i);
846 0 : const OUString& rAttrValue = xAttrList->getValueByIndex(i);
847 :
848 0 : OUString aLocalName;
849 0 : sal_uInt16 nLocalPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
850 0 : switch (rAttrTokenMap.Get(nLocalPrefix, aLocalName))
851 : {
852 : case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_DISPLAY:
853 0 : mbVisible = IsXMLToken(rAttrValue, XML_TRUE);
854 0 : break;
855 : case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_ORIENTATION:
856 0 : if (IsXMLToken(rAttrValue, XML_BOTH))
857 0 : meOrientation = BOTH;
858 0 : else if (IsXMLToken(rAttrValue, XML_ROW))
859 0 : meOrientation = ROW;
860 0 : else if (IsXMLToken(rAttrValue, XML_COLUMN))
861 0 : meOrientation = COLUMN;
862 0 : break;
863 : case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_DISPLAY_NAME:
864 : case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_DISPLAY_NAME_EXT:
865 0 : maDisplayName = rAttrValue;
866 0 : break;
867 : default:
868 : ;
869 : }
870 0 : }
871 0 : }
872 :
873 0 : ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
874 : {
875 0 : }
876 :
877 0 : SvXMLImportContext* ScXMLDataPilotGrandTotalContext::CreateChildContext(
878 : sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const Reference<XAttributeList>& /*xAttrList*/ )
879 : {
880 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
881 : }
882 :
883 0 : void ScXMLDataPilotGrandTotalContext::EndElement()
884 : {
885 0 : XMLTokenEnum eOrient = XML_NONE;
886 0 : switch (meOrientation)
887 : {
888 : case BOTH:
889 0 : eOrient = XML_BOTH;
890 0 : break;
891 : case ROW:
892 0 : eOrient = XML_ROW;
893 0 : break;
894 : case COLUMN:
895 0 : eOrient = XML_COLUMN;
896 0 : break;
897 : default:
898 : ;
899 : }
900 0 : mpTableContext->SetGrandTotal(eOrient, mbVisible, maDisplayName);
901 0 : }
902 :
903 1 : ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport& rImport,
904 : sal_uInt16 nPrfx,
905 : const ::rtl::OUString& rLName,
906 : const ::com::sun::star::uno::Reference<
907 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
908 : ScXMLDataPilotTableContext* pTempDataPilotTable) :
909 : SvXMLImportContext( rImport, nPrfx, rLName ),
910 1 : pDataPilotTable(pTempDataPilotTable)
911 : {
912 1 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
913 1 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableSourceCellRangeAttrTokenMap();
914 2 : for( sal_Int16 i=0; i < nAttrCount; ++i )
915 : {
916 1 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
917 1 : rtl::OUString aLocalName;
918 1 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
919 1 : sAttrName, &aLocalName );
920 1 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
921 :
922 1 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
923 : {
924 : case XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS :
925 : {
926 1 : ScRange aSourceRangeAddress;
927 1 : sal_Int32 nOffset(0);
928 1 : if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ))
929 1 : pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
930 : }
931 1 : break;
932 : case XML_TOK_SOURCE_CELL_RANGE_ATTR_NAME:
933 0 : pDataPilotTable->SetSourceRangeName(sValue);
934 0 : break;
935 : }
936 1 : }
937 1 : }
938 :
939 2 : ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
940 : {
941 2 : }
942 :
943 0 : SvXMLImportContext *ScXMLSourceCellRangeContext::CreateChildContext( sal_uInt16 nPrefix,
944 : const ::rtl::OUString& rLName,
945 : const ::com::sun::star::uno::Reference<
946 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
947 : {
948 0 : SvXMLImportContext *pContext = 0;
949 :
950 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTableSourceCellRangeElemTokenMap();
951 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
952 : {
953 : case XML_TOK_SOURCE_CELL_RANGE_ELEM_FILTER :
954 0 : pContext = new ScXMLDPFilterContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotTable);
955 0 : break;
956 : }
957 :
958 0 : if( !pContext )
959 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
960 :
961 0 : return pContext;
962 : }
963 :
964 1 : void ScXMLSourceCellRangeContext::EndElement()
965 : {
966 1 : }
967 :
968 8 : ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport& rImport,
969 : sal_uInt16 nPrfx,
970 : const ::rtl::OUString& rLName,
971 : const ::com::sun::star::uno::Reference<
972 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
973 : ScXMLDataPilotTableContext* pTempDataPilotTable) :
974 : SvXMLImportContext( rImport, nPrfx, rLName ),
975 : pDataPilotTable(pTempDataPilotTable),
976 : pDim(NULL),
977 : fStart(0.0),
978 : fEnd(0.0),
979 : fStep(0.0),
980 : nUsedHierarchy(1),
981 : nGroupPart(0),
982 : bSelectedPage(false),
983 : bIsGroupField(false),
984 : bDateValue(false),
985 : bAutoStart(false),
986 : bAutoEnd(false),
987 8 : mbHasHiddenMember(false)
988 : {
989 8 : bool bHasName = false;
990 8 : bool bDataLayout = false;
991 8 : OUString aDisplayName;
992 8 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
993 8 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotFieldAttrTokenMap();
994 41 : for( sal_Int16 i=0; i < nAttrCount; ++i )
995 : {
996 33 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
997 33 : rtl::OUString aLocalName;
998 33 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
999 33 : sAttrName, &aLocalName );
1000 33 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1001 :
1002 33 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1003 : {
1004 : case XML_TOK_DATA_PILOT_FIELD_ATTR_SOURCE_FIELD_NAME :
1005 : {
1006 8 : sName = sValue;
1007 8 : bHasName = true;
1008 : }
1009 8 : break;
1010 : case XML_TOK_DATA_PILOT_FIELD_ATTR_DISPLAY_NAME:
1011 : case XML_TOK_DATA_PILOT_FIELD_ATTR_DISPLAY_NAME_EXT:
1012 : {
1013 0 : aDisplayName = sValue;
1014 : }
1015 0 : break;
1016 : case XML_TOK_DATA_PILOT_FIELD_ATTR_IS_DATA_LAYOUT_FIELD :
1017 : {
1018 1 : bDataLayout = IsXMLToken(sValue, XML_TRUE);
1019 : }
1020 1 : break;
1021 : case XML_TOK_DATA_PILOT_FIELD_ATTR_FUNCTION :
1022 : {
1023 8 : nFunction = (sal_Int16) ScXMLConverter::GetFunctionFromString( sValue );
1024 : }
1025 8 : break;
1026 : case XML_TOK_DATA_PILOT_FIELD_ATTR_ORIENTATION :
1027 : {
1028 8 : nOrientation = (sal_Int16) ScXMLConverter::GetOrientationFromString( sValue );
1029 : }
1030 8 : break;
1031 : case XML_TOK_DATA_PILOT_FIELD_ATTR_SELECTED_PAGE :
1032 : {
1033 0 : sSelectedPage = sValue;
1034 0 : bSelectedPage = true;
1035 : }
1036 0 : break;
1037 : case XML_TOK_DATA_PILOT_FIELD_ATTR_USED_HIERARCHY :
1038 : {
1039 8 : nUsedHierarchy = sValue.toInt32();
1040 : }
1041 8 : break;
1042 : }
1043 33 : }
1044 8 : if (bHasName)
1045 : {
1046 8 : pDim = new ScDPSaveDimension(sName, bDataLayout);
1047 8 : if (!aDisplayName.isEmpty())
1048 0 : pDim->SetLayoutName(aDisplayName);
1049 8 : }
1050 8 : }
1051 :
1052 16 : ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
1053 : {
1054 16 : }
1055 :
1056 8 : SvXMLImportContext *ScXMLDataPilotFieldContext::CreateChildContext( sal_uInt16 nPrefix,
1057 : const ::rtl::OUString& rLName,
1058 : const ::com::sun::star::uno::Reference<
1059 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1060 : {
1061 8 : SvXMLImportContext *pContext = 0;
1062 :
1063 8 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotFieldElemTokenMap();
1064 8 : switch( rTokenMap.Get( nPrefix, rLName ) )
1065 : {
1066 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_LEVEL :
1067 8 : pContext = new ScXMLDataPilotLevelContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1068 8 : break;
1069 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_REFERENCE :
1070 0 : pContext = new ScXMLDataPilotFieldReferenceContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1071 0 : break;
1072 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_GROUPS :
1073 0 : pContext = new ScXMLDataPilotGroupsContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1074 0 : break;
1075 : }
1076 :
1077 8 : if( !pContext )
1078 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1079 :
1080 8 : return pContext;
1081 : }
1082 :
1083 18 : void ScXMLDataPilotFieldContext::AddMember(ScDPSaveMember* pMember)
1084 : {
1085 18 : if (pDim)
1086 : {
1087 18 : pDim->AddMember(pMember);
1088 18 : if (!pMember->GetIsVisible())
1089 : // This member is hidden.
1090 0 : mbHasHiddenMember = true;
1091 : }
1092 : else
1093 0 : delete pMember;
1094 18 : }
1095 :
1096 0 : void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString& rName)
1097 : {
1098 0 : if (pDim)
1099 0 : pDim->SetSubtotalName(rName);
1100 0 : }
1101 :
1102 0 : void ScXMLDataPilotFieldContext::AddGroup(const ::std::vector<rtl::OUString>& rMembers, const rtl::OUString& rName)
1103 : {
1104 0 : ScXMLDataPilotGroup aGroup;
1105 0 : aGroup.aMembers = rMembers;
1106 0 : aGroup.aName = rName;
1107 0 : aGroups.push_back(aGroup);
1108 0 : }
1109 :
1110 8 : void ScXMLDataPilotFieldContext::EndElement()
1111 : {
1112 8 : if (pDim)
1113 : {
1114 8 : pDim->SetUsedHierarchy(nUsedHierarchy);
1115 8 : pDim->SetFunction(nFunction);
1116 8 : pDim->SetOrientation(nOrientation);
1117 8 : if (bSelectedPage)
1118 : {
1119 0 : pDim->SetCurrentPage(&sSelectedPage);
1120 : }
1121 8 : pDataPilotTable->AddDimension(pDim);
1122 8 : if (bIsGroupField)
1123 : {
1124 0 : ScDPNumGroupInfo aInfo;
1125 0 : aInfo.mbEnable = true;
1126 0 : aInfo.mbDateValues = bDateValue;
1127 0 : aInfo.mbAutoStart = bAutoStart;
1128 0 : aInfo.mbAutoEnd = bAutoEnd;
1129 0 : aInfo.mfStart = fStart;
1130 0 : aInfo.mfEnd = fEnd;
1131 0 : aInfo.mfStep = fStep;
1132 0 : if (!sGroupSource.isEmpty())
1133 : {
1134 0 : ScDPSaveGroupDimension aGroupDim(sGroupSource, sName);
1135 0 : if (nGroupPart)
1136 0 : aGroupDim.SetDateInfo(aInfo, nGroupPart);
1137 : else
1138 : {
1139 0 : ::std::vector<ScXMLDataPilotGroup>::const_iterator aItr(aGroups.begin());
1140 0 : ::std::vector<ScXMLDataPilotGroup>::const_iterator aEndItr(aGroups.end());
1141 0 : while (aItr != aEndItr)
1142 : {
1143 0 : ScDPSaveGroupItem aItem(aItr->aName);
1144 0 : ::std::vector<rtl::OUString>::const_iterator aMembersItr(aItr->aMembers.begin());
1145 0 : ::std::vector<rtl::OUString>::const_iterator aMembersEndItr(aItr->aMembers.end());
1146 0 : while (aMembersItr != aMembersEndItr)
1147 : {
1148 0 : aItem.AddElement(*aMembersItr);
1149 0 : ++aMembersItr;
1150 : }
1151 0 : ++aItr;
1152 0 : aGroupDim.AddGroupItem(aItem);
1153 0 : }
1154 : }
1155 0 : pDataPilotTable->AddGroupDim(aGroupDim);
1156 : }
1157 : else //NumGroup
1158 : {
1159 0 : ScDPSaveNumGroupDimension aNumGroupDim(sName, aInfo);
1160 0 : if (nGroupPart)
1161 0 : aNumGroupDim.SetDateInfo(aInfo, nGroupPart);
1162 0 : pDataPilotTable->AddGroupDim(aNumGroupDim);
1163 : }
1164 : }
1165 : }
1166 8 : }
1167 :
1168 0 : ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1169 : const ::rtl::OUString& rLName,
1170 : const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1171 : ScXMLDataPilotFieldContext* pDataPilotField) :
1172 0 : SvXMLImportContext( rImport, nPrfx, rLName )
1173 : {
1174 0 : sheet::DataPilotFieldReference aReference;
1175 :
1176 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1177 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1178 : {
1179 0 : rtl::OUString sAttrName(xAttrList->getNameByIndex( i ));
1180 0 : rtl::OUString aLocalName;
1181 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1182 0 : sAttrName, &aLocalName );
1183 0 : rtl::OUString sValue(xAttrList->getValueByIndex( i ));
1184 :
1185 0 : if ( nPrefix == XML_NAMESPACE_TABLE )
1186 : {
1187 0 : if (IsXMLToken(aLocalName, XML_TYPE))
1188 : {
1189 0 : if (IsXMLToken(sValue, XML_NONE))
1190 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::NONE;
1191 0 : else if (IsXMLToken(sValue, XML_MEMBER_DIFFERENCE))
1192 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE;
1193 0 : else if (IsXMLToken(sValue, XML_MEMBER_PERCENTAGE))
1194 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE;
1195 0 : else if (IsXMLToken(sValue, XML_MEMBER_PERCENTAGE_DIFFERENCE))
1196 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
1197 0 : else if (IsXMLToken(sValue, XML_RUNNING_TOTAL))
1198 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::RUNNING_TOTAL;
1199 0 : else if (IsXMLToken(sValue, XML_ROW_PERCENTAGE))
1200 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE;
1201 0 : else if (IsXMLToken(sValue, XML_COLUMN_PERCENTAGE))
1202 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
1203 0 : else if (IsXMLToken(sValue, XML_TOTAL_PERCENTAGE))
1204 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
1205 0 : else if (IsXMLToken(sValue, XML_INDEX))
1206 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::INDEX;
1207 : }
1208 0 : else if (IsXMLToken(aLocalName, XML_FIELD_NAME))
1209 : {
1210 0 : aReference.ReferenceField = sValue;
1211 : }
1212 0 : else if (IsXMLToken(aLocalName, XML_MEMBER_TYPE))
1213 : {
1214 0 : if (IsXMLToken(sValue, XML_NAMED))
1215 0 : aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
1216 0 : else if (IsXMLToken(sValue, XML_PREVIOUS))
1217 0 : aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::PREVIOUS;
1218 0 : else if (IsXMLToken(sValue, XML_NEXT))
1219 0 : aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NEXT;
1220 : }
1221 0 : else if (IsXMLToken(aLocalName, XML_MEMBER_NAME))
1222 : {
1223 0 : aReference.ReferenceItemName = sValue;
1224 : }
1225 : }
1226 0 : }
1227 0 : pDataPilotField->SetFieldReference(aReference);
1228 0 : }
1229 :
1230 0 : ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1231 : {
1232 0 : }
1233 :
1234 8 : ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport& rImport,
1235 : sal_uInt16 nPrfx,
1236 : const ::rtl::OUString& rLName,
1237 : const ::com::sun::star::uno::Reference<
1238 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1239 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1240 : SvXMLImportContext( rImport, nPrfx, rLName ),
1241 8 : pDataPilotField(pTempDataPilotField)
1242 : {
1243 8 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1244 8 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotLevelAttrTokenMap();
1245 16 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1246 : {
1247 8 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1248 8 : rtl::OUString aLocalName;
1249 8 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1250 8 : sAttrName, &aLocalName );
1251 8 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1252 :
1253 8 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1254 : {
1255 : case XML_TOK_DATA_PILOT_LEVEL_ATTR_SHOW_EMPTY :
1256 : {
1257 8 : pDataPilotField->SetShowEmpty(IsXMLToken(sValue, XML_TRUE));
1258 : }
1259 8 : break;
1260 : }
1261 8 : }
1262 8 : }
1263 :
1264 16 : ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1265 : {
1266 16 : }
1267 :
1268 28 : SvXMLImportContext *ScXMLDataPilotLevelContext::CreateChildContext( sal_uInt16 nPrefix,
1269 : const ::rtl::OUString& rLName,
1270 : const ::com::sun::star::uno::Reference<
1271 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1272 : {
1273 28 : SvXMLImportContext *pContext = 0;
1274 :
1275 28 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotLevelElemTokenMap();
1276 28 : switch( rTokenMap.Get( nPrefix, rLName ) )
1277 : {
1278 : case XML_TOK_DATA_PILOT_LEVEL_ELEM_DATA_PILOT_SUBTOTALS :
1279 0 : pContext = new ScXMLDataPilotSubTotalsContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1280 0 : break;
1281 : case XML_TOK_DATA_PILOT_LEVEL_ELEM_DATA_PILOT_MEMBERS :
1282 7 : pContext = new ScXMLDataPilotMembersContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1283 7 : break;
1284 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_DISPLAY_INFO :
1285 7 : pContext = new ScXMLDataPilotDisplayInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1286 7 : break;
1287 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_SORT_INFO :
1288 7 : pContext = new ScXMLDataPilotSortInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1289 7 : break;
1290 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_LAYOUT_INFO :
1291 7 : pContext = new ScXMLDataPilotLayoutInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1292 7 : break;
1293 : }
1294 :
1295 28 : if( !pContext )
1296 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1297 :
1298 28 : return pContext;
1299 : }
1300 :
1301 8 : void ScXMLDataPilotLevelContext::EndElement()
1302 : {
1303 8 : }
1304 :
1305 7 : ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1306 : const ::rtl::OUString& rLName,
1307 : const ::com::sun::star::uno::Reference<
1308 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1309 : ScXMLDataPilotFieldContext* pDataPilotField) :
1310 7 : SvXMLImportContext( rImport, nPrfx, rLName )
1311 : {
1312 7 : sheet::DataPilotFieldAutoShowInfo aInfo;
1313 :
1314 7 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1315 35 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1316 : {
1317 28 : rtl::OUString sAttrName(xAttrList->getNameByIndex( i ));
1318 28 : rtl::OUString aLocalName;
1319 28 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1320 28 : sAttrName, &aLocalName );
1321 28 : rtl::OUString sValue(xAttrList->getValueByIndex( i ));
1322 :
1323 28 : if ( nPrefix == XML_NAMESPACE_TABLE )
1324 : {
1325 28 : if (IsXMLToken(aLocalName, XML_ENABLED))
1326 : {
1327 7 : if (IsXMLToken(sValue, XML_TRUE))
1328 0 : aInfo.IsEnabled = sal_True;
1329 : else
1330 7 : aInfo.IsEnabled = false;
1331 : }
1332 21 : else if (IsXMLToken(aLocalName, XML_DISPLAY_MEMBER_MODE))
1333 : {
1334 7 : if (IsXMLToken(sValue, XML_FROM_TOP))
1335 7 : aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_TOP;
1336 0 : else if (IsXMLToken(sValue, XML_FROM_BOTTOM))
1337 0 : aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM;
1338 : }
1339 14 : else if (IsXMLToken(aLocalName, XML_MEMBER_COUNT))
1340 : {
1341 7 : aInfo.ItemCount = sValue.toInt32();
1342 : }
1343 7 : else if (IsXMLToken(aLocalName, XML_DATA_FIELD))
1344 : {
1345 7 : aInfo.DataField = sValue;
1346 : }
1347 : }
1348 28 : }
1349 7 : pDataPilotField->SetAutoShowInfo(aInfo);
1350 7 : }
1351 :
1352 14 : ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1353 : {
1354 14 : }
1355 :
1356 7 : ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1357 : const ::rtl::OUString& rLName,
1358 : const ::com::sun::star::uno::Reference<
1359 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1360 : ScXMLDataPilotFieldContext* pDataPilotField) :
1361 7 : SvXMLImportContext( rImport, nPrfx, rLName )
1362 : {
1363 7 : sheet::DataPilotFieldSortInfo aInfo;
1364 :
1365 7 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1366 21 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1367 : {
1368 14 : rtl::OUString sAttrName(xAttrList->getNameByIndex( i ));
1369 14 : rtl::OUString aLocalName;
1370 14 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1371 14 : sAttrName, &aLocalName );
1372 14 : rtl::OUString sValue(xAttrList->getValueByIndex( i ));
1373 :
1374 14 : if ( nPrefix == XML_NAMESPACE_TABLE )
1375 : {
1376 14 : if (IsXMLToken(aLocalName, XML_ORDER))
1377 : {
1378 7 : if (IsXMLToken(sValue, XML_ASCENDING))
1379 7 : aInfo.IsAscending = sal_True;
1380 0 : else if (IsXMLToken(sValue, XML_DESCENDING))
1381 0 : aInfo.IsAscending = false;
1382 : }
1383 7 : else if (IsXMLToken(aLocalName, XML_SORT_MODE))
1384 : {
1385 7 : if (IsXMLToken(sValue, XML_NONE))
1386 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::NONE;
1387 7 : else if (IsXMLToken(sValue, XML_MANUAL))
1388 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
1389 7 : else if (IsXMLToken(sValue, XML_NAME))
1390 7 : aInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
1391 0 : else if (IsXMLToken(sValue, XML_DATA))
1392 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::DATA;
1393 : }
1394 0 : else if (IsXMLToken(aLocalName, XML_DATA_FIELD))
1395 0 : aInfo.Field = sValue;
1396 : }
1397 14 : }
1398 7 : pDataPilotField->SetSortInfo(aInfo);
1399 7 : }
1400 :
1401 14 : ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1402 : {
1403 14 : }
1404 :
1405 7 : ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1406 : const ::rtl::OUString& rLName,
1407 : const ::com::sun::star::uno::Reference<
1408 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1409 : ScXMLDataPilotFieldContext* pDataPilotField) :
1410 7 : SvXMLImportContext( rImport, nPrfx, rLName )
1411 : {
1412 7 : sheet::DataPilotFieldLayoutInfo aInfo;
1413 :
1414 7 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1415 21 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1416 : {
1417 14 : rtl::OUString sAttrName(xAttrList->getNameByIndex( i ));
1418 14 : rtl::OUString aLocalName;
1419 14 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1420 14 : sAttrName, &aLocalName );
1421 14 : rtl::OUString sValue(xAttrList->getValueByIndex( i ));
1422 :
1423 14 : if ( nPrefix == XML_NAMESPACE_TABLE )
1424 : {
1425 14 : if (IsXMLToken(aLocalName, XML_ADD_EMPTY_LINES))
1426 : {
1427 7 : if (IsXMLToken(sValue, XML_TRUE))
1428 0 : aInfo.AddEmptyLines = sal_True;
1429 : else
1430 7 : aInfo.AddEmptyLines = false;
1431 : }
1432 7 : else if (IsXMLToken(aLocalName, XML_LAYOUT_MODE))
1433 : {
1434 7 : if (IsXMLToken(sValue, XML_TABULAR_LAYOUT))
1435 7 : aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
1436 0 : else if (IsXMLToken(sValue, XML_OUTLINE_SUBTOTALS_TOP))
1437 0 : aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
1438 0 : else if (IsXMLToken(sValue, XML_OUTLINE_SUBTOTALS_BOTTOM))
1439 0 : aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
1440 : }
1441 : }
1442 14 : }
1443 7 : pDataPilotField->SetLayoutInfo(aInfo);}
1444 :
1445 14 : ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1446 : {
1447 14 : }
1448 :
1449 0 : ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport,
1450 : sal_uInt16 nPrfx,
1451 : const ::rtl::OUString& rLName,
1452 : const ::com::sun::star::uno::Reference<
1453 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
1454 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1455 : SvXMLImportContext( rImport, nPrfx, rLName ),
1456 : pDataPilotField(pTempDataPilotField),
1457 : nFunctionCount(0),
1458 0 : pFunctions(NULL)
1459 : {
1460 :
1461 : // has no attributes
1462 0 : }
1463 :
1464 0 : ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1465 : {
1466 0 : }
1467 :
1468 0 : SvXMLImportContext *ScXMLDataPilotSubTotalsContext::CreateChildContext( sal_uInt16 nPrefix,
1469 : const ::rtl::OUString& rLName,
1470 : const ::com::sun::star::uno::Reference<
1471 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1472 : {
1473 0 : SvXMLImportContext *pContext = 0;
1474 :
1475 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotSubTotalsElemTokenMap();
1476 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
1477 : {
1478 : case XML_TOK_DATA_PILOT_SUBTOTALS_ELEM_DATA_PILOT_SUBTOTAL :
1479 0 : pContext = new ScXMLDataPilotSubTotalContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1480 0 : break;
1481 : }
1482 :
1483 0 : if( !pContext )
1484 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1485 :
1486 0 : return pContext;
1487 : }
1488 :
1489 0 : void ScXMLDataPilotSubTotalsContext::EndElement()
1490 : {
1491 0 : pDataPilotField->SetSubTotals(pFunctions, nFunctionCount);
1492 0 : if (!maDisplayName.isEmpty())
1493 0 : pDataPilotField->SetSubTotalName(maDisplayName);
1494 0 : }
1495 :
1496 0 : void ScXMLDataPilotSubTotalsContext::AddFunction(sal_Int16 nFunction)
1497 : {
1498 0 : if (nFunctionCount)
1499 : {
1500 0 : ++nFunctionCount;
1501 0 : sal_uInt16* pTemp = new sal_uInt16[nFunctionCount];
1502 0 : for (sal_Int16 i = 0; i < nFunctionCount - 1; ++i)
1503 0 : pTemp[i] = pFunctions[i];
1504 0 : pTemp[nFunctionCount - 1] = nFunction;
1505 0 : delete[] pFunctions;
1506 0 : pFunctions = pTemp;
1507 : }
1508 : else
1509 : {
1510 0 : nFunctionCount = 1;
1511 0 : pFunctions = new sal_uInt16[nFunctionCount];
1512 0 : pFunctions[0] = nFunction;
1513 : }
1514 0 : }
1515 :
1516 0 : void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
1517 : {
1518 0 : maDisplayName = rName;
1519 0 : }
1520 :
1521 0 : ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport& rImport,
1522 : sal_uInt16 nPrfx,
1523 : const ::rtl::OUString& rLName,
1524 : const ::com::sun::star::uno::Reference<
1525 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1526 : ScXMLDataPilotSubTotalsContext* pTempDataPilotSubTotals) :
1527 : SvXMLImportContext( rImport, nPrfx, rLName ),
1528 0 : pDataPilotSubTotals(pTempDataPilotSubTotals)
1529 : {
1530 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1531 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotSubTotalAttrTokenMap();
1532 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1533 : {
1534 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1535 0 : rtl::OUString aLocalName;
1536 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1537 0 : sAttrName, &aLocalName );
1538 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1539 :
1540 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1541 : {
1542 : case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_FUNCTION :
1543 : {
1544 : pDataPilotSubTotals->AddFunction( sal::static_int_cast<sal_Int16>(
1545 0 : ScXMLConverter::GetFunctionFromString( sValue ) ) );
1546 : }
1547 0 : break;
1548 : case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_DISPLAY_NAME:
1549 : case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_DISPLAY_NAME_EXT:
1550 0 : pDataPilotSubTotals->SetDisplayName(sValue);
1551 0 : break;
1552 : }
1553 0 : }
1554 0 : }
1555 :
1556 0 : ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1557 : {
1558 0 : }
1559 :
1560 0 : SvXMLImportContext *ScXMLDataPilotSubTotalContext::CreateChildContext( sal_uInt16 nPrefix,
1561 : const ::rtl::OUString& rLName,
1562 : const ::com::sun::star::uno::Reference<
1563 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1564 : {
1565 0 : SvXMLImportContext *pContext = 0;
1566 :
1567 0 : if( !pContext )
1568 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1569 :
1570 0 : return pContext;
1571 : }
1572 :
1573 0 : void ScXMLDataPilotSubTotalContext::EndElement()
1574 : {
1575 0 : }
1576 :
1577 7 : ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport& rImport,
1578 : sal_uInt16 nPrfx,
1579 : const ::rtl::OUString& rLName,
1580 : const ::com::sun::star::uno::Reference<
1581 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
1582 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1583 : SvXMLImportContext( rImport, nPrfx, rLName ),
1584 7 : pDataPilotField(pTempDataPilotField)
1585 : {
1586 : // has no attributes
1587 7 : }
1588 :
1589 14 : ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1590 : {
1591 14 : }
1592 :
1593 18 : SvXMLImportContext *ScXMLDataPilotMembersContext::CreateChildContext( sal_uInt16 nPrefix,
1594 : const ::rtl::OUString& rLName,
1595 : const ::com::sun::star::uno::Reference<
1596 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1597 : {
1598 18 : SvXMLImportContext *pContext = 0;
1599 :
1600 18 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotMembersElemTokenMap();
1601 18 : switch( rTokenMap.Get( nPrefix, rLName ) )
1602 : {
1603 : case XML_TOK_DATA_PILOT_MEMBERS_ELEM_DATA_PILOT_MEMBER :
1604 18 : pContext = new ScXMLDataPilotMemberContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1605 18 : break;
1606 : }
1607 :
1608 18 : if( !pContext )
1609 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1610 :
1611 18 : return pContext;
1612 : }
1613 :
1614 7 : void ScXMLDataPilotMembersContext::EndElement()
1615 : {
1616 7 : }
1617 :
1618 18 : ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport& rImport,
1619 : sal_uInt16 nPrfx,
1620 : const ::rtl::OUString& rLName,
1621 : const ::com::sun::star::uno::Reference<
1622 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1623 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1624 : SvXMLImportContext( rImport, nPrfx, rLName ),
1625 : pDataPilotField(pTempDataPilotField),
1626 : bDisplay( sal_True ),
1627 : bDisplayDetails( sal_True ),
1628 18 : bHasName( false )
1629 : {
1630 18 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1631 18 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotMemberAttrTokenMap();
1632 72 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1633 : {
1634 54 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
1635 54 : rtl::OUString aLocalName;
1636 54 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1637 54 : sAttrName, &aLocalName );
1638 54 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
1639 :
1640 54 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1641 : {
1642 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_NAME :
1643 : {
1644 18 : sName = sValue;
1645 18 : bHasName = sal_True;
1646 : }
1647 18 : break;
1648 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY_NAME:
1649 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY_NAME_EXT:
1650 : {
1651 0 : maDisplayName = sValue;
1652 : }
1653 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY :
1654 : {
1655 18 : bDisplay = IsXMLToken(sValue, XML_TRUE);
1656 : }
1657 18 : break;
1658 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_SHOW_DETAILS :
1659 : {
1660 18 : bDisplayDetails = IsXMLToken(sValue, XML_TRUE);
1661 : }
1662 18 : break;
1663 : }
1664 54 : }
1665 18 : }
1666 :
1667 36 : ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1668 : {
1669 36 : }
1670 :
1671 0 : SvXMLImportContext *ScXMLDataPilotMemberContext::CreateChildContext( sal_uInt16 nPrefix,
1672 : const ::rtl::OUString& rLName,
1673 : const ::com::sun::star::uno::Reference<
1674 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1675 : {
1676 0 : SvXMLImportContext *pContext = 0;
1677 :
1678 0 : if( !pContext )
1679 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1680 :
1681 0 : return pContext;
1682 : }
1683 :
1684 18 : void ScXMLDataPilotMemberContext::EndElement()
1685 : {
1686 18 : if (bHasName) // #i53407# don't check sName, empty name is allowed
1687 : {
1688 18 : ScDPSaveMember* pMember = new ScDPSaveMember(sName);
1689 18 : if (!maDisplayName.isEmpty())
1690 0 : pMember->SetLayoutName(maDisplayName);
1691 18 : pMember->SetIsVisible(bDisplay);
1692 18 : pMember->SetShowDetails(bDisplayDetails);
1693 18 : pDataPilotField->AddMember(pMember);
1694 : }
1695 18 : }
1696 :
1697 0 : ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport& rImport,
1698 : sal_uInt16 nPrfx,
1699 : const ::rtl::OUString& rLName,
1700 : const ::com::sun::star::uno::Reference<
1701 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1702 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1703 : SvXMLImportContext( rImport, nPrfx, rLName ),
1704 0 : pDataPilotField(pTempDataPilotField)
1705 : {
1706 0 : rtl::OUString sGroupSource;
1707 0 : double fStart(0.0);
1708 0 : double fEnd(0.0);
1709 0 : double fStep(0.0);
1710 0 : sal_Int32 nGroupPart(0);
1711 0 : sal_Bool bDateValue(false);
1712 0 : sal_Bool bAutoStart(sal_True);
1713 0 : sal_Bool bAutoEnd(sal_True);
1714 :
1715 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1716 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1717 : {
1718 0 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1719 0 : rtl::OUString aLocalName;
1720 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1721 0 : sAttrName, &aLocalName );
1722 0 : rtl::OUString sValue = xAttrList->getValueByIndex( i );
1723 :
1724 : (void)nPrefix; //! compare below!
1725 :
1726 0 : if (IsXMLToken(aLocalName, XML_SOURCE_FIELD_NAME))
1727 0 : sGroupSource = sValue;
1728 0 : else if (IsXMLToken(aLocalName, XML_DATE_START))
1729 : {
1730 0 : bDateValue = sal_True;
1731 0 : if (IsXMLToken(sValue, XML_AUTO))
1732 0 : bAutoStart = sal_True;
1733 : else
1734 : {
1735 0 : GetScImport().GetMM100UnitConverter().convertDateTime(fStart, sValue);
1736 0 : bAutoStart = false;
1737 : }
1738 : }
1739 0 : else if (IsXMLToken(aLocalName, XML_DATE_END))
1740 : {
1741 0 : bDateValue = sal_True;
1742 0 : if (IsXMLToken(sValue, XML_AUTO))
1743 0 : bAutoEnd = sal_True;
1744 : else
1745 : {
1746 0 : GetScImport().GetMM100UnitConverter().convertDateTime(fEnd, sValue);
1747 0 : bAutoEnd = false;
1748 : }
1749 : }
1750 0 : else if (IsXMLToken(aLocalName, XML_START))
1751 : {
1752 0 : if (IsXMLToken(sValue, XML_AUTO))
1753 0 : bAutoStart = sal_True;
1754 : else
1755 : {
1756 0 : ::sax::Converter::convertDouble(fStart, sValue);
1757 0 : bAutoStart = false;
1758 : }
1759 : }
1760 0 : else if (IsXMLToken(aLocalName, XML_END))
1761 : {
1762 0 : if (IsXMLToken(sValue, XML_AUTO))
1763 0 : bAutoEnd = sal_True;
1764 : else
1765 : {
1766 0 : ::sax::Converter::convertDouble(fEnd, sValue);
1767 0 : bAutoEnd = false;
1768 : }
1769 : }
1770 0 : else if (IsXMLToken(aLocalName, XML_STEP))
1771 : {
1772 0 : ::sax::Converter::convertDouble(fStep, sValue);
1773 : }
1774 0 : else if (IsXMLToken(aLocalName, XML_GROUPED_BY))
1775 : {
1776 0 : if (IsXMLToken(sValue, XML_SECONDS))
1777 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS;
1778 0 : else if (IsXMLToken(sValue, XML_MINUTES))
1779 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES;
1780 0 : else if (IsXMLToken(sValue, XML_HOURS))
1781 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::HOURS;
1782 0 : else if (IsXMLToken(sValue, XML_DAYS))
1783 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
1784 0 : else if (IsXMLToken(sValue, XML_MONTHS))
1785 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
1786 0 : else if (IsXMLToken(sValue, XML_QUARTERS))
1787 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS;
1788 0 : else if (IsXMLToken(sValue, XML_YEARS))
1789 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::YEARS;
1790 : }
1791 0 : }
1792 0 : pDataPilotField->SetGrouping(sGroupSource, fStart, fEnd, fStep, nGroupPart, bDateValue, bAutoStart, bAutoEnd);
1793 0 : }
1794 :
1795 0 : ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1796 : {
1797 0 : }
1798 :
1799 0 : SvXMLImportContext *ScXMLDataPilotGroupsContext::CreateChildContext( sal_uInt16 nPrefix,
1800 : const ::rtl::OUString& rLName,
1801 : const ::com::sun::star::uno::Reference<
1802 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1803 : {
1804 0 : SvXMLImportContext *pContext = 0;
1805 :
1806 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1807 : {
1808 0 : if (IsXMLToken(rLName, XML_DATA_PILOT_GROUP))
1809 0 : pContext = new ScXMLDataPilotGroupContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1810 : }
1811 :
1812 0 : if( !pContext )
1813 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1814 :
1815 0 : return pContext;
1816 : }
1817 :
1818 0 : void ScXMLDataPilotGroupsContext::EndElement()
1819 : {
1820 0 : }
1821 :
1822 0 : ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport& rImport,
1823 : sal_uInt16 nPrfx,
1824 : const ::rtl::OUString& rLName,
1825 : const ::com::sun::star::uno::Reference<
1826 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1827 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1828 : SvXMLImportContext( rImport, nPrfx, rLName ),
1829 0 : pDataPilotField(pTempDataPilotField)
1830 : {
1831 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1832 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1833 : {
1834 0 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1835 0 : rtl::OUString aLocalName;
1836 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1837 0 : sAttrName, &aLocalName );
1838 0 : rtl::OUString sValue = xAttrList->getValueByIndex( i );
1839 :
1840 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1841 : {
1842 0 : if (IsXMLToken(aLocalName, XML_NAME))
1843 0 : sName = sValue;
1844 : }
1845 0 : }
1846 0 : }
1847 :
1848 0 : ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1849 : {
1850 0 : }
1851 :
1852 0 : SvXMLImportContext *ScXMLDataPilotGroupContext::CreateChildContext( sal_uInt16 nPrefix,
1853 : const ::rtl::OUString& rLName,
1854 : const ::com::sun::star::uno::Reference<
1855 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1856 : {
1857 0 : SvXMLImportContext *pContext = 0;
1858 :
1859 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1860 : {
1861 0 : if (IsXMLToken(rLName, XML_DATA_PILOT_MEMBER))
1862 0 : pContext = new ScXMLDataPilotGroupMemberContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1863 : }
1864 :
1865 0 : if( !pContext )
1866 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1867 :
1868 0 : return pContext;
1869 : }
1870 :
1871 0 : void ScXMLDataPilotGroupContext::EndElement()
1872 : {
1873 0 : pDataPilotField->AddGroup(aMembers, sName);
1874 0 : }
1875 :
1876 0 : ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport& rImport,
1877 : sal_uInt16 nPrfx,
1878 : const ::rtl::OUString& rLName,
1879 : const ::com::sun::star::uno::Reference<
1880 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1881 : ScXMLDataPilotGroupContext* pTempDataPilotGroup) :
1882 : SvXMLImportContext( rImport, nPrfx, rLName ),
1883 0 : pDataPilotGroup(pTempDataPilotGroup)
1884 : {
1885 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1886 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1887 : {
1888 0 : rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
1889 0 : rtl::OUString aLocalName;
1890 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1891 0 : sAttrName, &aLocalName );
1892 0 : rtl::OUString sValue = xAttrList->getValueByIndex( i );
1893 :
1894 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1895 : {
1896 0 : if (IsXMLToken(aLocalName, XML_NAME))
1897 0 : sName = sValue;
1898 : }
1899 0 : }
1900 0 : }
1901 :
1902 0 : ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1903 : {
1904 0 : }
1905 :
1906 0 : SvXMLImportContext *ScXMLDataPilotGroupMemberContext::CreateChildContext( sal_uInt16 nPrefix,
1907 : const ::rtl::OUString& rLName,
1908 : const ::com::sun::star::uno::Reference<
1909 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1910 : {
1911 0 : SvXMLImportContext *pContext = 0;
1912 :
1913 0 : if( !pContext )
1914 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1915 :
1916 0 : return pContext;
1917 : }
1918 :
1919 0 : void ScXMLDataPilotGroupMemberContext::EndElement()
1920 : {
1921 0 : if (!sName.isEmpty())
1922 0 : pDataPilotGroup->AddMember(sName);
1923 15 : }
1924 :
1925 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|