1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfilti.cxx,v $
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"
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
,
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
),
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
:
87 if (ScRangeStringConverter::GetRangeFromString( aScRange
, sValue
, pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
))
89 ScUnoConversion::FillApiAddress( aOutputPosition
, aScRange
.aStart
);
90 bCopyOutputData
= sal_True
;
94 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS
:
97 if (ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress
, sValue
, pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
))
98 bConditionSourceRange
= sal_True
;
101 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE
:
103 // not supported by StarOffice
106 case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES
:
108 bSkipDuplicates
= !IsXMLToken(sValue
, XML_TRUE
);
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);
135 case XML_TOK_FILTER_OR
:
137 pContext
= new ScXMLOrContext( GetScImport(), nPrefix
,
138 rLName
, xAttrList
, this);
141 case XML_TOK_FILTER_CONDITION
:
143 pContext
= new ScXMLConditionContext( GetScImport(), nPrefix
,
144 rLName
, xAttrList
, this);
150 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
155 void ScXMLFilterContext::EndElement()
157 pDatabaseRangeContext
->SetFilterUseRegularExpressions(bUseRegularExpressions
);
160 pDatabaseRangeContext
->SetFilterOutputPosition(aOutputPosition
);
161 pDatabaseRangeContext
->SetFilterCopyOutputData(bCopyOutputData
);
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
,
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
203 case XML_TOK_FILTER_CONDITION
:
205 pContext
= new ScXMLConditionContext( GetScImport(), nPrefix
,
206 rLName
, xAttrList
, pFilterContext
);
212 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
217 void ScXMLAndContext::EndElement()
219 pFilterContext
->CloseConnection();
222 ScXMLOrContext::ScXMLOrContext( ScXMLImport
& rImport
,
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
);
254 case XML_TOK_FILTER_CONDITION
:
256 pContext
= new ScXMLConditionContext( GetScImport(), nPrefix
,
257 rLName
, xAttrList
, pFilterContext
);
263 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
268 void ScXMLOrContext::EndElement()
270 pFilterContext
->CloseConnection();
273 ScXMLConditionContext::ScXMLConditionContext( ScXMLImport
& rImport
,
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();
302 case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE
:
304 bIsCaseSensitive
= IsXMLToken(sValue
, XML_TRUE
);
307 case XML_TOK_CONDITION_ATTR_DATA_TYPE
:
312 case XML_TOK_CONDITION_ATTR_VALUE
:
314 sConditionValue
= sValue
;
317 case XML_TOK_CONDITION_ATTR_OPERATOR
:
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
;
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
;
408 aFilterField
.StringValue
= sConditionValue
;
409 aFilterField
.IsNumeric
= sal_False
;
411 pFilterContext
->AddFilterField(aFilterField
);
414 //==========================================================================
416 ScXMLDPFilterContext::ScXMLDPFilterContext( ScXMLImport
& rImport
,
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
),
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
:
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
;
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
;
465 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE
:
467 // not supported by StarOffice
470 case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES
:
472 bSkipDuplicates
= !IsXMLToken(sValue
, XML_TRUE
);
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);
499 case XML_TOK_FILTER_OR
:
501 pContext
= new ScXMLDPOrContext( GetScImport(), nPrefix
,
502 rLName
, xAttrList
, this);
505 case XML_TOK_FILTER_CONDITION
:
507 pContext
= new ScXMLDPConditionContext( GetScImport(), nPrefix
,
508 rLName
, xAttrList
, this);
514 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
519 void ScXMLDPFilterContext::EndElement()
521 aFilterFields
.bRegExp
= bUseRegularExpressions
;
522 aFilterFields
.bCaseSens
= bIsCaseSensitive
;
523 aFilterFields
.bDuplicate
= !bSkipDuplicates
;
524 // pDataPilotTable->SetFilterUseRegularExpressions(bUseRegularExpressions);
527 pDataPilotTable
->SetFilterOutputPosition(aOutputPosition
);
528 pDataPilotTable
->SetFilterCopyOutputData(bCopyOutputData
);
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
;
548 ScXMLDPAndContext::ScXMLDPAndContext( ScXMLImport
& rImport
,
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
579 case XML_TOK_FILTER_CONDITION
:
581 pContext
= new ScXMLDPConditionContext( GetScImport(), nPrefix
,
582 rLName
, xAttrList
, pFilterContext
);
588 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
593 void ScXMLDPAndContext::EndElement()
595 pFilterContext
->CloseConnection();
598 ScXMLDPOrContext::ScXMLDPOrContext( ScXMLImport
& rImport
,
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
);
630 case XML_TOK_FILTER_CONDITION
:
632 pContext
= new ScXMLDPConditionContext( GetScImport(), nPrefix
,
633 rLName
, xAttrList
, pFilterContext
);
639 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
644 void ScXMLDPOrContext::EndElement()
646 pFilterContext
->CloseConnection();
649 ScXMLDPConditionContext::ScXMLDPConditionContext( ScXMLImport
& rImport
,
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();
678 case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE
:
680 bIsCaseSensitive
= IsXMLToken(sValue
, XML_TRUE
);
683 case XML_TOK_CONDITION_ATTR_DATA_TYPE
:
688 case XML_TOK_CONDITION_ATTR_VALUE
:
690 sConditionValue
= sValue
;
693 case XML_TOK_CONDITION_ATTR_OPERATOR
:
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
,
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
;
760 aFilterField
.eConnect
= SC_AND
;
761 pFilterContext
->SetIsCaseSensitive(bIsCaseSensitive
);
762 sal_Bool bUseRegularExpressions
;
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
;
774 aFilterField
.nVal
= dVal
;
775 *aFilterField
.pStr
= EMPTY_STRING
;
780 aFilterField
.pStr
= new String(sConditionValue
);
781 aFilterField
.bQueryByString
= sal_True
;
782 aFilterField
.nVal
= 0;
784 pFilterContext
->AddFilterField(aFilterField
);