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