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 :
58 0 : ScXMLDataPilotTablesContext::ScXMLDataPilotTablesContext( ScXMLImport& rImport,
59 : sal_uInt16 nPrfx,
60 : const OUString& rLName,
61 : const ::com::sun::star::uno::Reference<
62 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
63 0 : SvXMLImportContext( rImport, nPrfx, rLName )
64 : {
65 : // has no Attributes
66 0 : rImport.LockSolarMutex();
67 0 : }
68 :
69 0 : ScXMLDataPilotTablesContext::~ScXMLDataPilotTablesContext()
70 : {
71 0 : GetScImport().UnlockSolarMutex();
72 0 : }
73 :
74 0 : SvXMLImportContext *ScXMLDataPilotTablesContext::CreateChildContext( sal_uInt16 nPrefix,
75 : const OUString& rLName,
76 : const ::com::sun::star::uno::Reference<
77 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
78 : {
79 0 : SvXMLImportContext *pContext = 0;
80 :
81 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTablesElemTokenMap();
82 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
83 : {
84 : case XML_TOK_DATA_PILOT_TABLE :
85 : {
86 : pContext = new ScXMLDataPilotTableContext( GetScImport(), nPrefix,
87 0 : rLName, xAttrList);
88 : }
89 0 : break;
90 : }
91 :
92 0 : if( !pContext )
93 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
94 :
95 0 : return pContext;
96 : }
97 :
98 0 : void ScXMLDataPilotTablesContext::EndElement()
99 : {
100 0 : }
101 :
102 0 : ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
103 0 : mbVisible(true) {}
104 :
105 0 : ScXMLDataPilotTableContext::ScXMLDataPilotTableContext( ScXMLImport& rImport,
106 : sal_uInt16 nPrfx,
107 : const OUString& rLName,
108 : const ::com::sun::star::uno::Reference<
109 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
110 : SvXMLImportContext( rImport, nPrfx, rLName ),
111 0 : pDoc(GetScImport().GetDocument()),
112 : pDPObject(NULL),
113 : pDPDimSaveData(NULL),
114 : sDataPilotTableName(),
115 : sApplicationData(),
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 0 : bHeaderGridLayout(false)
129 : {
130 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
131 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableAttrTokenMap();
132 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
133 : {
134 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
135 0 : OUString aLocalName;
136 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
137 0 : sAttrName, &aLocalName );
138 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
139 :
140 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
141 : {
142 : case XML_TOK_DATA_PILOT_TABLE_ATTR_NAME :
143 : {
144 0 : sDataPilotTableName = sValue;
145 : }
146 0 : break;
147 : case XML_TOK_DATA_PILOT_TABLE_ATTR_APPLICATION_DATA :
148 : {
149 0 : sApplicationData = sValue;
150 : }
151 0 : 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 0 : sal_Int32 nOffset(0);
189 0 : bTargetRangeAddress = ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
190 : }
191 0 : break;
192 : case XML_TOK_DATA_PILOT_TABLE_ATTR_BUTTONS :
193 : {
194 0 : sButtons = sValue;
195 : }
196 0 : 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 0 : }
214 :
215 0 : pDPObject = new ScDPObject(pDoc);
216 0 : pDPSave.reset(new ScDPSaveData());
217 0 : }
218 :
219 0 : ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
220 : {
221 0 : delete pDPDimSaveData;
222 0 : }
223 :
224 0 : 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 0 : SvXMLImportContext *pContext = 0;
230 :
231 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTableElemTokenMap();
232 0 : 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 0 : pContext = new ScXMLSourceCellRangeContext(GetScImport(), nPrefix, rLName, xAttrList, this);
267 0 : nSourceType = CELLRANGE;
268 : }
269 0 : break;
270 : case XML_TOK_DATA_PILOT_TABLE_ELEM_DATA_PILOT_FIELD :
271 0 : pContext = new ScXMLDataPilotFieldContext(GetScImport(), nPrefix, rLName, xAttrList, this);
272 0 : break;
273 : }
274 :
275 0 : if( !pContext )
276 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
277 :
278 0 : return pContext;
279 : }
280 :
281 : namespace {
282 :
283 0 : 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 0 : switch (eType)
290 : {
291 : case ScDPOutputGeometry::Column:
292 : {
293 0 : if (rColDims.size() <= nPos)
294 0 : return NULL;
295 :
296 0 : return rColDims[nPos];
297 : }
298 : case ScDPOutputGeometry::Row:
299 : {
300 0 : if (rRowDims.size() <= nPos)
301 0 : return NULL;
302 :
303 0 : return rRowDims[nPos];
304 : }
305 : case ScDPOutputGeometry::Page:
306 : {
307 0 : if (rPageDims.size() <= nPos)
308 0 : return NULL;
309 :
310 0 : return rPageDims[nPos];
311 : }
312 : case ScDPOutputGeometry::Data:
313 0 : break;
314 : case ScDPOutputGeometry::None:
315 0 : break;
316 : default:
317 0 : break;
318 : }
319 0 : return NULL;
320 : }
321 :
322 0 : ScDPOutputGeometry::FieldType toFieldType(sal_uInt16 nOrient)
323 : {
324 0 : 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 0 : return ScDPOutputGeometry::Row;
334 : case sheet::DataPilotFieldOrientation_HIDDEN:
335 0 : break;
336 : default:
337 0 : break;
338 : }
339 0 : return ScDPOutputGeometry::None;
340 : }
341 :
342 : }
343 :
344 0 : void ScXMLDataPilotTableContext::SetButtons()
345 : {
346 0 : ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter);
347 0 : aGeometry.setColumnFieldCount(mnColFieldCount);
348 0 : aGeometry.setRowFieldCount(mnRowFieldCount);
349 0 : aGeometry.setPageFieldCount(mnPageFieldCount);
350 0 : aGeometry.setDataFieldCount(mnDataFieldCount);
351 0 : aGeometry.setDataLayoutType(toFieldType(mnDataLayoutType));
352 :
353 0 : std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims;
354 0 : pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims);
355 0 : pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims);
356 0 : pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aPageDims);
357 :
358 0 : OUString sAddress;
359 0 : sal_Int32 nOffset = 0;
360 0 : while( nOffset >= 0 )
361 : {
362 0 : ScRangeStringConverter::GetTokenByOffset( sAddress, sButtons, nOffset );
363 0 : if( nOffset >= 0 )
364 : {
365 0 : ScAddress aScAddress;
366 0 : sal_Int32 nAddrOffset(0);
367 0 : if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset ))
368 : {
369 0 : std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress);
370 : const ScDPSaveDimension* pDim = getDimension(
371 0 : aRowDims, aColDims, aPageDims, aBtnType.first, aBtnType.second);
372 :
373 0 : bool bDimension = pDim != NULL;
374 0 : bool bDataLayout = pDim && pDim->IsDataLayout();
375 0 : bool bHasHidden = pDim && pDim->HasInvisibleMember();
376 0 : bool bPageDim = pDim && pDim->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE;
377 :
378 0 : if (bPageDim)
379 : {
380 : // Page dimension needs 2 buttons.
381 :
382 0 : pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), SC_MF_BUTTON);
383 :
384 0 : sal_Int16 nMFlag = SC_MF_BUTTON_POPUP;
385 0 : if (bHasHidden)
386 0 : nMFlag |= SC_MF_HIDDEN_MEMBER;
387 0 : pDoc->ApplyFlagsTab(aScAddress.Col()+1, aScAddress.Row(), aScAddress.Col()+1, aScAddress.Row(), aScAddress.Tab(), nMFlag);
388 : }
389 : else
390 : {
391 0 : sal_Int16 nMFlag = SC_MF_BUTTON;
392 0 : if (bDataLayout)
393 : {
394 : // Data layout dimension only has a plain button with no popup.
395 : }
396 0 : else if (bDimension)
397 : {
398 : // Normal dimension has a popup arrow button.
399 0 : if (bHasHidden)
400 0 : nMFlag |= SC_MF_HIDDEN_MEMBER;
401 :
402 0 : nMFlag |= SC_MF_BUTTON_POPUP;
403 : }
404 :
405 0 : pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag);
406 : }
407 : }
408 : }
409 : }
410 :
411 0 : if ( pDPObject )
412 0 : pDPObject->RefreshAfterLoad();
413 0 : }
414 :
415 0 : void ScXMLDataPilotTableContext::SetSelectedPage( const OUString& rDimName, const OUString& rSelected )
416 : {
417 0 : maSelectedPages.insert(SelectedPagesType::value_type(rDimName, rSelected));
418 0 : }
419 :
420 0 : void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim)
421 : {
422 0 : if (pDPSave)
423 : {
424 0 : if (pDim->IsDataLayout())
425 0 : mnDataLayoutType = pDim->GetOrientation();
426 :
427 : // if a dimension with that name has already been inserted,
428 : // mark the new one as duplicate
429 0 : if ( !pDim->IsDataLayout() &&
430 0 : pDPSave->GetExistingDimensionByName(pDim->GetName()) )
431 0 : pDim->SetDupFlag(true);
432 :
433 0 : switch (pDim->GetOrientation())
434 : {
435 : case sheet::DataPilotFieldOrientation_ROW:
436 0 : ++mnRowFieldCount;
437 0 : break;
438 : case sheet::DataPilotFieldOrientation_COLUMN:
439 0 : ++mnColFieldCount;
440 0 : break;
441 : case sheet::DataPilotFieldOrientation_PAGE:
442 0 : ++mnPageFieldCount;
443 0 : break;
444 : case sheet::DataPilotFieldOrientation_DATA:
445 0 : ++mnDataFieldCount;
446 0 : break;
447 : case sheet::DataPilotFieldOrientation_HIDDEN:
448 0 : break;
449 : default:
450 0 : break;
451 : }
452 :
453 0 : pDPSave->AddDimension(pDim);
454 : }
455 0 : }
456 :
457 0 : void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim)
458 : {
459 0 : if (!pDPDimSaveData)
460 0 : pDPDimSaveData = new ScDPDimensionSaveData();
461 0 : pDPDimSaveData->AddNumGroupDimension(aNumGroupDim);
462 0 : }
463 :
464 0 : void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGroupDim)
465 : {
466 0 : if (!pDPDimSaveData)
467 0 : pDPDimSaveData = new ScDPDimensionSaveData();
468 0 : pDPDimSaveData->AddGroupDimension(aGroupDim);
469 0 : }
470 :
471 0 : void ScXMLDataPilotTableContext::EndElement()
472 : {
473 0 : if (!bTargetRangeAddress)
474 0 : return;
475 :
476 0 : pDPObject->SetName(sDataPilotTableName);
477 0 : pDPObject->SetTag(sApplicationData);
478 0 : pDPObject->SetOutRange(aTargetRangeAddress);
479 0 : pDPObject->SetHeaderLayout(bHeaderGridLayout);
480 :
481 0 : sc::PivotTableSources& rPivotSources = GetScImport().GetPivotTableSources();
482 :
483 0 : 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 0 : if (bSourceCellRange)
523 : {
524 0 : ScSheetSourceDesc aSheetDesc(pDoc);
525 0 : if (!sSourceRangeName.isEmpty())
526 : // Range name takes precedence.
527 0 : aSheetDesc.SetRangeName(sSourceRangeName);
528 : else
529 0 : aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
530 0 : aSheetDesc.SetQueryParam(aSourceQueryParam);
531 0 : rPivotSources.appendSheetSource(pDPObject, aSheetDesc);
532 : }
533 : }
534 0 : break;
535 : }
536 :
537 0 : rPivotSources.appendSelectedPages(pDPObject, maSelectedPages);
538 :
539 0 : pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
540 0 : pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
541 0 : 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 0 : pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
548 0 : pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
549 0 : pDPSave->SetFilterButton(bShowFilter);
550 0 : pDPSave->SetDrillDown(bDrillDown);
551 0 : if (pDPDimSaveData)
552 0 : pDPSave->SetDimensionData(pDPDimSaveData);
553 0 : pDPObject->SetSaveData(*pDPSave);
554 :
555 0 : ScDPCollection* pDPCollection = pDoc->GetDPCollection();
556 :
557 : // #i94570# Names have to be unique, or the tables can't be accessed by API.
558 0 : if ( pDPCollection->GetByName(pDPObject->GetName()) )
559 0 : pDPObject->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading
560 :
561 0 : pDPCollection->InsertNewTable(pDPObject);
562 0 : 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 0 : 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 0 : pDataPilotTable(pTempDataPilotTable)
916 : {
917 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
918 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableSourceCellRangeAttrTokenMap();
919 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
920 : {
921 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
922 0 : OUString aLocalName;
923 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
924 0 : sAttrName, &aLocalName );
925 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
926 :
927 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
928 : {
929 : case XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS :
930 : {
931 0 : ScRange aSourceRangeAddress;
932 0 : sal_Int32 nOffset(0);
933 0 : if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ))
934 0 : pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
935 : }
936 0 : break;
937 : case XML_TOK_SOURCE_CELL_RANGE_ATTR_NAME:
938 0 : pDataPilotTable->SetSourceRangeName(sValue);
939 0 : break;
940 : }
941 0 : }
942 0 : }
943 :
944 0 : ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
945 : {
946 0 : }
947 :
948 0 : 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 0 : SvXMLImportContext *pContext = 0;
954 :
955 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTableSourceCellRangeElemTokenMap();
956 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
957 : {
958 : case XML_TOK_SOURCE_CELL_RANGE_ELEM_FILTER :
959 0 : pContext = new ScXMLDPFilterContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotTable);
960 0 : break;
961 : }
962 :
963 0 : if( !pContext )
964 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
965 :
966 0 : return pContext;
967 : }
968 :
969 0 : void ScXMLSourceCellRangeContext::EndElement()
970 : {
971 0 : }
972 :
973 0 : 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 : bSelectedPage(false),
988 : bIsGroupField(false),
989 : bDateValue(false),
990 : bAutoStart(false),
991 : bAutoEnd(false),
992 0 : mbHasHiddenMember(false)
993 : {
994 0 : bool bHasName = false;
995 0 : bool bDataLayout = false;
996 0 : OUString aDisplayName;
997 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
998 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotFieldAttrTokenMap();
999 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1000 : {
1001 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1002 0 : OUString aLocalName;
1003 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1004 0 : sAttrName, &aLocalName );
1005 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
1006 :
1007 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1008 : {
1009 : case XML_TOK_DATA_PILOT_FIELD_ATTR_SOURCE_FIELD_NAME :
1010 : {
1011 0 : sName = sValue;
1012 0 : bHasName = true;
1013 : }
1014 0 : break;
1015 : case XML_TOK_DATA_PILOT_FIELD_ATTR_DISPLAY_NAME:
1016 : case XML_TOK_DATA_PILOT_FIELD_ATTR_DISPLAY_NAME_EXT:
1017 : {
1018 0 : aDisplayName = sValue;
1019 : }
1020 0 : break;
1021 : case XML_TOK_DATA_PILOT_FIELD_ATTR_IS_DATA_LAYOUT_FIELD :
1022 : {
1023 0 : bDataLayout = IsXMLToken(sValue, XML_TRUE);
1024 : }
1025 0 : break;
1026 : case XML_TOK_DATA_PILOT_FIELD_ATTR_FUNCTION :
1027 : {
1028 0 : nFunction = (sal_Int16) ScXMLConverter::GetFunctionFromString( sValue );
1029 : }
1030 0 : break;
1031 : case XML_TOK_DATA_PILOT_FIELD_ATTR_ORIENTATION :
1032 : {
1033 0 : nOrientation = (sal_Int16) ScXMLConverter::GetOrientationFromString( sValue );
1034 : }
1035 0 : break;
1036 : case XML_TOK_DATA_PILOT_FIELD_ATTR_SELECTED_PAGE :
1037 : {
1038 0 : sSelectedPage = sValue;
1039 0 : bSelectedPage = true;
1040 : }
1041 0 : break;
1042 : case XML_TOK_DATA_PILOT_FIELD_ATTR_USED_HIERARCHY :
1043 : {
1044 0 : nUsedHierarchy = sValue.toInt32();
1045 : }
1046 0 : break;
1047 : }
1048 0 : }
1049 0 : if (bHasName)
1050 : {
1051 0 : pDim = new ScDPSaveDimension(sName, bDataLayout);
1052 0 : if (!aDisplayName.isEmpty())
1053 0 : pDim->SetLayoutName(aDisplayName);
1054 0 : }
1055 0 : }
1056 :
1057 0 : ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
1058 : {
1059 0 : }
1060 :
1061 0 : SvXMLImportContext *ScXMLDataPilotFieldContext::CreateChildContext( sal_uInt16 nPrefix,
1062 : const OUString& rLName,
1063 : const ::com::sun::star::uno::Reference<
1064 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1065 : {
1066 0 : SvXMLImportContext *pContext = 0;
1067 :
1068 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotFieldElemTokenMap();
1069 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
1070 : {
1071 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_LEVEL :
1072 0 : pContext = new ScXMLDataPilotLevelContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1073 0 : break;
1074 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_REFERENCE :
1075 0 : pContext = new ScXMLDataPilotFieldReferenceContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1076 0 : break;
1077 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_GROUPS :
1078 0 : pContext = new ScXMLDataPilotGroupsContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1079 0 : break;
1080 : }
1081 :
1082 0 : if( !pContext )
1083 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1084 :
1085 0 : return pContext;
1086 : }
1087 :
1088 0 : void ScXMLDataPilotFieldContext::AddMember(ScDPSaveMember* pMember)
1089 : {
1090 0 : if (pDim)
1091 : {
1092 0 : pDim->AddMember(pMember);
1093 0 : if (!pMember->GetIsVisible())
1094 : // This member is hidden.
1095 0 : mbHasHiddenMember = true;
1096 : }
1097 : else
1098 0 : delete pMember;
1099 0 : }
1100 :
1101 0 : void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString& rName)
1102 : {
1103 0 : if (pDim)
1104 0 : pDim->SetSubtotalName(rName);
1105 0 : }
1106 :
1107 0 : void ScXMLDataPilotFieldContext::AddGroup(const ::std::vector<OUString>& rMembers, const OUString& rName)
1108 : {
1109 0 : ScXMLDataPilotGroup aGroup;
1110 0 : aGroup.aMembers = rMembers;
1111 0 : aGroup.aName = rName;
1112 0 : aGroups.push_back(aGroup);
1113 0 : }
1114 :
1115 0 : void ScXMLDataPilotFieldContext::EndElement()
1116 : {
1117 0 : if (pDim)
1118 : {
1119 0 : pDim->SetUsedHierarchy(nUsedHierarchy);
1120 0 : pDim->SetFunction(nFunction);
1121 0 : pDim->SetOrientation(nOrientation);
1122 0 : if (bSelectedPage)
1123 : {
1124 0 : pDataPilotTable->SetSelectedPage(pDim->GetName(), sSelectedPage);
1125 : }
1126 0 : pDataPilotTable->AddDimension(pDim);
1127 0 : if (bIsGroupField)
1128 : {
1129 0 : ScDPNumGroupInfo aInfo;
1130 0 : aInfo.mbEnable = true;
1131 0 : aInfo.mbDateValues = bDateValue;
1132 0 : aInfo.mbAutoStart = bAutoStart;
1133 0 : aInfo.mbAutoEnd = bAutoEnd;
1134 0 : aInfo.mfStart = fStart;
1135 0 : aInfo.mfEnd = fEnd;
1136 0 : aInfo.mfStep = fStep;
1137 0 : if (!sGroupSource.isEmpty())
1138 : {
1139 0 : ScDPSaveGroupDimension aGroupDim(sGroupSource, sName);
1140 0 : if (nGroupPart)
1141 0 : aGroupDim.SetDateInfo(aInfo, nGroupPart);
1142 : else
1143 : {
1144 0 : ::std::vector<ScXMLDataPilotGroup>::const_iterator aItr(aGroups.begin());
1145 0 : ::std::vector<ScXMLDataPilotGroup>::const_iterator aEndItr(aGroups.end());
1146 0 : while (aItr != aEndItr)
1147 : {
1148 0 : ScDPSaveGroupItem aItem(aItr->aName);
1149 0 : ::std::vector<OUString>::const_iterator aMembersItr(aItr->aMembers.begin());
1150 0 : ::std::vector<OUString>::const_iterator aMembersEndItr(aItr->aMembers.end());
1151 0 : while (aMembersItr != aMembersEndItr)
1152 : {
1153 0 : aItem.AddElement(*aMembersItr);
1154 0 : ++aMembersItr;
1155 : }
1156 0 : ++aItr;
1157 0 : aGroupDim.AddGroupItem(aItem);
1158 0 : }
1159 : }
1160 0 : pDataPilotTable->AddGroupDim(aGroupDim);
1161 : }
1162 : else //NumGroup
1163 : {
1164 0 : ScDPSaveNumGroupDimension aNumGroupDim(sName, aInfo);
1165 0 : if (nGroupPart)
1166 0 : aNumGroupDim.SetDateInfo(aInfo, nGroupPart);
1167 0 : pDataPilotTable->AddGroupDim(aNumGroupDim);
1168 : }
1169 : }
1170 : }
1171 0 : }
1172 :
1173 0 : ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1174 : const OUString& rLName,
1175 : const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1176 : ScXMLDataPilotFieldContext* pDataPilotField) :
1177 0 : SvXMLImportContext( rImport, nPrfx, rLName )
1178 : {
1179 0 : sheet::DataPilotFieldReference aReference;
1180 :
1181 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1182 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1183 : {
1184 0 : OUString sAttrName(xAttrList->getNameByIndex( i ));
1185 0 : OUString aLocalName;
1186 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1187 0 : sAttrName, &aLocalName );
1188 0 : OUString sValue(xAttrList->getValueByIndex( i ));
1189 :
1190 0 : if ( nPrefix == XML_NAMESPACE_TABLE )
1191 : {
1192 0 : if (IsXMLToken(aLocalName, XML_TYPE))
1193 : {
1194 0 : if (IsXMLToken(sValue, XML_NONE))
1195 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::NONE;
1196 0 : else if (IsXMLToken(sValue, XML_MEMBER_DIFFERENCE))
1197 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE;
1198 0 : else if (IsXMLToken(sValue, XML_MEMBER_PERCENTAGE))
1199 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE;
1200 0 : else if (IsXMLToken(sValue, XML_MEMBER_PERCENTAGE_DIFFERENCE))
1201 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
1202 0 : else if (IsXMLToken(sValue, XML_RUNNING_TOTAL))
1203 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::RUNNING_TOTAL;
1204 0 : else if (IsXMLToken(sValue, XML_ROW_PERCENTAGE))
1205 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE;
1206 0 : else if (IsXMLToken(sValue, XML_COLUMN_PERCENTAGE))
1207 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
1208 0 : else if (IsXMLToken(sValue, XML_TOTAL_PERCENTAGE))
1209 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
1210 0 : else if (IsXMLToken(sValue, XML_INDEX))
1211 0 : aReference.ReferenceType = sheet::DataPilotFieldReferenceType::INDEX;
1212 : }
1213 0 : else if (IsXMLToken(aLocalName, XML_FIELD_NAME))
1214 : {
1215 0 : aReference.ReferenceField = sValue;
1216 : }
1217 0 : else if (IsXMLToken(aLocalName, XML_MEMBER_TYPE))
1218 : {
1219 0 : if (IsXMLToken(sValue, XML_NAMED))
1220 0 : aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
1221 0 : else if (IsXMLToken(sValue, XML_PREVIOUS))
1222 0 : aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::PREVIOUS;
1223 0 : else if (IsXMLToken(sValue, XML_NEXT))
1224 0 : aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NEXT;
1225 : }
1226 0 : else if (IsXMLToken(aLocalName, XML_MEMBER_NAME))
1227 : {
1228 0 : aReference.ReferenceItemName = sValue;
1229 : }
1230 : }
1231 0 : }
1232 0 : pDataPilotField->SetFieldReference(aReference);
1233 0 : }
1234 :
1235 0 : ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1236 : {
1237 0 : }
1238 :
1239 0 : ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport& rImport,
1240 : sal_uInt16 nPrfx,
1241 : const OUString& rLName,
1242 : const ::com::sun::star::uno::Reference<
1243 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1244 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1245 : SvXMLImportContext( rImport, nPrfx, rLName ),
1246 0 : pDataPilotField(pTempDataPilotField)
1247 : {
1248 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1249 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotLevelAttrTokenMap();
1250 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1251 : {
1252 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1253 0 : OUString aLocalName;
1254 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1255 0 : sAttrName, &aLocalName );
1256 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
1257 :
1258 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1259 : {
1260 : case XML_TOK_DATA_PILOT_LEVEL_ATTR_SHOW_EMPTY :
1261 : {
1262 0 : pDataPilotField->SetShowEmpty(IsXMLToken(sValue, XML_TRUE));
1263 : }
1264 0 : break;
1265 : }
1266 0 : }
1267 0 : }
1268 :
1269 0 : ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1270 : {
1271 0 : }
1272 :
1273 0 : SvXMLImportContext *ScXMLDataPilotLevelContext::CreateChildContext( sal_uInt16 nPrefix,
1274 : const OUString& rLName,
1275 : const ::com::sun::star::uno::Reference<
1276 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1277 : {
1278 0 : SvXMLImportContext *pContext = 0;
1279 :
1280 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotLevelElemTokenMap();
1281 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
1282 : {
1283 : case XML_TOK_DATA_PILOT_LEVEL_ELEM_DATA_PILOT_SUBTOTALS :
1284 0 : pContext = new ScXMLDataPilotSubTotalsContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1285 0 : break;
1286 : case XML_TOK_DATA_PILOT_LEVEL_ELEM_DATA_PILOT_MEMBERS :
1287 0 : pContext = new ScXMLDataPilotMembersContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1288 0 : break;
1289 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_DISPLAY_INFO :
1290 0 : pContext = new ScXMLDataPilotDisplayInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1291 0 : break;
1292 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_SORT_INFO :
1293 0 : pContext = new ScXMLDataPilotSortInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1294 0 : break;
1295 : case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_LAYOUT_INFO :
1296 0 : pContext = new ScXMLDataPilotLayoutInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1297 0 : break;
1298 : }
1299 :
1300 0 : if( !pContext )
1301 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1302 :
1303 0 : return pContext;
1304 : }
1305 :
1306 0 : void ScXMLDataPilotLevelContext::EndElement()
1307 : {
1308 0 : }
1309 :
1310 0 : ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1311 : const OUString& rLName,
1312 : const ::com::sun::star::uno::Reference<
1313 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1314 : ScXMLDataPilotFieldContext* pDataPilotField) :
1315 0 : SvXMLImportContext( rImport, nPrfx, rLName )
1316 : {
1317 0 : sheet::DataPilotFieldAutoShowInfo aInfo;
1318 :
1319 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1320 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1321 : {
1322 0 : OUString sAttrName(xAttrList->getNameByIndex( i ));
1323 0 : OUString aLocalName;
1324 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1325 0 : sAttrName, &aLocalName );
1326 0 : OUString sValue(xAttrList->getValueByIndex( i ));
1327 :
1328 0 : if ( nPrefix == XML_NAMESPACE_TABLE )
1329 : {
1330 0 : if (IsXMLToken(aLocalName, XML_ENABLED))
1331 : {
1332 0 : if (IsXMLToken(sValue, XML_TRUE))
1333 0 : aInfo.IsEnabled = sal_True;
1334 : else
1335 0 : aInfo.IsEnabled = false;
1336 : }
1337 0 : else if (IsXMLToken(aLocalName, XML_DISPLAY_MEMBER_MODE))
1338 : {
1339 0 : if (IsXMLToken(sValue, XML_FROM_TOP))
1340 0 : aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_TOP;
1341 0 : else if (IsXMLToken(sValue, XML_FROM_BOTTOM))
1342 0 : aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM;
1343 : }
1344 0 : else if (IsXMLToken(aLocalName, XML_MEMBER_COUNT))
1345 : {
1346 0 : aInfo.ItemCount = sValue.toInt32();
1347 : }
1348 0 : else if (IsXMLToken(aLocalName, XML_DATA_FIELD))
1349 : {
1350 0 : aInfo.DataField = sValue;
1351 : }
1352 : }
1353 0 : }
1354 0 : pDataPilotField->SetAutoShowInfo(aInfo);
1355 0 : }
1356 :
1357 0 : ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1358 : {
1359 0 : }
1360 :
1361 0 : ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1362 : const OUString& rLName,
1363 : const ::com::sun::star::uno::Reference<
1364 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1365 : ScXMLDataPilotFieldContext* pDataPilotField) :
1366 0 : SvXMLImportContext( rImport, nPrfx, rLName )
1367 : {
1368 0 : sheet::DataPilotFieldSortInfo aInfo;
1369 :
1370 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1371 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1372 : {
1373 0 : OUString sAttrName(xAttrList->getNameByIndex( i ));
1374 0 : OUString aLocalName;
1375 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1376 0 : sAttrName, &aLocalName );
1377 0 : OUString sValue(xAttrList->getValueByIndex( i ));
1378 :
1379 0 : if ( nPrefix == XML_NAMESPACE_TABLE )
1380 : {
1381 0 : if (IsXMLToken(aLocalName, XML_ORDER))
1382 : {
1383 0 : if (IsXMLToken(sValue, XML_ASCENDING))
1384 0 : aInfo.IsAscending = sal_True;
1385 0 : else if (IsXMLToken(sValue, XML_DESCENDING))
1386 0 : aInfo.IsAscending = false;
1387 : }
1388 0 : else if (IsXMLToken(aLocalName, XML_SORT_MODE))
1389 : {
1390 0 : if (IsXMLToken(sValue, XML_NONE))
1391 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::NONE;
1392 0 : else if (IsXMLToken(sValue, XML_MANUAL))
1393 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
1394 0 : else if (IsXMLToken(sValue, XML_NAME))
1395 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
1396 0 : else if (IsXMLToken(sValue, XML_DATA))
1397 0 : aInfo.Mode = sheet::DataPilotFieldSortMode::DATA;
1398 : }
1399 0 : else if (IsXMLToken(aLocalName, XML_DATA_FIELD))
1400 0 : aInfo.Field = sValue;
1401 : }
1402 0 : }
1403 0 : pDataPilotField->SetSortInfo(aInfo);
1404 0 : }
1405 :
1406 0 : ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1407 : {
1408 0 : }
1409 :
1410 0 : ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1411 : const OUString& rLName,
1412 : const ::com::sun::star::uno::Reference<
1413 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1414 : ScXMLDataPilotFieldContext* pDataPilotField) :
1415 0 : SvXMLImportContext( rImport, nPrfx, rLName )
1416 : {
1417 0 : sheet::DataPilotFieldLayoutInfo aInfo;
1418 :
1419 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1420 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1421 : {
1422 0 : OUString sAttrName(xAttrList->getNameByIndex( i ));
1423 0 : OUString aLocalName;
1424 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1425 0 : sAttrName, &aLocalName );
1426 0 : OUString sValue(xAttrList->getValueByIndex( i ));
1427 :
1428 0 : if ( nPrefix == XML_NAMESPACE_TABLE )
1429 : {
1430 0 : if (IsXMLToken(aLocalName, XML_ADD_EMPTY_LINES))
1431 : {
1432 0 : if (IsXMLToken(sValue, XML_TRUE))
1433 0 : aInfo.AddEmptyLines = sal_True;
1434 : else
1435 0 : aInfo.AddEmptyLines = false;
1436 : }
1437 0 : else if (IsXMLToken(aLocalName, XML_LAYOUT_MODE))
1438 : {
1439 0 : if (IsXMLToken(sValue, XML_TABULAR_LAYOUT))
1440 0 : aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
1441 0 : else if (IsXMLToken(sValue, XML_OUTLINE_SUBTOTALS_TOP))
1442 0 : aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
1443 0 : else if (IsXMLToken(sValue, XML_OUTLINE_SUBTOTALS_BOTTOM))
1444 0 : aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
1445 : }
1446 : }
1447 0 : }
1448 0 : pDataPilotField->SetLayoutInfo(aInfo);}
1449 :
1450 0 : ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1451 : {
1452 0 : }
1453 :
1454 0 : ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport,
1455 : sal_uInt16 nPrfx,
1456 : const OUString& rLName,
1457 : const ::com::sun::star::uno::Reference<
1458 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
1459 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1460 : SvXMLImportContext( rImport, nPrfx, rLName ),
1461 : pDataPilotField(pTempDataPilotField),
1462 : nFunctionCount(0),
1463 0 : pFunctions(NULL)
1464 : {
1465 :
1466 : // has no attributes
1467 0 : }
1468 :
1469 0 : ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1470 : {
1471 0 : }
1472 :
1473 0 : SvXMLImportContext *ScXMLDataPilotSubTotalsContext::CreateChildContext( sal_uInt16 nPrefix,
1474 : const OUString& rLName,
1475 : const ::com::sun::star::uno::Reference<
1476 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1477 : {
1478 0 : SvXMLImportContext *pContext = 0;
1479 :
1480 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotSubTotalsElemTokenMap();
1481 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
1482 : {
1483 : case XML_TOK_DATA_PILOT_SUBTOTALS_ELEM_DATA_PILOT_SUBTOTAL :
1484 0 : pContext = new ScXMLDataPilotSubTotalContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1485 0 : break;
1486 : }
1487 :
1488 0 : if( !pContext )
1489 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1490 :
1491 0 : return pContext;
1492 : }
1493 :
1494 0 : void ScXMLDataPilotSubTotalsContext::EndElement()
1495 : {
1496 0 : pDataPilotField->SetSubTotals(pFunctions, nFunctionCount);
1497 0 : if (!maDisplayName.isEmpty())
1498 0 : pDataPilotField->SetSubTotalName(maDisplayName);
1499 0 : }
1500 :
1501 0 : void ScXMLDataPilotSubTotalsContext::AddFunction(sal_Int16 nFunction)
1502 : {
1503 0 : if (nFunctionCount)
1504 : {
1505 0 : ++nFunctionCount;
1506 0 : sal_uInt16* pTemp = new sal_uInt16[nFunctionCount];
1507 0 : for (sal_Int16 i = 0; i < nFunctionCount - 1; ++i)
1508 0 : pTemp[i] = pFunctions[i];
1509 0 : pTemp[nFunctionCount - 1] = nFunction;
1510 0 : delete[] pFunctions;
1511 0 : pFunctions = pTemp;
1512 : }
1513 : else
1514 : {
1515 0 : nFunctionCount = 1;
1516 0 : pFunctions = new sal_uInt16[nFunctionCount];
1517 0 : pFunctions[0] = nFunction;
1518 : }
1519 0 : }
1520 :
1521 0 : void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
1522 : {
1523 0 : maDisplayName = rName;
1524 0 : }
1525 :
1526 0 : ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport& rImport,
1527 : sal_uInt16 nPrfx,
1528 : const OUString& rLName,
1529 : const ::com::sun::star::uno::Reference<
1530 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1531 : ScXMLDataPilotSubTotalsContext* pTempDataPilotSubTotals) :
1532 : SvXMLImportContext( rImport, nPrfx, rLName ),
1533 0 : pDataPilotSubTotals(pTempDataPilotSubTotals)
1534 : {
1535 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1536 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotSubTotalAttrTokenMap();
1537 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1538 : {
1539 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1540 0 : OUString aLocalName;
1541 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1542 0 : sAttrName, &aLocalName );
1543 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
1544 :
1545 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1546 : {
1547 : case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_FUNCTION :
1548 : {
1549 : pDataPilotSubTotals->AddFunction( sal::static_int_cast<sal_Int16>(
1550 0 : ScXMLConverter::GetFunctionFromString( sValue ) ) );
1551 : }
1552 0 : break;
1553 : case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_DISPLAY_NAME:
1554 : case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_DISPLAY_NAME_EXT:
1555 0 : pDataPilotSubTotals->SetDisplayName(sValue);
1556 0 : break;
1557 : }
1558 0 : }
1559 0 : }
1560 :
1561 0 : ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1562 : {
1563 0 : }
1564 :
1565 0 : SvXMLImportContext *ScXMLDataPilotSubTotalContext::CreateChildContext( sal_uInt16 nPrefix,
1566 : const OUString& rLName,
1567 : const ::com::sun::star::uno::Reference<
1568 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1569 : {
1570 0 : SvXMLImportContext *pContext = 0;
1571 :
1572 0 : if( !pContext )
1573 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1574 :
1575 0 : return pContext;
1576 : }
1577 :
1578 0 : void ScXMLDataPilotSubTotalContext::EndElement()
1579 : {
1580 0 : }
1581 :
1582 0 : ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport& rImport,
1583 : sal_uInt16 nPrfx,
1584 : const OUString& rLName,
1585 : const ::com::sun::star::uno::Reference<
1586 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
1587 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1588 : SvXMLImportContext( rImport, nPrfx, rLName ),
1589 0 : pDataPilotField(pTempDataPilotField)
1590 : {
1591 : // has no attributes
1592 0 : }
1593 :
1594 0 : ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1595 : {
1596 0 : }
1597 :
1598 0 : SvXMLImportContext *ScXMLDataPilotMembersContext::CreateChildContext( sal_uInt16 nPrefix,
1599 : const OUString& rLName,
1600 : const ::com::sun::star::uno::Reference<
1601 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1602 : {
1603 0 : SvXMLImportContext *pContext = 0;
1604 :
1605 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotMembersElemTokenMap();
1606 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
1607 : {
1608 : case XML_TOK_DATA_PILOT_MEMBERS_ELEM_DATA_PILOT_MEMBER :
1609 0 : pContext = new ScXMLDataPilotMemberContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1610 0 : break;
1611 : }
1612 :
1613 0 : if( !pContext )
1614 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1615 :
1616 0 : return pContext;
1617 : }
1618 :
1619 0 : void ScXMLDataPilotMembersContext::EndElement()
1620 : {
1621 0 : }
1622 :
1623 0 : ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport& rImport,
1624 : sal_uInt16 nPrfx,
1625 : const OUString& rLName,
1626 : const ::com::sun::star::uno::Reference<
1627 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1628 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1629 : SvXMLImportContext( rImport, nPrfx, rLName ),
1630 : pDataPilotField(pTempDataPilotField),
1631 : bDisplay( true ),
1632 : bDisplayDetails( true ),
1633 0 : bHasName( false )
1634 : {
1635 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1636 0 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotMemberAttrTokenMap();
1637 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
1638 : {
1639 0 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1640 0 : OUString aLocalName;
1641 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1642 0 : sAttrName, &aLocalName );
1643 0 : const OUString& sValue(xAttrList->getValueByIndex( i ));
1644 :
1645 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1646 : {
1647 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_NAME :
1648 : {
1649 0 : sName = sValue;
1650 0 : bHasName = true;
1651 : }
1652 0 : break;
1653 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY_NAME:
1654 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY_NAME_EXT:
1655 : {
1656 0 : maDisplayName = sValue;
1657 : }
1658 0 : break;
1659 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY :
1660 : {
1661 0 : bDisplay = IsXMLToken(sValue, XML_TRUE);
1662 : }
1663 0 : break;
1664 : case XML_TOK_DATA_PILOT_MEMBER_ATTR_SHOW_DETAILS :
1665 : {
1666 0 : bDisplayDetails = IsXMLToken(sValue, XML_TRUE);
1667 : }
1668 0 : break;
1669 : }
1670 0 : }
1671 0 : }
1672 :
1673 0 : ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1674 : {
1675 0 : }
1676 :
1677 0 : SvXMLImportContext *ScXMLDataPilotMemberContext::CreateChildContext( sal_uInt16 nPrefix,
1678 : const OUString& rLName,
1679 : const ::com::sun::star::uno::Reference<
1680 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1681 : {
1682 0 : SvXMLImportContext *pContext = 0;
1683 :
1684 0 : if( !pContext )
1685 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1686 :
1687 0 : return pContext;
1688 : }
1689 :
1690 0 : void ScXMLDataPilotMemberContext::EndElement()
1691 : {
1692 0 : if (bHasName) // #i53407# don't check sName, empty name is allowed
1693 : {
1694 0 : ScDPSaveMember* pMember = new ScDPSaveMember(sName);
1695 0 : if (!maDisplayName.isEmpty())
1696 0 : pMember->SetLayoutName(maDisplayName);
1697 0 : pMember->SetIsVisible(bDisplay);
1698 0 : pMember->SetShowDetails(bDisplayDetails);
1699 0 : pDataPilotField->AddMember(pMember);
1700 : }
1701 0 : }
1702 :
1703 0 : ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport& rImport,
1704 : sal_uInt16 nPrfx,
1705 : const OUString& rLName,
1706 : const ::com::sun::star::uno::Reference<
1707 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1708 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1709 : SvXMLImportContext( rImport, nPrfx, rLName ),
1710 0 : pDataPilotField(pTempDataPilotField)
1711 : {
1712 0 : OUString sGroupSource;
1713 0 : double fStart(0.0);
1714 0 : double fEnd(0.0);
1715 0 : double fStep(0.0);
1716 0 : sal_Int32 nGroupPart(0);
1717 0 : sal_Bool bDateValue(false);
1718 0 : sal_Bool bAutoStart(sal_True);
1719 0 : sal_Bool bAutoEnd(sal_True);
1720 :
1721 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1722 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1723 : {
1724 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
1725 0 : OUString aLocalName;
1726 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1727 0 : sAttrName, &aLocalName );
1728 0 : OUString sValue = xAttrList->getValueByIndex( i );
1729 :
1730 : (void)nPrefix; //! compare below!
1731 :
1732 0 : if (IsXMLToken(aLocalName, XML_SOURCE_FIELD_NAME))
1733 0 : sGroupSource = sValue;
1734 0 : else if (IsXMLToken(aLocalName, XML_DATE_START))
1735 : {
1736 0 : bDateValue = sal_True;
1737 0 : if (IsXMLToken(sValue, XML_AUTO))
1738 0 : bAutoStart = sal_True;
1739 : else
1740 : {
1741 0 : GetScImport().GetMM100UnitConverter().convertDateTime(fStart, sValue);
1742 0 : bAutoStart = false;
1743 : }
1744 : }
1745 0 : else if (IsXMLToken(aLocalName, XML_DATE_END))
1746 : {
1747 0 : bDateValue = sal_True;
1748 0 : if (IsXMLToken(sValue, XML_AUTO))
1749 0 : bAutoEnd = sal_True;
1750 : else
1751 : {
1752 0 : GetScImport().GetMM100UnitConverter().convertDateTime(fEnd, sValue);
1753 0 : bAutoEnd = false;
1754 : }
1755 : }
1756 0 : else if (IsXMLToken(aLocalName, XML_START))
1757 : {
1758 0 : if (IsXMLToken(sValue, XML_AUTO))
1759 0 : bAutoStart = sal_True;
1760 : else
1761 : {
1762 0 : ::sax::Converter::convertDouble(fStart, sValue);
1763 0 : bAutoStart = false;
1764 : }
1765 : }
1766 0 : else if (IsXMLToken(aLocalName, XML_END))
1767 : {
1768 0 : if (IsXMLToken(sValue, XML_AUTO))
1769 0 : bAutoEnd = sal_True;
1770 : else
1771 : {
1772 0 : ::sax::Converter::convertDouble(fEnd, sValue);
1773 0 : bAutoEnd = false;
1774 : }
1775 : }
1776 0 : else if (IsXMLToken(aLocalName, XML_STEP))
1777 : {
1778 0 : ::sax::Converter::convertDouble(fStep, sValue);
1779 : }
1780 0 : else if (IsXMLToken(aLocalName, XML_GROUPED_BY))
1781 : {
1782 0 : if (IsXMLToken(sValue, XML_SECONDS))
1783 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS;
1784 0 : else if (IsXMLToken(sValue, XML_MINUTES))
1785 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES;
1786 0 : else if (IsXMLToken(sValue, XML_HOURS))
1787 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::HOURS;
1788 0 : else if (IsXMLToken(sValue, XML_DAYS))
1789 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
1790 0 : else if (IsXMLToken(sValue, XML_MONTHS))
1791 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
1792 0 : else if (IsXMLToken(sValue, XML_QUARTERS))
1793 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS;
1794 0 : else if (IsXMLToken(sValue, XML_YEARS))
1795 0 : nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::YEARS;
1796 : }
1797 0 : }
1798 0 : pDataPilotField->SetGrouping(sGroupSource, fStart, fEnd, fStep, nGroupPart, bDateValue, bAutoStart, bAutoEnd);
1799 0 : }
1800 :
1801 0 : ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1802 : {
1803 0 : }
1804 :
1805 0 : SvXMLImportContext *ScXMLDataPilotGroupsContext::CreateChildContext( sal_uInt16 nPrefix,
1806 : const OUString& rLName,
1807 : const ::com::sun::star::uno::Reference<
1808 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1809 : {
1810 0 : SvXMLImportContext *pContext = 0;
1811 :
1812 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1813 : {
1814 0 : if (IsXMLToken(rLName, XML_DATA_PILOT_GROUP))
1815 0 : pContext = new ScXMLDataPilotGroupContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1816 : }
1817 :
1818 0 : if( !pContext )
1819 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1820 :
1821 0 : return pContext;
1822 : }
1823 :
1824 0 : void ScXMLDataPilotGroupsContext::EndElement()
1825 : {
1826 0 : }
1827 :
1828 0 : ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport& rImport,
1829 : sal_uInt16 nPrfx,
1830 : const OUString& rLName,
1831 : const ::com::sun::star::uno::Reference<
1832 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1833 : ScXMLDataPilotFieldContext* pTempDataPilotField) :
1834 : SvXMLImportContext( rImport, nPrfx, rLName ),
1835 0 : pDataPilotField(pTempDataPilotField)
1836 : {
1837 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1838 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1839 : {
1840 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
1841 0 : OUString aLocalName;
1842 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1843 0 : sAttrName, &aLocalName );
1844 0 : OUString sValue = xAttrList->getValueByIndex( i );
1845 :
1846 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1847 : {
1848 0 : if (IsXMLToken(aLocalName, XML_NAME))
1849 0 : sName = sValue;
1850 : }
1851 0 : }
1852 0 : }
1853 :
1854 0 : ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1855 : {
1856 0 : }
1857 :
1858 0 : SvXMLImportContext *ScXMLDataPilotGroupContext::CreateChildContext( sal_uInt16 nPrefix,
1859 : const OUString& rLName,
1860 : const ::com::sun::star::uno::Reference<
1861 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1862 : {
1863 0 : SvXMLImportContext *pContext = 0;
1864 :
1865 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1866 : {
1867 0 : if (IsXMLToken(rLName, XML_DATA_PILOT_MEMBER))
1868 0 : pContext = new ScXMLDataPilotGroupMemberContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1869 : }
1870 :
1871 0 : if( !pContext )
1872 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1873 :
1874 0 : return pContext;
1875 : }
1876 :
1877 0 : void ScXMLDataPilotGroupContext::EndElement()
1878 : {
1879 0 : pDataPilotField->AddGroup(aMembers, sName);
1880 0 : }
1881 :
1882 0 : ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport& rImport,
1883 : sal_uInt16 nPrfx,
1884 : const OUString& rLName,
1885 : const ::com::sun::star::uno::Reference<
1886 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1887 : ScXMLDataPilotGroupContext* pTempDataPilotGroup) :
1888 : SvXMLImportContext( rImport, nPrfx, rLName ),
1889 0 : pDataPilotGroup(pTempDataPilotGroup)
1890 : {
1891 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1892 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
1893 : {
1894 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
1895 0 : OUString aLocalName;
1896 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1897 0 : sAttrName, &aLocalName );
1898 0 : OUString sValue = xAttrList->getValueByIndex( i );
1899 :
1900 0 : if (nPrefix == XML_NAMESPACE_TABLE)
1901 : {
1902 0 : if (IsXMLToken(aLocalName, XML_NAME))
1903 0 : sName = sValue;
1904 : }
1905 0 : }
1906 0 : }
1907 :
1908 0 : ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1909 : {
1910 0 : }
1911 :
1912 0 : SvXMLImportContext *ScXMLDataPilotGroupMemberContext::CreateChildContext( sal_uInt16 nPrefix,
1913 : const OUString& rLName,
1914 : const ::com::sun::star::uno::Reference<
1915 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1916 : {
1917 0 : SvXMLImportContext *pContext = 0;
1918 :
1919 0 : if( !pContext )
1920 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1921 :
1922 0 : return pContext;
1923 : }
1924 :
1925 0 : void ScXMLDataPilotGroupMemberContext::EndElement()
1926 : {
1927 0 : if (!sName.isEmpty())
1928 0 : pDataPilotGroup->AddMember(sName);
1929 0 : }
1930 :
1931 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|