LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - xmlfilti.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 97 418 23.2 %
Date: 2012-12-27 Functions: 21 57 36.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "xmlfilti.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "docuno.hxx"
      23             : #include "convuno.hxx"
      24             : #include "XMLConverter.hxx"
      25             : #include "rangeutl.hxx"
      26             : #include "queryentry.hxx"
      27             : 
      28             : #include <xmloff/xmltkmap.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <xmloff/xmltoken.hxx>
      31             : 
      32             : using namespace com::sun::star;
      33             : using namespace xmloff::token;
      34             : 
      35             : using ::com::sun::star::uno::Reference;
      36             : using ::com::sun::star::xml::sax::XAttributeList;
      37             : 
      38           1 : ScXMLFilterContext::ConnStackItem::ConnStackItem(bool bOr) : mbOr(bOr), mnCondCount(0) {}
      39             : 
      40           1 : ScXMLFilterContext::ScXMLFilterContext( ScXMLImport& rImport,
      41             :                                         sal_uInt16 nPrfx,
      42             :                                         const rtl::OUString& rLName,
      43             :                                         const Reference<XAttributeList>& xAttrList,
      44             :                                         ScQueryParam& rParam,
      45             :                                         ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
      46             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      47             :     mrQueryParam(rParam),
      48             :     pDatabaseRangeContext(pTempDatabaseRangeContext),
      49             :     bSkipDuplicates(false),
      50             :     bCopyOutputData(false),
      51           1 :     bConditionSourceRange(false)
      52             : {
      53           1 :     ScDocument* pDoc(GetScImport().GetDocument());
      54             : 
      55           1 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      56           1 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetFilterAttrTokenMap();
      57           1 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      58             :     {
      59           0 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
      60           0 :         rtl::OUString aLocalName;
      61           0 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
      62           0 :                                             sAttrName, &aLocalName );
      63           0 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
      64             : 
      65           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      66             :         {
      67             :             case XML_TOK_FILTER_ATTR_TARGET_RANGE_ADDRESS :
      68             :             {
      69           0 :                 ScRange aScRange;
      70           0 :                 sal_Int32 nOffset(0);
      71           0 :                 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
      72             :                 {
      73           0 :                     ScUnoConversion::FillApiAddress( aOutputPosition, aScRange.aStart );
      74           0 :                     bCopyOutputData = true;
      75             :                 }
      76             :             }
      77           0 :             break;
      78             :             case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS :
      79             :             {
      80           0 :                 sal_Int32 nOffset(0);
      81           0 :                 if (ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
      82           0 :                     bConditionSourceRange = true;
      83             :             }
      84           0 :             break;
      85             :             case XML_TOK_FILTER_ATTR_CONDITION_SOURCE :
      86             :             {
      87             :                 // not supported by StarOffice
      88             :             }
      89           0 :             break;
      90             :             case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES :
      91             :             {
      92           0 :                 bSkipDuplicates = !IsXMLToken(sValue, XML_TRUE);
      93             :             }
      94           0 :             break;
      95             :         }
      96           0 :     }
      97           1 : }
      98             : 
      99           2 : ScXMLFilterContext::~ScXMLFilterContext()
     100             : {
     101           2 : }
     102             : 
     103           1 : SvXMLImportContext *ScXMLFilterContext::CreateChildContext( sal_uInt16 nPrefix,
     104             :                                             const ::rtl::OUString& rLName,
     105             :                                             const ::com::sun::star::uno::Reference<
     106             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     107             : {
     108           1 :     SvXMLImportContext *pContext(0);
     109             : 
     110           1 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
     111           1 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     112             :     {
     113             :         case XML_TOK_FILTER_AND:
     114             :         {
     115             :             pContext = new ScXMLAndContext(
     116           0 :                 GetScImport(), nPrefix, rLName, xAttrList, mrQueryParam, this);
     117             :         }
     118           0 :         break;
     119             :         case XML_TOK_FILTER_OR:
     120             :         {
     121             :             pContext = new ScXMLOrContext(
     122           1 :                 GetScImport(), nPrefix, rLName, xAttrList, mrQueryParam, this);
     123             :         }
     124           1 :         break;
     125             :         case XML_TOK_FILTER_CONDITION:
     126             :         {
     127             :             pContext = new ScXMLConditionContext(
     128           0 :                 GetScImport(), nPrefix, rLName, xAttrList, mrQueryParam, this);
     129             :         }
     130           0 :         break;
     131             :     }
     132             : 
     133           1 :     if( !pContext )
     134           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     135             : 
     136           1 :     return pContext;
     137             : }
     138             : 
     139           1 : void ScXMLFilterContext::EndElement()
     140             : {
     141           1 :     mrQueryParam.bInplace = !bCopyOutputData;
     142           1 :     mrQueryParam.bDuplicate = !bSkipDuplicates;
     143             : 
     144           1 :     if (bCopyOutputData)
     145             :     {
     146           0 :         mrQueryParam.nDestCol = aOutputPosition.Column;
     147           0 :         mrQueryParam.nDestRow = aOutputPosition.Row;
     148           0 :         mrQueryParam.nDestTab = aOutputPosition.Sheet;
     149             :     }
     150             : 
     151           1 :     if (bConditionSourceRange)
     152           0 :         pDatabaseRangeContext->SetFilterConditionSourceRangeAddress(aConditionSourceRangeAddress);
     153           1 : }
     154             : 
     155           1 : void ScXMLFilterContext::OpenConnection(bool b)
     156             : {
     157           1 :     maConnStack.push_back(ConnStackItem(b));
     158           1 : }
     159             : 
     160           1 : void ScXMLFilterContext::CloseConnection()
     161             : {
     162           1 :     maConnStack.pop_back();
     163           1 : }
     164             : 
     165           1 : bool ScXMLFilterContext::GetConnection()
     166             : {
     167             :     // For condition items in each stack, the first one gets the connection of
     168             :     // the last stack, while the rest of them get that of the current stack.
     169             : 
     170           1 :     if (maConnStack.empty())
     171             :         // This should never happen.
     172           0 :         return true;
     173             : 
     174           1 :     ConnStackItem& rItem = maConnStack.back();
     175           1 :     if (rItem.mnCondCount)
     176             :         // secondary item gets the current connection.
     177           0 :         return rItem.mbOr;
     178             : 
     179           1 :     if (maConnStack.size() < 2)
     180             :         // There is no last stack.  Likely the first condition in the first
     181             :         // stack whose connection is not used.
     182           1 :         return true;
     183             : 
     184           0 :     ++rItem.mnCondCount;
     185           0 :     std::vector<ConnStackItem>::reverse_iterator itr = maConnStack.rbegin();
     186           0 :     ++itr;
     187           0 :     return itr->mbOr; // connection of the last stack.
     188             : }
     189             : 
     190           0 : ScXMLAndContext::ScXMLAndContext( ScXMLImport& rImport,
     191             :                                   sal_uInt16 nPrfx,
     192             :                                   const rtl::OUString& rLName,
     193             :                                   const Reference<XAttributeList>& /* xAttrList */,
     194             :                                   ScQueryParam& rParam,
     195             :                                   ScXMLFilterContext* pTempFilterContext) :
     196             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     197             :     mrQueryParam(rParam),
     198           0 :     pFilterContext(pTempFilterContext)
     199             : {
     200           0 :     pFilterContext->OpenConnection(false);
     201           0 : }
     202             : 
     203           0 : ScXMLAndContext::~ScXMLAndContext()
     204             : {
     205           0 : }
     206             : 
     207           0 : SvXMLImportContext *ScXMLAndContext::CreateChildContext( sal_uInt16 nPrefix,
     208             :                                             const ::rtl::OUString& rLName,
     209             :                                             const ::com::sun::star::uno::Reference<
     210             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     211             : {
     212           0 :     SvXMLImportContext *pContext(0);
     213             : 
     214           0 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
     215           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     216             :     {
     217             :         case XML_TOK_FILTER_OR:
     218             :         {
     219             :             // not supported in StarOffice
     220             :         }
     221           0 :         break;
     222             :         case XML_TOK_FILTER_CONDITION:
     223             :         {
     224             :             pContext = new ScXMLConditionContext(
     225           0 :                 GetScImport(), nPrefix, rLName, xAttrList, mrQueryParam, pFilterContext);
     226             :         }
     227           0 :         break;
     228             :     }
     229             : 
     230           0 :     if( !pContext )
     231           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     232             : 
     233           0 :     return pContext;
     234             : }
     235             : 
     236           0 : void ScXMLAndContext::EndElement()
     237             : {
     238           0 :     pFilterContext->CloseConnection();
     239           0 : }
     240             : 
     241           1 : ScXMLOrContext::ScXMLOrContext( ScXMLImport& rImport,
     242             :                                 sal_uInt16 nPrfx,
     243             :                                 const rtl::OUString& rLName,
     244             :                                 const Reference<
     245             :                                     ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
     246             :                                 ScQueryParam& rParam,
     247             :                                 ScXMLFilterContext* pTempFilterContext) :
     248             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     249             :     mrQueryParam(rParam),
     250           1 :     pFilterContext(pTempFilterContext)
     251             : {
     252           1 :     pFilterContext->OpenConnection(true);
     253           1 : }
     254             : 
     255           2 : ScXMLOrContext::~ScXMLOrContext()
     256             : {
     257           2 : }
     258             : 
     259           1 : SvXMLImportContext *ScXMLOrContext::CreateChildContext( sal_uInt16 nPrefix,
     260             :                                             const ::rtl::OUString& rLName,
     261             :                                             const ::com::sun::star::uno::Reference<
     262             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     263             : {
     264           1 :     SvXMLImportContext *pContext(0);
     265             : 
     266           1 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
     267           1 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     268             :     {
     269             :         case XML_TOK_FILTER_AND:
     270             :         {
     271             :             pContext = new ScXMLAndContext(
     272           0 :                 GetScImport(), nPrefix, rLName, xAttrList, mrQueryParam, pFilterContext);
     273             :         }
     274           0 :         break;
     275             :         case XML_TOK_FILTER_CONDITION:
     276             :         {
     277             :             pContext = new ScXMLConditionContext(
     278           1 :                 GetScImport(), nPrefix, rLName, xAttrList, mrQueryParam, pFilterContext);
     279             :         }
     280           1 :         break;
     281             :     }
     282             : 
     283           1 :     if( !pContext )
     284           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     285             : 
     286           1 :     return pContext;
     287             : }
     288             : 
     289           1 : void ScXMLOrContext::EndElement()
     290             : {
     291           1 :     pFilterContext->CloseConnection();
     292           1 : }
     293             : 
     294           1 : ScXMLConditionContext::ScXMLConditionContext(
     295             :     ScXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
     296             :     const Reference<XAttributeList>& xAttrList,
     297             :     ScQueryParam& rParam,
     298             :     ScXMLFilterContext* pTempFilterContext) :
     299             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     300             :     mrQueryParam(rParam),
     301             :     pFilterContext(pTempFilterContext),
     302           1 :     bIsCaseSensitive(false)
     303             : {
     304           1 :     sDataType = GetXMLToken(XML_TEXT);
     305             : 
     306           1 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     307           1 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterConditionAttrTokenMap());
     308           4 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     309             :     {
     310           3 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
     311           3 :         rtl::OUString aLocalName;
     312           3 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
     313           3 :                                             sAttrName, &aLocalName );
     314           3 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
     315             : 
     316           3 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     317             :         {
     318             :             case XML_TOK_CONDITION_ATTR_FIELD_NUMBER :
     319             :             {
     320           1 :                 nField = sValue.toInt32();
     321             :             }
     322           1 :             break;
     323             :             case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE :
     324             :             {
     325           0 :                 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
     326             :             }
     327           0 :             break;
     328             :             case XML_TOK_CONDITION_ATTR_DATA_TYPE :
     329             :             {
     330           0 :                 sDataType = sValue;
     331             :             }
     332           0 :             break;
     333             :             case XML_TOK_CONDITION_ATTR_VALUE :
     334             :             {
     335           1 :                 sConditionValue = sValue;
     336             :             }
     337           1 :             break;
     338             :             case XML_TOK_CONDITION_ATTR_OPERATOR :
     339             :             {
     340           1 :                 sOperator = sValue;
     341             :             }
     342           1 :             break;
     343             :         }
     344           3 :     }
     345           1 : }
     346             : 
     347           2 : ScXMLConditionContext::~ScXMLConditionContext()
     348             : {
     349           2 : }
     350             : 
     351           0 : SvXMLImportContext *ScXMLConditionContext::CreateChildContext( sal_uInt16 nPrefix,
     352             :                                             const ::rtl::OUString& rLName,
     353             :                                             const Reference<XAttributeList>& xAttrList )
     354             : {
     355           0 :     SvXMLImportContext *pContext = NULL;
     356             : 
     357           0 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterConditionElemTokenMap());
     358           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     359             :     {
     360             :         case XML_TOK_CONDITION_FILTER_SET_ITEM:
     361             :         {
     362             :             pContext = new ScXMLSetItemContext(
     363           0 :                 GetScImport(), nPrefix, rLName, xAttrList, *this);
     364             :         }
     365           0 :         break;
     366             :     }
     367             : 
     368           0 :     if( !pContext )
     369           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     370             : 
     371           0 :     return pContext;
     372             : }
     373             : 
     374           1 : void ScXMLConditionContext::GetOperator(
     375             :     const rtl::OUString& aOpStr, ScQueryParam& rParam, ScQueryEntry& rEntry) const
     376             : {
     377           1 :     rParam.bRegExp = false;
     378           1 :     if (IsXMLToken(aOpStr, XML_MATCH))
     379             :     {
     380           0 :         rParam.bRegExp = true;
     381           0 :         rEntry.eOp = SC_EQUAL;
     382             :     }
     383           1 :     else if (IsXMLToken(aOpStr, XML_NOMATCH))
     384             :     {
     385           0 :         rParam.bRegExp = true;
     386           0 :         rEntry.eOp = SC_NOT_EQUAL;
     387             :     }
     388           1 :     else if (aOpStr.compareToAscii("=") == 0)
     389           1 :         rEntry.eOp = SC_EQUAL;
     390           0 :     else if (aOpStr.compareToAscii("!=") == 0)
     391           0 :         rEntry.eOp = SC_NOT_EQUAL;
     392           0 :     else if (IsXMLToken(aOpStr, XML_BOTTOM_PERCENT))
     393           0 :         rEntry.eOp = SC_BOTPERC;
     394           0 :     else if (IsXMLToken(aOpStr, XML_BOTTOM_VALUES))
     395           0 :         rEntry.eOp = SC_BOTVAL;
     396           0 :     else if (IsXMLToken(aOpStr, XML_EMPTY))
     397           0 :         rEntry.SetQueryByEmpty();
     398           0 :     else if (aOpStr.compareToAscii(">") == 0)
     399           0 :         rEntry.eOp = SC_GREATER;
     400           0 :     else if (aOpStr.compareToAscii(">=") == 0)
     401           0 :         rEntry.eOp = SC_GREATER_EQUAL;
     402           0 :     else if (aOpStr.compareToAscii("<") == 0)
     403           0 :         rEntry.eOp = SC_LESS;
     404           0 :     else if (aOpStr.compareToAscii("<=") == 0)
     405           0 :         rEntry.eOp = SC_LESS_EQUAL;
     406           0 :     else if (IsXMLToken(aOpStr, XML_NOEMPTY))
     407           0 :         rEntry.SetQueryByNonEmpty();
     408           0 :     else if (IsXMLToken(aOpStr, XML_TOP_PERCENT))
     409           0 :         rEntry.eOp = SC_TOPPERC;
     410           0 :     else if (IsXMLToken(aOpStr, XML_TOP_VALUES))
     411           0 :         rEntry.eOp = SC_TOPVAL;
     412           0 :     else if (IsXMLToken(aOpStr, XML_CONTAINS))
     413           0 :         rEntry.eOp = SC_CONTAINS;
     414           0 :     else if (IsXMLToken(aOpStr, XML_DOES_NOT_CONTAIN))
     415           0 :         rEntry.eOp = SC_DOES_NOT_CONTAIN;
     416           0 :     else if (IsXMLToken(aOpStr, XML_BEGINS_WITH))
     417           0 :         rEntry.eOp = SC_BEGINS_WITH;
     418           0 :     else if (IsXMLToken(aOpStr, XML_DOES_NOT_BEGIN_WITH))
     419           0 :         rEntry.eOp = SC_DOES_NOT_BEGIN_WITH;
     420           0 :     else if (IsXMLToken(aOpStr, XML_ENDS_WITH))
     421           0 :         rEntry.eOp = SC_ENDS_WITH;
     422           0 :     else if (IsXMLToken(aOpStr, XML_DOES_NOT_END_WITH))
     423           0 :         rEntry.eOp = SC_DOES_NOT_END_WITH;
     424           1 : }
     425             : 
     426           0 : void ScXMLConditionContext::AddSetItem(const ScQueryEntry::Item& rItem)
     427             : {
     428           0 :     maQueryItems.push_back(rItem);
     429           0 : }
     430             : 
     431           1 : void ScXMLConditionContext::EndElement()
     432             : {
     433           1 :     ScQueryEntry& rEntry = mrQueryParam.AppendEntry();
     434             : 
     435             :     // We currently don't support per-condition case sensitivity.
     436           1 :     mrQueryParam.bCaseSens = bIsCaseSensitive;
     437             : 
     438           1 :     rEntry.bDoQuery = true;
     439           1 :     rEntry.eConnect = pFilterContext->GetConnection() ? SC_OR : SC_AND;
     440             : 
     441           1 :     GetOperator(sOperator, mrQueryParam, rEntry);
     442           1 :     SCCOLROW nStartPos = mrQueryParam.bByRow ? mrQueryParam.nCol1 : mrQueryParam.nRow1;
     443           1 :     rEntry.nField = nField + nStartPos;
     444             : 
     445           1 :     if (maQueryItems.empty())
     446             :     {
     447           1 :         ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
     448           1 :         if (IsXMLToken(sDataType, XML_NUMBER))
     449             :         {
     450           0 :             rItem.mfVal = sConditionValue.toDouble();
     451           0 :             rItem.meType = ScQueryEntry::ByValue;
     452             :         }
     453             :         else
     454             :         {
     455           1 :             rItem.maString = sConditionValue;
     456           1 :             rItem.meType = ScQueryEntry::ByString;
     457             :         }
     458             :     }
     459             :     else
     460           0 :         rEntry.GetQueryItems().swap(maQueryItems);
     461           1 : }
     462             : 
     463           0 : const ScXMLImport& ScXMLSetItemContext::GetScImport() const
     464             : {
     465           0 :     return static_cast<const ScXMLImport&>(GetImport());
     466             : }
     467             : 
     468           0 : ScXMLImport& ScXMLSetItemContext::GetScImport()
     469             : {
     470           0 :     return static_cast<ScXMLImport&>(GetImport());
     471             : }
     472             : 
     473           0 : ScXMLSetItemContext::ScXMLSetItemContext(
     474             :     ScXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName,
     475             :     const Reference<XAttributeList>& xAttrList, ScXMLConditionContext& rParent) :
     476           0 :     SvXMLImportContext(rImport, nPrfx, rLName)
     477             : {
     478           0 :     sal_Int32 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     479           0 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetFilterSetItemAttrTokenMap();
     480           0 :     for (sal_Int32 i = 0; i < nAttrCount; ++i)
     481             :     {
     482           0 :         const rtl::OUString& sAttrName = xAttrList->getNameByIndex(i);
     483           0 :         rtl::OUString aLocalName;
     484             :         sal_uInt16 nPrefix =
     485           0 :             GetScImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
     486             : 
     487           0 :         const rtl::OUString& sValue = xAttrList->getValueByIndex(i);
     488             : 
     489           0 :         switch (rAttrTokenMap.Get(nPrefix, aLocalName))
     490             :         {
     491             :             case XML_TOK_FILTER_SET_ITEM_ATTR_VALUE:
     492             :             {
     493           0 :                 ScQueryEntry::Item aItem;
     494           0 :                 aItem.maString = sValue;
     495           0 :                 aItem.meType = ScQueryEntry::ByString;
     496           0 :                 aItem.mfVal = 0.0;
     497           0 :                 rParent.AddSetItem(aItem);
     498             :             }
     499           0 :             break;
     500             :         }
     501           0 :     }
     502           0 : }
     503             : 
     504           0 : SvXMLImportContext* ScXMLSetItemContext::CreateChildContext(
     505             :     sal_uInt16 nPrefix, const ::rtl::OUString& rLName,
     506             :     const Reference<XAttributeList>& /*xAttrList*/ )
     507             : {
     508           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );;
     509             : }
     510             : 
     511           0 : ScXMLSetItemContext::~ScXMLSetItemContext()
     512             : {
     513           0 : }
     514             : 
     515           0 : void ScXMLSetItemContext::EndElement()
     516             : {
     517           0 : }
     518             : 
     519             : //==========================================================================
     520             : 
     521           0 : ScXMLDPFilterContext::ScXMLDPFilterContext( ScXMLImport& rImport,
     522             :                                       sal_uInt16 nPrfx,
     523             :                                       const ::rtl::OUString& rLName,
     524             :                                       const ::com::sun::star::uno::Reference<
     525             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     526             :                                         ScXMLDataPilotTableContext* pTempDataPilotTableContext) :
     527             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     528             :     pDataPilotTable(pTempDataPilotTableContext),
     529             :     aFilterFields(),
     530             :     nFilterFieldCount(0),
     531             :     bSkipDuplicates(false),
     532             :     bCopyOutputData(false),
     533             :     bUseRegularExpressions(false),
     534             :     bConnectionOr(true),
     535             :     bNextConnectionOr(true),
     536           0 :     bConditionSourceRange(false)
     537             : {
     538           0 :     ScDocument* pDoc(GetScImport().GetDocument());
     539             : 
     540           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     541           0 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterAttrTokenMap());
     542           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     543             :     {
     544           0 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
     545           0 :         rtl::OUString aLocalName;
     546           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     547           0 :                                             sAttrName, &aLocalName ));
     548           0 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
     549             : 
     550           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     551             :         {
     552             :             case XML_TOK_FILTER_ATTR_TARGET_RANGE_ADDRESS :
     553             :             {
     554           0 :                 ScRange aScRange;
     555           0 :                 sal_Int32 nOffset(0);
     556           0 :                 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
     557             :                 {
     558           0 :                     aOutputPosition = aScRange.aStart;
     559           0 :                     bCopyOutputData = true;
     560             :                 }
     561             :             }
     562           0 :             break;
     563             :             case XML_TOK_FILTER_ATTR_CONDITION_SOURCE_RANGE_ADDRESS :
     564             :             {
     565           0 :                 sal_Int32 nOffset(0);
     566           0 :                 if(ScRangeStringConverter::GetRangeFromString( aConditionSourceRangeAddress, sValue, pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
     567           0 :                     bConditionSourceRange = true;
     568             :             }
     569           0 :             break;
     570             :             case XML_TOK_FILTER_ATTR_CONDITION_SOURCE :
     571             :             {
     572             :                 // not supported by StarOffice
     573             :             }
     574           0 :             break;
     575             :             case XML_TOK_FILTER_ATTR_DISPLAY_DUPLICATES :
     576             :             {
     577           0 :                 bSkipDuplicates = !IsXMLToken(sValue, XML_TRUE);
     578             :             }
     579           0 :             break;
     580             :         }
     581           0 :     }
     582           0 : }
     583             : 
     584           0 : ScXMLDPFilterContext::~ScXMLDPFilterContext()
     585             : {
     586           0 : }
     587             : 
     588           0 : SvXMLImportContext *ScXMLDPFilterContext::CreateChildContext( sal_uInt16 nPrefix,
     589             :                                             const ::rtl::OUString& rLName,
     590             :                                             const ::com::sun::star::uno::Reference<
     591             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     592             : {
     593           0 :     SvXMLImportContext *pContext(0);
     594             : 
     595           0 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
     596           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     597             :     {
     598             :         case XML_TOK_FILTER_AND:
     599             :         {
     600             :             pContext = new ScXMLDPAndContext( GetScImport(), nPrefix,
     601           0 :                                                           rLName, xAttrList, this);
     602             :         }
     603           0 :         break;
     604             :         case XML_TOK_FILTER_OR:
     605             :         {
     606             :             pContext = new ScXMLDPOrContext( GetScImport(), nPrefix,
     607           0 :                                                           rLName, xAttrList, this);
     608             :         }
     609           0 :         break;
     610             :         case XML_TOK_FILTER_CONDITION:
     611             :         {
     612             :             pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
     613           0 :                                                           rLName, xAttrList, this);
     614             :         }
     615           0 :         break;
     616             :     }
     617             : 
     618           0 :     if( !pContext )
     619           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     620             : 
     621           0 :     return pContext;
     622             : }
     623             : 
     624           0 : void ScXMLDPFilterContext::EndElement()
     625             : {
     626           0 :     aFilterFields.bRegExp = bUseRegularExpressions;
     627           0 :     aFilterFields.bCaseSens = bIsCaseSensitive;
     628           0 :     aFilterFields.bDuplicate = !bSkipDuplicates;
     629           0 :     if (bCopyOutputData)
     630           0 :         pDataPilotTable->SetFilterOutputPosition(aOutputPosition);
     631             : 
     632           0 :     pDataPilotTable->SetSourceQueryParam(aFilterFields);
     633           0 :     if (bConditionSourceRange)
     634           0 :         pDataPilotTable->SetFilterSourceRange(aConditionSourceRangeAddress);
     635           0 : }
     636             : 
     637           0 : void ScXMLDPFilterContext::AddFilterField (const ScQueryEntry& aFilterField)
     638             : {
     639           0 :     aFilterFields.Resize(nFilterFieldCount + 1);
     640           0 :     ScQueryEntry& rEntry(aFilterFields.GetEntry(nFilterFieldCount));
     641           0 :     rEntry = aFilterField;
     642           0 :     rEntry.bDoQuery = true;
     643           0 :     ++nFilterFieldCount;
     644           0 : }
     645             : 
     646           0 : ScXMLDPAndContext::ScXMLDPAndContext( ScXMLImport& rImport,
     647             :                                       sal_uInt16 nPrfx,
     648             :                                       const ::rtl::OUString& rLName,
     649             :                                       const ::com::sun::star::uno::Reference<
     650             :                                       ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
     651             :                                         ScXMLDPFilterContext* pTempFilterContext) :
     652           0 :     SvXMLImportContext( rImport, nPrfx, rLName )
     653             : {
     654           0 :     pFilterContext = pTempFilterContext;
     655           0 :     pFilterContext->OpenConnection(false);
     656           0 : }
     657             : 
     658           0 : ScXMLDPAndContext::~ScXMLDPAndContext()
     659             : {
     660           0 : }
     661             : 
     662           0 : SvXMLImportContext *ScXMLDPAndContext::CreateChildContext( sal_uInt16 nPrefix,
     663             :                                             const ::rtl::OUString& rLName,
     664             :                                             const ::com::sun::star::uno::Reference<
     665             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     666             : {
     667           0 :     SvXMLImportContext *pContext(0);
     668             : 
     669           0 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
     670           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     671             :     {
     672             :         case XML_TOK_FILTER_OR:
     673             :         {
     674             :             // not supported in StarOffice
     675             :         }
     676           0 :         break;
     677             :         case XML_TOK_FILTER_CONDITION:
     678             :         {
     679             :             pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
     680           0 :                                                           rLName, xAttrList, pFilterContext);
     681             :         }
     682           0 :         break;
     683             :     }
     684             : 
     685           0 :     if( !pContext )
     686           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     687             : 
     688           0 :     return pContext;
     689             : }
     690             : 
     691           0 : void ScXMLDPAndContext::EndElement()
     692             : {
     693           0 :     pFilterContext->CloseConnection();
     694           0 : }
     695             : 
     696           0 : ScXMLDPOrContext::ScXMLDPOrContext( ScXMLImport& rImport,
     697             :                                       sal_uInt16 nPrfx,
     698             :                                       const ::rtl::OUString& rLName,
     699             :                                       const ::com::sun::star::uno::Reference<
     700             :                                       ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */,
     701             :                                         ScXMLDPFilterContext* pTempFilterContext) :
     702             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     703           0 :     pFilterContext(pTempFilterContext)
     704             : {
     705           0 :     pFilterContext->OpenConnection(true);
     706           0 : }
     707             : 
     708           0 : ScXMLDPOrContext::~ScXMLDPOrContext()
     709             : {
     710           0 : }
     711             : 
     712           0 : SvXMLImportContext *ScXMLDPOrContext::CreateChildContext( sal_uInt16 nPrefix,
     713             :                                             const ::rtl::OUString& rLName,
     714             :                                             const ::com::sun::star::uno::Reference<
     715             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     716             : {
     717           0 :     SvXMLImportContext *pContext(0);
     718             : 
     719           0 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetFilterElemTokenMap());
     720           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     721             :     {
     722             :         case XML_TOK_FILTER_AND:
     723             :         {
     724             :             pContext = new ScXMLDPAndContext( GetScImport(), nPrefix,
     725           0 :                                                           rLName, xAttrList, pFilterContext);
     726             :         }
     727           0 :         break;
     728             :         case XML_TOK_FILTER_CONDITION:
     729             :         {
     730             :             pContext = new ScXMLDPConditionContext( GetScImport(), nPrefix,
     731           0 :                                                           rLName, xAttrList, pFilterContext);
     732             :         }
     733           0 :         break;
     734             :     }
     735             : 
     736           0 :     if( !pContext )
     737           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     738             : 
     739           0 :     return pContext;
     740             : }
     741             : 
     742           0 : void ScXMLDPOrContext::EndElement()
     743             : {
     744           0 :     pFilterContext->CloseConnection();
     745           0 : }
     746             : 
     747           0 : ScXMLDPConditionContext::ScXMLDPConditionContext( ScXMLImport& rImport,
     748             :                                       sal_uInt16 nPrfx,
     749             :                                       const ::rtl::OUString& rLName,
     750             :                                       const ::com::sun::star::uno::Reference<
     751             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     752             :                                         ScXMLDPFilterContext* pTempFilterContext) :
     753             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     754             :     pFilterContext(pTempFilterContext),
     755           0 :     sDataType(GetXMLToken(XML_TEXT)),
     756           0 :     bIsCaseSensitive(false)
     757             : {
     758             : 
     759           0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     760           0 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetFilterConditionAttrTokenMap());
     761           0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     762             :     {
     763           0 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
     764           0 :         rtl::OUString aLocalName;
     765           0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     766           0 :                                             sAttrName, &aLocalName ));
     767           0 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
     768             : 
     769           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     770             :         {
     771             :             case XML_TOK_CONDITION_ATTR_FIELD_NUMBER :
     772             :             {
     773           0 :                 nField = sValue.toInt32();
     774             :             }
     775           0 :             break;
     776             :             case XML_TOK_CONDITION_ATTR_CASE_SENSITIVE :
     777             :             {
     778           0 :                 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
     779             :             }
     780           0 :             break;
     781             :             case XML_TOK_CONDITION_ATTR_DATA_TYPE :
     782             :             {
     783           0 :                 sDataType = sValue;
     784             :             }
     785           0 :             break;
     786             :             case XML_TOK_CONDITION_ATTR_VALUE :
     787             :             {
     788           0 :                 sConditionValue = sValue;
     789             :             }
     790           0 :             break;
     791             :             case XML_TOK_CONDITION_ATTR_OPERATOR :
     792             :             {
     793           0 :                 sOperator = sValue;
     794             :             }
     795           0 :             break;
     796             :         }
     797           0 :     }
     798           0 : }
     799             : 
     800           0 : ScXMLDPConditionContext::~ScXMLDPConditionContext()
     801             : {
     802           0 : }
     803             : 
     804           0 : SvXMLImportContext *ScXMLDPConditionContext::CreateChildContext( sal_uInt16 nPrefix,
     805             :                                             const ::rtl::OUString& rLName,
     806             :                                             const ::com::sun::star::uno::Reference<
     807             :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
     808             : {
     809           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );
     810             : }
     811             : 
     812           0 : void ScXMLDPConditionContext::getOperatorXML(
     813             :     const rtl::OUString sTempOperator, ScQueryOp& aFilterOperator, bool& bUseRegularExpressions) const
     814             : {
     815           0 :     bUseRegularExpressions = false;
     816           0 :     if (IsXMLToken(sTempOperator, XML_MATCH))
     817             :     {
     818           0 :         bUseRegularExpressions = true;
     819           0 :         aFilterOperator = SC_EQUAL;
     820             :     }
     821           0 :     else if (IsXMLToken(sTempOperator, XML_NOMATCH))
     822             :     {
     823           0 :         bUseRegularExpressions = true;
     824           0 :         aFilterOperator = SC_NOT_EQUAL;
     825             :     }
     826           0 :     else if (sTempOperator.compareToAscii("=") == 0)
     827           0 :         aFilterOperator = SC_EQUAL;
     828           0 :     else if (sTempOperator.compareToAscii("!=") == 0)
     829           0 :         aFilterOperator = SC_NOT_EQUAL;
     830           0 :     else if (IsXMLToken(sTempOperator, XML_BOTTOM_PERCENT))
     831           0 :         aFilterOperator = SC_BOTPERC;
     832           0 :     else if (IsXMLToken(sTempOperator, XML_BOTTOM_VALUES))
     833           0 :         aFilterOperator = SC_BOTVAL;
     834           0 :     else if (sTempOperator.compareToAscii(">") == 0)
     835           0 :         aFilterOperator = SC_GREATER;
     836           0 :     else if (sTempOperator.compareToAscii(">=") == 0)
     837           0 :         aFilterOperator = SC_GREATER_EQUAL;
     838           0 :     else if (sTempOperator.compareToAscii("<") == 0)
     839           0 :         aFilterOperator = SC_LESS;
     840           0 :     else if (sTempOperator.compareToAscii("<=") == 0)
     841           0 :         aFilterOperator = SC_LESS_EQUAL;
     842           0 :     else if (IsXMLToken(sTempOperator, XML_TOP_PERCENT))
     843           0 :         aFilterOperator = SC_TOPPERC;
     844           0 :     else if (IsXMLToken(sTempOperator, XML_TOP_VALUES))
     845           0 :         aFilterOperator = SC_TOPVAL;
     846           0 : }
     847             : 
     848           0 : void ScXMLDPConditionContext::EndElement()
     849             : {
     850           0 :     ScQueryEntry aFilterField;
     851           0 :     if (pFilterContext->GetConnection())
     852           0 :         aFilterField.eConnect = SC_OR;
     853             :     else
     854           0 :         aFilterField.eConnect = SC_AND;
     855           0 :     pFilterContext->SetIsCaseSensitive(bIsCaseSensitive);
     856           0 :     if (IsXMLToken(sOperator, XML_EMPTY))
     857           0 :         aFilterField.SetQueryByEmpty();
     858           0 :     else if (IsXMLToken(sOperator, XML_NOEMPTY))
     859           0 :         aFilterField.SetQueryByNonEmpty();
     860             :     else
     861             :     {
     862           0 :         bool bUseRegularExpressions = false;
     863           0 :         getOperatorXML(sOperator, aFilterField.eOp, bUseRegularExpressions);
     864           0 :         pFilterContext->SetUseRegularExpressions(bUseRegularExpressions);
     865           0 :         aFilterField.nField = nField;
     866           0 :         ScQueryEntry::Item& rItem = aFilterField.GetQueryItem();
     867           0 :         if (IsXMLToken(sDataType, XML_NUMBER))
     868             :         {
     869           0 :             rItem.mfVal = sConditionValue.toDouble();
     870           0 :             rItem.maString = sConditionValue;
     871           0 :             rItem.meType = ScQueryEntry::ByValue;
     872             :         }
     873             :         else
     874             :         {
     875           0 :             rItem.maString = sConditionValue;
     876           0 :             rItem.meType = ScQueryEntry::ByString;
     877           0 :             rItem.mfVal = 0.0;
     878             :         }
     879             :     }
     880           0 :     pFilterContext->AddFilterField(aFilterField);
     881          15 : }
     882             : 
     883             : 
     884             : 
     885             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10