LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlsorti.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 124 0.0 %
Date: 2012-08-25 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 199 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xmlsorti.hxx"
      30                 :            : #include "xmlimprt.hxx"
      31                 :            : #include "docuno.hxx"
      32                 :            : #include "convuno.hxx"
      33                 :            : #include "XMLConverter.hxx"
      34                 :            : #include "unonames.hxx"
      35                 :            : #include "rangeutl.hxx"
      36                 :            : 
      37                 :            : #include <xmloff/xmltkmap.hxx>
      38                 :            : #include <xmloff/nmspmap.hxx>
      39                 :            : #include <comphelper/extract.hxx>
      40                 :            : #include <xmloff/xmltoken.hxx>
      41                 :            : 
      42                 :            : #define SC_USERLIST "UserList"
      43                 :            : 
      44                 :            : using namespace com::sun::star;
      45                 :            : using namespace xmloff::token;
      46                 :            : 
      47                 :            : //------------------------------------------------------------------
      48                 :            : 
      49                 :          0 : ScXMLSortContext::ScXMLSortContext( ScXMLImport& rImport,
      50                 :            :                                       sal_uInt16 nPrfx,
      51                 :            :                                       const ::rtl::OUString& rLName,
      52                 :            :                                       const ::com::sun::star::uno::Reference<
      53                 :            :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
      54                 :            :                                         ScXMLDatabaseRangeContext* pTempDatabaseRangeContext) :
      55                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
      56                 :            :     pDatabaseRangeContext(pTempDatabaseRangeContext),
      57                 :            :     sCountry(),
      58                 :            :     sLanguage(),
      59                 :            :     sAlgorithm(),
      60                 :            :     nUserListIndex(0),
      61                 :            :     bCopyOutputData(false),
      62                 :            :     bBindFormatsToContent(true),
      63                 :            :     bIsCaseSensitive(false),
      64         [ #  # ]:          0 :     bEnabledUserList(false)
      65                 :            : {
      66 [ #  # ][ #  # ]:          0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
                 [ #  # ]
      67         [ #  # ]:          0 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetSortAttrTokenMap());
      68         [ #  # ]:          0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      69                 :            :     {
      70 [ #  # ][ #  # ]:          0 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
      71                 :          0 :         rtl::OUString aLocalName;
      72                 :          0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
      73         [ #  # ]:          0 :                                             sAttrName, &aLocalName ));
      74 [ #  # ][ #  # ]:          0 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
      75                 :            : 
      76 [ #  # ][ #  #  :          0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
             #  #  #  #  
                      # ]
      77                 :            :         {
      78                 :            :             case XML_TOK_SORT_ATTR_BIND_STYLES_TO_CONTENT :
      79                 :            :             {
      80         [ #  # ]:          0 :                 bBindFormatsToContent = IsXMLToken(sValue, XML_TRUE);
      81                 :            :             }
      82                 :          0 :             break;
      83                 :            :             case XML_TOK_SORT_ATTR_TARGET_RANGE_ADDRESS :
      84                 :            :             {
      85                 :          0 :                 ScRange aScRange;
      86                 :          0 :                 sal_Int32 nOffset(0);
      87 [ #  # ][ #  # ]:          0 :                 if (ScRangeStringConverter::GetRangeFromString( aScRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ))
      88                 :            :                 {
      89                 :          0 :                     ScUnoConversion::FillApiAddress( aOutputPosition, aScRange.aStart );
      90                 :          0 :                     bCopyOutputData = true;
      91                 :            :                 }
      92                 :            :             }
      93                 :          0 :             break;
      94                 :            :             case XML_TOK_SORT_ATTR_CASE_SENSITIVE :
      95                 :            :             {
      96         [ #  # ]:          0 :                 bIsCaseSensitive = IsXMLToken(sValue, XML_TRUE);
      97                 :            :             }
      98                 :          0 :             break;
      99                 :            :             case XML_TOK_SORT_ATTR_LANGUAGE :
     100                 :          0 :                 sLanguage = sValue;
     101                 :          0 :             break;
     102                 :            :             case XML_TOK_SORT_ATTR_COUNTRY :
     103                 :          0 :                 sCountry = sValue;
     104                 :          0 :             break;
     105                 :            :             case XML_TOK_SORT_ATTR_ALGORITHM :
     106                 :          0 :                 sAlgorithm = sValue;
     107                 :          0 :             break;
     108                 :            :         }
     109                 :          0 :     }
     110                 :          0 : }
     111                 :            : 
     112         [ #  # ]:          0 : ScXMLSortContext::~ScXMLSortContext()
     113                 :            : {
     114         [ #  # ]:          0 : }
     115                 :            : 
     116                 :          0 : SvXMLImportContext *ScXMLSortContext::CreateChildContext( sal_uInt16 nPrefix,
     117                 :            :                                             const ::rtl::OUString& rLName,
     118                 :            :                                             const ::com::sun::star::uno::Reference<
     119                 :            :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     120                 :            : {
     121                 :          0 :     SvXMLImportContext *pContext(0);
     122                 :            : 
     123                 :          0 :     const SvXMLTokenMap& rTokenMap(GetScImport().GetSortElemTokenMap());
     124         [ #  # ]:          0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     125                 :            :     {
     126                 :            :         case XML_TOK_SORT_SORT_BY :
     127                 :            :         {
     128                 :            :             pContext = new ScXMLSortByContext( GetScImport(), nPrefix,
     129         [ #  # ]:          0 :                                                           rLName, xAttrList, this);
     130                 :            :         }
     131                 :          0 :         break;
     132                 :            :     }
     133                 :            : 
     134         [ #  # ]:          0 :     if( !pContext )
     135         [ #  # ]:          0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     136                 :            : 
     137                 :          0 :     return pContext;
     138                 :            : }
     139                 :            : 
     140                 :          0 : void ScXMLSortContext::EndElement()
     141                 :            : {
     142                 :          0 :     sal_Int32 nLangLength(sLanguage.getLength());
     143                 :          0 :     sal_Int32 nCountryLength(sCountry.getLength());
     144                 :          0 :     sal_Int32 nAlgoLength(sAlgorithm.getLength());
     145                 :          0 :     sal_uInt8 i (0);
     146 [ #  # ][ #  # ]:          0 :     if (nLangLength || nCountryLength)
     147                 :          0 :         ++i;
     148         [ #  # ]:          0 :     if (nAlgoLength)
     149                 :          0 :         ++i;
     150         [ #  # ]:          0 :     uno::Sequence <beans::PropertyValue> aSortDescriptor(7 + i);
     151 [ #  # ][ #  # ]:          0 :     aSortDescriptor[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_BINDFMT));
     152 [ #  # ][ #  # ]:          0 :     aSortDescriptor[0].Value = ::cppu::bool2any(bBindFormatsToContent);
     153 [ #  # ][ #  # ]:          0 :     aSortDescriptor[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_COPYOUT));
     154 [ #  # ][ #  # ]:          0 :     aSortDescriptor[1].Value = ::cppu::bool2any(bCopyOutputData);
     155 [ #  # ][ #  # ]:          0 :     aSortDescriptor[2].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISCASE));
     156 [ #  # ][ #  # ]:          0 :     aSortDescriptor[2].Value = ::cppu::bool2any(bIsCaseSensitive);
     157 [ #  # ][ #  # ]:          0 :     aSortDescriptor[3].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ISULIST));
     158 [ #  # ][ #  # ]:          0 :     aSortDescriptor[3].Value = ::cppu::bool2any(bEnabledUserList);
     159 [ #  # ][ #  # ]:          0 :     aSortDescriptor[4].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_OUTPOS));
     160 [ #  # ][ #  # ]:          0 :     aSortDescriptor[4].Value <<= aOutputPosition;
     161 [ #  # ][ #  # ]:          0 :     aSortDescriptor[5].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_UINDEX));
     162 [ #  # ][ #  # ]:          0 :     aSortDescriptor[5].Value <<= nUserListIndex;
     163 [ #  # ][ #  # ]:          0 :     aSortDescriptor[6].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SORTFLD));
     164 [ #  # ][ #  # ]:          0 :     aSortDescriptor[6].Value <<= aSortFields;
     165 [ #  # ][ #  # ]:          0 :     if (nLangLength || nCountryLength)
     166                 :            :     {
     167                 :          0 :         lang::Locale aLocale;
     168                 :          0 :         aLocale.Language = sLanguage;
     169                 :          0 :         aLocale.Country = sCountry;
     170 [ #  # ][ #  # ]:          0 :         aSortDescriptor[7].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_COLLLOC));
     171 [ #  # ][ #  # ]:          0 :         aSortDescriptor[7].Value <<= aLocale;
     172                 :            :     }
     173         [ #  # ]:          0 :     if (nAlgoLength)
     174                 :            :     {
     175 [ #  # ][ #  # ]:          0 :         aSortDescriptor[6 + i].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_COLLALG));
     176 [ #  # ][ #  # ]:          0 :         aSortDescriptor[6 + i].Value <<= sAlgorithm;
     177                 :            :     }
     178 [ #  # ][ #  # ]:          0 :     pDatabaseRangeContext->SetSortSequence(aSortDescriptor);
     179                 :          0 : }
     180                 :            : 
     181                 :          0 : void ScXMLSortContext::AddSortField(const rtl::OUString& sFieldNumber, const rtl::OUString& sDataType, const rtl::OUString& sOrder)
     182                 :            : {
     183                 :          0 :     util::SortField aSortField;
     184                 :          0 :     aSortField.Field = sFieldNumber.toInt32();
     185 [ #  # ][ #  # ]:          0 :     if (IsXMLToken(sOrder, XML_ASCENDING))
     186                 :          0 :         aSortField.SortAscending = true;
     187                 :            :     else
     188                 :          0 :         aSortField.SortAscending = false;
     189         [ #  # ]:          0 :     if (sDataType.getLength() > 8)
     190                 :            :     {
     191                 :          0 :         rtl::OUString sTemp = sDataType.copy(0, 8);
     192         [ #  # ]:          0 :         if (sTemp.compareToAscii(SC_USERLIST) == 0)
     193                 :            :         {
     194                 :          0 :             bEnabledUserList = true;
     195                 :          0 :             sTemp = sDataType.copy(8);
     196                 :          0 :             nUserListIndex = static_cast<sal_Int16>(sTemp.toInt32());
     197                 :            :         }
     198                 :            :         else
     199                 :            :         {
     200 [ #  # ][ #  # ]:          0 :             if (IsXMLToken(sDataType, XML_AUTOMATIC))
     201                 :          0 :                 aSortField.FieldType = util::SortFieldType_AUTOMATIC;
     202                 :          0 :         }
     203                 :            :     }
     204                 :            :     else
     205                 :            :     {
     206 [ #  # ][ #  # ]:          0 :         if (IsXMLToken(sDataType, XML_TEXT))
     207                 :          0 :             aSortField.FieldType = util::SortFieldType_ALPHANUMERIC;
     208 [ #  # ][ #  # ]:          0 :         else if (IsXMLToken(sDataType, XML_NUMBER))
     209                 :          0 :             aSortField.FieldType = util::SortFieldType_NUMERIC;
     210                 :            :     }
     211         [ #  # ]:          0 :     aSortFields.realloc(aSortFields.getLength() + 1);
     212         [ #  # ]:          0 :     aSortFields[aSortFields.getLength() - 1] = aSortField;
     213                 :          0 : }
     214                 :            : 
     215                 :          0 : ScXMLSortByContext::ScXMLSortByContext( 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                 :            :                                         ScXMLSortContext* pTempSortContext) :
     221                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
     222                 :            :     pSortContext(pTempSortContext),
     223         [ #  # ]:          0 :     sDataType(GetXMLToken(XML_AUTOMATIC)),
     224         [ #  # ]:          0 :     sOrder(GetXMLToken(XML_ASCENDING))
     225                 :            : {
     226 [ #  # ][ #  # ]:          0 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
                 [ #  # ]
     227         [ #  # ]:          0 :     const SvXMLTokenMap& rAttrTokenMap(GetScImport().GetSortSortByAttrTokenMap());
     228         [ #  # ]:          0 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     229                 :            :     {
     230 [ #  # ][ #  # ]:          0 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
     231                 :          0 :         rtl::OUString aLocalName;
     232                 :          0 :         sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
     233         [ #  # ]:          0 :                                             sAttrName, &aLocalName ));
     234 [ #  # ][ #  # ]:          0 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
     235                 :            : 
     236         [ #  # ]:          0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
           [ #  #  #  # ]
     237                 :            :         {
     238                 :            :             case XML_TOK_SORT_BY_ATTR_FIELD_NUMBER :
     239                 :            :             {
     240                 :          0 :                 sFieldNumber = sValue;
     241                 :            :             }
     242                 :          0 :             break;
     243                 :            :             case XML_TOK_SORT_BY_ATTR_DATA_TYPE :
     244                 :            :             {
     245                 :          0 :                 sDataType = sValue;
     246                 :            :             }
     247                 :          0 :             break;
     248                 :            :             case XML_TOK_SORT_BY_ATTR_ORDER :
     249                 :            :             {
     250                 :          0 :                 sOrder = sValue;
     251                 :            :             }
     252                 :          0 :             break;
     253                 :            :         }
     254                 :          0 :     }
     255                 :          0 : }
     256                 :            : 
     257                 :          0 : ScXMLSortByContext::~ScXMLSortByContext()
     258                 :            : {
     259         [ #  # ]:          0 : }
     260                 :            : 
     261                 :          0 : SvXMLImportContext *ScXMLSortByContext::CreateChildContext( sal_uInt16 nPrefix,
     262                 :            :                                             const ::rtl::OUString& rLName,
     263                 :            :                                             const ::com::sun::star::uno::Reference<
     264                 :            :                                         ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
     265                 :            : {
     266         [ #  # ]:          0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );
     267                 :            : }
     268                 :            : 
     269                 :          0 : void ScXMLSortByContext::EndElement()
     270                 :            : {
     271                 :          0 :     pSortContext->AddSortField(sFieldNumber, sDataType, sOrder);
     272                 :          0 : }
     273                 :            : 
     274                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10