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