Update ooo320-m1
[ooovba.git] / sc / source / filter / xml / xmldrani.cxx
blob558860e938678db1bff106bd7be9addc1e6c91e9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmldrani.cxx,v $
10 * $Revision: 1.31 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "xmldrani.hxx"
39 #include "xmlimprt.hxx"
40 #include "xmlfilti.hxx"
41 #include "xmlsorti.hxx"
42 #include "document.hxx"
43 #include "globstr.hrc"
44 #include "docuno.hxx"
45 #include "dbcolect.hxx"
46 #include "datauno.hxx"
47 #include "attrib.hxx"
48 #include "unonames.hxx"
49 #include "convuno.hxx"
50 #include "XMLConverter.hxx"
51 #include "rangeutl.hxx"
53 #include <xmloff/xmltkmap.hxx>
54 #include <xmloff/nmspmap.hxx>
55 #include <xmloff/xmltoken.hxx>
56 #include <xmloff/xmlnmspe.hxx>
57 #include <xmloff/xmluconv.hxx>
58 #include <xmloff/xmlerror.hxx>
59 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
60 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
61 #include <com/sun/star/sheet/XDatabaseRange.hpp>
62 #include <com/sun/star/table/CellRangeAddress.hpp>
63 #include <comphelper/extract.hxx>
64 #include <com/sun/star/uno/RuntimeException.hpp>
65 #include <com/sun/star/xml/sax/XLocator.hpp>
67 #define SC_ENABLEUSERSORTLIST "EnableUserSortList"
68 #define SC_USERSORTLISTINDEX "UserSortListIndex"
69 #define SC_USERLIST "UserList"
71 using namespace com::sun::star;
72 using namespace xmloff::token;
74 //------------------------------------------------------------------
76 ScXMLDatabaseRangesContext::ScXMLDatabaseRangesContext( ScXMLImport& rImport,
77 USHORT nPrfx,
78 const ::rtl::OUString& rLName,
79 const ::com::sun::star::uno::Reference<
80 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ ) :
81 SvXMLImportContext( rImport, nPrfx, rLName )
83 // has no attributes
84 rImport.LockSolarMutex();
87 ScXMLDatabaseRangesContext::~ScXMLDatabaseRangesContext()
89 GetScImport().UnlockSolarMutex();
92 SvXMLImportContext *ScXMLDatabaseRangesContext::CreateChildContext( USHORT nPrefix,
93 const ::rtl::OUString& rLName,
94 const ::com::sun::star::uno::Reference<
95 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
97 SvXMLImportContext *pContext = 0;
99 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangesElemTokenMap();
100 switch( rTokenMap.Get( nPrefix, rLName ) )
102 case XML_TOK_DATABASE_RANGE :
104 pContext = new ScXMLDatabaseRangeContext( GetScImport(), nPrefix,
105 rLName, xAttrList);
107 break;
110 if( !pContext )
111 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
113 return pContext;
116 void ScXMLDatabaseRangesContext::EndElement()
120 ScXMLDatabaseRangeContext::ScXMLDatabaseRangeContext( ScXMLImport& rImport,
121 USHORT nPrfx,
122 const ::rtl::OUString& rLName,
123 const ::com::sun::star::uno::Reference<
124 ::com::sun::star::xml::sax::XAttributeList>& xAttrList) :
125 SvXMLImportContext( rImport, nPrfx, rLName ),
126 sDatabaseRangeName(ScGlobal::GetRscString(STR_DB_NONAME)),
127 aSortSequence(),
128 eOrientation(table::TableOrientation_ROWS),
129 nRefresh(0),
130 nSubTotalsUserListIndex(0),
131 bContainsSort(sal_False),
132 bContainsSubTotal(sal_False),
133 bNative(sal_True),
134 bIsSelection(sal_False),
135 bKeepFormats(sal_False),
136 bMoveCells(sal_False),
137 bStripData(sal_False),
138 bContainsHeader(sal_True),
139 bAutoFilter(sal_False),
140 bSubTotalsBindFormatsToContent(sal_False),
141 bSubTotalsIsCaseSensitive(sal_False),
142 bSubTotalsInsertPageBreaks(sal_False),
143 bSubTotalsSortGroups(sal_False),
144 bSubTotalsEnabledUserList(sal_False),
145 bSubTotalsAscending(sal_True),
146 bFilterCopyOutputData(sal_False),
147 bFilterIsCaseSensitive(sal_False),
148 bFilterSkipDuplicates(sal_False),
149 bFilterUseRegularExpressions(sal_False),
150 bFilterConditionSourceRange(sal_False)
152 nSourceType = sheet::DataImportMode_NONE;
153 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
154 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeAttrTokenMap();
155 for( sal_Int16 i=0; i < nAttrCount; ++i )
157 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
158 rtl::OUString aLocalName;
159 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
160 sAttrName, &aLocalName );
161 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
163 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
165 case XML_TOK_DATABASE_RANGE_ATTR_NAME :
167 sDatabaseRangeName = sValue;
169 break;
170 case XML_TOK_DATABASE_RANGE_ATTR_IS_SELECTION :
172 bIsSelection = IsXMLToken(sValue, XML_TRUE);
174 break;
175 case XML_TOK_DATABASE_RANGE_ATTR_ON_UPDATE_KEEP_STYLES :
177 bKeepFormats = IsXMLToken(sValue, XML_TRUE);
179 break;
180 case XML_TOK_DATABASE_RANGE_ATTR_ON_UPDATE_KEEP_SIZE :
182 bMoveCells = !IsXMLToken(sValue, XML_TRUE);
184 break;
185 case XML_TOK_DATABASE_RANGE_ATTR_HAS_PERSISTENT_DATA :
187 bStripData = !IsXMLToken(sValue, XML_TRUE);
189 break;
190 case XML_TOK_DATABASE_RANGE_ATTR_ORIENTATION :
192 if (IsXMLToken(sValue, XML_COLUMN))
193 eOrientation = table::TableOrientation_COLUMNS;
195 break;
196 case XML_TOK_DATABASE_RANGE_ATTR_CONTAINS_HEADER :
198 bContainsHeader = IsXMLToken(sValue, XML_TRUE);
200 break;
201 case XML_TOK_DATABASE_RANGE_ATTR_DISPLAY_FILTER_BUTTONS :
203 bAutoFilter = IsXMLToken(sValue, XML_TRUE);
205 break;
206 case XML_TOK_DATABASE_RANGE_ATTR_TARGET_RANGE_ADDRESS :
208 sRangeAddress = sValue;
210 break;
211 case XML_TOK_DATABASE_RANGE_ATTR_REFRESH_DELAY :
213 double fTime;
214 if( SvXMLUnitConverter::convertTime( fTime, sValue ) )
215 nRefresh = Max( (sal_Int32)(fTime * 86400.0), (sal_Int32)0 );
217 break;
222 ScXMLDatabaseRangeContext::~ScXMLDatabaseRangeContext()
226 SvXMLImportContext *ScXMLDatabaseRangeContext::CreateChildContext( USHORT nPrefix,
227 const ::rtl::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( GetScImport(), nPrefix,
257 rLName, xAttrList, this);
259 break;
260 case XML_TOK_SORT :
262 bContainsSort = sal_True;
263 pContext = new ScXMLSortContext( GetScImport(), nPrefix,
264 rLName, xAttrList, this);
266 break;
267 case XML_TOK_DATABASE_RANGE_SUBTOTAL_RULES :
269 bContainsSubTotal = sal_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 void ScXMLDatabaseRangeContext::EndElement()
284 if (GetScImport().GetModel().is())
286 uno::Reference <beans::XPropertySet> xPropertySet( GetScImport().GetModel(), uno::UNO_QUERY );
287 ScDocument* pDoc = GetScImport().GetDocument();
288 if (pDoc && xPropertySet.is())
290 uno::Reference <sheet::XDatabaseRanges> xDatabaseRanges(xPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_DATABASERNG))), uno::UNO_QUERY);
291 if (xDatabaseRanges.is())
293 table::CellRangeAddress aCellRangeAddress;
294 sal_Int32 nOffset(0);
295 if (ScRangeStringConverter::GetRangeFromString( aCellRangeAddress, sRangeAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
297 sal_Bool bInsert(sal_True);
300 xDatabaseRanges->addNewByName(sDatabaseRangeName, aCellRangeAddress);
302 catch ( uno::RuntimeException& rRuntimeException )
304 bInsert = sal_False;
305 rtl::OUString sErrorMessage(RTL_CONSTASCII_USTRINGPARAM("DatabaseRange "));
306 sErrorMessage += sDatabaseRangeName;
307 sErrorMessage += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" could not be created with the range "));
308 sErrorMessage += sRangeAddress;
309 uno::Sequence<rtl::OUString> aSeq(1);
310 aSeq[0] = sErrorMessage;
311 uno::Reference<xml::sax::XLocator> xLocator;
312 GetScImport().SetError(XMLERROR_API | XMLERROR_FLAG_ERROR, aSeq, rRuntimeException.Message, xLocator);
314 if (bInsert)
316 uno::Reference <sheet::XDatabaseRange> xDatabaseRange(xDatabaseRanges->getByName(sDatabaseRangeName), uno::UNO_QUERY);
317 if (xDatabaseRange.is())
319 uno::Reference <beans::XPropertySet> xDatabaseRangePropertySet (xDatabaseRange, uno::UNO_QUERY);
320 if (xDatabaseRangePropertySet.is())
322 xDatabaseRangePropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_KEEPFORM)), uno::makeAny(bKeepFormats));
323 xDatabaseRangePropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_MOVCELLS)), uno::makeAny(bMoveCells));
324 xDatabaseRangePropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_STRIPDAT)), uno::makeAny(bStripData));
326 uno::Sequence <beans::PropertyValue> aImportDescriptor(xDatabaseRange->getImportDescriptor());
327 sal_Int32 nImportProperties = aImportDescriptor.getLength();
328 for (sal_Int16 i = 0; i < nImportProperties; ++i)
330 if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_DBNAME)))
332 if (sDatabaseName.getLength())
334 aImportDescriptor[i].Value <<= sDatabaseName;
336 else
338 aImportDescriptor[i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONRES));
339 aImportDescriptor[i].Value <<= sConnectionRessource;
342 else if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SRCOBJ)))
343 aImportDescriptor[i].Value <<= sSourceObject;
344 else if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SRCTYPE)))
345 aImportDescriptor[i].Value <<= nSourceType;
346 else if (aImportDescriptor[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISNATIVE)))
347 aImportDescriptor[i].Value <<= bNative;
349 ScDBCollection* pDBCollection = pDoc->GetDBCollection();
350 sal_uInt16 nIndex;
351 pDBCollection->SearchName(sDatabaseRangeName, nIndex);
352 ScDBData* pDBData = (*pDBCollection)[nIndex];
353 pDBData->SetImportSelection(bIsSelection);
354 pDBData->SetAutoFilter(bAutoFilter);
355 if (bAutoFilter)
356 pDoc->ApplyFlagsTab( static_cast<SCCOL>(aCellRangeAddress.StartColumn), static_cast<SCROW>(aCellRangeAddress.StartRow),
357 static_cast<SCCOL>(aCellRangeAddress.EndColumn), static_cast<SCROW>(aCellRangeAddress.StartRow),
358 aCellRangeAddress.Sheet, SC_MF_AUTO );
359 ScImportParam aImportParam;
360 ScImportDescriptor::FillImportParam(aImportParam, aImportDescriptor);
361 pDBData->SetImportParam(aImportParam);
362 if (bContainsSort)
364 sal_uInt32 nOldSize(aSortSequence.getLength());
365 aSortSequence.realloc(nOldSize + 1);
366 beans::PropertyValue aProperty;
367 aProperty.Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ORIENT));
368 aProperty.Value <<= eOrientation;
369 aSortSequence[nOldSize] = aProperty;
370 ScSortParam aSortParam;
371 ScSortDescriptor::FillSortParam(aSortParam, aSortSequence);
373 //#98317#; until now the Fields are relative to the left top edge of the range, but the
374 // core wants to have the absolute position (column/row)
375 SCCOLROW nFieldStart = aSortParam.bByRow ? static_cast<SCCOLROW>(aCellRangeAddress.StartColumn) : static_cast<SCCOLROW>(aCellRangeAddress.StartRow);
376 for (sal_uInt16 i = 0; i < MAXSORT; ++i)
378 if (aSortParam.bDoSort[i])
379 aSortParam.nField[i] += nFieldStart;
382 pDBData->SetSortParam(aSortParam);
384 uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor(
385 xDatabaseRange->getFilterDescriptor(), uno::UNO_QUERY );
386 if (xSheetFilterDescriptor.is())
388 uno::Reference <beans::XPropertySet> xFilterPropertySet (xSheetFilterDescriptor, uno::UNO_QUERY);
389 if (xFilterPropertySet.is())
391 sal_Bool bOrientation(table::TableOrientation_COLUMNS == eOrientation);
392 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ORIENT)), uno::makeAny(bOrientation));
393 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONTHDR)), uno::makeAny(bContainsHeader));
394 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_COPYOUT)), uno::makeAny(bFilterCopyOutputData));
395 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE)), uno::makeAny(bFilterIsCaseSensitive));
396 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SKIPDUP)), uno::makeAny(bFilterSkipDuplicates));
397 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_USEREGEX)), uno::makeAny(bFilterUseRegularExpressions));
398 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_OUTPOS)), uno::makeAny(aFilterOutputPosition));
400 xSheetFilterDescriptor->setFilterFields2(aFilterFields);
401 if (bFilterConditionSourceRange)
403 ScRange aAdvSource;
404 ScUnoConversion::FillScRange( aAdvSource, aFilterConditionSourceRangeAddress );
405 pDBData->SetAdvancedQuerySource(&aAdvSource);
408 if (bContainsSubTotal)
410 uno::Reference <sheet::XSubTotalDescriptor> xSubTotalDescriptor(xDatabaseRange->getSubTotalDescriptor());
411 if (xSubTotalDescriptor.is())
413 uno::Reference <beans::XPropertySet> xSubTotalPropertySet (xSubTotalDescriptor, uno::UNO_QUERY);
414 if( xSubTotalPropertySet.is())
416 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_BINDFMT)), uno::makeAny(bSubTotalsBindFormatsToContent));
417 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ENABLEUSERSORTLIST)), uno::makeAny(bSubTotalsEnabledUserList));
418 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_USERSORTLISTINDEX)), uno::makeAny(nSubTotalsUserListIndex));
419 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INSBRK)), uno::makeAny(bSubTotalsInsertPageBreaks));
420 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE)), uno::makeAny(bSubTotalsIsCaseSensitive));
422 ScSubTotalParam aSubTotalParam;
423 aSubTotalParam.bDoSort = bSubTotalsSortGroups;
424 aSubTotalParam.bAscending = bSubTotalsAscending;
425 aSubTotalParam.bUserDef = bSubTotalsEnabledUserList;
426 aSubTotalParam.nUserIndex = nSubTotalsUserListIndex;
427 pDBData->SetSubTotalParam(aSubTotalParam);
428 std::vector < ScSubTotalRule >::iterator aItr(aSubTotalRules.begin());
429 while (!aSubTotalRules.empty())
431 xSubTotalDescriptor->addNew(aItr->aSubTotalColumns, aItr->nSubTotalRuleGroupFieldNumber);
432 aItr = aSubTotalRules.erase(aItr);
436 if ( pDBData->HasImportParam() && !pDBData->HasImportSelection() )
438 pDBData->SetRefreshDelay( nRefresh );
439 pDBData->SetRefreshHandler( pDBCollection->GetRefreshHandler() );
440 pDBData->SetRefreshControl( pDoc->GetRefreshTimerControlAddress() );
450 ScXMLSourceSQLContext::ScXMLSourceSQLContext( ScXMLImport& rImport,
451 USHORT nPrfx,
452 const ::rtl::OUString& rLName,
453 const ::com::sun::star::uno::Reference<
454 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
455 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
456 SvXMLImportContext( rImport, nPrfx, rLName ),
457 pDatabaseRangeContext(pTempDatabaseRangeContext)
459 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
460 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceSQLAttrTokenMap();
461 for( sal_Int16 i=0; i < nAttrCount; ++i )
463 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
464 rtl::OUString aLocalName;
465 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
466 sAttrName, &aLocalName );
467 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
469 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
471 case XML_TOK_SOURCE_SQL_ATTR_DATABASE_NAME :
473 sDBName = sValue;
475 break;
476 case XML_TOK_SOURCE_SQL_ATTR_SQL_STATEMENT :
478 pDatabaseRangeContext->SetSourceObject(sValue);
480 break;
481 case XML_TOK_SOURCE_SQL_ATTR_PARSE_SQL_STATEMENT :
483 pDatabaseRangeContext->SetNative(IsXMLToken(sValue, XML_TRUE));
485 break;
488 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_SQL);
491 ScXMLSourceSQLContext::~ScXMLSourceSQLContext()
495 SvXMLImportContext *ScXMLSourceSQLContext::CreateChildContext( USHORT nPrefix,
496 const ::rtl::OUString& rLName,
497 const ::com::sun::star::uno::Reference<
498 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
500 SvXMLImportContext *pContext = 0;
502 if ( nPrefix == XML_NAMESPACE_FORM )
504 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
506 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
507 rLName, xAttrList, pDatabaseRangeContext);
511 if( !pContext )
512 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
514 return pContext;
517 void ScXMLSourceSQLContext::EndElement()
519 if (sDBName.getLength())
520 pDatabaseRangeContext->SetDatabaseName(sDBName);
523 ScXMLSourceTableContext::ScXMLSourceTableContext( ScXMLImport& rImport,
524 USHORT nPrfx,
525 const ::rtl::OUString& rLName,
526 const ::com::sun::star::uno::Reference<
527 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
528 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
529 SvXMLImportContext( rImport, nPrfx, rLName ),
530 pDatabaseRangeContext(pTempDatabaseRangeContext)
532 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
533 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceTableAttrTokenMap();
534 for( sal_Int16 i=0; i < nAttrCount; ++i )
536 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
537 rtl::OUString aLocalName;
538 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
539 sAttrName, &aLocalName );
540 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
542 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
544 case XML_TOK_SOURCE_TABLE_ATTR_DATABASE_NAME :
546 sDBName = sValue;
548 break;
549 case XML_TOK_SOURCE_TABLE_ATTR_TABLE_NAME :
551 pDatabaseRangeContext->SetSourceObject(sValue);
553 break;
556 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_TABLE);
559 ScXMLSourceTableContext::~ScXMLSourceTableContext()
563 SvXMLImportContext *ScXMLSourceTableContext::CreateChildContext( USHORT nPrefix,
564 const ::rtl::OUString& rLName,
565 const ::com::sun::star::uno::Reference<
566 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
568 SvXMLImportContext *pContext = 0;
570 if ( nPrefix == XML_NAMESPACE_FORM )
572 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
574 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
575 rLName, xAttrList, pDatabaseRangeContext);
579 if( !pContext )
580 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
582 return pContext;
585 void ScXMLSourceTableContext::EndElement()
587 if (sDBName.getLength())
588 pDatabaseRangeContext->SetDatabaseName(sDBName);
591 ScXMLSourceQueryContext::ScXMLSourceQueryContext( ScXMLImport& rImport,
592 USHORT nPrfx,
593 const ::rtl::OUString& rLName,
594 const ::com::sun::star::uno::Reference<
595 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
596 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
597 SvXMLImportContext( rImport, nPrfx, rLName ),
598 pDatabaseRangeContext(pTempDatabaseRangeContext)
600 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
601 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceQueryAttrTokenMap();
602 for( sal_Int16 i=0; i < nAttrCount; ++i )
604 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
605 rtl::OUString aLocalName;
606 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
607 sAttrName, &aLocalName );
608 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
610 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
612 case XML_TOK_SOURCE_QUERY_ATTR_DATABASE_NAME :
614 sDBName = sValue;
616 break;
617 case XML_TOK_SOURCE_QUERY_ATTR_QUERY_NAME :
619 pDatabaseRangeContext->SetSourceObject(sValue);
621 break;
624 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_QUERY);
627 ScXMLSourceQueryContext::~ScXMLSourceQueryContext()
631 SvXMLImportContext *ScXMLSourceQueryContext::CreateChildContext( USHORT nPrefix,
632 const ::rtl::OUString& rLName,
633 const ::com::sun::star::uno::Reference<
634 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
636 SvXMLImportContext *pContext = 0;
638 if ( nPrefix == XML_NAMESPACE_FORM )
640 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
642 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
643 rLName, xAttrList, pDatabaseRangeContext);
647 if( !pContext )
648 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
650 return pContext;
653 void ScXMLSourceQueryContext::EndElement()
655 if (sDBName.getLength())
656 pDatabaseRangeContext->SetDatabaseName(sDBName);
659 ScXMLConResContext::ScXMLConResContext( ScXMLImport& rImport,
660 USHORT nPrfx,
661 const ::rtl::OUString& rLName,
662 const ::com::sun::star::uno::Reference<
663 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
664 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
665 SvXMLImportContext( rImport, nPrfx, rLName ),
666 pDatabaseRangeContext( pTempDatabaseRangeContext )
668 rtl::OUString sConRes;
669 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
670 for( sal_Int16 i=0; i < nAttrCount; i++ )
672 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
673 rtl::OUString aLocalName;
674 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
675 sAttrName, &aLocalName );
676 rtl::OUString sValue = xAttrList->getValueByIndex( i );
678 if (nPrefix == XML_NAMESPACE_XLINK)
680 if (IsXMLToken(aLocalName, XML_HREF))
681 sConRes = sValue;
684 if (sConRes.getLength())
685 pDatabaseRangeContext->SetConnectionRessource(sConRes);
688 ScXMLConResContext::~ScXMLConResContext()
692 SvXMLImportContext *ScXMLConResContext::CreateChildContext( USHORT nPrefix,
693 const ::rtl::OUString& rLName,
694 const ::com::sun::star::uno::Reference<
695 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
697 SvXMLImportContext *pContext = 0;
699 if( !pContext )
700 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
702 return pContext;
705 void ScXMLConResContext::EndElement()
709 ScXMLSubTotalRulesContext::ScXMLSubTotalRulesContext( ScXMLImport& rImport,
710 USHORT nPrfx,
711 const ::rtl::OUString& rLName,
712 const ::com::sun::star::uno::Reference<
713 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
714 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
715 SvXMLImportContext( rImport, nPrfx, rLName ),
716 pDatabaseRangeContext(pTempDatabaseRangeContext)
718 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
719 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesAttrTokenMap();
720 for( sal_Int16 i=0; i < nAttrCount; ++i )
722 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
723 rtl::OUString aLocalName;
724 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
725 sAttrName, &aLocalName );
726 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
728 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
730 case XML_TOK_SUBTOTAL_RULES_ATTR_BIND_STYLES_TO_CONTENT :
732 pDatabaseRangeContext->SetSubTotalsBindFormatsToContent(IsXMLToken(sValue, XML_TRUE));
734 break;
735 case XML_TOK_SUBTOTAL_RULES_ATTR_CASE_SENSITIVE :
737 pDatabaseRangeContext->SetSubTotalsIsCaseSensitive(IsXMLToken(sValue, XML_TRUE));
739 break;
740 case XML_TOK_SUBTOTAL_RULES_ATTR_PAGE_BREAKS_ON_GROUP_CHANGE :
742 pDatabaseRangeContext->SetSubTotalsInsertPageBreaks(IsXMLToken(sValue, XML_TRUE));
744 break;
749 ScXMLSubTotalRulesContext::~ScXMLSubTotalRulesContext()
753 SvXMLImportContext *ScXMLSubTotalRulesContext::CreateChildContext( USHORT nPrefix,
754 const ::rtl::OUString& rLName,
755 const ::com::sun::star::uno::Reference<
756 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
758 SvXMLImportContext *pContext = 0;
760 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesElemTokenMap();
761 switch( rTokenMap.Get( nPrefix, rLName ) )
763 case XML_TOK_SUBTOTAL_RULES_SORT_GROUPS :
765 pContext = new ScXMLSortGroupsContext( GetScImport(), nPrefix,
766 rLName, xAttrList, pDatabaseRangeContext);
768 break;
769 case XML_TOK_SUBTOTAL_RULES_SUBTOTAL_RULE :
771 pContext = new ScXMLSubTotalRuleContext( GetScImport(), nPrefix,
772 rLName, xAttrList, pDatabaseRangeContext);
774 break;
777 if( !pContext )
778 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
780 return pContext;
783 void ScXMLSubTotalRulesContext::EndElement()
787 ScXMLSortGroupsContext::ScXMLSortGroupsContext( ScXMLImport& rImport,
788 USHORT nPrfx,
789 const ::rtl::OUString& rLName,
790 const ::com::sun::star::uno::Reference<
791 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
792 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
793 SvXMLImportContext( rImport, nPrfx, rLName ),
794 pDatabaseRangeContext(pTempDatabaseRangeContext)
796 pDatabaseRangeContext->SetSubTotalsSortGroups(sal_True);
797 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
798 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSortGroupsAttrTokenMap();
799 for( sal_Int16 i=0; i < nAttrCount; ++i )
801 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
802 rtl::OUString aLocalName;
803 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
804 sAttrName, &aLocalName );
805 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
807 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
809 case XML_TOK_SORT_GROUPS_ATTR_DATA_TYPE :
811 if (sValue.getLength() > 8)
813 rtl::OUString sTemp = sValue.copy(0, 8);
814 if (sTemp.compareToAscii(SC_USERLIST) == 0)
816 pDatabaseRangeContext->SetSubTotalsEnabledUserList(sal_True);
817 sTemp = sValue.copy(8);
818 pDatabaseRangeContext->SetSubTotalsUserListIndex(static_cast<sal_Int16>(sTemp.toInt32()));
820 else
822 //if (IsXMLToken(sValue, XML_AUTOMATIC))
823 //aSortField.FieldType = util::SortFieldType_AUTOMATIC;
824 // is not supported by StarOffice
827 else
829 //if (IsXMLToken(sValue, XML_TEXT))
830 //aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
831 // is not supported by StarOffice
832 //else if (IsXMLToken(sValue, XML_NUMBER))
833 //aSortField.FieldType = util::SortFieldType_NUMERIC;
834 // is not supported by StarOffice
837 break;
838 case XML_TOK_SORT_GROUPS_ATTR_ORDER :
840 if (IsXMLToken(sValue, XML_ASCENDING))
841 pDatabaseRangeContext->SetSubTotalsAscending(sal_True);
842 else
843 pDatabaseRangeContext->SetSubTotalsAscending(sal_False);
845 break;
850 ScXMLSortGroupsContext::~ScXMLSortGroupsContext()
854 SvXMLImportContext *ScXMLSortGroupsContext::CreateChildContext( USHORT nPrefix,
855 const ::rtl::OUString& rLName,
856 const ::com::sun::star::uno::Reference<
857 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
859 SvXMLImportContext *pContext = 0;
861 if( !pContext )
862 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
864 return pContext;
867 void ScXMLSortGroupsContext::EndElement()
871 ScXMLSubTotalRuleContext::ScXMLSubTotalRuleContext( ScXMLImport& rImport,
872 USHORT nPrfx,
873 const ::rtl::OUString& rLName,
874 const ::com::sun::star::uno::Reference<
875 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
876 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
877 SvXMLImportContext( rImport, nPrfx, rLName ),
878 pDatabaseRangeContext(pTempDatabaseRangeContext)
880 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
881 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleAttrTokenMap();
882 for( sal_Int16 i=0; i < nAttrCount; ++i )
884 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
885 rtl::OUString aLocalName;
886 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
887 sAttrName, &aLocalName );
888 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
890 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
892 case XML_TOK_SUBTOTAL_RULE_ATTR_GROUP_BY_FIELD_NUMBER :
894 aSubTotalRule.nSubTotalRuleGroupFieldNumber = static_cast<sal_Int16>(sValue.toInt32());
896 break;
901 ScXMLSubTotalRuleContext::~ScXMLSubTotalRuleContext()
905 SvXMLImportContext *ScXMLSubTotalRuleContext::CreateChildContext( USHORT nPrefix,
906 const ::rtl::OUString& rLName,
907 const ::com::sun::star::uno::Reference<
908 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
910 SvXMLImportContext *pContext = 0;
912 const SvXMLTokenMap& rTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleElemTokenMap();
913 switch( rTokenMap.Get( nPrefix, rLName ) )
915 case XML_TOK_SUBTOTAL_RULE_SUBTOTAL_FIELD :
917 pContext = new ScXMLSubTotalFieldContext( GetScImport(), nPrefix,
918 rLName, xAttrList, this);
920 break;
923 if( !pContext )
924 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
926 return pContext;
929 void ScXMLSubTotalRuleContext::EndElement()
931 if (pDatabaseRangeContext)
932 pDatabaseRangeContext->AddSubTotalRule(aSubTotalRule);
935 ScXMLSubTotalFieldContext::ScXMLSubTotalFieldContext( ScXMLImport& rImport,
936 USHORT nPrfx,
937 const ::rtl::OUString& rLName,
938 const ::com::sun::star::uno::Reference<
939 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
940 ScXMLSubTotalRuleContext* pTempSubTotalRuleContext) :
941 SvXMLImportContext( rImport, nPrfx, rLName ),
942 pSubTotalRuleContext(pTempSubTotalRuleContext)
944 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
945 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRuleSubTotalFieldAttrTokenMap();
946 for( sal_Int16 i=0; i < nAttrCount; ++i )
948 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
949 rtl::OUString aLocalName;
950 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
951 sAttrName, &aLocalName );
952 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
954 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
956 case XML_TOK_SUBTOTAL_FIELD_ATTR_FIELD_NUMBER :
958 sFieldNumber = sValue;
960 break;
961 case XML_TOK_SUBTOTAL_FIELD_ATTR_FUNCTION :
963 sFunction = sValue;
965 break;
970 ScXMLSubTotalFieldContext::~ScXMLSubTotalFieldContext()
974 SvXMLImportContext *ScXMLSubTotalFieldContext::CreateChildContext( USHORT nPrefix,
975 const ::rtl::OUString& rLName,
976 const ::com::sun::star::uno::Reference<
977 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
979 SvXMLImportContext *pContext = 0;
981 if( !pContext )
982 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
984 return pContext;
987 void ScXMLSubTotalFieldContext::EndElement()
989 sheet::SubTotalColumn aSubTotalColumn;
990 aSubTotalColumn.Column = sFieldNumber.toInt32();
991 aSubTotalColumn.Function = ScXMLConverter::GetFunctionFromString( sFunction );
992 pSubTotalRuleContext->AddSubTotalColumn(aSubTotalColumn);