Bump version to 4.3-4
[LibreOffice.git] / sc / source / filter / xml / xmldpimp.cxx
blobdb4cb90eceb50eda69c9a66048e931d73201d764
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
35 #include "pivotsource.hxx"
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>
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>
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;
58 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 SvXMLImportContext( rImport, nPrfx, rLName )
65 // has no Attributes
66 rImport.LockSolarMutex();
69 ScXMLDataPilotTablesContext::~ScXMLDataPilotTablesContext()
71 GetScImport().UnlockSolarMutex();
74 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 )
79 SvXMLImportContext *pContext = 0;
81 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTablesElemTokenMap();
82 switch( rTokenMap.Get( nPrefix, rLName ) )
84 case XML_TOK_DATA_PILOT_TABLE :
86 pContext = new ScXMLDataPilotTableContext( GetScImport(), nPrefix,
87 rLName, xAttrList);
89 break;
92 if( !pContext )
93 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
95 return pContext;
98 void ScXMLDataPilotTablesContext::EndElement()
102 ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
103 mbVisible(true) {}
105 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 pDoc(GetScImport().GetDocument()),
112 pDPObject(NULL),
113 pDPDimSaveData(NULL),
114 sDataPilotTableName(),
115 sApplicationData(),
116 nSourceType(SQL),
117 mnRowFieldCount(0),
118 mnColFieldCount(0),
119 mnPageFieldCount(0),
120 mnDataFieldCount(0),
121 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN),
122 bIsNative(true),
123 bIgnoreEmptyRows(false),
124 bIdentifyCategories(false),
125 bTargetRangeAddress(false),
126 bSourceCellRange(false),
127 bShowFilter(true),
128 bDrillDown(true),
129 bHeaderGridLayout(false)
131 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
132 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableAttrTokenMap();
133 for( sal_Int16 i=0; i < nAttrCount; ++i )
135 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
136 OUString aLocalName;
137 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
138 sAttrName, &aLocalName );
139 const OUString& sValue(xAttrList->getValueByIndex( i ));
141 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
143 case XML_TOK_DATA_PILOT_TABLE_ATTR_NAME :
145 sDataPilotTableName = sValue;
147 break;
148 case XML_TOK_DATA_PILOT_TABLE_ATTR_APPLICATION_DATA :
150 sApplicationData = sValue;
152 break;
153 case XML_TOK_DATA_PILOT_TABLE_ATTR_GRAND_TOTAL :
155 if (IsXMLToken(sValue, XML_BOTH))
157 maRowGrandTotal.mbVisible = true;
158 maColGrandTotal.mbVisible = true;
160 else if (IsXMLToken(sValue, XML_ROW))
162 maRowGrandTotal.mbVisible = true;
163 maColGrandTotal.mbVisible = false;
165 else if (IsXMLToken(sValue, XML_COLUMN))
167 maRowGrandTotal.mbVisible = false;
168 maColGrandTotal.mbVisible = true;
170 else
172 maRowGrandTotal.mbVisible = false;
173 maColGrandTotal.mbVisible = false;
176 break;
177 case XML_TOK_DATA_PILOT_TABLE_ATTR_IGNORE_EMPTY_ROWS :
179 bIgnoreEmptyRows = IsXMLToken(sValue, XML_TRUE);
181 break;
182 case XML_TOK_DATA_PILOT_TABLE_ATTR_IDENTIFY_CATEGORIES :
184 bIdentifyCategories = IsXMLToken(sValue, XML_TRUE);
186 break;
187 case XML_TOK_DATA_PILOT_TABLE_ATTR_TARGET_RANGE_ADDRESS :
189 sal_Int32 nOffset(0);
190 bTargetRangeAddress = ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
192 break;
193 case XML_TOK_DATA_PILOT_TABLE_ATTR_BUTTONS :
195 sButtons = sValue;
197 break;
198 case XML_TOK_DATA_PILOT_TABLE_ATTR_SHOW_FILTER_BUTTON :
200 bShowFilter = IsXMLToken(sValue, XML_TRUE);
202 break;
203 case XML_TOK_DATA_PILOT_TABLE_ATTR_DRILL_DOWN :
205 bDrillDown = IsXMLToken(sValue, XML_TRUE);
207 break;
208 case XML_TOK_DATA_PILOT_TABLE_ATTR_HEADER_GRID_LAYOUT :
210 bHeaderGridLayout = IsXMLToken(sValue, XML_TRUE);
212 break;
216 pDPObject = new ScDPObject(pDoc);
217 pDPSave.reset(new ScDPSaveData());
220 ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
222 delete pDPDimSaveData;
225 SvXMLImportContext *ScXMLDataPilotTableContext::CreateChildContext( sal_uInt16 nPrefix,
226 const OUString& rLName,
227 const ::com::sun::star::uno::Reference<
228 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
230 SvXMLImportContext *pContext = 0;
232 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTableElemTokenMap();
233 switch( rTokenMap.Get( nPrefix, rLName ) )
235 case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_SQL :
237 pContext = new ScXMLDPSourceSQLContext(GetScImport(), nPrefix, rLName, xAttrList, this);
238 nSourceType = SQL;
240 break;
241 case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_TABLE :
243 pContext = new ScXMLDPSourceTableContext(GetScImport(), nPrefix, rLName, xAttrList, this);
244 nSourceType = TABLE;
246 break;
247 case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_QUERY :
249 pContext = new ScXMLDPSourceQueryContext(GetScImport(), nPrefix, rLName, xAttrList, this);
250 nSourceType = QUERY;
252 break;
253 case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_SERVICE :
255 pContext = new ScXMLSourceServiceContext(GetScImport(), nPrefix, rLName, xAttrList, this);
256 nSourceType = SERVICE;
258 break;
259 case XML_TOK_DATA_PILOT_TABLE_ELEM_GRAND_TOTAL:
260 case XML_TOK_DATA_PILOT_TABLE_ELEM_GRAND_TOTAL_EXT:
262 pContext = new ScXMLDataPilotGrandTotalContext(GetScImport(), nPrefix, rLName, xAttrList, this);
264 break;
265 case XML_TOK_DATA_PILOT_TABLE_ELEM_SOURCE_CELL_RANGE :
267 pContext = new ScXMLSourceCellRangeContext(GetScImport(), nPrefix, rLName, xAttrList, this);
268 nSourceType = CELLRANGE;
270 break;
271 case XML_TOK_DATA_PILOT_TABLE_ELEM_DATA_PILOT_FIELD :
272 pContext = new ScXMLDataPilotFieldContext(GetScImport(), nPrefix, rLName, xAttrList, this);
273 break;
276 if( !pContext )
277 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
279 return pContext;
282 namespace {
284 const ScDPSaveDimension* getDimension(
285 const std::vector<const ScDPSaveDimension*>& rRowDims,
286 const std::vector<const ScDPSaveDimension*>& rColDims,
287 const std::vector<const ScDPSaveDimension*>& rPageDims,
288 ScDPOutputGeometry::FieldType eType, size_t nPos)
290 switch (eType)
292 case ScDPOutputGeometry::Column:
294 if (rColDims.size() <= nPos)
295 return NULL;
297 return rColDims[nPos];
299 case ScDPOutputGeometry::Row:
301 if (rRowDims.size() <= nPos)
302 return NULL;
304 return rRowDims[nPos];
306 case ScDPOutputGeometry::Page:
308 if (rPageDims.size() <= nPos)
309 return NULL;
311 return rPageDims[nPos];
313 case ScDPOutputGeometry::Data:
314 break;
315 case ScDPOutputGeometry::None:
316 break;
317 default:
318 break;
320 return NULL;
323 ScDPOutputGeometry::FieldType toFieldType(sal_uInt16 nOrient)
325 switch (nOrient)
327 case sheet::DataPilotFieldOrientation_COLUMN:
328 return ScDPOutputGeometry::Column;
329 case sheet::DataPilotFieldOrientation_DATA:
330 return ScDPOutputGeometry::Data;
331 case sheet::DataPilotFieldOrientation_PAGE:
332 return ScDPOutputGeometry::Page;
333 case sheet::DataPilotFieldOrientation_ROW:
334 return ScDPOutputGeometry::Row;
335 case sheet::DataPilotFieldOrientation_HIDDEN:
336 break;
337 default:
338 break;
340 return ScDPOutputGeometry::None;
345 void ScXMLDataPilotTableContext::SetButtons()
347 ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter);
348 aGeometry.setColumnFieldCount(mnColFieldCount);
349 aGeometry.setRowFieldCount(mnRowFieldCount);
350 aGeometry.setPageFieldCount(mnPageFieldCount);
351 aGeometry.setDataFieldCount(mnDataFieldCount);
352 aGeometry.setDataLayoutType(toFieldType(mnDataLayoutType));
354 std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims;
355 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims);
356 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims);
357 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aPageDims);
359 OUString sAddress;
360 sal_Int32 nOffset = 0;
361 while( nOffset >= 0 )
363 ScRangeStringConverter::GetTokenByOffset( sAddress, sButtons, nOffset );
364 if( nOffset >= 0 )
366 ScAddress aScAddress;
367 sal_Int32 nAddrOffset(0);
368 if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset ))
370 std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress);
371 const ScDPSaveDimension* pDim = getDimension(
372 aRowDims, aColDims, aPageDims, aBtnType.first, aBtnType.second);
374 bool bDimension = pDim != NULL;
375 bool bDataLayout = pDim && pDim->IsDataLayout();
376 bool bHasHidden = pDim && pDim->HasInvisibleMember();
377 bool bPageDim = pDim && pDim->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE;
379 if (bPageDim)
381 // Page dimension needs 2 buttons.
383 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), SC_MF_BUTTON);
385 sal_Int16 nMFlag = SC_MF_BUTTON_POPUP;
386 if (bHasHidden)
387 nMFlag |= SC_MF_HIDDEN_MEMBER;
388 pDoc->ApplyFlagsTab(aScAddress.Col()+1, aScAddress.Row(), aScAddress.Col()+1, aScAddress.Row(), aScAddress.Tab(), nMFlag);
390 else
392 sal_Int16 nMFlag = SC_MF_BUTTON;
393 if (bDataLayout)
395 // Data layout dimension only has a plain button with no popup.
397 else if (bDimension)
399 // Normal dimension has a popup arrow button.
400 if (bHasHidden)
401 nMFlag |= SC_MF_HIDDEN_MEMBER;
403 nMFlag |= SC_MF_BUTTON_POPUP;
406 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag);
412 if ( pDPObject )
413 pDPObject->RefreshAfterLoad();
416 void ScXMLDataPilotTableContext::SetSelectedPage( const OUString& rDimName, const OUString& rSelected )
418 maSelectedPages.insert(SelectedPagesType::value_type(rDimName, rSelected));
421 void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim)
423 if (pDPSave)
425 if (pDim->IsDataLayout())
426 mnDataLayoutType = pDim->GetOrientation();
428 // if a dimension with that name has already been inserted,
429 // mark the new one as duplicate
430 if ( !pDim->IsDataLayout() &&
431 pDPSave->GetExistingDimensionByName(pDim->GetName()) )
432 pDim->SetDupFlag(true);
434 switch (pDim->GetOrientation())
436 case sheet::DataPilotFieldOrientation_ROW:
437 ++mnRowFieldCount;
438 break;
439 case sheet::DataPilotFieldOrientation_COLUMN:
440 ++mnColFieldCount;
441 break;
442 case sheet::DataPilotFieldOrientation_PAGE:
443 ++mnPageFieldCount;
444 break;
445 case sheet::DataPilotFieldOrientation_DATA:
446 ++mnDataFieldCount;
447 break;
448 case sheet::DataPilotFieldOrientation_HIDDEN:
449 break;
450 default:
451 break;
454 pDPSave->AddDimension(pDim);
458 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim)
460 if (!pDPDimSaveData)
461 pDPDimSaveData = new ScDPDimensionSaveData();
462 pDPDimSaveData->AddNumGroupDimension(aNumGroupDim);
465 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGroupDim)
467 if (!pDPDimSaveData)
468 pDPDimSaveData = new ScDPDimensionSaveData();
469 pDPDimSaveData->AddGroupDimension(aGroupDim);
472 void ScXMLDataPilotTableContext::EndElement()
474 if (!bTargetRangeAddress)
475 return;
477 pDPObject->SetName(sDataPilotTableName);
478 pDPObject->SetTag(sApplicationData);
479 pDPObject->SetOutRange(aTargetRangeAddress);
480 pDPObject->SetHeaderLayout(bHeaderGridLayout);
482 sc::PivotTableSources& rPivotSources = GetScImport().GetPivotTableSources();
484 switch (nSourceType)
486 case SQL :
488 ScImportSourceDesc aImportDesc(pDoc);
489 aImportDesc.aDBName = sDatabaseName;
490 aImportDesc.aObject = sSourceObject;
491 aImportDesc.nType = sheet::DataImportMode_SQL;
492 aImportDesc.bNative = bIsNative;
493 rPivotSources.appendDBSource(pDPObject, aImportDesc);
495 break;
496 case TABLE :
498 ScImportSourceDesc aImportDesc(pDoc);
499 aImportDesc.aDBName = sDatabaseName;
500 aImportDesc.aObject = sSourceObject;
501 aImportDesc.nType = sheet::DataImportMode_TABLE;
502 rPivotSources.appendDBSource(pDPObject, aImportDesc);
504 break;
505 case QUERY :
507 ScImportSourceDesc aImportDesc(pDoc);
508 aImportDesc.aDBName = sDatabaseName;
509 aImportDesc.aObject = sSourceObject;
510 aImportDesc.nType = sheet::DataImportMode_QUERY;
511 rPivotSources.appendDBSource(pDPObject, aImportDesc);
513 break;
514 case SERVICE :
516 ScDPServiceDesc aServiceDesc(sServiceName, sServiceSourceName, sServiceSourceObject,
517 sServiceUsername, sServicePassword);
518 rPivotSources.appendServiceSource(pDPObject, aServiceDesc);
520 break;
521 case CELLRANGE :
523 if (bSourceCellRange)
525 ScSheetSourceDesc aSheetDesc(pDoc);
526 if (!sSourceRangeName.isEmpty())
527 // Range name takes precedence.
528 aSheetDesc.SetRangeName(sSourceRangeName);
529 else
530 aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
531 aSheetDesc.SetQueryParam(aSourceQueryParam);
532 rPivotSources.appendSheetSource(pDPObject, aSheetDesc);
535 break;
538 rPivotSources.appendSelectedPages(pDPObject, maSelectedPages);
540 pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
541 pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
542 if (!maRowGrandTotal.maDisplayName.isEmpty())
543 // TODO: Right now, we only support one grand total name for both
544 // column and row totals. Take the value from the row total for
545 // now.
546 pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
548 pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
549 pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
550 pDPSave->SetFilterButton(bShowFilter);
551 pDPSave->SetDrillDown(bDrillDown);
552 if (pDPDimSaveData)
553 pDPSave->SetDimensionData(pDPDimSaveData);
554 pDPObject->SetSaveData(*pDPSave);
556 ScDPCollection* pDPCollection = pDoc->GetDPCollection();
558 // #i94570# Names have to be unique, or the tables can't be accessed by API.
559 if ( pDPCollection->GetByName(pDPObject->GetName()) )
560 pDPObject->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading
562 pDPCollection->InsertNewTable(pDPObject);
563 SetButtons();
566 void ScXMLDataPilotTableContext::SetGrandTotal(
567 XMLTokenEnum eOrientation, bool bVisible, const OUString& rDisplayName)
569 switch (eOrientation)
571 case XML_BOTH:
572 maRowGrandTotal.mbVisible = bVisible;
573 maRowGrandTotal.maDisplayName = rDisplayName;
574 maColGrandTotal.mbVisible = bVisible;
575 maColGrandTotal.maDisplayName = rDisplayName;
576 break;
577 case XML_ROW:
578 maRowGrandTotal.mbVisible = bVisible;
579 maRowGrandTotal.maDisplayName = rDisplayName;
580 break;
581 case XML_COLUMN:
582 maColGrandTotal.mbVisible = bVisible;
583 maColGrandTotal.maDisplayName = rDisplayName;
584 break;
585 default:
586 break;
590 ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( ScXMLImport& rImport,
591 sal_uInt16 nPrfx,
592 const OUString& rLName,
593 const ::com::sun::star::uno::Reference<
594 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
595 ScXMLDataPilotTableContext* pTempDataPilotTable) :
596 SvXMLImportContext( rImport, nPrfx, rLName ),
597 pDataPilotTable(pTempDataPilotTable)
599 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
600 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceSQLAttrTokenMap();
601 for( sal_Int16 i=0; i < nAttrCount; ++i )
603 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
604 OUString aLocalName;
605 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
606 sAttrName, &aLocalName );
607 const OUString& sValue(xAttrList->getValueByIndex( i ));
609 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
611 case XML_TOK_SOURCE_SQL_ATTR_DATABASE_NAME :
613 pDataPilotTable->SetDatabaseName(sValue);
615 break;
616 case XML_TOK_SOURCE_SQL_ATTR_SQL_STATEMENT :
618 pDataPilotTable->SetSourceObject(sValue);
620 break;
621 case XML_TOK_SOURCE_SQL_ATTR_PARSE_SQL_STATEMENT :
623 pDataPilotTable->SetNative(!IsXMLToken(sValue, XML_TRUE));
625 break;
630 ScXMLDPSourceSQLContext::~ScXMLDPSourceSQLContext()
634 SvXMLImportContext *ScXMLDPSourceSQLContext::CreateChildContext( sal_uInt16 nPrefix,
635 const OUString& rLName,
636 const ::com::sun::star::uno::Reference<
637 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
639 SvXMLImportContext *pContext = 0;
641 if( !pContext )
642 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
644 return pContext;
647 void ScXMLDPSourceSQLContext::EndElement()
651 ScXMLDPSourceTableContext::ScXMLDPSourceTableContext( ScXMLImport& rImport,
652 sal_uInt16 nPrfx,
653 const OUString& rLName,
654 const ::com::sun::star::uno::Reference<
655 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
656 ScXMLDataPilotTableContext* pTempDataPilotTable) :
657 SvXMLImportContext( rImport, nPrfx, rLName ),
658 pDataPilotTable(pTempDataPilotTable)
660 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
661 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceTableAttrTokenMap();
662 for( sal_Int16 i=0; i < nAttrCount; ++i )
664 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
665 OUString aLocalName;
666 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
667 sAttrName, &aLocalName );
668 const OUString& sValue(xAttrList->getValueByIndex( i ));
670 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
672 case XML_TOK_SOURCE_TABLE_ATTR_DATABASE_NAME :
674 pDataPilotTable->SetDatabaseName(sValue);
676 break;
677 case XML_TOK_SOURCE_TABLE_ATTR_TABLE_NAME :
679 pDataPilotTable->SetSourceObject(sValue);
681 break;
686 ScXMLDPSourceTableContext::~ScXMLDPSourceTableContext()
690 SvXMLImportContext *ScXMLDPSourceTableContext::CreateChildContext( sal_uInt16 nPrefix,
691 const OUString& rLName,
692 const ::com::sun::star::uno::Reference<
693 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
695 SvXMLImportContext *pContext = 0;
697 if( !pContext )
698 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
700 return pContext;
703 void ScXMLDPSourceTableContext::EndElement()
707 ScXMLDPSourceQueryContext::ScXMLDPSourceQueryContext( ScXMLImport& rImport,
708 sal_uInt16 nPrfx,
709 const OUString& rLName,
710 const ::com::sun::star::uno::Reference<
711 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
712 ScXMLDataPilotTableContext* pTempDataPilotTable) :
713 SvXMLImportContext( rImport, nPrfx, rLName ),
714 pDataPilotTable(pTempDataPilotTable)
716 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
717 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceQueryAttrTokenMap();
718 for( sal_Int16 i=0; i < nAttrCount; ++i )
720 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
721 OUString aLocalName;
722 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
723 sAttrName, &aLocalName );
724 const OUString& sValue(xAttrList->getValueByIndex( i ));
726 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
728 case XML_TOK_SOURCE_QUERY_ATTR_DATABASE_NAME :
730 pDataPilotTable->SetDatabaseName(sValue);
732 break;
733 case XML_TOK_SOURCE_QUERY_ATTR_QUERY_NAME :
735 pDataPilotTable->SetSourceObject(sValue);
737 break;
742 ScXMLDPSourceQueryContext::~ScXMLDPSourceQueryContext()
746 SvXMLImportContext *ScXMLDPSourceQueryContext::CreateChildContext( sal_uInt16 nPrefix,
747 const OUString& rLName,
748 const ::com::sun::star::uno::Reference<
749 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
751 SvXMLImportContext *pContext = 0;
753 if( !pContext )
754 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
756 return pContext;
759 void ScXMLDPSourceQueryContext::EndElement()
763 ScXMLSourceServiceContext::ScXMLSourceServiceContext( ScXMLImport& rImport,
764 sal_uInt16 nPrfx,
765 const OUString& rLName,
766 const ::com::sun::star::uno::Reference<
767 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
768 ScXMLDataPilotTableContext* pTempDataPilotTable) :
769 SvXMLImportContext( rImport, nPrfx, rLName ),
770 pDataPilotTable(pTempDataPilotTable)
772 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
773 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableSourceServiceAttrTokenMap();
774 for( sal_Int16 i=0; i < nAttrCount; ++i )
776 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
777 OUString aLocalName;
778 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
779 sAttrName, &aLocalName );
780 const OUString& sValue(xAttrList->getValueByIndex( i ));
782 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
784 case XML_TOK_SOURCE_SERVICE_ATTR_NAME :
786 pDataPilotTable->SetServiceName(sValue);
788 break;
789 case XML_TOK_SOURCE_SERVICE_ATTR_SOURCE_NAME :
791 pDataPilotTable->SetServiceSourceName(sValue);
793 break;
794 case XML_TOK_SOURCE_SERVICE_ATTR_OBJECT_NAME :
796 pDataPilotTable->SetServiceSourceObject(sValue);
798 break;
799 case XML_TOK_SOURCE_SERVICE_ATTR_USER_NAME :
801 pDataPilotTable->SetServiceUsername(sValue);
803 break;
804 case XML_TOK_SOURCE_SERVICE_ATTR_PASSWORD :
806 pDataPilotTable->SetServicePassword(sValue);
808 break;
813 ScXMLSourceServiceContext::~ScXMLSourceServiceContext()
817 SvXMLImportContext *ScXMLSourceServiceContext::CreateChildContext( sal_uInt16 nPrefix,
818 const OUString& rLName,
819 const ::com::sun::star::uno::Reference<
820 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
822 SvXMLImportContext *pContext = 0;
824 if( !pContext )
825 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
827 return pContext;
830 void ScXMLSourceServiceContext::EndElement()
834 ScXMLImport& ScXMLDataPilotGrandTotalContext::GetScImport()
836 return static_cast<ScXMLImport&>(GetImport());
839 ScXMLDataPilotGrandTotalContext::ScXMLDataPilotGrandTotalContext(
840 ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, const Reference<XAttributeList>& xAttrList,
841 ScXMLDataPilotTableContext* pTableContext ) :
842 SvXMLImportContext( rImport, nPrefix, rLName ),
843 mpTableContext(pTableContext),
844 meOrientation(NONE),
845 mbVisible(false)
847 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
848 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotGrandTotalAttrTokenMap();
849 for (sal_Int16 i = 0; i < nAttrCount; ++i)
851 const OUString& rAttrName = xAttrList->getNameByIndex(i);
852 const OUString& rAttrValue = xAttrList->getValueByIndex(i);
854 OUString aLocalName;
855 sal_uInt16 nLocalPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
856 switch (rAttrTokenMap.Get(nLocalPrefix, aLocalName))
858 case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_DISPLAY:
859 mbVisible = IsXMLToken(rAttrValue, XML_TRUE);
860 break;
861 case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_ORIENTATION:
862 if (IsXMLToken(rAttrValue, XML_BOTH))
863 meOrientation = BOTH;
864 else if (IsXMLToken(rAttrValue, XML_ROW))
865 meOrientation = ROW;
866 else if (IsXMLToken(rAttrValue, XML_COLUMN))
867 meOrientation = COLUMN;
868 break;
869 case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_DISPLAY_NAME:
870 case XML_TOK_DATA_PILOT_GRAND_TOTAL_ATTR_DISPLAY_NAME_EXT:
871 maDisplayName = rAttrValue;
872 break;
873 default:
874 break;
879 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
883 SvXMLImportContext* ScXMLDataPilotGrandTotalContext::CreateChildContext(
884 sal_uInt16 nPrefix, const OUString& rLocalName, const Reference<XAttributeList>& /*xAttrList*/ )
886 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
889 void ScXMLDataPilotGrandTotalContext::EndElement()
891 XMLTokenEnum eOrient = XML_NONE;
892 switch (meOrientation)
894 case BOTH:
895 eOrient = XML_BOTH;
896 break;
897 case ROW:
898 eOrient = XML_ROW;
899 break;
900 case COLUMN:
901 eOrient = XML_COLUMN;
902 break;
903 default:
904 break;
906 mpTableContext->SetGrandTotal(eOrient, mbVisible, maDisplayName);
909 ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport& rImport,
910 sal_uInt16 nPrfx,
911 const OUString& rLName,
912 const ::com::sun::star::uno::Reference<
913 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
914 ScXMLDataPilotTableContext* pTempDataPilotTable) :
915 SvXMLImportContext( rImport, nPrfx, rLName ),
916 pDataPilotTable(pTempDataPilotTable)
918 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
919 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotTableSourceCellRangeAttrTokenMap();
920 for( sal_Int16 i=0; i < nAttrCount; ++i )
922 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
923 OUString aLocalName;
924 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
925 sAttrName, &aLocalName );
926 const OUString& sValue(xAttrList->getValueByIndex( i ));
928 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
930 case XML_TOK_SOURCE_CELL_RANGE_ATTR_CELL_RANGE_ADDRESS :
932 ScRange aSourceRangeAddress;
933 sal_Int32 nOffset(0);
934 if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ))
935 pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
937 break;
938 case XML_TOK_SOURCE_CELL_RANGE_ATTR_NAME:
939 pDataPilotTable->SetSourceRangeName(sValue);
940 break;
945 ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
949 SvXMLImportContext *ScXMLSourceCellRangeContext::CreateChildContext( sal_uInt16 nPrefix,
950 const OUString& rLName,
951 const ::com::sun::star::uno::Reference<
952 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
954 SvXMLImportContext *pContext = 0;
956 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotTableSourceCellRangeElemTokenMap();
957 switch( rTokenMap.Get( nPrefix, rLName ) )
959 case XML_TOK_SOURCE_CELL_RANGE_ELEM_FILTER :
960 pContext = new ScXMLDPFilterContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotTable);
961 break;
964 if( !pContext )
965 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
967 return pContext;
970 void ScXMLSourceCellRangeContext::EndElement()
974 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport& rImport,
975 sal_uInt16 nPrfx,
976 const OUString& rLName,
977 const ::com::sun::star::uno::Reference<
978 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
979 ScXMLDataPilotTableContext* pTempDataPilotTable) :
980 SvXMLImportContext( rImport, nPrfx, rLName ),
981 pDataPilotTable(pTempDataPilotTable),
982 pDim(NULL),
983 fStart(0.0),
984 fEnd(0.0),
985 fStep(0.0),
986 nUsedHierarchy(1),
987 nGroupPart(0),
988 nFunction(0),
989 nOrientation(0),
990 bSelectedPage(false),
991 bIsGroupField(false),
992 bDateValue(false),
993 bAutoStart(false),
994 bAutoEnd(false),
995 mbHasHiddenMember(false)
997 bool bHasName = false;
998 bool bDataLayout = false;
999 OUString aDisplayName;
1000 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1001 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotFieldAttrTokenMap();
1002 for( sal_Int16 i=0; i < nAttrCount; ++i )
1004 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1005 OUString aLocalName;
1006 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1007 sAttrName, &aLocalName );
1008 const OUString& sValue(xAttrList->getValueByIndex( i ));
1010 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1012 case XML_TOK_DATA_PILOT_FIELD_ATTR_SOURCE_FIELD_NAME :
1014 sName = sValue;
1015 bHasName = true;
1017 break;
1018 case XML_TOK_DATA_PILOT_FIELD_ATTR_DISPLAY_NAME:
1019 case XML_TOK_DATA_PILOT_FIELD_ATTR_DISPLAY_NAME_EXT:
1021 aDisplayName = sValue;
1023 break;
1024 case XML_TOK_DATA_PILOT_FIELD_ATTR_IS_DATA_LAYOUT_FIELD :
1026 bDataLayout = IsXMLToken(sValue, XML_TRUE);
1028 break;
1029 case XML_TOK_DATA_PILOT_FIELD_ATTR_FUNCTION :
1031 nFunction = (sal_Int16) ScXMLConverter::GetFunctionFromString( sValue );
1033 break;
1034 case XML_TOK_DATA_PILOT_FIELD_ATTR_ORIENTATION :
1036 nOrientation = (sal_Int16) ScXMLConverter::GetOrientationFromString( sValue );
1038 break;
1039 case XML_TOK_DATA_PILOT_FIELD_ATTR_SELECTED_PAGE :
1041 sSelectedPage = sValue;
1042 bSelectedPage = true;
1044 break;
1045 case XML_TOK_DATA_PILOT_FIELD_ATTR_USED_HIERARCHY :
1047 nUsedHierarchy = sValue.toInt32();
1049 break;
1052 if (bHasName)
1054 pDim = new ScDPSaveDimension(sName, bDataLayout);
1055 if (!aDisplayName.isEmpty())
1056 pDim->SetLayoutName(aDisplayName);
1060 ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
1064 SvXMLImportContext *ScXMLDataPilotFieldContext::CreateChildContext( sal_uInt16 nPrefix,
1065 const OUString& rLName,
1066 const ::com::sun::star::uno::Reference<
1067 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1069 SvXMLImportContext *pContext = 0;
1071 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotFieldElemTokenMap();
1072 switch( rTokenMap.Get( nPrefix, rLName ) )
1074 case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_LEVEL :
1075 pContext = new ScXMLDataPilotLevelContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1076 break;
1077 case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_REFERENCE :
1078 pContext = new ScXMLDataPilotFieldReferenceContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1079 break;
1080 case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_GROUPS :
1081 pContext = new ScXMLDataPilotGroupsContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1082 break;
1085 if( !pContext )
1086 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1088 return pContext;
1091 void ScXMLDataPilotFieldContext::AddMember(ScDPSaveMember* pMember)
1093 if (pDim)
1095 pDim->AddMember(pMember);
1096 if (!pMember->GetIsVisible())
1097 // This member is hidden.
1098 mbHasHiddenMember = true;
1100 else
1101 delete pMember;
1104 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString& rName)
1106 if (pDim)
1107 pDim->SetSubtotalName(rName);
1110 void ScXMLDataPilotFieldContext::AddGroup(const ::std::vector<OUString>& rMembers, const OUString& rName)
1112 ScXMLDataPilotGroup aGroup;
1113 aGroup.aMembers = rMembers;
1114 aGroup.aName = rName;
1115 aGroups.push_back(aGroup);
1118 void ScXMLDataPilotFieldContext::EndElement()
1120 if (pDim)
1122 pDim->SetUsedHierarchy(nUsedHierarchy);
1123 pDim->SetFunction(nFunction);
1124 pDim->SetOrientation(nOrientation);
1125 if (bSelectedPage)
1127 pDataPilotTable->SetSelectedPage(pDim->GetName(), sSelectedPage);
1129 pDataPilotTable->AddDimension(pDim);
1130 if (bIsGroupField)
1132 ScDPNumGroupInfo aInfo;
1133 aInfo.mbEnable = true;
1134 aInfo.mbDateValues = bDateValue;
1135 aInfo.mbAutoStart = bAutoStart;
1136 aInfo.mbAutoEnd = bAutoEnd;
1137 aInfo.mfStart = fStart;
1138 aInfo.mfEnd = fEnd;
1139 aInfo.mfStep = fStep;
1140 if (!sGroupSource.isEmpty())
1142 ScDPSaveGroupDimension aGroupDim(sGroupSource, sName);
1143 if (nGroupPart)
1144 aGroupDim.SetDateInfo(aInfo, nGroupPart);
1145 else
1147 ::std::vector<ScXMLDataPilotGroup>::const_iterator aItr(aGroups.begin());
1148 ::std::vector<ScXMLDataPilotGroup>::const_iterator aEndItr(aGroups.end());
1149 while (aItr != aEndItr)
1151 ScDPSaveGroupItem aItem(aItr->aName);
1152 ::std::vector<OUString>::const_iterator aMembersItr(aItr->aMembers.begin());
1153 ::std::vector<OUString>::const_iterator aMembersEndItr(aItr->aMembers.end());
1154 while (aMembersItr != aMembersEndItr)
1156 aItem.AddElement(*aMembersItr);
1157 ++aMembersItr;
1159 ++aItr;
1160 aGroupDim.AddGroupItem(aItem);
1163 pDataPilotTable->AddGroupDim(aGroupDim);
1165 else //NumGroup
1167 ScDPSaveNumGroupDimension aNumGroupDim(sName, aInfo);
1168 if (nGroupPart)
1169 aNumGroupDim.SetDateInfo(aInfo, nGroupPart);
1170 pDataPilotTable->AddGroupDim(aNumGroupDim);
1176 ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1177 const OUString& rLName,
1178 const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1179 ScXMLDataPilotFieldContext* pDataPilotField) :
1180 SvXMLImportContext( rImport, nPrfx, rLName )
1182 sheet::DataPilotFieldReference aReference;
1184 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1185 for( sal_Int16 i=0; i < nAttrCount; i++ )
1187 OUString sAttrName(xAttrList->getNameByIndex( i ));
1188 OUString aLocalName;
1189 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1190 sAttrName, &aLocalName );
1191 OUString sValue(xAttrList->getValueByIndex( i ));
1193 if ( nPrefix == XML_NAMESPACE_TABLE )
1195 if (IsXMLToken(aLocalName, XML_TYPE))
1197 if (IsXMLToken(sValue, XML_NONE))
1198 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::NONE;
1199 else if (IsXMLToken(sValue, XML_MEMBER_DIFFERENCE))
1200 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE;
1201 else if (IsXMLToken(sValue, XML_MEMBER_PERCENTAGE))
1202 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE;
1203 else if (IsXMLToken(sValue, XML_MEMBER_PERCENTAGE_DIFFERENCE))
1204 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
1205 else if (IsXMLToken(sValue, XML_RUNNING_TOTAL))
1206 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::RUNNING_TOTAL;
1207 else if (IsXMLToken(sValue, XML_ROW_PERCENTAGE))
1208 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE;
1209 else if (IsXMLToken(sValue, XML_COLUMN_PERCENTAGE))
1210 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
1211 else if (IsXMLToken(sValue, XML_TOTAL_PERCENTAGE))
1212 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
1213 else if (IsXMLToken(sValue, XML_INDEX))
1214 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::INDEX;
1216 else if (IsXMLToken(aLocalName, XML_FIELD_NAME))
1218 aReference.ReferenceField = sValue;
1220 else if (IsXMLToken(aLocalName, XML_MEMBER_TYPE))
1222 if (IsXMLToken(sValue, XML_NAMED))
1223 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
1224 else if (IsXMLToken(sValue, XML_PREVIOUS))
1225 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::PREVIOUS;
1226 else if (IsXMLToken(sValue, XML_NEXT))
1227 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NEXT;
1229 else if (IsXMLToken(aLocalName, XML_MEMBER_NAME))
1231 aReference.ReferenceItemName = sValue;
1235 pDataPilotField->SetFieldReference(aReference);
1238 ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1242 ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport& rImport,
1243 sal_uInt16 nPrfx,
1244 const OUString& rLName,
1245 const ::com::sun::star::uno::Reference<
1246 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1247 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1248 SvXMLImportContext( rImport, nPrfx, rLName ),
1249 pDataPilotField(pTempDataPilotField)
1251 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1252 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotLevelAttrTokenMap();
1253 for( sal_Int16 i=0; i < nAttrCount; ++i )
1255 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1256 OUString aLocalName;
1257 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1258 sAttrName, &aLocalName );
1259 const OUString& sValue(xAttrList->getValueByIndex( i ));
1261 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1263 case XML_TOK_DATA_PILOT_LEVEL_ATTR_SHOW_EMPTY :
1265 pDataPilotField->SetShowEmpty(IsXMLToken(sValue, XML_TRUE));
1267 break;
1272 ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1276 SvXMLImportContext *ScXMLDataPilotLevelContext::CreateChildContext( sal_uInt16 nPrefix,
1277 const OUString& rLName,
1278 const ::com::sun::star::uno::Reference<
1279 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1281 SvXMLImportContext *pContext = 0;
1283 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotLevelElemTokenMap();
1284 switch( rTokenMap.Get( nPrefix, rLName ) )
1286 case XML_TOK_DATA_PILOT_LEVEL_ELEM_DATA_PILOT_SUBTOTALS :
1287 pContext = new ScXMLDataPilotSubTotalsContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1288 break;
1289 case XML_TOK_DATA_PILOT_LEVEL_ELEM_DATA_PILOT_MEMBERS :
1290 pContext = new ScXMLDataPilotMembersContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1291 break;
1292 case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_DISPLAY_INFO :
1293 pContext = new ScXMLDataPilotDisplayInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1294 break;
1295 case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_SORT_INFO :
1296 pContext = new ScXMLDataPilotSortInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1297 break;
1298 case XML_TOK_DATA_PILOT_FIELD_ELEM_DATA_PILOT_LAYOUT_INFO :
1299 pContext = new ScXMLDataPilotLayoutInfoContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1300 break;
1303 if( !pContext )
1304 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1306 return pContext;
1309 void ScXMLDataPilotLevelContext::EndElement()
1313 ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1314 const OUString& rLName,
1315 const ::com::sun::star::uno::Reference<
1316 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1317 ScXMLDataPilotFieldContext* pDataPilotField) :
1318 SvXMLImportContext( rImport, nPrfx, rLName )
1320 sheet::DataPilotFieldAutoShowInfo aInfo;
1322 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1323 for( sal_Int16 i=0; i < nAttrCount; i++ )
1325 OUString sAttrName(xAttrList->getNameByIndex( i ));
1326 OUString aLocalName;
1327 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1328 sAttrName, &aLocalName );
1329 OUString sValue(xAttrList->getValueByIndex( i ));
1331 if ( nPrefix == XML_NAMESPACE_TABLE )
1333 if (IsXMLToken(aLocalName, XML_ENABLED))
1335 if (IsXMLToken(sValue, XML_TRUE))
1336 aInfo.IsEnabled = sal_True;
1337 else
1338 aInfo.IsEnabled = false;
1340 else if (IsXMLToken(aLocalName, XML_DISPLAY_MEMBER_MODE))
1342 if (IsXMLToken(sValue, XML_FROM_TOP))
1343 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_TOP;
1344 else if (IsXMLToken(sValue, XML_FROM_BOTTOM))
1345 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM;
1347 else if (IsXMLToken(aLocalName, XML_MEMBER_COUNT))
1349 aInfo.ItemCount = sValue.toInt32();
1351 else if (IsXMLToken(aLocalName, XML_DATA_FIELD))
1353 aInfo.DataField = sValue;
1357 pDataPilotField->SetAutoShowInfo(aInfo);
1360 ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1364 ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1365 const OUString& rLName,
1366 const ::com::sun::star::uno::Reference<
1367 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1368 ScXMLDataPilotFieldContext* pDataPilotField) :
1369 SvXMLImportContext( rImport, nPrfx, rLName )
1371 sheet::DataPilotFieldSortInfo aInfo;
1373 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1374 for( sal_Int16 i=0; i < nAttrCount; i++ )
1376 OUString sAttrName(xAttrList->getNameByIndex( i ));
1377 OUString aLocalName;
1378 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1379 sAttrName, &aLocalName );
1380 OUString sValue(xAttrList->getValueByIndex( i ));
1382 if ( nPrefix == XML_NAMESPACE_TABLE )
1384 if (IsXMLToken(aLocalName, XML_ORDER))
1386 if (IsXMLToken(sValue, XML_ASCENDING))
1387 aInfo.IsAscending = sal_True;
1388 else if (IsXMLToken(sValue, XML_DESCENDING))
1389 aInfo.IsAscending = false;
1391 else if (IsXMLToken(aLocalName, XML_SORT_MODE))
1393 if (IsXMLToken(sValue, XML_NONE))
1394 aInfo.Mode = sheet::DataPilotFieldSortMode::NONE;
1395 else if (IsXMLToken(sValue, XML_MANUAL))
1396 aInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
1397 else if (IsXMLToken(sValue, XML_NAME))
1398 aInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
1399 else if (IsXMLToken(sValue, XML_DATA))
1400 aInfo.Mode = sheet::DataPilotFieldSortMode::DATA;
1402 else if (IsXMLToken(aLocalName, XML_DATA_FIELD))
1403 aInfo.Field = sValue;
1406 pDataPilotField->SetSortInfo(aInfo);
1409 ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1413 ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
1414 const OUString& rLName,
1415 const ::com::sun::star::uno::Reference<
1416 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1417 ScXMLDataPilotFieldContext* pDataPilotField) :
1418 SvXMLImportContext( rImport, nPrfx, rLName )
1420 sheet::DataPilotFieldLayoutInfo aInfo;
1422 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1423 for( sal_Int16 i=0; i < nAttrCount; i++ )
1425 OUString sAttrName(xAttrList->getNameByIndex( i ));
1426 OUString aLocalName;
1427 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1428 sAttrName, &aLocalName );
1429 OUString sValue(xAttrList->getValueByIndex( i ));
1431 if ( nPrefix == XML_NAMESPACE_TABLE )
1433 if (IsXMLToken(aLocalName, XML_ADD_EMPTY_LINES))
1435 if (IsXMLToken(sValue, XML_TRUE))
1436 aInfo.AddEmptyLines = sal_True;
1437 else
1438 aInfo.AddEmptyLines = false;
1440 else if (IsXMLToken(aLocalName, XML_LAYOUT_MODE))
1442 if (IsXMLToken(sValue, XML_TABULAR_LAYOUT))
1443 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
1444 else if (IsXMLToken(sValue, XML_OUTLINE_SUBTOTALS_TOP))
1445 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
1446 else if (IsXMLToken(sValue, XML_OUTLINE_SUBTOTALS_BOTTOM))
1447 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
1451 pDataPilotField->SetLayoutInfo(aInfo);}
1453 ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1457 ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport,
1458 sal_uInt16 nPrfx,
1459 const OUString& rLName,
1460 const ::com::sun::star::uno::Reference<
1461 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
1462 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1463 SvXMLImportContext( rImport, nPrfx, rLName ),
1464 pDataPilotField(pTempDataPilotField),
1465 nFunctionCount(0),
1466 pFunctions(NULL)
1469 // has no attributes
1472 ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1474 delete[] pFunctions;
1477 SvXMLImportContext *ScXMLDataPilotSubTotalsContext::CreateChildContext( sal_uInt16 nPrefix,
1478 const OUString& rLName,
1479 const ::com::sun::star::uno::Reference<
1480 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1482 SvXMLImportContext *pContext = 0;
1484 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotSubTotalsElemTokenMap();
1485 switch( rTokenMap.Get( nPrefix, rLName ) )
1487 case XML_TOK_DATA_PILOT_SUBTOTALS_ELEM_DATA_PILOT_SUBTOTAL :
1488 pContext = new ScXMLDataPilotSubTotalContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1489 break;
1492 if( !pContext )
1493 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1495 return pContext;
1498 void ScXMLDataPilotSubTotalsContext::EndElement()
1500 pDataPilotField->SetSubTotals(pFunctions, nFunctionCount);
1501 if (!maDisplayName.isEmpty())
1502 pDataPilotField->SetSubTotalName(maDisplayName);
1505 void ScXMLDataPilotSubTotalsContext::AddFunction(sal_Int16 nFunction)
1507 if (nFunctionCount)
1509 ++nFunctionCount;
1510 sal_uInt16* pTemp = new sal_uInt16[nFunctionCount];
1511 for (sal_Int16 i = 0; i < nFunctionCount - 1; ++i)
1512 pTemp[i] = pFunctions[i];
1513 pTemp[nFunctionCount - 1] = nFunction;
1514 delete[] pFunctions;
1515 pFunctions = pTemp;
1517 else
1519 nFunctionCount = 1;
1520 pFunctions = new sal_uInt16[nFunctionCount];
1521 pFunctions[0] = nFunction;
1525 void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
1527 maDisplayName = rName;
1530 ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport& rImport,
1531 sal_uInt16 nPrfx,
1532 const OUString& rLName,
1533 const ::com::sun::star::uno::Reference<
1534 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1535 ScXMLDataPilotSubTotalsContext* pTempDataPilotSubTotals) :
1536 SvXMLImportContext( rImport, nPrfx, rLName ),
1537 pDataPilotSubTotals(pTempDataPilotSubTotals)
1539 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1540 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotSubTotalAttrTokenMap();
1541 for( sal_Int16 i=0; i < nAttrCount; ++i )
1543 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1544 OUString aLocalName;
1545 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1546 sAttrName, &aLocalName );
1547 const OUString& sValue(xAttrList->getValueByIndex( i ));
1549 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1551 case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_FUNCTION :
1553 pDataPilotSubTotals->AddFunction( sal::static_int_cast<sal_Int16>(
1554 ScXMLConverter::GetFunctionFromString( sValue ) ) );
1556 break;
1557 case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_DISPLAY_NAME:
1558 case XML_TOK_DATA_PILOT_SUBTOTAL_ATTR_DISPLAY_NAME_EXT:
1559 pDataPilotSubTotals->SetDisplayName(sValue);
1560 break;
1565 ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1569 SvXMLImportContext *ScXMLDataPilotSubTotalContext::CreateChildContext( sal_uInt16 nPrefix,
1570 const OUString& rLName,
1571 const ::com::sun::star::uno::Reference<
1572 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1574 SvXMLImportContext *pContext = 0;
1576 if( !pContext )
1577 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1579 return pContext;
1582 void ScXMLDataPilotSubTotalContext::EndElement()
1586 ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport& rImport,
1587 sal_uInt16 nPrfx,
1588 const OUString& rLName,
1589 const ::com::sun::star::uno::Reference<
1590 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
1591 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1592 SvXMLImportContext( rImport, nPrfx, rLName ),
1593 pDataPilotField(pTempDataPilotField)
1595 // has no attributes
1598 ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1602 SvXMLImportContext *ScXMLDataPilotMembersContext::CreateChildContext( sal_uInt16 nPrefix,
1603 const OUString& rLName,
1604 const ::com::sun::star::uno::Reference<
1605 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1607 SvXMLImportContext *pContext = 0;
1609 const SvXMLTokenMap& rTokenMap = GetScImport().GetDataPilotMembersElemTokenMap();
1610 switch( rTokenMap.Get( nPrefix, rLName ) )
1612 case XML_TOK_DATA_PILOT_MEMBERS_ELEM_DATA_PILOT_MEMBER :
1613 pContext = new ScXMLDataPilotMemberContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1614 break;
1617 if( !pContext )
1618 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1620 return pContext;
1623 void ScXMLDataPilotMembersContext::EndElement()
1627 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport& rImport,
1628 sal_uInt16 nPrfx,
1629 const OUString& rLName,
1630 const ::com::sun::star::uno::Reference<
1631 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1632 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1633 SvXMLImportContext( rImport, nPrfx, rLName ),
1634 pDataPilotField(pTempDataPilotField),
1635 bDisplay( true ),
1636 bDisplayDetails( true ),
1637 bHasName( false )
1639 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1640 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataPilotMemberAttrTokenMap();
1641 for( sal_Int16 i=0; i < nAttrCount; ++i )
1643 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
1644 OUString aLocalName;
1645 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1646 sAttrName, &aLocalName );
1647 const OUString& sValue(xAttrList->getValueByIndex( i ));
1649 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
1651 case XML_TOK_DATA_PILOT_MEMBER_ATTR_NAME :
1653 sName = sValue;
1654 bHasName = true;
1656 break;
1657 case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY_NAME:
1658 case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY_NAME_EXT:
1660 maDisplayName = sValue;
1662 break;
1663 case XML_TOK_DATA_PILOT_MEMBER_ATTR_DISPLAY :
1665 bDisplay = IsXMLToken(sValue, XML_TRUE);
1667 break;
1668 case XML_TOK_DATA_PILOT_MEMBER_ATTR_SHOW_DETAILS :
1670 bDisplayDetails = IsXMLToken(sValue, XML_TRUE);
1672 break;
1677 ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1681 SvXMLImportContext *ScXMLDataPilotMemberContext::CreateChildContext( sal_uInt16 nPrefix,
1682 const OUString& rLName,
1683 const ::com::sun::star::uno::Reference<
1684 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1686 SvXMLImportContext *pContext = 0;
1688 if( !pContext )
1689 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1691 return pContext;
1694 void ScXMLDataPilotMemberContext::EndElement()
1696 if (bHasName) // #i53407# don't check sName, empty name is allowed
1698 ScDPSaveMember* pMember = new ScDPSaveMember(sName);
1699 if (!maDisplayName.isEmpty())
1700 pMember->SetLayoutName(maDisplayName);
1701 pMember->SetIsVisible(bDisplay);
1702 pMember->SetShowDetails(bDisplayDetails);
1703 pDataPilotField->AddMember(pMember);
1707 ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport& rImport,
1708 sal_uInt16 nPrfx,
1709 const OUString& rLName,
1710 const ::com::sun::star::uno::Reference<
1711 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1712 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1713 SvXMLImportContext( rImport, nPrfx, rLName ),
1714 pDataPilotField(pTempDataPilotField)
1716 OUString sGroupSource;
1717 double fStart(0.0);
1718 double fEnd(0.0);
1719 double fStep(0.0);
1720 sal_Int32 nGroupPart(0);
1721 bool bDateValue(false);
1722 bool bAutoStart(true);
1723 bool bAutoEnd(true);
1725 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1726 for( sal_Int16 i=0; i < nAttrCount; i++ )
1728 OUString sAttrName = xAttrList->getNameByIndex( i );
1729 OUString aLocalName;
1730 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1731 sAttrName, &aLocalName );
1732 OUString sValue = xAttrList->getValueByIndex( i );
1734 (void)nPrefix; //! compare below!
1736 if (IsXMLToken(aLocalName, XML_SOURCE_FIELD_NAME))
1737 sGroupSource = sValue;
1738 else if (IsXMLToken(aLocalName, XML_DATE_START))
1740 bDateValue = true;
1741 if (IsXMLToken(sValue, XML_AUTO))
1742 bAutoStart = true;
1743 else
1745 GetScImport().GetMM100UnitConverter().convertDateTime(fStart, sValue);
1746 bAutoStart = false;
1749 else if (IsXMLToken(aLocalName, XML_DATE_END))
1751 bDateValue = true;
1752 if (IsXMLToken(sValue, XML_AUTO))
1753 bAutoEnd = true;
1754 else
1756 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd, sValue);
1757 bAutoEnd = false;
1760 else if (IsXMLToken(aLocalName, XML_START))
1762 if (IsXMLToken(sValue, XML_AUTO))
1763 bAutoStart = true;
1764 else
1766 ::sax::Converter::convertDouble(fStart, sValue);
1767 bAutoStart = false;
1770 else if (IsXMLToken(aLocalName, XML_END))
1772 if (IsXMLToken(sValue, XML_AUTO))
1773 bAutoEnd = true;
1774 else
1776 ::sax::Converter::convertDouble(fEnd, sValue);
1777 bAutoEnd = false;
1780 else if (IsXMLToken(aLocalName, XML_STEP))
1782 ::sax::Converter::convertDouble(fStep, sValue);
1784 else if (IsXMLToken(aLocalName, XML_GROUPED_BY))
1786 if (IsXMLToken(sValue, XML_SECONDS))
1787 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS;
1788 else if (IsXMLToken(sValue, XML_MINUTES))
1789 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES;
1790 else if (IsXMLToken(sValue, XML_HOURS))
1791 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::HOURS;
1792 else if (IsXMLToken(sValue, XML_DAYS))
1793 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
1794 else if (IsXMLToken(sValue, XML_MONTHS))
1795 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
1796 else if (IsXMLToken(sValue, XML_QUARTERS))
1797 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS;
1798 else if (IsXMLToken(sValue, XML_YEARS))
1799 nGroupPart = com::sun::star::sheet::DataPilotFieldGroupBy::YEARS;
1802 pDataPilotField->SetGrouping(sGroupSource, fStart, fEnd, fStep, nGroupPart, bDateValue, bAutoStart, bAutoEnd);
1805 ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1809 SvXMLImportContext *ScXMLDataPilotGroupsContext::CreateChildContext( sal_uInt16 nPrefix,
1810 const OUString& rLName,
1811 const ::com::sun::star::uno::Reference<
1812 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1814 SvXMLImportContext *pContext = 0;
1816 if (nPrefix == XML_NAMESPACE_TABLE)
1818 if (IsXMLToken(rLName, XML_DATA_PILOT_GROUP))
1819 pContext = new ScXMLDataPilotGroupContext(GetScImport(), nPrefix, rLName, xAttrList, pDataPilotField);
1822 if( !pContext )
1823 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1825 return pContext;
1828 void ScXMLDataPilotGroupsContext::EndElement()
1832 ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport& rImport,
1833 sal_uInt16 nPrfx,
1834 const OUString& rLName,
1835 const ::com::sun::star::uno::Reference<
1836 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1837 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1838 SvXMLImportContext( rImport, nPrfx, rLName ),
1839 pDataPilotField(pTempDataPilotField)
1841 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1842 for( sal_Int16 i=0; i < nAttrCount; i++ )
1844 OUString sAttrName = xAttrList->getNameByIndex( i );
1845 OUString aLocalName;
1846 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1847 sAttrName, &aLocalName );
1848 OUString sValue = xAttrList->getValueByIndex( i );
1850 if (nPrefix == XML_NAMESPACE_TABLE)
1852 if (IsXMLToken(aLocalName, XML_NAME))
1853 sName = sValue;
1858 ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1862 SvXMLImportContext *ScXMLDataPilotGroupContext::CreateChildContext( sal_uInt16 nPrefix,
1863 const OUString& rLName,
1864 const ::com::sun::star::uno::Reference<
1865 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
1867 SvXMLImportContext *pContext = 0;
1869 if (nPrefix == XML_NAMESPACE_TABLE)
1871 if (IsXMLToken(rLName, XML_DATA_PILOT_MEMBER) || IsXMLToken(rLName, XML_DATA_PILOT_GROUP_MEMBER))
1872 pContext = new ScXMLDataPilotGroupMemberContext(GetScImport(), nPrefix, rLName, xAttrList, this);
1875 if( !pContext )
1876 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1878 return pContext;
1881 void ScXMLDataPilotGroupContext::EndElement()
1883 pDataPilotField->AddGroup(aMembers, sName);
1886 ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport& rImport,
1887 sal_uInt16 nPrfx,
1888 const OUString& rLName,
1889 const ::com::sun::star::uno::Reference<
1890 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
1891 ScXMLDataPilotGroupContext* pTempDataPilotGroup) :
1892 SvXMLImportContext( rImport, nPrfx, rLName ),
1893 pDataPilotGroup(pTempDataPilotGroup)
1895 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1896 for( sal_Int16 i=0; i < nAttrCount; i++ )
1898 OUString sAttrName = xAttrList->getNameByIndex( i );
1899 OUString aLocalName;
1900 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
1901 sAttrName, &aLocalName );
1902 OUString sValue = xAttrList->getValueByIndex( i );
1904 if (nPrefix == XML_NAMESPACE_TABLE)
1906 if (IsXMLToken(aLocalName, XML_NAME))
1907 sName = sValue;
1912 ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1916 SvXMLImportContext *ScXMLDataPilotGroupMemberContext::CreateChildContext( sal_uInt16 nPrefix,
1917 const OUString& rLName,
1918 const ::com::sun::star::uno::Reference<
1919 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1921 SvXMLImportContext *pContext = 0;
1923 if( !pContext )
1924 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1926 return pContext;
1929 void ScXMLDataPilotGroupMemberContext::EndElement()
1931 if (!sName.isEmpty())
1932 pDataPilotGroup->AddMember(sName);
1935 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */