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