fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / xml / xmldrani.cxx
blobf6108cbe88bcc69b6a551b4419783bf8f1d9a998
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 "xmldrani.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlfilti.hxx"
23 #include "xmlsorti.hxx"
24 #include "document.hxx"
25 #include "globstr.hrc"
26 #include "globalnames.hxx"
27 #include "docuno.hxx"
28 #include "dbdata.hxx"
29 #include "datauno.hxx"
30 #include "attrib.hxx"
31 #include "unonames.hxx"
32 #include "convuno.hxx"
33 #include "XMLConverter.hxx"
34 #include "rangeutl.hxx"
35 #include "queryentry.hxx"
36 #include "dputil.hxx"
37 #include <sortparam.hxx>
39 #include <xmloff/xmltkmap.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include <xmloff/xmltoken.hxx>
42 #include <xmloff/xmlnmspe.hxx>
43 #include <xmloff/xmlerror.hxx>
45 #include <sax/tools/converter.hxx>
47 #include <com/sun/star/sheet/DataImportMode.hpp>
48 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
49 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
50 #include <com/sun/star/sheet/XDatabaseRange.hpp>
51 #include <com/sun/star/table/CellRangeAddress.hpp>
52 #include <comphelper/extract.hxx>
53 #include <com/sun/star/uno/RuntimeException.hpp>
54 #include <com/sun/star/xml/sax/XLocator.hpp>
56 #include <memory>
58 using namespace com::sun::star;
59 using namespace xmloff::token;
61 ScXMLDatabaseRangesContext::ScXMLDatabaseRangesContext( ScXMLImport& rImport,
62 sal_uInt16 nPrfx,
63 const OUString& rLName,
64 const ::com::sun::star::uno::Reference<
65 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
66 SvXMLImportContext( rImport, nPrfx, rLName )
68 // has no attributes
69 rImport.LockSolarMutex();
72 ScXMLDatabaseRangesContext::~ScXMLDatabaseRangesContext()
74 GetScImport().UnlockSolarMutex();
77 SvXMLImportContext *ScXMLDatabaseRangesContext::CreateChildContext( sal_uInt16 nPrefix,
78 const OUString& rLName,
79 const ::com::sun::star::uno::Reference<
80 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
82 SvXMLImportContext *pContext = 0;
84 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangesElemTokenMap();
85 switch( rTokenMap.Get( nPrefix, rLName ) )
87 case XML_TOK_DATABASE_RANGE :
89 pContext = new ScXMLDatabaseRangeContext( GetScImport(), nPrefix,
90 rLName, xAttrList);
92 break;
95 if( !pContext )
96 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
98 return pContext;
101 void ScXMLDatabaseRangesContext::EndElement()
105 ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( 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 mpQueryParam(new ScQueryParam),
112 sDatabaseRangeName(STR_DB_LOCAL_NONAME),
113 aSortSequence(),
114 nRefresh(0),
115 nSubTotalsUserListIndex(0),
116 mbValidRange(true),
117 bContainsSort(false),
118 bContainsSubTotal(false),
119 bNative(true),
120 bIsSelection(false),
121 bKeepFormats(false),
122 bMoveCells(false),
123 bStripData(false),
124 bAutoFilter(false),
125 bSubTotalsBindFormatsToContent(false),
126 bSubTotalsIsCaseSensitive(false),
127 bSubTotalsInsertPageBreaks(false),
128 bSubTotalsSortGroups(false),
129 bSubTotalsEnabledUserList(false),
130 bSubTotalsAscending(true),
131 bFilterConditionSourceRange(false),
132 bHasHeader(true),
133 bByRow(false),
134 meRangeType(ScDBCollection::GlobalNamed)
136 nSourceType = sheet::DataImportMode_NONE;
137 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
138 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeAttrTokenMap();
139 for( sal_Int16 i=0; i < nAttrCount; ++i )
141 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
142 OUString aLocalName;
143 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
144 sAttrName, &aLocalName );
145 const OUString& sValue(xAttrList->getValueByIndex( i ));
147 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
149 case XML_TOK_DATABASE_RANGE_ATTR_NAME :
151 sDatabaseRangeName = sValue;
153 break;
154 case XML_TOK_DATABASE_RANGE_ATTR_IS_SELECTION :
156 bIsSelection = IsXMLToken(sValue, XML_TRUE);
158 break;
159 case XML_TOK_DATABASE_RANGE_ATTR_ON_UPDATE_KEEP_STYLES :
161 bKeepFormats = IsXMLToken(sValue, XML_TRUE);
163 break;
164 case XML_TOK_DATABASE_RANGE_ATTR_ON_UPDATE_KEEP_SIZE :
166 bMoveCells = !IsXMLToken(sValue, XML_TRUE);
168 break;
169 case XML_TOK_DATABASE_RANGE_ATTR_HAS_PERSISTENT_DATA :
171 bStripData = !IsXMLToken(sValue, XML_TRUE);
173 break;
174 case XML_TOK_DATABASE_RANGE_ATTR_ORIENTATION :
176 bByRow = !IsXMLToken(sValue, XML_COLUMN);
177 mpQueryParam->bByRow = bByRow;
179 break;
180 case XML_TOK_DATABASE_RANGE_ATTR_CONTAINS_HEADER :
182 bHasHeader = IsXMLToken(sValue, XML_TRUE);
183 mpQueryParam->bHasHeader = bHasHeader;
185 break;
186 case XML_TOK_DATABASE_RANGE_ATTR_DISPLAY_FILTER_BUTTONS :
188 bAutoFilter = IsXMLToken(sValue, XML_TRUE);
190 break;
191 case XML_TOK_DATABASE_RANGE_ATTR_TARGET_RANGE_ADDRESS :
193 ScDocument* pDoc = GetScImport().GetDocument();
194 sal_Int32 nOffset = 0;
195 if (!ScRangeStringConverter::GetRangeFromString(
196 maRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset))
197 mbValidRange = false;
199 break;
200 case XML_TOK_DATABASE_RANGE_ATTR_REFRESH_DELAY :
202 double fTime;
203 if (::sax::Converter::convertDuration( fTime, sValue ))
204 nRefresh = std::max( (sal_Int32)(fTime * 86400.0), (sal_Int32)0 );
206 break;
210 mpQueryParam->nTab = maRange.aStart.Tab();
211 mpQueryParam->nCol1 = maRange.aStart.Col();
212 mpQueryParam->nRow1 = maRange.aStart.Row();
213 mpQueryParam->nCol2 = maRange.aEnd.Col();
214 mpQueryParam->nRow2 = maRange.aEnd.Row();
216 if (sDatabaseRangeName.matchAsciiL(STR_DB_LOCAL_NONAME, strlen(STR_DB_LOCAL_NONAME)))
217 meRangeType = ScDBCollection::SheetAnonymous;
218 else if (sDatabaseRangeName.matchAsciiL(STR_DB_GLOBAL_NONAME, strlen(STR_DB_GLOBAL_NONAME)))
219 meRangeType = ScDBCollection::GlobalAnonymous;
222 ScXMLDatabaseRangeContext::~ScXMLDatabaseRangeContext()
226 SvXMLImportContext *ScXMLDatabaseRangeContext::CreateChildContext( sal_uInt16 nPrefix,
227 const OUString& rLName,
228 const ::com::sun::star::uno::Reference<
229 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
231 SvXMLImportContext *pContext = 0;
233 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangeElemTokenMap();
234 switch( rTokenMap.Get( nPrefix, rLName ) )
236 case XML_TOK_DATABASE_RANGE_SOURCE_SQL :
238 pContext = new ScXMLSourceSQLContext( GetScImport(), nPrefix,
239 rLName, xAttrList, this);
241 break;
242 case XML_TOK_DATABASE_RANGE_SOURCE_TABLE :
244 pContext = new ScXMLSourceTableContext( GetScImport(), nPrefix,
245 rLName, xAttrList, this);
247 break;
248 case XML_TOK_DATABASE_RANGE_SOURCE_QUERY :
250 pContext = new ScXMLSourceQueryContext( GetScImport(), nPrefix,
251 rLName, xAttrList, this);
253 break;
254 case XML_TOK_FILTER :
256 pContext = new ScXMLFilterContext(
257 GetScImport(), nPrefix, rLName, xAttrList, *mpQueryParam, this);
259 break;
260 case XML_TOK_SORT :
262 bContainsSort = true;
263 pContext = new ScXMLSortContext( GetScImport(), nPrefix,
264 rLName, xAttrList, this);
266 break;
267 case XML_TOK_DATABASE_RANGE_SUBTOTAL_RULES :
269 bContainsSubTotal = true;
270 pContext = new ScXMLSubTotalRulesContext( GetScImport(), nPrefix,
271 rLName, xAttrList, this);
273 break;
276 if( !pContext )
277 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
279 return pContext;
282 ScDBData* ScXMLDatabaseRangeContext::ConvertToDBData(const OUString& rName)
284 if (!mbValidRange)
285 return NULL;
287 ScDocument* pDoc = GetScImport().GetDocument();
289 ::std::unique_ptr<ScDBData> pData(
290 new ScDBData(rName, maRange.aStart.Tab(), maRange.aStart.Col(), maRange.aStart.Row(), maRange.aEnd.Col(), maRange.aEnd.Row(), bByRow, bHasHeader));
292 pData->SetAutoFilter(bAutoFilter);
293 pData->SetKeepFmt(bKeepFormats);
294 pData->SetDoSize(bMoveCells);
295 pData->SetStripData(bStripData);
297 pData->SetQueryParam(*mpQueryParam);
299 if (bFilterConditionSourceRange)
301 ScRange aAdvSource;
302 ScUnoConversion::FillScRange(aAdvSource, aFilterConditionSourceRangeAddress);
303 pData->SetAdvancedQuerySource(&aAdvSource);
307 ScImportParam aParam;
308 aParam.bNative = bNative;
309 aParam.aDBName = sDatabaseName.isEmpty() ? sConnectionResource : sDatabaseName;
310 aParam.aStatement = sSourceObject;
311 sheet::DataImportMode eMode = static_cast<sheet::DataImportMode>(nSourceType);
312 switch (eMode)
314 case sheet::DataImportMode_NONE:
315 aParam.bImport = false;
316 break;
317 case sheet::DataImportMode_SQL:
318 aParam.bImport = true;
319 aParam.bSql = true;
320 break;
321 case sheet::DataImportMode_TABLE:
322 aParam.bImport = true;
323 aParam.bSql = false;
324 aParam.nType = ScDbTable;
325 break;
326 case sheet::DataImportMode_QUERY:
327 aParam.bImport = true;
328 aParam.bSql = false;
329 aParam.nType = ScDbQuery;
330 break;
331 default:
332 OSL_FAIL("Unknown data import mode");
333 aParam.bImport = false;
335 pData->SetImportParam(aParam);
338 if (bContainsSort)
340 size_t nOldSize = aSortSequence.getLength();
341 aSortSequence.realloc(nOldSize + 1);
342 beans::PropertyValue aProperty;
343 aProperty.Name = SC_UNONAME_ORIENT;
344 table::TableOrientation eOrient = mpQueryParam->bByRow ?
345 table::TableOrientation_ROWS : table::TableOrientation_COLUMNS;
346 aProperty.Value <<= eOrient;
347 aSortSequence[nOldSize] = aProperty;
348 ScSortParam aParam;
349 ScSortDescriptor::FillSortParam(aParam, aSortSequence);
351 SCCOLROW nStartPos = aParam.bByRow ? maRange.aStart.Col() : maRange.aStart.Row();
352 for (size_t i = 0; i < aParam.GetSortKeyCount(); ++i)
354 if (!aParam.maKeyState[i].bDoSort)
355 break;
356 aParam.maKeyState[i].nField += nStartPos;
359 pData->SetSortParam(aParam);
362 if (bContainsSubTotal)
364 ScSubTotalParam aParam;
365 aParam.bIncludePattern = bSubTotalsBindFormatsToContent;
366 aParam.bUserDef = bSubTotalsEnabledUserList;
367 aParam.nUserIndex = nSubTotalsUserListIndex;
368 aParam.bPagebreak = bSubTotalsInsertPageBreaks;
369 aParam.bCaseSens = bSubTotalsIsCaseSensitive;
370 aParam.bDoSort = bSubTotalsSortGroups;
371 aParam.bAscending = bSubTotalsAscending;
372 aParam.bUserDef = bSubTotalsEnabledUserList;
373 aParam.nUserIndex = nSubTotalsUserListIndex;
374 std::vector <ScSubTotalRule>::iterator itr = aSubTotalRules.begin(), itrEnd = aSubTotalRules.end();
375 for (size_t nPos = 0; itr != itrEnd; ++itr, ++nPos)
377 if (nPos >= MAXSUBTOTAL)
378 break;
380 const uno::Sequence<sheet::SubTotalColumn>& rColumns = itr->aSubTotalColumns;
381 sal_Int32 nColCount = rColumns.getLength();
382 sal_Int16 nGroupColumn = itr->nSubTotalRuleGroupFieldNumber;
383 aParam.bGroupActive[nPos] = true;
384 aParam.nField[nPos] = static_cast<SCCOL>(nGroupColumn);
386 SCCOL nCount = static_cast<SCCOL>(nColCount);
387 aParam.nSubTotals[nPos] = nCount;
388 if (nCount != 0)
390 aParam.pSubTotals[nPos] = new SCCOL[nCount];
391 aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount];
393 const sheet::SubTotalColumn* pAry = rColumns.getConstArray();
394 for (SCCOL i = 0; i < nCount; ++i)
396 aParam.pSubTotals[nPos][i] = static_cast<SCCOL>(pAry[i].Column);
397 aParam.pFunctions[nPos][i] = ScDPUtil::toSubTotalFunc(pAry[i].Function);
400 else
402 aParam.pSubTotals[nPos] = NULL;
403 aParam.pFunctions[nPos] = NULL;
407 pData->SetSubTotalParam(aParam);
410 if (pData->HasImportParam() && !pData->HasImportSelection())
412 pData->SetRefreshDelay(nRefresh);
413 pData->SetRefreshHandler(pDoc->GetDBCollection()->GetRefreshHandler());
414 pData->SetRefreshControl(&pDoc->GetRefreshTimerControlAddress());
417 return pData.release();
420 namespace {
422 bool setAutoFilterFlags(ScDocument& rDoc, const ScDBData& rData)
424 if (!rData.HasAutoFilter())
425 return false;
427 // Set autofilter flags so that the buttons get displayed.
428 ScRange aRange;
429 rData.GetArea(aRange);
430 rDoc.ApplyFlagsTab(
431 aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aStart.Row(),
432 aRange.aStart.Tab(), SC_MF_AUTO);
433 return false;
438 void ScXMLDatabaseRangeContext::EndElement()
440 ScDocument* pDoc = GetScImport().GetDocument();
441 if (!pDoc)
442 return;
444 if (meRangeType == ScDBCollection::SheetAnonymous)
446 OUString aName(STR_DB_LOCAL_NONAME);
447 ::std::unique_ptr<ScDBData> pData(ConvertToDBData(aName));
449 if (pData.get())
451 ScRange aRange;
452 pData->GetArea(aRange);
454 setAutoFilterFlags(*pDoc, *pData);
455 pDoc->SetAnonymousDBData(aRange.aStart.Tab(), pData.release());
457 return;
459 else if (meRangeType == ScDBCollection::GlobalAnonymous)
461 OUString aName(STR_DB_GLOBAL_NONAME);
462 ::std::unique_ptr<ScDBData> pData(ConvertToDBData(aName));
464 if (pData.get())
466 ScRange aRange;
467 pData->GetArea(aRange);
469 if (setAutoFilterFlags(*pDoc, *pData))
470 pDoc->SetAnonymousDBData(aRange.aStart.Tab(), pData.release());
471 else
472 pDoc->GetDBCollection()->getAnonDBs().insert(pData.release());
474 return;
476 else if (meRangeType == ScDBCollection::GlobalNamed)
478 ::std::unique_ptr<ScDBData> pData(ConvertToDBData(sDatabaseRangeName));
480 if (pData.get())
482 setAutoFilterFlags(*pDoc, *pData);
483 if (pDoc->GetDBCollection()->getNamedDBs().insert(pData.get()))
485 pData.release();
491 ScXMLSourceSQLContext::ScXMLSourceSQLContext( ScXMLImport& rImport,
492 sal_uInt16 nPrfx,
493 const OUString& rLName,
494 const ::com::sun::star::uno::Reference<
495 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
496 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
497 SvXMLImportContext( rImport, nPrfx, rLName ),
498 pDatabaseRangeContext(pTempDatabaseRangeContext)
500 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
501 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceSQLAttrTokenMap();
502 for( sal_Int16 i=0; i < nAttrCount; ++i )
504 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
505 OUString aLocalName;
506 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
507 sAttrName, &aLocalName );
508 const OUString& sValue(xAttrList->getValueByIndex( i ));
510 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
512 case XML_TOK_SOURCE_SQL_ATTR_DATABASE_NAME :
514 sDBName = sValue;
516 break;
517 case XML_TOK_SOURCE_SQL_ATTR_SQL_STATEMENT :
519 pDatabaseRangeContext->SetSourceObject(sValue);
521 break;
522 case XML_TOK_SOURCE_SQL_ATTR_PARSE_SQL_STATEMENT :
524 pDatabaseRangeContext->SetNative(IsXMLToken(sValue, XML_TRUE));
526 break;
529 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_SQL);
532 ScXMLSourceSQLContext::~ScXMLSourceSQLContext()
536 SvXMLImportContext *ScXMLSourceSQLContext::CreateChildContext( sal_uInt16 nPrefix,
537 const OUString& rLName,
538 const ::com::sun::star::uno::Reference<
539 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
541 SvXMLImportContext *pContext = 0;
543 if ( nPrefix == XML_NAMESPACE_FORM )
545 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && sDBName.isEmpty())
547 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
548 rLName, xAttrList, pDatabaseRangeContext);
552 if( !pContext )
553 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
555 return pContext;
558 void ScXMLSourceSQLContext::EndElement()
560 if (!sDBName.isEmpty())
561 pDatabaseRangeContext->SetDatabaseName(sDBName);
564 ScXMLSourceTableContext::ScXMLSourceTableContext( ScXMLImport& rImport,
565 sal_uInt16 nPrfx,
566 const OUString& rLName,
567 const ::com::sun::star::uno::Reference<
568 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
569 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
570 SvXMLImportContext( rImport, nPrfx, rLName ),
571 pDatabaseRangeContext(pTempDatabaseRangeContext)
573 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
574 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceTableAttrTokenMap();
575 for( sal_Int16 i=0; i < nAttrCount; ++i )
577 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
578 OUString aLocalName;
579 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
580 sAttrName, &aLocalName );
581 const OUString& sValue(xAttrList->getValueByIndex( i ));
583 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
585 case XML_TOK_SOURCE_TABLE_ATTR_DATABASE_NAME :
587 sDBName = sValue;
589 break;
590 case XML_TOK_SOURCE_TABLE_ATTR_TABLE_NAME :
592 pDatabaseRangeContext->SetSourceObject(sValue);
594 break;
597 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_TABLE);
600 ScXMLSourceTableContext::~ScXMLSourceTableContext()
604 SvXMLImportContext *ScXMLSourceTableContext::CreateChildContext( sal_uInt16 nPrefix,
605 const OUString& rLName,
606 const ::com::sun::star::uno::Reference<
607 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
609 SvXMLImportContext *pContext = 0;
611 if ( nPrefix == XML_NAMESPACE_FORM )
613 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && sDBName.isEmpty())
615 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
616 rLName, xAttrList, pDatabaseRangeContext);
620 if( !pContext )
621 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
623 return pContext;
626 void ScXMLSourceTableContext::EndElement()
628 if (!sDBName.isEmpty())
629 pDatabaseRangeContext->SetDatabaseName(sDBName);
632 ScXMLSourceQueryContext::ScXMLSourceQueryContext( ScXMLImport& rImport,
633 sal_uInt16 nPrfx,
634 const OUString& rLName,
635 const ::com::sun::star::uno::Reference<
636 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
637 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
638 SvXMLImportContext( rImport, nPrfx, rLName ),
639 pDatabaseRangeContext(pTempDatabaseRangeContext)
641 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
642 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceQueryAttrTokenMap();
643 for( sal_Int16 i=0; i < nAttrCount; ++i )
645 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
646 OUString aLocalName;
647 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
648 sAttrName, &aLocalName );
649 const OUString& sValue(xAttrList->getValueByIndex( i ));
651 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
653 case XML_TOK_SOURCE_QUERY_ATTR_DATABASE_NAME :
655 sDBName = sValue;
657 break;
658 case XML_TOK_SOURCE_QUERY_ATTR_QUERY_NAME :
660 pDatabaseRangeContext->SetSourceObject(sValue);
662 break;
665 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_QUERY);
668 ScXMLSourceQueryContext::~ScXMLSourceQueryContext()
672 SvXMLImportContext *ScXMLSourceQueryContext::CreateChildContext( sal_uInt16 nPrefix,
673 const OUString& rLName,
674 const ::com::sun::star::uno::Reference<
675 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
677 SvXMLImportContext *pContext = 0;
679 if ( nPrefix == XML_NAMESPACE_FORM )
681 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && sDBName.isEmpty())
683 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
684 rLName, xAttrList, pDatabaseRangeContext);
688 if( !pContext )
689 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
691 return pContext;
694 void ScXMLSourceQueryContext::EndElement()
696 if (!sDBName.isEmpty())
697 pDatabaseRangeContext->SetDatabaseName(sDBName);
700 ScXMLConResContext::ScXMLConResContext( ScXMLImport& rImport,
701 sal_uInt16 nPrfx,
702 const OUString& rLName,
703 const ::com::sun::star::uno::Reference<
704 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
705 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
706 SvXMLImportContext( rImport, nPrfx, rLName ),
707 pDatabaseRangeContext( pTempDatabaseRangeContext )
709 OUString sConRes;
710 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
711 for( sal_Int16 i=0; i < nAttrCount; i++ )
713 OUString sAttrName = xAttrList->getNameByIndex( i );
714 OUString aLocalName;
715 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
716 sAttrName, &aLocalName );
717 OUString sValue = xAttrList->getValueByIndex( i );
719 if (nPrefix == XML_NAMESPACE_XLINK)
721 if (IsXMLToken(aLocalName, XML_HREF))
722 sConRes = sValue;
725 if (!sConRes.isEmpty())
726 pDatabaseRangeContext->SetConnectionResource(sConRes);
729 ScXMLConResContext::~ScXMLConResContext()
733 SvXMLImportContext *ScXMLConResContext::CreateChildContext( sal_uInt16 nPrefix,
734 const OUString& rLName,
735 const ::com::sun::star::uno::Reference<
736 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
738 SvXMLImportContext *pContext = 0;
740 if( !pContext )
741 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
743 return pContext;
746 void ScXMLConResContext::EndElement()
750 ScXMLSubTotalRulesContext::ScXMLSubTotalRulesContext( ScXMLImport& rImport,
751 sal_uInt16 nPrfx,
752 const OUString& rLName,
753 const ::com::sun::star::uno::Reference<
754 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
755 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
756 SvXMLImportContext( rImport, nPrfx, rLName ),
757 pDatabaseRangeContext(pTempDatabaseRangeContext)
759 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
760 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesAttrTokenMap();
761 for( sal_Int16 i=0; i < nAttrCount; ++i )
763 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
764 OUString aLocalName;
765 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
766 sAttrName, &aLocalName );
767 const OUString& sValue(xAttrList->getValueByIndex( i ));
769 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
771 case XML_TOK_SUBTOTAL_RULES_ATTR_BIND_STYLES_TO_CONTENT :
773 pDatabaseRangeContext->SetSubTotalsBindFormatsToContent(IsXMLToken(sValue, XML_TRUE));
775 break;
776 case XML_TOK_SUBTOTAL_RULES_ATTR_CASE_SENSITIVE :
778 pDatabaseRangeContext->SetSubTotalsIsCaseSensitive(IsXMLToken(sValue, XML_TRUE));
780 break;
781 case XML_TOK_SUBTOTAL_RULES_ATTR_PAGE_BREAKS_ON_GROUP_CHANGE :
783 pDatabaseRangeContext->SetSubTotalsInsertPageBreaks(IsXMLToken(sValue, XML_TRUE));
785 break;
790 ScXMLSubTotalRulesContext::~ScXMLSubTotalRulesContext()
794 SvXMLImportContext *ScXMLSubTotalRulesContext::CreateChildContext( sal_uInt16 nPrefix,
795 const OUString& rLName,
796 const ::com::sun::star::uno::Reference<
797 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
799 SvXMLImportContext *pContext = 0;
801 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesElemTokenMap();
802 switch( rTokenMap.Get( nPrefix, rLName ) )
804 case XML_TOK_SUBTOTAL_RULES_SORT_GROUPS :
806 pContext = new ScXMLSortGroupsContext( GetScImport(), nPrefix,
807 rLName, xAttrList, pDatabaseRangeContext);
809 break;
810 case XML_TOK_SUBTOTAL_RULES_SUBTOTAL_RULE :
812 pContext = new ScXMLSubTotalRuleContext( GetScImport(), nPrefix,
813 rLName, xAttrList, pDatabaseRangeContext);
815 break;
818 if( !pContext )
819 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
821 return pContext;
824 void ScXMLSubTotalRulesContext::EndElement()
828 ScXMLSortGroupsContext::ScXMLSortGroupsContext( ScXMLImport& rImport,
829 sal_uInt16 nPrfx,
830 const OUString& rLName,
831 const ::com::sun::star::uno::Reference<
832 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
833 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
834 SvXMLImportContext( rImport, nPrfx, rLName ),
835 pDatabaseRangeContext(pTempDatabaseRangeContext)
837 pDatabaseRangeContext->SetSubTotalsSortGroups(true);
838 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
839 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSortGroupsAttrTokenMap();
840 for( sal_Int16 i=0; i < nAttrCount; ++i )
842 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
843 OUString aLocalName;
844 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
845 sAttrName, &aLocalName );
846 const OUString& sValue(xAttrList->getValueByIndex( i ));
848 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
850 case XML_TOK_SORT_GROUPS_ATTR_DATA_TYPE :
852 if (sValue.getLength() > 8)
854 OUString sTemp = sValue.copy(0, 8);
855 if (sTemp == "UserList")
857 pDatabaseRangeContext->SetSubTotalsEnabledUserList(true);
858 sTemp = sValue.copy(8);
859 pDatabaseRangeContext->SetSubTotalsUserListIndex(static_cast<sal_Int16>(sTemp.toInt32()));
861 else
863 //if (IsXMLToken(sValue, XML_AUTOMATIC))
864 //aSortField.FieldType = util::SortFieldType_AUTOMATIC;
865 // is not supported by StarOffice
868 else
870 //if (IsXMLToken(sValue, XML_TEXT))
871 //aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
872 // is not supported by StarOffice
873 //else if (IsXMLToken(sValue, XML_NUMBER))
874 //aSortField.FieldType = util::SortFieldType_NUMERIC;
875 // is not supported by StarOffice
878 break;
879 case XML_TOK_SORT_GROUPS_ATTR_ORDER :
881 if (IsXMLToken(sValue, XML_ASCENDING))
882 pDatabaseRangeContext->SetSubTotalsAscending(true);
883 else
884 pDatabaseRangeContext->SetSubTotalsAscending(false);
886 break;
891 ScXMLSortGroupsContext::~ScXMLSortGroupsContext()
895 SvXMLImportContext *ScXMLSortGroupsContext::CreateChildContext( sal_uInt16 nPrefix,
896 const OUString& rLName,
897 const ::com::sun::star::uno::Reference<
898 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
900 SvXMLImportContext *pContext = 0;
902 if( !pContext )
903 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
905 return pContext;
908 void ScXMLSortGroupsContext::EndElement()
912 ScXMLSubTotalRuleContext::ScXMLSubTotalRuleContext( ScXMLImport& rImport,
913 sal_uInt16 nPrfx,
914 const OUString& rLName,
915 const ::com::sun::star::uno::Reference<
916 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
917 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
918 SvXMLImportContext( rImport, nPrfx, rLName ),
919 pDatabaseRangeContext(pTempDatabaseRangeContext)
921 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
922 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleAttrTokenMap();
923 for( sal_Int16 i=0; i < nAttrCount; ++i )
925 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
926 OUString aLocalName;
927 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
928 sAttrName, &aLocalName );
929 const OUString& sValue(xAttrList->getValueByIndex( i ));
931 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
933 case XML_TOK_SUBTOTAL_RULE_ATTR_GROUP_BY_FIELD_NUMBER :
935 aSubTotalRule.nSubTotalRuleGroupFieldNumber = static_cast<sal_Int16>(sValue.toInt32());
937 break;
942 ScXMLSubTotalRuleContext::~ScXMLSubTotalRuleContext()
946 SvXMLImportContext *ScXMLSubTotalRuleContext::CreateChildContext( sal_uInt16 nPrefix,
947 const OUString& rLName,
948 const ::com::sun::star::uno::Reference<
949 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
951 SvXMLImportContext *pContext = 0;
953 const SvXMLTokenMap& rTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleElemTokenMap();
954 switch( rTokenMap.Get( nPrefix, rLName ) )
956 case XML_TOK_SUBTOTAL_RULE_SUBTOTAL_FIELD :
958 pContext = new ScXMLSubTotalFieldContext( GetScImport(), nPrefix,
959 rLName, xAttrList, this);
961 break;
964 if( !pContext )
965 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
967 return pContext;
970 void ScXMLSubTotalRuleContext::EndElement()
972 if (pDatabaseRangeContext)
973 pDatabaseRangeContext->AddSubTotalRule(aSubTotalRule);
976 ScXMLSubTotalFieldContext::ScXMLSubTotalFieldContext( ScXMLImport& rImport,
977 sal_uInt16 nPrfx,
978 const OUString& rLName,
979 const ::com::sun::star::uno::Reference<
980 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
981 ScXMLSubTotalRuleContext* pTempSubTotalRuleContext) :
982 SvXMLImportContext( rImport, nPrfx, rLName ),
983 pSubTotalRuleContext(pTempSubTotalRuleContext)
985 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
986 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRuleSubTotalFieldAttrTokenMap();
987 for( sal_Int16 i=0; i < nAttrCount; ++i )
989 const OUString& sAttrName(xAttrList->getNameByIndex( i ));
990 OUString aLocalName;
991 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
992 sAttrName, &aLocalName );
993 const OUString& sValue(xAttrList->getValueByIndex( i ));
995 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
997 case XML_TOK_SUBTOTAL_FIELD_ATTR_FIELD_NUMBER :
999 sFieldNumber = sValue;
1001 break;
1002 case XML_TOK_SUBTOTAL_FIELD_ATTR_FUNCTION :
1004 sFunction = sValue;
1006 break;
1011 ScXMLSubTotalFieldContext::~ScXMLSubTotalFieldContext()
1015 SvXMLImportContext *ScXMLSubTotalFieldContext::CreateChildContext( sal_uInt16 nPrefix,
1016 const OUString& rLName,
1017 const ::com::sun::star::uno::Reference<
1018 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
1020 SvXMLImportContext *pContext = 0;
1022 if( !pContext )
1023 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
1025 return pContext;
1028 void ScXMLSubTotalFieldContext::EndElement()
1030 sheet::SubTotalColumn aSubTotalColumn;
1031 aSubTotalColumn.Column = sFieldNumber.toInt32();
1032 aSubTotalColumn.Function = ScXMLConverter::GetFunctionFromString( sFunction );
1033 pSubTotalRuleContext->AddSubTotalColumn(aSubTotalColumn);
1036 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */