update ooo310-m15
[ooovba.git] / sc / source / filter / xml / xmldrani.cxx
blobdfc87cc7498c7d242755c3a2d346097f29930b43
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::XSheetFilterDescriptor> xSheetFilterDescriptor(xDatabaseRange->getFilterDescriptor());
385 if (xSheetFilterDescriptor.is())
387 uno::Reference <beans::XPropertySet> xFilterPropertySet (xSheetFilterDescriptor, uno::UNO_QUERY);
388 if (xFilterPropertySet.is())
390 sal_Bool bOrientation(table::TableOrientation_COLUMNS == eOrientation);
391 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ORIENT)), uno::makeAny(bOrientation));
392 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CONTHDR)), uno::makeAny(bContainsHeader));
393 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_COPYOUT)), uno::makeAny(bFilterCopyOutputData));
394 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE)), uno::makeAny(bFilterIsCaseSensitive));
395 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SKIPDUP)), uno::makeAny(bFilterSkipDuplicates));
396 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_USEREGEX)), uno::makeAny(bFilterUseRegularExpressions));
397 xFilterPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_OUTPOS)), uno::makeAny(aFilterOutputPosition));
399 xSheetFilterDescriptor->setFilterFields(aFilterFields);
400 if (bFilterConditionSourceRange)
402 ScRange aAdvSource;
403 ScUnoConversion::FillScRange( aAdvSource, aFilterConditionSourceRangeAddress );
404 pDBData->SetAdvancedQuerySource(&aAdvSource);
407 if (bContainsSubTotal)
409 uno::Reference <sheet::XSubTotalDescriptor> xSubTotalDescriptor(xDatabaseRange->getSubTotalDescriptor());
410 if (xSubTotalDescriptor.is())
412 uno::Reference <beans::XPropertySet> xSubTotalPropertySet (xSubTotalDescriptor, uno::UNO_QUERY);
413 if( xSubTotalPropertySet.is())
415 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_BINDFMT)), uno::makeAny(bSubTotalsBindFormatsToContent));
416 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ENABLEUSERSORTLIST)), uno::makeAny(bSubTotalsEnabledUserList));
417 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_USERSORTLISTINDEX)), uno::makeAny(nSubTotalsUserListIndex));
418 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INSBRK)), uno::makeAny(bSubTotalsInsertPageBreaks));
419 xSubTotalPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE)), uno::makeAny(bSubTotalsIsCaseSensitive));
421 ScSubTotalParam aSubTotalParam;
422 aSubTotalParam.bDoSort = bSubTotalsSortGroups;
423 aSubTotalParam.bAscending = bSubTotalsAscending;
424 aSubTotalParam.bUserDef = bSubTotalsEnabledUserList;
425 aSubTotalParam.nUserIndex = nSubTotalsUserListIndex;
426 pDBData->SetSubTotalParam(aSubTotalParam);
427 std::vector < ScSubTotalRule >::iterator aItr(aSubTotalRules.begin());
428 while (!aSubTotalRules.empty())
430 xSubTotalDescriptor->addNew(aItr->aSubTotalColumns, aItr->nSubTotalRuleGroupFieldNumber);
431 aItr = aSubTotalRules.erase(aItr);
435 if ( pDBData->HasImportParam() && !pDBData->HasImportSelection() )
437 pDBData->SetRefreshDelay( nRefresh );
438 pDBData->SetRefreshHandler( pDBCollection->GetRefreshHandler() );
439 pDBData->SetRefreshControl( pDoc->GetRefreshTimerControlAddress() );
449 ScXMLSourceSQLContext::ScXMLSourceSQLContext( ScXMLImport& rImport,
450 USHORT nPrfx,
451 const ::rtl::OUString& rLName,
452 const ::com::sun::star::uno::Reference<
453 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
454 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
455 SvXMLImportContext( rImport, nPrfx, rLName ),
456 pDatabaseRangeContext(pTempDatabaseRangeContext)
458 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
459 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceSQLAttrTokenMap();
460 for( sal_Int16 i=0; i < nAttrCount; ++i )
462 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
463 rtl::OUString aLocalName;
464 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
465 sAttrName, &aLocalName );
466 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
468 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
470 case XML_TOK_SOURCE_SQL_ATTR_DATABASE_NAME :
472 sDBName = sValue;
474 break;
475 case XML_TOK_SOURCE_SQL_ATTR_SQL_STATEMENT :
477 pDatabaseRangeContext->SetSourceObject(sValue);
479 break;
480 case XML_TOK_SOURCE_SQL_ATTR_PARSE_SQL_STATEMENT :
482 pDatabaseRangeContext->SetNative(IsXMLToken(sValue, XML_TRUE));
484 break;
487 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_SQL);
490 ScXMLSourceSQLContext::~ScXMLSourceSQLContext()
494 SvXMLImportContext *ScXMLSourceSQLContext::CreateChildContext( USHORT nPrefix,
495 const ::rtl::OUString& rLName,
496 const ::com::sun::star::uno::Reference<
497 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
499 SvXMLImportContext *pContext = 0;
501 if ( nPrefix == XML_NAMESPACE_FORM )
503 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
505 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
506 rLName, xAttrList, pDatabaseRangeContext);
510 if( !pContext )
511 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
513 return pContext;
516 void ScXMLSourceSQLContext::EndElement()
518 if (sDBName.getLength())
519 pDatabaseRangeContext->SetDatabaseName(sDBName);
522 ScXMLSourceTableContext::ScXMLSourceTableContext( ScXMLImport& rImport,
523 USHORT nPrfx,
524 const ::rtl::OUString& rLName,
525 const ::com::sun::star::uno::Reference<
526 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
527 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
528 SvXMLImportContext( rImport, nPrfx, rLName ),
529 pDatabaseRangeContext(pTempDatabaseRangeContext)
531 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
532 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceTableAttrTokenMap();
533 for( sal_Int16 i=0; i < nAttrCount; ++i )
535 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
536 rtl::OUString aLocalName;
537 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
538 sAttrName, &aLocalName );
539 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
541 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
543 case XML_TOK_SOURCE_TABLE_ATTR_DATABASE_NAME :
545 sDBName = sValue;
547 break;
548 case XML_TOK_SOURCE_TABLE_ATTR_TABLE_NAME :
550 pDatabaseRangeContext->SetSourceObject(sValue);
552 break;
555 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_TABLE);
558 ScXMLSourceTableContext::~ScXMLSourceTableContext()
562 SvXMLImportContext *ScXMLSourceTableContext::CreateChildContext( USHORT nPrefix,
563 const ::rtl::OUString& rLName,
564 const ::com::sun::star::uno::Reference<
565 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
567 SvXMLImportContext *pContext = 0;
569 if ( nPrefix == XML_NAMESPACE_FORM )
571 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
573 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
574 rLName, xAttrList, pDatabaseRangeContext);
578 if( !pContext )
579 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
581 return pContext;
584 void ScXMLSourceTableContext::EndElement()
586 if (sDBName.getLength())
587 pDatabaseRangeContext->SetDatabaseName(sDBName);
590 ScXMLSourceQueryContext::ScXMLSourceQueryContext( ScXMLImport& rImport,
591 USHORT nPrfx,
592 const ::rtl::OUString& rLName,
593 const ::com::sun::star::uno::Reference<
594 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
595 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
596 SvXMLImportContext( rImport, nPrfx, rLName ),
597 pDatabaseRangeContext(pTempDatabaseRangeContext)
599 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
600 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSourceQueryAttrTokenMap();
601 for( sal_Int16 i=0; i < nAttrCount; ++i )
603 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
604 rtl::OUString aLocalName;
605 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
606 sAttrName, &aLocalName );
607 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
609 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
611 case XML_TOK_SOURCE_QUERY_ATTR_DATABASE_NAME :
613 sDBName = sValue;
615 break;
616 case XML_TOK_SOURCE_QUERY_ATTR_QUERY_NAME :
618 pDatabaseRangeContext->SetSourceObject(sValue);
620 break;
623 pDatabaseRangeContext->SetSourceType(sheet::DataImportMode_QUERY);
626 ScXMLSourceQueryContext::~ScXMLSourceQueryContext()
630 SvXMLImportContext *ScXMLSourceQueryContext::CreateChildContext( USHORT nPrefix,
631 const ::rtl::OUString& rLName,
632 const ::com::sun::star::uno::Reference<
633 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
635 SvXMLImportContext *pContext = 0;
637 if ( nPrefix == XML_NAMESPACE_FORM )
639 if (IsXMLToken(rLName, XML_CONNECTION_RESOURCE) && (sDBName.getLength() == 0))
641 pContext = new ScXMLConResContext( GetScImport(), nPrefix,
642 rLName, xAttrList, pDatabaseRangeContext);
646 if( !pContext )
647 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
649 return pContext;
652 void ScXMLSourceQueryContext::EndElement()
654 if (sDBName.getLength())
655 pDatabaseRangeContext->SetDatabaseName(sDBName);
658 ScXMLConResContext::ScXMLConResContext( ScXMLImport& rImport,
659 USHORT nPrfx,
660 const ::rtl::OUString& rLName,
661 const ::com::sun::star::uno::Reference<
662 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
663 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
664 SvXMLImportContext( rImport, nPrfx, rLName ),
665 pDatabaseRangeContext( pTempDatabaseRangeContext )
667 rtl::OUString sConRes;
668 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
669 for( sal_Int16 i=0; i < nAttrCount; i++ )
671 rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
672 rtl::OUString aLocalName;
673 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
674 sAttrName, &aLocalName );
675 rtl::OUString sValue = xAttrList->getValueByIndex( i );
677 if (nPrefix == XML_NAMESPACE_XLINK)
679 if (IsXMLToken(aLocalName, XML_HREF))
680 sConRes = sValue;
683 if (sConRes.getLength())
684 pDatabaseRangeContext->SetConnectionRessource(sConRes);
687 ScXMLConResContext::~ScXMLConResContext()
691 SvXMLImportContext *ScXMLConResContext::CreateChildContext( USHORT nPrefix,
692 const ::rtl::OUString& rLName,
693 const ::com::sun::star::uno::Reference<
694 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
696 SvXMLImportContext *pContext = 0;
698 if( !pContext )
699 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
701 return pContext;
704 void ScXMLConResContext::EndElement()
708 ScXMLSubTotalRulesContext::ScXMLSubTotalRulesContext( ScXMLImport& rImport,
709 USHORT nPrfx,
710 const ::rtl::OUString& rLName,
711 const ::com::sun::star::uno::Reference<
712 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
713 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
714 SvXMLImportContext( rImport, nPrfx, rLName ),
715 pDatabaseRangeContext(pTempDatabaseRangeContext)
717 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
718 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesAttrTokenMap();
719 for( sal_Int16 i=0; i < nAttrCount; ++i )
721 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
722 rtl::OUString aLocalName;
723 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
724 sAttrName, &aLocalName );
725 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
727 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
729 case XML_TOK_SUBTOTAL_RULES_ATTR_BIND_STYLES_TO_CONTENT :
731 pDatabaseRangeContext->SetSubTotalsBindFormatsToContent(IsXMLToken(sValue, XML_TRUE));
733 break;
734 case XML_TOK_SUBTOTAL_RULES_ATTR_CASE_SENSITIVE :
736 pDatabaseRangeContext->SetSubTotalsIsCaseSensitive(IsXMLToken(sValue, XML_TRUE));
738 break;
739 case XML_TOK_SUBTOTAL_RULES_ATTR_PAGE_BREAKS_ON_GROUP_CHANGE :
741 pDatabaseRangeContext->SetSubTotalsInsertPageBreaks(IsXMLToken(sValue, XML_TRUE));
743 break;
748 ScXMLSubTotalRulesContext::~ScXMLSubTotalRulesContext()
752 SvXMLImportContext *ScXMLSubTotalRulesContext::CreateChildContext( USHORT nPrefix,
753 const ::rtl::OUString& rLName,
754 const ::com::sun::star::uno::Reference<
755 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
757 SvXMLImportContext *pContext = 0;
759 const SvXMLTokenMap& rTokenMap = GetScImport().GetDatabaseRangeSubTotalRulesElemTokenMap();
760 switch( rTokenMap.Get( nPrefix, rLName ) )
762 case XML_TOK_SUBTOTAL_RULES_SORT_GROUPS :
764 pContext = new ScXMLSortGroupsContext( GetScImport(), nPrefix,
765 rLName, xAttrList, pDatabaseRangeContext);
767 break;
768 case XML_TOK_SUBTOTAL_RULES_SUBTOTAL_RULE :
770 pContext = new ScXMLSubTotalRuleContext( GetScImport(), nPrefix,
771 rLName, xAttrList, pDatabaseRangeContext);
773 break;
776 if( !pContext )
777 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
779 return pContext;
782 void ScXMLSubTotalRulesContext::EndElement()
786 ScXMLSortGroupsContext::ScXMLSortGroupsContext( ScXMLImport& rImport,
787 USHORT nPrfx,
788 const ::rtl::OUString& rLName,
789 const ::com::sun::star::uno::Reference<
790 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
791 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
792 SvXMLImportContext( rImport, nPrfx, rLName ),
793 pDatabaseRangeContext(pTempDatabaseRangeContext)
795 pDatabaseRangeContext->SetSubTotalsSortGroups(sal_True);
796 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
797 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSortGroupsAttrTokenMap();
798 for( sal_Int16 i=0; i < nAttrCount; ++i )
800 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
801 rtl::OUString aLocalName;
802 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
803 sAttrName, &aLocalName );
804 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
806 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
808 case XML_TOK_SORT_GROUPS_ATTR_DATA_TYPE :
810 if (sValue.getLength() > 8)
812 rtl::OUString sTemp = sValue.copy(0, 8);
813 if (sTemp.compareToAscii(SC_USERLIST) == 0)
815 pDatabaseRangeContext->SetSubTotalsEnabledUserList(sal_True);
816 sTemp = sValue.copy(8);
817 pDatabaseRangeContext->SetSubTotalsUserListIndex(static_cast<sal_Int16>(sTemp.toInt32()));
819 else
821 //if (IsXMLToken(sValue, XML_AUTOMATIC))
822 //aSortField.FieldType = util::SortFieldType_AUTOMATIC;
823 // is not supported by StarOffice
826 else
828 //if (IsXMLToken(sValue, XML_TEXT))
829 //aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
830 // is not supported by StarOffice
831 //else if (IsXMLToken(sValue, XML_NUMBER))
832 //aSortField.FieldType = util::SortFieldType_NUMERIC;
833 // is not supported by StarOffice
836 break;
837 case XML_TOK_SORT_GROUPS_ATTR_ORDER :
839 if (IsXMLToken(sValue, XML_ASCENDING))
840 pDatabaseRangeContext->SetSubTotalsAscending(sal_True);
841 else
842 pDatabaseRangeContext->SetSubTotalsAscending(sal_False);
844 break;
849 ScXMLSortGroupsContext::~ScXMLSortGroupsContext()
853 SvXMLImportContext *ScXMLSortGroupsContext::CreateChildContext( USHORT nPrefix,
854 const ::rtl::OUString& rLName,
855 const ::com::sun::star::uno::Reference<
856 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
858 SvXMLImportContext *pContext = 0;
860 if( !pContext )
861 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
863 return pContext;
866 void ScXMLSortGroupsContext::EndElement()
870 ScXMLSubTotalRuleContext::ScXMLSubTotalRuleContext( ScXMLImport& rImport,
871 USHORT nPrfx,
872 const ::rtl::OUString& rLName,
873 const ::com::sun::star::uno::Reference<
874 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
875 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
876 SvXMLImportContext( rImport, nPrfx, rLName ),
877 pDatabaseRangeContext(pTempDatabaseRangeContext)
879 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
880 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleAttrTokenMap();
881 for( sal_Int16 i=0; i < nAttrCount; ++i )
883 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
884 rtl::OUString aLocalName;
885 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
886 sAttrName, &aLocalName );
887 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
889 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
891 case XML_TOK_SUBTOTAL_RULE_ATTR_GROUP_BY_FIELD_NUMBER :
893 aSubTotalRule.nSubTotalRuleGroupFieldNumber = static_cast<sal_Int16>(sValue.toInt32());
895 break;
900 ScXMLSubTotalRuleContext::~ScXMLSubTotalRuleContext()
904 SvXMLImportContext *ScXMLSubTotalRuleContext::CreateChildContext( USHORT nPrefix,
905 const ::rtl::OUString& rLName,
906 const ::com::sun::star::uno::Reference<
907 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
909 SvXMLImportContext *pContext = 0;
911 const SvXMLTokenMap& rTokenMap = GetScImport().GetSubTotalRulesSubTotalRuleElemTokenMap();
912 switch( rTokenMap.Get( nPrefix, rLName ) )
914 case XML_TOK_SUBTOTAL_RULE_SUBTOTAL_FIELD :
916 pContext = new ScXMLSubTotalFieldContext( GetScImport(), nPrefix,
917 rLName, xAttrList, this);
919 break;
922 if( !pContext )
923 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
925 return pContext;
928 void ScXMLSubTotalRuleContext::EndElement()
930 if (pDatabaseRangeContext)
931 pDatabaseRangeContext->AddSubTotalRule(aSubTotalRule);
934 ScXMLSubTotalFieldContext::ScXMLSubTotalFieldContext( ScXMLImport& rImport,
935 USHORT nPrfx,
936 const ::rtl::OUString& rLName,
937 const ::com::sun::star::uno::Reference<
938 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
939 ScXMLSubTotalRuleContext* pTempSubTotalRuleContext) :
940 SvXMLImportContext( rImport, nPrfx, rLName ),
941 pSubTotalRuleContext(pTempSubTotalRuleContext)
943 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
944 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetSubTotalRuleSubTotalFieldAttrTokenMap();
945 for( sal_Int16 i=0; i < nAttrCount; ++i )
947 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
948 rtl::OUString aLocalName;
949 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
950 sAttrName, &aLocalName );
951 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
953 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
955 case XML_TOK_SUBTOTAL_FIELD_ATTR_FIELD_NUMBER :
957 sFieldNumber = sValue;
959 break;
960 case XML_TOK_SUBTOTAL_FIELD_ATTR_FUNCTION :
962 sFunction = sValue;
964 break;
969 ScXMLSubTotalFieldContext::~ScXMLSubTotalFieldContext()
973 SvXMLImportContext *ScXMLSubTotalFieldContext::CreateChildContext( USHORT nPrefix,
974 const ::rtl::OUString& rLName,
975 const ::com::sun::star::uno::Reference<
976 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
978 SvXMLImportContext *pContext = 0;
980 if( !pContext )
981 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
983 return pContext;
986 void ScXMLSubTotalFieldContext::EndElement()
988 sheet::SubTotalColumn aSubTotalColumn;
989 aSubTotalColumn.Column = sFieldNumber.toInt32();
990 aSubTotalColumn.Function = ScXMLConverter::GetFunctionFromString( sFunction );
991 pSubTotalRuleContext->AddSubTotalColumn(aSubTotalColumn);