1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28 // INCLUDE ---------------------------------------------------------------
29
30 #include "xmlfilti.hxx"
31 #include "xmlimprt.hxx"
32 #include "docuno.hxx"
33 #include "convuno.hxx"
34 #include "XMLConverter.hxx"
35 #include "rangeutl.hxx"
36
37 #include <xmloff/xmltkmap.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40
41 using namespace com::sun::star;
42 using namespace xmloff::token;
43
44 //------------------------------------------------------------------
45
ScXMLFilterContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDatabaseRangeContext * pTempDatabaseRangeContext)46 ScXMLFilterContext::ScXMLFilterContext( ScXMLImport& rImport,
47 sal_uInt16 nPrfx,
48 const ::rtl::OUString& rLName,
49 const ::com::sun::star::uno::Reference<
50 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
51 ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
52 SvXMLImportContext( rImport, nPrfx, rLName ),
53 pDatabaseRangeContext(pTempDatabaseRangeContext),
54 aFilterFields(),
55 bSkipDuplicates(sal_False),
56 bCopyOutputData(sal_False),
57 bUseRegularExpressions(sal_False),
58 bConnectionOr(sal_True),
59 bNextConnectionOr(sal_True),
60 bConditionSourceRange(sal_False)
61 {
62 ScDocument* pDoc(GetScImport().GetDocument());
63
64 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
65 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetFilterAttrTokenMap();
66 for( sal_Int16 i=0; i < nAttrCount; ++i )
67 {
68 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
69 rtl::OUString aLocalName;
70 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
71 sAttrName, &aLocalName );
72 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
73
74 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
75 {
76 case XML_TOK_FILTER_ATTR_TARGET_RANGE_ADDRESS :
77 {
78 ScRange aScRange;
79 sal_Int32 nOffset(0);
80 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
81 {
82 ScUnoConversion::FillApiAddress( aOutputPosition, aScRange.aStart );
83 bCopyOutputData = sal_True;
84 }
85 }
86 break;
87 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS :
88 {
89 sal_Int32 nOffset(0);
90 if (ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
91 bConditionSourceRange = sal_True;
92 }
93 break;
94 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE :
95 {
96 // not supported by StarOffice
97 }
98 break;
99 case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES :
100 {
101 bSkipDuplicates = !IsXMLToken(sValue, XML_TRUE);
102 }
103 break;
104 }
105 }
106 }
107
~ScXMLFilterContext()108 ScXMLFilterContext::~ScXMLFilterContext()
109 {
110 }
111
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)112 SvXMLImportContext *ScXMLFilterContext::CreateChildContext( sal_uInt16 nPrefix,
113 const ::rtl::OUString& rLName,
114 const ::com::sun::star::uno::Reference<
115 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
116 {
117 SvXMLImportContext *pContext(0);
118
119 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
120 switch( rTokenMap.Get( nPrefix, rLName ) )
121 {
122 case XML_TOK_FILTER_AND:
123 {
124 pContext = new ScXMLAndContext( GetScImport(), nPrefix,
125 rLName, xAttrList, this);
126 }
127 break;
128 case XML_TOK_FILTER_OR:
129 {
130 pContext = new ScXMLOrContext( GetScImport(), nPrefix,
131 rLName, xAttrList, this);
132 }
133 break;
134 case XML_TOK_FILTER_CONDITION:
135 {
136 pContext = new ScXMLConditionContext( GetScImport(), nPrefix,
137 rLName, xAttrList, this);
138 }
139 break;
140 }
141
142 if( !pContext )
143 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
144
145 return pContext;
146 }
147
EndElement()148 void ScXMLFilterContext::EndElement()
149 {
150 pDatabaseRangeContext->SetFilterUseRegularExpressions(bUseRegularExpressions);
151 if (bCopyOutputData)
152 {
153 pDatabaseRangeContext->SetFilterOutputPosition(aOutputPosition);
154 pDatabaseRangeContext->SetFilterCopyOutputData(bCopyOutputData);
155 }
156 else
157 pDatabaseRangeContext->SetFilterCopyOutputData(sal_False);
158 pDatabaseRangeContext->SetFilterIsCaseSensitive(bIsCaseSensitive);
159 pDatabaseRangeContext->SetFilterSkipDuplicates(bSkipDuplicates);
160 pDatabaseRangeContext->SetFilterFields(aFilterFields);
161 if (bConditionSourceRange)
162 pDatabaseRangeContext->SetFilterConditionSourceRangeAddress(aConditionSourceRangeAddress);
163 }
164
ScXMLAndContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &,ScXMLFilterContext * pTempFilterContext)165 ScXMLAndContext::ScXMLAndContext( ScXMLImport& rImport,
166 sal_uInt16 nPrfx,
167 const ::rtl::OUString& rLName,
168 const ::com::sun::star::uno::Reference<
169 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
170 ScXMLFilterContext* pTempFilterContext) :
171 SvXMLImportContext( rImport, nPrfx, rLName ),
172 pFilterContext(pTempFilterContext)
173 {
174 pFilterContext->OpenConnection(sal_False);
175 }
176
~ScXMLAndContext()177 ScXMLAndContext::~ScXMLAndContext()
178 {
179 }
180
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)181 SvXMLImportContext *ScXMLAndContext::CreateChildContext( sal_uInt16 nPrefix,
182 const ::rtl::OUString& rLName,
183 const ::com::sun::star::uno::Reference<
184 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
185 {
186 SvXMLImportContext *pContext(0);
187
188 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
189 switch( rTokenMap.Get( nPrefix, rLName ) )
190 {
191 case XML_TOK_FILTER_OR:
192 {
193 // not supported in StarOffice
194 }
195 break;
196 case XML_TOK_FILTER_CONDITION:
197 {
198 pContext = new ScXMLConditionContext( GetScImport(), nPrefix,
199 rLName, xAttrList, pFilterContext);
200 }
201 break;
202 }
203
204 if( !pContext )
205 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
206
207 return pContext;
208 }
209
EndElement()210 void ScXMLAndContext::EndElement()
211 {
212 pFilterContext->CloseConnection();
213 }
214
ScXMLOrContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &,ScXMLFilterContext * pTempFilterContext)215 ScXMLOrContext::ScXMLOrContext( ScXMLImport& rImport,
216 sal_uInt16 nPrfx,
217 const ::rtl::OUString& rLName,
218 const ::com::sun::star::uno::Reference<
219 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
220 ScXMLFilterContext* pTempFilterContext) :
221 SvXMLImportContext( rImport, nPrfx, rLName ),
222 pFilterContext(pTempFilterContext)
223 {
224 pFilterContext->OpenConnection(sal_True);
225 }
226
~ScXMLOrContext()227 ScXMLOrContext::~ScXMLOrContext()
228 {
229 }
230
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)231 SvXMLImportContext *ScXMLOrContext::CreateChildContext( sal_uInt16 nPrefix,
232 const ::rtl::OUString& rLName,
233 const ::com::sun::star::uno::Reference<
234 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
235 {
236 SvXMLImportContext *pContext(0);
237
238 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
239 switch( rTokenMap.Get( nPrefix, rLName ) )
240 {
241 case XML_TOK_FILTER_AND:
242 {
243 pContext = new ScXMLAndContext( GetScImport(), nPrefix,
244 rLName, xAttrList, pFilterContext);
245 }
246 break;
247 case XML_TOK_FILTER_CONDITION:
248 {
249 pContext = new ScXMLConditionContext( GetScImport(), nPrefix,
250 rLName, xAttrList, pFilterContext);
251 }
252 break;
253 }
254
255 if( !pContext )
256 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
257
258 return pContext;
259 }
260
EndElement()261 void ScXMLOrContext::EndElement()
262 {
263 pFilterContext->CloseConnection();
264 }
265
ScXMLConditionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLFilterContext * pTempFilterContext)266 ScXMLConditionContext::ScXMLConditionContext( ScXMLImport& rImport,
267 sal_uInt16 nPrfx,
268 const ::rtl::OUString& rLName,
269 const ::com::sun::star::uno::Reference<
270 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
271 ScXMLFilterContext* pTempFilterContext) :
272 SvXMLImportContext( rImport, nPrfx, rLName ),
273 pFilterContext(pTempFilterContext),
274 bIsCaseSensitive(sal_False)
275 {
276 sDataType = GetXMLToken(XML_TEXT);
277
278 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
279 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterConditionAttrTokenMap());
280 for( sal_Int16 i=0; i < nAttrCount; ++i )
281 {
282 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
283 rtl::OUString aLocalName;
284 sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
285 sAttrName, &aLocalName );
286 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
287
288 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
289 {
290 case XML_TOK_CONDITION_ATTR_FIELD_NUMBER :
291 {
292 nField = sValue.toInt32();
293 }
294 break;
295 case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE :
296 {
297 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
298 }
299 break;
300 case XML_TOK_CONDITION_ATTR_DATA_TYPE :
301 {
302 sDataType = sValue;
303 }
304 break;
305 case XML_TOK_CONDITION_ATTR_VALUE :
306 {
307 sConditionValue = sValue;
308 }
309 break;
310 case XML_TOK_CONDITION_ATTR_OPERATOR :
311 {
312 sOperator = sValue;
313 }
314 break;
315 }
316 }
317 }
318
~ScXMLConditionContext()319 ScXMLConditionContext::~ScXMLConditionContext()
320 {
321 }
322
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)323 SvXMLImportContext *ScXMLConditionContext::CreateChildContext( sal_uInt16 nPrefix,
324 const ::rtl::OUString& rLName,
325 const ::com::sun::star::uno::Reference<
326 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
327 {
328 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
329 }
330
getOperatorXML(const rtl::OUString sTempOperator,sal_Int32 & aFilterOperator,sal_Bool & bUseRegularExpressions) const331 void ScXMLConditionContext::getOperatorXML(const rtl::OUString sTempOperator, sal_Int32& aFilterOperator, sal_Bool& bUseRegularExpressions) const
332 {
333 bUseRegularExpressions = sal_False;
334 if (IsXMLToken(sTempOperator, XML_MATCH))
335 {
336 bUseRegularExpressions = sal_True;
337 aFilterOperator = sheet::FilterOperator2::EQUAL;
338 }
339 else if (IsXMLToken(sTempOperator, XML_NOMATCH))
340 {
341 bUseRegularExpressions = sal_True;
342 aFilterOperator = sheet::FilterOperator2::NOT_EQUAL;
343 }
344 else if (sTempOperator.compareToAscii("=") == 0)
345 aFilterOperator = sheet::FilterOperator2::EQUAL;
346 else if (sTempOperator.compareToAscii("!=") == 0)
347 aFilterOperator = sheet::FilterOperator2::NOT_EQUAL;
348 else if (IsXMLToken(sTempOperator, XML_BOTTOM_PERCENT))
349 aFilterOperator = sheet::FilterOperator2::BOTTOM_PERCENT;
350 else if (IsXMLToken(sTempOperator, XML_BOTTOM_VALUES))
351 aFilterOperator = sheet::FilterOperator2::BOTTOM_VALUES;
352 else if (IsXMLToken(sTempOperator, XML_EMPTY))
353 aFilterOperator = sheet::FilterOperator2::EMPTY;
354 else if (sTempOperator.compareToAscii(">") == 0)
355 aFilterOperator = sheet::FilterOperator2::GREATER;
356 else if (sTempOperator.compareToAscii(">=") == 0)
357 aFilterOperator = sheet::FilterOperator2::GREATER_EQUAL;
358 else if (sTempOperator.compareToAscii("<") == 0)
359 aFilterOperator = sheet::FilterOperator2::LESS;
360 else if (sTempOperator.compareToAscii("<=") == 0)
361 aFilterOperator = sheet::FilterOperator2::LESS_EQUAL;
362 else if (IsXMLToken(sTempOperator, XML_NOEMPTY))
363 aFilterOperator = sheet::FilterOperator2::NOT_EMPTY;
364 else if (IsXMLToken(sTempOperator, XML_TOP_PERCENT))
365 aFilterOperator = sheet::FilterOperator2::TOP_PERCENT;
366 else if (IsXMLToken(sTempOperator, XML_TOP_VALUES))
367 aFilterOperator = sheet::FilterOperator2::TOP_VALUES;
368 else if (IsXMLToken(sTempOperator, XML_CONTAINS))
369 aFilterOperator = sheet::FilterOperator2::CONTAINS;
370 else if (IsXMLToken(sTempOperator, XML_DOES_NOT_CONTAIN))
371 aFilterOperator = sheet::FilterOperator2::DOES_NOT_CONTAIN;
372 else if (IsXMLToken(sTempOperator, XML_BEGINS_WITH))
373 aFilterOperator = sheet::FilterOperator2::BEGINS_WITH;
374 else if (IsXMLToken(sTempOperator, XML_DOES_NOT_BEGIN_WITH))
375 aFilterOperator = sheet::FilterOperator2::DOES_NOT_BEGIN_WITH;
376 else if (IsXMLToken(sTempOperator, XML_ENDS_WITH))
377 aFilterOperator = sheet::FilterOperator2::ENDS_WITH;
378 else if (IsXMLToken(sTempOperator, XML_DOES_NOT_END_WITH))
379 aFilterOperator = sheet::FilterOperator2::DOES_NOT_END_WITH;
380 }
381
EndElement()382 void ScXMLConditionContext::EndElement()
383 {
384 sheet::TableFilterField2 aFilterField;
385 if (pFilterContext->GetConnection())
386 aFilterField.Connection = sheet::FilterConnection_OR;
387 else
388 aFilterField.Connection = sheet::FilterConnection_AND;
389 pFilterContext->SetIsCaseSensitive(bIsCaseSensitive);
390 sal_Bool bUseRegularExpressions;
391 getOperatorXML(sOperator, aFilterField.Operator, bUseRegularExpressions);
392 pFilterContext->SetUseRegularExpressions(bUseRegularExpressions);
393 aFilterField.Field = nField;
394 if (IsXMLToken(sDataType, XML_NUMBER))
395 {
396 aFilterField.NumericValue = sConditionValue.toDouble();
397 aFilterField.IsNumeric = sal_True;
398 }
399 else
400 {
401 aFilterField.StringValue = sConditionValue;
402 aFilterField.IsNumeric = sal_False;
403 }
404 pFilterContext->AddFilterField(aFilterField);
405 }
406
407 //==========================================================================
408
ScXMLDPFilterContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDataPilotTableContext * pTempDataPilotTableContext)409 ScXMLDPFilterContext::ScXMLDPFilterContext( ScXMLImport& rImport,
410 sal_uInt16 nPrfx,
411 const ::rtl::OUString& rLName,
412 const ::com::sun::star::uno::Reference<
413 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
414 ScXMLDataPilotTableContext* pTempDataPilotTableContext) :
415 SvXMLImportContext( rImport, nPrfx, rLName ),
416 pDataPilotTable(pTempDataPilotTableContext),
417 aFilterFields(),
418 nFilterFieldCount(0),
419 bSkipDuplicates(sal_False),
420 bCopyOutputData(sal_False),
421 bUseRegularExpressions(sal_False),
422 bConnectionOr(sal_True),
423 bNextConnectionOr(sal_True),
424 bConditionSourceRange(sal_False)
425 {
426 ScDocument* pDoc(GetScImport().GetDocument());
427
428 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
429 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterAttrTokenMap());
430 for( sal_Int16 i=0; i < nAttrCount; ++i )
431 {
432 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
433 rtl::OUString aLocalName;
434 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
435 sAttrName, &aLocalName ));
436 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
437
438 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
439 {
440 case XML_TOK_FILTER_ATTR_TARGET_RANGE_ADDRESS :
441 {
442 ScRange aScRange;
443 sal_Int32 nOffset(0);
444 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
445 {
446 aOutputPosition = aScRange.aStart;
447 bCopyOutputData = sal_True;
448 }
449 }
450 break;
451 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS :
452 {
453 sal_Int32 nOffset(0);
454 if(ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
455 bConditionSourceRange = sal_True;
456 }
457 break;
458 case XML_TOK_FILTER_ATTR_CONDITION_SOURCE :
459 {
460 // not supported by StarOffice
461 }
462 break;
463 case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES :
464 {
465 bSkipDuplicates = !IsXMLToken(sValue, XML_TRUE);
466 }
467 break;
468 }
469 }
470 }
471
~ScXMLDPFilterContext()472 ScXMLDPFilterContext::~ScXMLDPFilterContext()
473 {
474 }
475
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)476 SvXMLImportContext *ScXMLDPFilterContext::CreateChildContext( sal_uInt16 nPrefix,
477 const ::rtl::OUString& rLName,
478 const ::com::sun::star::uno::Reference<
479 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
480 {
481 SvXMLImportContext *pContext(0);
482
483 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
484 switch( rTokenMap.Get( nPrefix, rLName ) )
485 {
486 case XML_TOK_FILTER_AND:
487 {
488 pContext = new ScXMLDPAndContext( GetScImport(), nPrefix,
489 rLName, xAttrList, this);
490 }
491 break;
492 case XML_TOK_FILTER_OR:
493 {
494 pContext = new ScXMLDPOrContext( GetScImport(), nPrefix,
495 rLName, xAttrList, this);
496 }
497 break;
498 case XML_TOK_FILTER_CONDITION:
499 {
500 pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
501 rLName, xAttrList, this);
502 }
503 break;
504 }
505
506 if( !pContext )
507 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
508
509 return pContext;
510 }
511
EndElement()512 void ScXMLDPFilterContext::EndElement()
513 {
514 aFilterFields.bRegExp = bUseRegularExpressions;
515 aFilterFields.bCaseSens = bIsCaseSensitive;
516 aFilterFields.bDuplicate = !bSkipDuplicates;
517 // pDataPilotTable->SetFilterUseRegularExpressions(bUseRegularExpressions);
518 if (bCopyOutputData)
519 {
520 pDataPilotTable->SetFilterOutputPosition(aOutputPosition);
521 pDataPilotTable->SetFilterCopyOutputData(bCopyOutputData);
522 }
523 else
524 pDataPilotTable->SetFilterCopyOutputData(sal_False);
525 // pDataPilotTable->SetFilterIsCaseSensitive(bIsCaseSensitive);
526 // pDataPilotTable->SetFilterSkipDuplicates(bSkipDuplicates);
527 pDataPilotTable->SetSourceQueryParam(aFilterFields);
528 if (bConditionSourceRange)
529 pDataPilotTable->SetFilterSourceRange(aConditionSourceRangeAddress);
530 }
531
AddFilterField(const ScQueryEntry & aFilterField)532 void ScXMLDPFilterContext::AddFilterField (const ScQueryEntry& aFilterField)
533 {
534 aFilterFields.Resize(nFilterFieldCount + 1);
535 ScQueryEntry& rEntry(aFilterFields.GetEntry(nFilterFieldCount));
536 rEntry = aFilterField;
537 rEntry.bDoQuery = sal_True;
538 ++nFilterFieldCount;
539 }
540
ScXMLDPAndContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &,ScXMLDPFilterContext * pTempFilterContext)541 ScXMLDPAndContext::ScXMLDPAndContext( ScXMLImport& rImport,
542 sal_uInt16 nPrfx,
543 const ::rtl::OUString& rLName,
544 const ::com::sun::star::uno::Reference<
545 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
546 ScXMLDPFilterContext* pTempFilterContext) :
547 SvXMLImportContext( rImport, nPrfx, rLName )
548 {
549 pFilterContext = pTempFilterContext;
550 pFilterContext->OpenConnection(sal_False);
551 }
552
~ScXMLDPAndContext()553 ScXMLDPAndContext::~ScXMLDPAndContext()
554 {
555 }
556
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)557 SvXMLImportContext *ScXMLDPAndContext::CreateChildContext( sal_uInt16 nPrefix,
558 const ::rtl::OUString& rLName,
559 const ::com::sun::star::uno::Reference<
560 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
561 {
562 SvXMLImportContext *pContext(0);
563
564 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
565 switch( rTokenMap.Get( nPrefix, rLName ) )
566 {
567 case XML_TOK_FILTER_OR:
568 {
569 // not supported in StarOffice
570 }
571 break;
572 case XML_TOK_FILTER_CONDITION:
573 {
574 pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
575 rLName, xAttrList, pFilterContext);
576 }
577 break;
578 }
579
580 if( !pContext )
581 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
582
583 return pContext;
584 }
585
EndElement()586 void ScXMLDPAndContext::EndElement()
587 {
588 pFilterContext->CloseConnection();
589 }
590
ScXMLDPOrContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &,ScXMLDPFilterContext * pTempFilterContext)591 ScXMLDPOrContext::ScXMLDPOrContext( ScXMLImport& rImport,
592 sal_uInt16 nPrfx,
593 const ::rtl::OUString& rLName,
594 const ::com::sun::star::uno::Reference<
595 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
596 ScXMLDPFilterContext* pTempFilterContext) :
597 SvXMLImportContext( rImport, nPrfx, rLName ),
598 pFilterContext(pTempFilterContext)
599 {
600 pFilterContext->OpenConnection(sal_True);
601 }
602
~ScXMLDPOrContext()603 ScXMLDPOrContext::~ScXMLDPOrContext()
604 {
605 }
606
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)607 SvXMLImportContext *ScXMLDPOrContext::CreateChildContext( sal_uInt16 nPrefix,
608 const ::rtl::OUString& rLName,
609 const ::com::sun::star::uno::Reference<
610 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
611 {
612 SvXMLImportContext *pContext(0);
613
614 const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
615 switch( rTokenMap.Get( nPrefix, rLName ) )
616 {
617 case XML_TOK_FILTER_AND:
618 {
619 pContext = new ScXMLDPAndContext( GetScImport(), nPrefix,
620 rLName, xAttrList, pFilterContext);
621 }
622 break;
623 case XML_TOK_FILTER_CONDITION:
624 {
625 pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
626 rLName, xAttrList, pFilterContext);
627 }
628 break;
629 }
630
631 if( !pContext )
632 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
633
634 return pContext;
635 }
636
EndElement()637 void ScXMLDPOrContext::EndElement()
638 {
639 pFilterContext->CloseConnection();
640 }
641
ScXMLDPConditionContext(ScXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList,ScXMLDPFilterContext * pTempFilterContext)642 ScXMLDPConditionContext::ScXMLDPConditionContext( ScXMLImport& rImport,
643 sal_uInt16 nPrfx,
644 const ::rtl::OUString& rLName,
645 const ::com::sun::star::uno::Reference<
646 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
647 ScXMLDPFilterContext* pTempFilterContext) :
648 SvXMLImportContext( rImport, nPrfx, rLName ),
649 pFilterContext(pTempFilterContext),
650 sDataType(GetXMLToken(XML_TEXT)),
651 bIsCaseSensitive(sal_False)
652 {
653
654 sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
655 const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterConditionAttrTokenMap());
656 for( sal_Int16 i=0; i < nAttrCount; ++i )
657 {
658 const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
659 rtl::OUString aLocalName;
660 sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
661 sAttrName, &aLocalName ));
662 const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
663
664 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
665 {
666 case XML_TOK_CONDITION_ATTR_FIELD_NUMBER :
667 {
668 nField = sValue.toInt32();
669 }
670 break;
671 case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE :
672 {
673 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
674 }
675 break;
676 case XML_TOK_CONDITION_ATTR_DATA_TYPE :
677 {
678 sDataType = sValue;
679 }
680 break;
681 case XML_TOK_CONDITION_ATTR_VALUE :
682 {
683 sConditionValue = sValue;
684 }
685 break;
686 case XML_TOK_CONDITION_ATTR_OPERATOR :
687 {
688 sOperator = sValue;
689 }
690 break;
691 }
692 }
693 }
694
~ScXMLDPConditionContext()695 ScXMLDPConditionContext::~ScXMLDPConditionContext()
696 {
697 }
698
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> &)699 SvXMLImportContext *ScXMLDPConditionContext::CreateChildContext( sal_uInt16 nPrefix,
700 const ::rtl::OUString& rLName,
701 const ::com::sun::star::uno::Reference<
702 ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
703 {
704 return new SvXMLImportContext( GetImport(), nPrefix, rLName );
705 }
706
getOperatorXML(const rtl::OUString sTempOperator,ScQueryOp & aFilterOperator,sal_Bool & bUseRegularExpressions,double & dVal) const707 void ScXMLDPConditionContext::getOperatorXML(const rtl::OUString sTempOperator, ScQueryOp& aFilterOperator, sal_Bool& bUseRegularExpressions,
708 double& dVal) const
709 {
710 bUseRegularExpressions = sal_False;
711 if (IsXMLToken(sTempOperator, XML_MATCH))
712 {
713 bUseRegularExpressions = sal_True;
714 aFilterOperator = SC_EQUAL;
715 }
716 else if (IsXMLToken(sTempOperator, XML_NOMATCH))
717 {
718 bUseRegularExpressions = sal_True;
719 aFilterOperator = SC_NOT_EQUAL;
720 }
721 else if (sTempOperator.compareToAscii("=") == 0)
722 aFilterOperator = SC_EQUAL;
723 else if (sTempOperator.compareToAscii("!=") == 0)
724 aFilterOperator = SC_NOT_EQUAL;
725 else if (IsXMLToken(sTempOperator, XML_BOTTOM_PERCENT))
726 aFilterOperator = SC_BOTPERC;
727 else if (IsXMLToken(sTempOperator, XML_BOTTOM_VALUES))
728 aFilterOperator = SC_BOTVAL;
729 else if (IsXMLToken(sTempOperator, XML_EMPTY))
730 dVal = SC_EMPTYFIELDS;
731 else if (sTempOperator.compareToAscii(">") == 0)
732 aFilterOperator = SC_GREATER;
733 else if (sTempOperator.compareToAscii(">=") == 0)
734 aFilterOperator = SC_GREATER_EQUAL;
735 else if (sTempOperator.compareToAscii("<") == 0)
736 aFilterOperator = SC_LESS;
737 else if (sTempOperator.compareToAscii("<=") == 0)
738 aFilterOperator = SC_LESS_EQUAL;
739 else if (IsXMLToken(sTempOperator, XML_NOEMPTY))
740 dVal = SC_NONEMPTYFIELDS;
741 else if (IsXMLToken(sTempOperator, XML_TOP_PERCENT))
742 aFilterOperator = SC_TOPPERC;
743 else if (IsXMLToken(sTempOperator, XML_TOP_VALUES))
744 aFilterOperator = SC_TOPVAL;
745 }
746
EndElement()747 void ScXMLDPConditionContext::EndElement()
748 {
749 ScQueryEntry aFilterField;
750 if (pFilterContext->GetConnection())
751 aFilterField.eConnect = SC_OR;
752 else
753 aFilterField.eConnect = SC_AND;
754 pFilterContext->SetIsCaseSensitive(bIsCaseSensitive);
755 sal_Bool bUseRegularExpressions;
756 double dVal(0.0);
757 getOperatorXML(sOperator, aFilterField.eOp, bUseRegularExpressions, dVal);
758 pFilterContext->SetUseRegularExpressions(bUseRegularExpressions);
759 aFilterField.nField = nField;
760 if (IsXMLToken(sDataType, XML_NUMBER))
761 {
762 aFilterField.nVal = sConditionValue.toDouble();
763 *aFilterField.pStr = sConditionValue;
764 aFilterField.bQueryByString = sal_False;
765 if (dVal != 0.0)
766 {
767 aFilterField.nVal = dVal;
768 *aFilterField.pStr = EMPTY_STRING;
769 }
770 }
771 else
772 {
773 aFilterField.pStr = new String(sConditionValue);
774 aFilterField.bQueryByString = sal_True;
775 aFilterField.nVal = 0;
776 }
777 pFilterContext->AddFilterField(aFilterField);
778 }
779
780
781
782