merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / xml / xmlfilti.cxx
blobd3fb512140e489862df7eff7dae2f6371b4a30b6
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: xmlfilti.cxx,v $
10 * $Revision: 1.17 $
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"
35 // INCLUDE ---------------------------------------------------------------
37 #include "xmlfilti.hxx"
38 #include "xmlimprt.hxx"
39 #include "docuno.hxx"
40 #include "convuno.hxx"
41 #include "XMLConverter.hxx"
42 #include "rangeutl.hxx"
44 #include <xmloff/xmltkmap.hxx>
45 #include <xmloff/nmspmap.hxx>
46 #include <xmloff/xmltoken.hxx>
48 using namespace com::sun::star;
49 using namespace xmloff::token;
51 //------------------------------------------------------------------
53 ScXMLFilterContext::ScXMLFilterContext( ScXMLImport& rImport,
54 USHORT nPrfx,
55 const ::rtl::OUString& rLName,
56 const ::com::sun::star::uno::Reference<
57 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
58 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
59 SvXMLImportContext( rImport, nPrfx, rLName ),
60 pDatabaseRangeContext(pTempDatabaseRangeContext),
61 aFilterFields(),
62 bSkipDuplicates(sal_False),
63 bCopyOutputData(sal_False),
64 bUseRegularExpressions(sal_False),
65 bConnectionOr(sal_True),
66 bNextConnectionOr(sal_True),
67 bConditionSourceRange(sal_False)
69 ScDocument* pDoc(GetScImport().GetDocument());
71 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
72 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetFilterAttrTokenMap();
73 for( sal_Int16 i=0; i < nAttrCount; ++i )
75 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
76 rtl::OUString aLocalName;
77 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
78 sAttrName, &aLocalName );
79 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
81 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
83 case XML_TOK_FILTER_ATTR_TARGET_RANGE_ADDRESS :
85 ScRange aScRange;
86 sal_Int32 nOffset(0);
87 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
89 ScUnoConversion::FillApiAddress( aOutputPosition, aScRange.aStart );
90 bCopyOutputData = sal_True;
93 break;
94 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS :
96 sal_Int32 nOffset(0);
97 if (ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
98 bConditionSourceRange = sal_True;
100 break;
101 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE :
103 // not supported by StarOffice
105 break;
106 case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES :
108 bSkipDuplicates = !IsXMLToken(sValue, XML_TRUE);
110 break;
115 ScXMLFilterContext::~ScXMLFilterContext()
119 SvXMLImportContext *ScXMLFilterContext::CreateChildContext( USHORT nPrefix,
120 const ::rtl::OUString& rLName,
121 const ::com::sun::star::uno::Reference<
122 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
124 SvXMLImportContext *pContext(0);
126 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
127 switch( rTokenMap.Get( nPrefix, rLName ) )
129 case XML_TOK_FILTER_AND:
131 pContext = new ScXMLAndContext( GetScImport(), nPrefix,
132 rLName, xAttrList, this);
134 break;
135 case XML_TOK_FILTER_OR:
137 pContext = new ScXMLOrContext( GetScImport(), nPrefix,
138 rLName, xAttrList, this);
140 break;
141 case XML_TOK_FILTER_CONDITION:
143 pContext = new ScXMLConditionContext( GetScImport(), nPrefix,
144 rLName, xAttrList, this);
146 break;
149 if( !pContext )
150 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
152 return pContext;
155 void ScXMLFilterContext::EndElement()
157 pDatabaseRangeContext->SetFilterUseRegularExpressions(bUseRegularExpressions);
158 if (bCopyOutputData)
160 pDatabaseRangeContext->SetFilterOutputPosition(aOutputPosition);
161 pDatabaseRangeContext->SetFilterCopyOutputData(bCopyOutputData);
163 else
164 pDatabaseRangeContext->SetFilterCopyOutputData(sal_False);
165 pDatabaseRangeContext->SetFilterIsCaseSensitive(bIsCaseSensitive);
166 pDatabaseRangeContext->SetFilterSkipDuplicates(bSkipDuplicates);
167 pDatabaseRangeContext->SetFilterFields(aFilterFields);
168 if (bConditionSourceRange)
169 pDatabaseRangeContext->SetFilterConditionSourceRangeAddress(aConditionSourceRangeAddress);
172 ScXMLAndContext::ScXMLAndContext( ScXMLImport& rImport,
173 USHORT nPrfx,
174 const ::rtl::OUString& rLName,
175 const ::com::sun::star::uno::Reference<
176 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
177 ScXMLFilterContext* pTempFilterContext) :
178 SvXMLImportContext( rImport, nPrfx, rLName ),
179 pFilterContext(pTempFilterContext)
181 pFilterContext->OpenConnection(sal_False);
184 ScXMLAndContext::~ScXMLAndContext()
188 SvXMLImportContext *ScXMLAndContext::CreateChildContext( USHORT nPrefix,
189 const ::rtl::OUString& rLName,
190 const ::com::sun::star::uno::Reference<
191 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
193 SvXMLImportContext *pContext(0);
195 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
196 switch( rTokenMap.Get( nPrefix, rLName ) )
198 case XML_TOK_FILTER_OR:
200 // not supported in StarOffice
202 break;
203 case XML_TOK_FILTER_CONDITION:
205 pContext = new ScXMLConditionContext( GetScImport(), nPrefix,
206 rLName, xAttrList, pFilterContext);
208 break;
211 if( !pContext )
212 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
214 return pContext;
217 void ScXMLAndContext::EndElement()
219 pFilterContext->CloseConnection();
222 ScXMLOrContext::ScXMLOrContext( ScXMLImport& rImport,
223 USHORT nPrfx,
224 const ::rtl::OUString& rLName,
225 const ::com::sun::star::uno::Reference<
226 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
227 ScXMLFilterContext* pTempFilterContext) :
228 SvXMLImportContext( rImport, nPrfx, rLName ),
229 pFilterContext(pTempFilterContext)
231 pFilterContext->OpenConnection(sal_True);
234 ScXMLOrContext::~ScXMLOrContext()
238 SvXMLImportContext *ScXMLOrContext::CreateChildContext( USHORT nPrefix,
239 const ::rtl::OUString& rLName,
240 const ::com::sun::star::uno::Reference<
241 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
243 SvXMLImportContext *pContext(0);
245 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
246 switch( rTokenMap.Get( nPrefix, rLName ) )
248 case XML_TOK_FILTER_AND:
250 pContext = new ScXMLAndContext( GetScImport(), nPrefix,
251 rLName, xAttrList, pFilterContext);
253 break;
254 case XML_TOK_FILTER_CONDITION:
256 pContext = new ScXMLConditionContext( GetScImport(), nPrefix,
257 rLName, xAttrList, pFilterContext);
259 break;
262 if( !pContext )
263 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
265 return pContext;
268 void ScXMLOrContext::EndElement()
270 pFilterContext->CloseConnection();
273 ScXMLConditionContext::ScXMLConditionContext( ScXMLImport& rImport,
274 USHORT nPrfx,
275 const ::rtl::OUString& rLName,
276 const ::com::sun::star::uno::Reference<
277 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
278 ScXMLFilterContext* pTempFilterContext) :
279 SvXMLImportContext( rImport, nPrfx, rLName ),
280 pFilterContext(pTempFilterContext),
281 bIsCaseSensitive(sal_False)
283 sDataType = GetXMLToken(XML_TEXT);
285 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
286 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterConditionAttrTokenMap());
287 for( sal_Int16 i=0; i < nAttrCount; ++i )
289 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
290 rtl::OUString aLocalName;
291 USHORT nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
292 sAttrName, &aLocalName );
293 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
295 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
297 case XML_TOK_CONDITION_ATTR_FIELD_NUMBER :
299 nField = sValue.toInt32();
301 break;
302 case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE :
304 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
306 break;
307 case XML_TOK_CONDITION_ATTR_DATA_TYPE :
309 sDataType = sValue;
311 break;
312 case XML_TOK_CONDITION_ATTR_VALUE :
314 sConditionValue = sValue;
316 break;
317 case XML_TOK_CONDITION_ATTR_OPERATOR :
319 sOperator = sValue;
321 break;
326 ScXMLConditionContext::~ScXMLConditionContext()
330 SvXMLImportContext *ScXMLConditionContext::CreateChildContext( USHORT nPrefix,
331 const ::rtl::OUString& rLName,
332 const ::com::sun::star::uno::Reference<
333 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
335 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
338 void ScXMLConditionContext::getOperatorXML(const rtl::OUString sTempOperator, sal_Int32& aFilterOperator, sal_Bool& bUseRegularExpressions) const
340 bUseRegularExpressions = sal_False;
341 if (IsXMLToken(sTempOperator, XML_MATCH))
343 bUseRegularExpressions = sal_True;
344 aFilterOperator = sheet::FilterOperator2::EQUAL;
346 else if (IsXMLToken(sTempOperator, XML_NOMATCH))
348 bUseRegularExpressions = sal_True;
349 aFilterOperator = sheet::FilterOperator2::NOT_EQUAL;
351 else if (sTempOperator.compareToAscii("=") == 0)
352 aFilterOperator = sheet::FilterOperator2::EQUAL;
353 else if (sTempOperator.compareToAscii("!=") == 0)
354 aFilterOperator = sheet::FilterOperator2::NOT_EQUAL;
355 else if (IsXMLToken(sTempOperator, XML_BOTTOM_PERCENT))
356 aFilterOperator = sheet::FilterOperator2::BOTTOM_PERCENT;
357 else if (IsXMLToken(sTempOperator, XML_BOTTOM_VALUES))
358 aFilterOperator = sheet::FilterOperator2::BOTTOM_VALUES;
359 else if (IsXMLToken(sTempOperator, XML_EMPTY))
360 aFilterOperator = sheet::FilterOperator2::EMPTY;
361 else if (sTempOperator.compareToAscii(">") == 0)
362 aFilterOperator = sheet::FilterOperator2::GREATER;
363 else if (sTempOperator.compareToAscii(">=") == 0)
364 aFilterOperator = sheet::FilterOperator2::GREATER_EQUAL;
365 else if (sTempOperator.compareToAscii("<") == 0)
366 aFilterOperator = sheet::FilterOperator2::LESS;
367 else if (sTempOperator.compareToAscii("<=") == 0)
368 aFilterOperator = sheet::FilterOperator2::LESS_EQUAL;
369 else if (IsXMLToken(sTempOperator, XML_NOEMPTY))
370 aFilterOperator = sheet::FilterOperator2::NOT_EMPTY;
371 else if (IsXMLToken(sTempOperator, XML_TOP_PERCENT))
372 aFilterOperator = sheet::FilterOperator2::TOP_PERCENT;
373 else if (IsXMLToken(sTempOperator, XML_TOP_VALUES))
374 aFilterOperator = sheet::FilterOperator2::TOP_VALUES;
375 else if (IsXMLToken(sTempOperator, XML_CONTAINS))
376 aFilterOperator = sheet::FilterOperator2::CONTAINS;
377 else if (IsXMLToken(sTempOperator, XML_DOES_NOT_CONTAIN))
378 aFilterOperator = sheet::FilterOperator2::DOES_NOT_CONTAIN;
379 else if (IsXMLToken(sTempOperator, XML_BEGINS_WITH))
380 aFilterOperator = sheet::FilterOperator2::BEGINS_WITH;
381 else if (IsXMLToken(sTempOperator, XML_DOES_NOT_BEGIN_WITH))
382 aFilterOperator = sheet::FilterOperator2::DOES_NOT_BEGIN_WITH;
383 else if (IsXMLToken(sTempOperator, XML_ENDS_WITH))
384 aFilterOperator = sheet::FilterOperator2::ENDS_WITH;
385 else if (IsXMLToken(sTempOperator, XML_DOES_NOT_END_WITH))
386 aFilterOperator = sheet::FilterOperator2::DOES_NOT_END_WITH;
389 void ScXMLConditionContext::EndElement()
391 sheet::TableFilterField2 aFilterField;
392 if (pFilterContext->GetConnection())
393 aFilterField.Connection = sheet::FilterConnection_OR;
394 else
395 aFilterField.Connection = sheet::FilterConnection_AND;
396 pFilterContext->SetIsCaseSensitive(bIsCaseSensitive);
397 sal_Bool bUseRegularExpressions;
398 getOperatorXML(sOperator, aFilterField.Operator, bUseRegularExpressions);
399 pFilterContext->SetUseRegularExpressions(bUseRegularExpressions);
400 aFilterField.Field = nField;
401 if (IsXMLToken(sDataType, XML_NUMBER))
403 aFilterField.NumericValue = sConditionValue.toDouble();
404 aFilterField.IsNumeric = sal_True;
406 else
408 aFilterField.StringValue = sConditionValue;
409 aFilterField.IsNumeric = sal_False;
411 pFilterContext->AddFilterField(aFilterField);
414 //==========================================================================
416 ScXMLDPFilterContext::ScXMLDPFilterContext( ScXMLImport& rImport,
417 USHORT nPrfx,
418 const ::rtl::OUString& rLName,
419 const ::com::sun::star::uno::Reference<
420 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
421 ScXMLDataPilotTableContext* pTempDataPilotTableContext) :
422 SvXMLImportContext( rImport, nPrfx, rLName ),
423 pDataPilotTable(pTempDataPilotTableContext),
424 aFilterFields(),
425 nFilterFieldCount(0),
426 bSkipDuplicates(sal_False),
427 bCopyOutputData(sal_False),
428 bUseRegularExpressions(sal_False),
429 bConnectionOr(sal_True),
430 bNextConnectionOr(sal_True),
431 bConditionSourceRange(sal_False)
433 ScDocument* pDoc(GetScImport().GetDocument());
435 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
436 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterAttrTokenMap());
437 for( sal_Int16 i=0; i < nAttrCount; ++i )
439 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
440 rtl::OUString aLocalName;
441 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
442 sAttrName, &aLocalName ));
443 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
445 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
447 case XML_TOK_FILTER_ATTR_TARGET_RANGE_ADDRESS :
449 ScRange aScRange;
450 sal_Int32 nOffset(0);
451 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
453 aOutputPosition = aScRange.aStart;
454 bCopyOutputData = sal_True;
457 break;
458 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS :
460 sal_Int32 nOffset(0);
461 if(ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
462 bConditionSourceRange = sal_True;
464 break;
465 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE :
467 // not supported by StarOffice
469 break;
470 case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES :
472 bSkipDuplicates = !IsXMLToken(sValue, XML_TRUE);
474 break;
479 ScXMLDPFilterContext::~ScXMLDPFilterContext()
483 SvXMLImportContext *ScXMLDPFilterContext::CreateChildContext( USHORT nPrefix,
484 const ::rtl::OUString& rLName,
485 const ::com::sun::star::uno::Reference<
486 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
488 SvXMLImportContext *pContext(0);
490 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
491 switch( rTokenMap.Get( nPrefix, rLName ) )
493 case XML_TOK_FILTER_AND:
495 pContext = new ScXMLDPAndContext( GetScImport(), nPrefix,
496 rLName, xAttrList, this);
498 break;
499 case XML_TOK_FILTER_OR:
501 pContext = new ScXMLDPOrContext( GetScImport(), nPrefix,
502 rLName, xAttrList, this);
504 break;
505 case XML_TOK_FILTER_CONDITION:
507 pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
508 rLName, xAttrList, this);
510 break;
513 if( !pContext )
514 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
516 return pContext;
519 void ScXMLDPFilterContext::EndElement()
521 aFilterFields.bRegExp = bUseRegularExpressions;
522 aFilterFields.bCaseSens = bIsCaseSensitive;
523 aFilterFields.bDuplicate = !bSkipDuplicates;
524 // pDataPilotTable->SetFilterUseRegularExpressions(bUseRegularExpressions);
525 if (bCopyOutputData)
527 pDataPilotTable->SetFilterOutputPosition(aOutputPosition);
528 pDataPilotTable->SetFilterCopyOutputData(bCopyOutputData);
530 else
531 pDataPilotTable->SetFilterCopyOutputData(sal_False);
532 // pDataPilotTable->SetFilterIsCaseSensitive(bIsCaseSensitive);
533 // pDataPilotTable->SetFilterSkipDuplicates(bSkipDuplicates);
534 pDataPilotTable->SetSourceQueryParam(aFilterFields);
535 if (bConditionSourceRange)
536 pDataPilotTable->SetFilterSourceRange(aConditionSourceRangeAddress);
539 void ScXMLDPFilterContext::AddFilterField (const ScQueryEntry& aFilterField)
541 aFilterFields.Resize(nFilterFieldCount + 1);
542 ScQueryEntry& rEntry(aFilterFields.GetEntry(nFilterFieldCount));
543 rEntry = aFilterField;
544 rEntry.bDoQuery = sal_True;
545 ++nFilterFieldCount;
548 ScXMLDPAndContext::ScXMLDPAndContext( ScXMLImport& rImport,
549 USHORT nPrfx,
550 const ::rtl::OUString& rLName,
551 const ::com::sun::star::uno::Reference<
552 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
553 ScXMLDPFilterContext* pTempFilterContext) :
554 SvXMLImportContext( rImport, nPrfx, rLName )
556 pFilterContext = pTempFilterContext;
557 pFilterContext->OpenConnection(sal_False);
560 ScXMLDPAndContext::~ScXMLDPAndContext()
564 SvXMLImportContext *ScXMLDPAndContext::CreateChildContext( USHORT nPrefix,
565 const ::rtl::OUString& rLName,
566 const ::com::sun::star::uno::Reference<
567 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
569 SvXMLImportContext *pContext(0);
571 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
572 switch( rTokenMap.Get( nPrefix, rLName ) )
574 case XML_TOK_FILTER_OR:
576 // not supported in StarOffice
578 break;
579 case XML_TOK_FILTER_CONDITION:
581 pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
582 rLName, xAttrList, pFilterContext);
584 break;
587 if( !pContext )
588 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
590 return pContext;
593 void ScXMLDPAndContext::EndElement()
595 pFilterContext->CloseConnection();
598 ScXMLDPOrContext::ScXMLDPOrContext( ScXMLImport& rImport,
599 USHORT nPrfx,
600 const ::rtl::OUString& rLName,
601 const ::com::sun::star::uno::Reference<
602 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
603 ScXMLDPFilterContext* pTempFilterContext) :
604 SvXMLImportContext( rImport, nPrfx, rLName ),
605 pFilterContext(pTempFilterContext)
607 pFilterContext->OpenConnection(sal_True);
610 ScXMLDPOrContext::~ScXMLDPOrContext()
614 SvXMLImportContext *ScXMLDPOrContext::CreateChildContext( USHORT nPrefix,
615 const ::rtl::OUString& rLName,
616 const ::com::sun::star::uno::Reference<
617 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
619 SvXMLImportContext *pContext(0);
621 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
622 switch( rTokenMap.Get( nPrefix, rLName ) )
624 case XML_TOK_FILTER_AND:
626 pContext = new ScXMLDPAndContext( GetScImport(), nPrefix,
627 rLName, xAttrList, pFilterContext);
629 break;
630 case XML_TOK_FILTER_CONDITION:
632 pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
633 rLName, xAttrList, pFilterContext);
635 break;
638 if( !pContext )
639 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
641 return pContext;
644 void ScXMLDPOrContext::EndElement()
646 pFilterContext->CloseConnection();
649 ScXMLDPConditionContext::ScXMLDPConditionContext( ScXMLImport& rImport,
650 USHORT nPrfx,
651 const ::rtl::OUString& rLName,
652 const ::com::sun::star::uno::Reference<
653 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
654 ScXMLDPFilterContext* pTempFilterContext) :
655 SvXMLImportContext( rImport, nPrfx, rLName ),
656 pFilterContext(pTempFilterContext),
657 sDataType(GetXMLToken(XML_TEXT)),
658 bIsCaseSensitive(sal_False)
661 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
662 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterConditionAttrTokenMap());
663 for( sal_Int16 i=0; i < nAttrCount; ++i )
665 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
666 rtl::OUString aLocalName;
667 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
668 sAttrName, &aLocalName ));
669 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
671 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
673 case XML_TOK_CONDITION_ATTR_FIELD_NUMBER :
675 nField = sValue.toInt32();
677 break;
678 case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE :
680 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
682 break;
683 case XML_TOK_CONDITION_ATTR_DATA_TYPE :
685 sDataType = sValue;
687 break;
688 case XML_TOK_CONDITION_ATTR_VALUE :
690 sConditionValue = sValue;
692 break;
693 case XML_TOK_CONDITION_ATTR_OPERATOR :
695 sOperator = sValue;
697 break;
702 ScXMLDPConditionContext::~ScXMLDPConditionContext()
706 SvXMLImportContext *ScXMLDPConditionContext::CreateChildContext( USHORT nPrefix,
707 const ::rtl::OUString& rLName,
708 const ::com::sun::star::uno::Reference<
709 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
711 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
714 void ScXMLDPConditionContext::getOperatorXML(const rtl::OUString sTempOperator, ScQueryOp& aFilterOperator, sal_Bool& bUseRegularExpressions,
715 double& dVal) const
717 bUseRegularExpressions = sal_False;
718 if (IsXMLToken(sTempOperator, XML_MATCH))
720 bUseRegularExpressions = sal_True;
721 aFilterOperator = SC_EQUAL;
723 else if (IsXMLToken(sTempOperator, XML_NOMATCH))
725 bUseRegularExpressions = sal_True;
726 aFilterOperator = SC_NOT_EQUAL;
728 else if (sTempOperator.compareToAscii("=") == 0)
729 aFilterOperator = SC_EQUAL;
730 else if (sTempOperator.compareToAscii("!=") == 0)
731 aFilterOperator = SC_NOT_EQUAL;
732 else if (IsXMLToken(sTempOperator, XML_BOTTOM_PERCENT))
733 aFilterOperator = SC_BOTPERC;
734 else if (IsXMLToken(sTempOperator, XML_BOTTOM_VALUES))
735 aFilterOperator = SC_BOTVAL;
736 else if (IsXMLToken(sTempOperator, XML_EMPTY))
737 dVal = SC_EMPTYFIELDS;
738 else if (sTempOperator.compareToAscii(">") == 0)
739 aFilterOperator = SC_GREATER;
740 else if (sTempOperator.compareToAscii(">=") == 0)
741 aFilterOperator = SC_GREATER_EQUAL;
742 else if (sTempOperator.compareToAscii("<") == 0)
743 aFilterOperator = SC_LESS;
744 else if (sTempOperator.compareToAscii("<=") == 0)
745 aFilterOperator = SC_LESS_EQUAL;
746 else if (IsXMLToken(sTempOperator, XML_NOEMPTY))
747 dVal = SC_NONEMPTYFIELDS;
748 else if (IsXMLToken(sTempOperator, XML_TOP_PERCENT))
749 aFilterOperator = SC_TOPPERC;
750 else if (IsXMLToken(sTempOperator, XML_TOP_VALUES))
751 aFilterOperator = SC_TOPVAL;
754 void ScXMLDPConditionContext::EndElement()
756 ScQueryEntry aFilterField;
757 if (pFilterContext->GetConnection())
758 aFilterField.eConnect = SC_OR;
759 else
760 aFilterField.eConnect = SC_AND;
761 pFilterContext->SetIsCaseSensitive(bIsCaseSensitive);
762 sal_Bool bUseRegularExpressions;
763 double dVal(0.0);
764 getOperatorXML(sOperator, aFilterField.eOp, bUseRegularExpressions, dVal);
765 pFilterContext->SetUseRegularExpressions(bUseRegularExpressions);
766 aFilterField.nField = nField;
767 if (IsXMLToken(sDataType, XML_NUMBER))
769 aFilterField.nVal = sConditionValue.toDouble();
770 *aFilterField.pStr = sConditionValue;
771 aFilterField.bQueryByString = sal_False;
772 if (dVal != 0.0)
774 aFilterField.nVal = dVal;
775 *aFilterField.pStr = EMPTY_STRING;
778 else
780 aFilterField.pStr = new String(sConditionValue);
781 aFilterField.bQueryByString = sal_True;
782 aFilterField.nVal = 0;
784 pFilterContext->AddFilterField(aFilterField);