LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - XMLDetectiveContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 95 6.3 %
Date: 2012-12-27 Functions: 2 19 10.5 %
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             : 
      21             : 
      22             : 
      23             : //___________________________________________________________________
      24             : #include "XMLDetectiveContext.hxx"
      25             : 
      26             : #include <sax/tools/converter.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : #include <xmloff/xmltoken.hxx>
      29             : #include "convuno.hxx"
      30             : #include "xmlimprt.hxx"
      31             : #include "XMLConverter.hxx"
      32             : #include "rangeutl.hxx"
      33             : 
      34             : #include <algorithm>
      35             : 
      36             : using ::rtl::OUString;
      37             : using namespace ::com::sun::star;
      38             : using namespace xmloff::token;
      39             : 
      40             : 
      41             : //___________________________________________________________________
      42             : 
      43           0 : ScMyImpDetectiveObj::ScMyImpDetectiveObj() :
      44             :     aSourceRange(),
      45             :     eObjType( SC_DETOBJ_NONE ),
      46           0 :     bHasError( false )
      47             : {
      48           0 : }
      49             : 
      50             : //___________________________________________________________________
      51             : 
      52           0 : bool ScMyImpDetectiveOp::operator<(const ScMyImpDetectiveOp& rDetOp) const
      53             : {
      54           0 :     return (nIndex < rDetOp.nIndex);
      55             : }
      56             : 
      57          22 : void ScMyImpDetectiveOpArray::Sort()
      58             : {
      59          22 :     aDetectiveOpList.sort();
      60          22 : }
      61             : 
      62          22 : bool ScMyImpDetectiveOpArray::GetFirstOp( ScMyImpDetectiveOp& rDetOp )
      63             : {
      64          22 :     if( aDetectiveOpList.empty() )
      65          22 :         return false;
      66           0 :     ScMyImpDetectiveOpList::iterator aItr = aDetectiveOpList.begin();
      67           0 :     rDetOp = *aItr;
      68           0 :     aDetectiveOpList.erase( aItr );
      69           0 :     return true;
      70             : }
      71             : 
      72             : 
      73             : //___________________________________________________________________
      74             : 
      75           0 : ScXMLDetectiveContext::ScXMLDetectiveContext(
      76             :         ScXMLImport& rImport,
      77             :         sal_uInt16 nPrfx,
      78             :         const OUString& rLName,
      79             :         ScMyImpDetectiveObjVec* pNewDetectiveObjVec ) :
      80             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      81           0 :     pDetectiveObjVec( pNewDetectiveObjVec )
      82             : {
      83           0 : }
      84             : 
      85           0 : ScXMLDetectiveContext::~ScXMLDetectiveContext()
      86             : {
      87           0 : }
      88             : 
      89           0 : SvXMLImportContext *ScXMLDetectiveContext::CreateChildContext(
      90             :         sal_uInt16 nPrefix,
      91             :         const OUString& rLName,
      92             :         const uno::Reference< xml::sax::XAttributeList>& xAttrList )
      93             : {
      94           0 :     SvXMLImportContext*     pContext    = NULL;
      95           0 :     const SvXMLTokenMap&    rTokenMap   = GetScImport().GetDetectiveElemTokenMap();
      96             : 
      97           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
      98             :     {
      99             :         case XML_TOK_DETECTIVE_ELEM_HIGHLIGHTED:
     100           0 :             pContext = new ScXMLDetectiveHighlightedContext( GetScImport(), nPrefix, rLName, xAttrList, pDetectiveObjVec );
     101           0 :         break;
     102             :         case XML_TOK_DETECTIVE_ELEM_OPERATION:
     103           0 :             pContext = new ScXMLDetectiveOperationContext( GetScImport(), nPrefix, rLName, xAttrList );
     104           0 :         break;
     105             :     }
     106           0 :     if( !pContext )
     107           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     108             : 
     109           0 :     return pContext;
     110             : }
     111             : 
     112           0 : void ScXMLDetectiveContext::EndElement()
     113             : {
     114           0 : }
     115             : 
     116             : 
     117             : //___________________________________________________________________
     118             : 
     119           0 : ScXMLDetectiveHighlightedContext::ScXMLDetectiveHighlightedContext(
     120             :         ScXMLImport& rImport,
     121             :         sal_uInt16 nPrfx,
     122             :         const OUString& rLName,
     123             :         const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     124             :         ScMyImpDetectiveObjVec* pNewDetectiveObjVec ):
     125             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     126             :     pDetectiveObjVec( pNewDetectiveObjVec ),
     127             :     aDetectiveObj(),
     128           0 :     bValid( false )
     129             : {
     130           0 :     if( !xAttrList.is() ) return;
     131             : 
     132           0 :     sal_Int16               nAttrCount      = xAttrList->getLength();
     133           0 :     const SvXMLTokenMap&    rAttrTokenMap   = GetScImport().GetDetectiveHighlightedAttrTokenMap();
     134             : 
     135           0 :     for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
     136             :     {
     137           0 :         const rtl::OUString& sAttrName  (xAttrList->getNameByIndex( nIndex ));
     138           0 :         const rtl::OUString& sValue     (xAttrList->getValueByIndex( nIndex ));
     139           0 :         OUString aLocalName;
     140           0 :         sal_uInt16 nPrefix      = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     141             : 
     142           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     143             :         {
     144             :             case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CELL_RANGE:
     145             :             {
     146           0 :                 sal_Int32 nOffset(0);
     147           0 :                 ScXMLImport::MutexGuard aGuard(GetScImport());
     148           0 :                 bValid = ScRangeStringConverter::GetRangeFromString( aDetectiveObj.aSourceRange, sValue, GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset );
     149             :             }
     150           0 :             break;
     151             :             case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_DIRECTION:
     152           0 :                 aDetectiveObj.eObjType = ScXMLConverter::GetDetObjTypeFromString( sValue );
     153           0 :             break;
     154             :             case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_CONTAINS_ERROR:
     155           0 :                 aDetectiveObj.bHasError = IsXMLToken(sValue, XML_TRUE);
     156           0 :             break;
     157             :             case XML_TOK_DETECTIVE_HIGHLIGHTED_ATTR_MARKED_INVALID:
     158             :                 {
     159           0 :                     if (IsXMLToken(sValue, XML_TRUE))
     160           0 :                         aDetectiveObj.eObjType = SC_DETOBJ_CIRCLE;
     161             :                 }
     162           0 :             break;
     163             :         }
     164           0 :     }
     165             : }
     166             : 
     167           0 : ScXMLDetectiveHighlightedContext::~ScXMLDetectiveHighlightedContext()
     168             : {
     169           0 : }
     170             : 
     171           0 : SvXMLImportContext *ScXMLDetectiveHighlightedContext::CreateChildContext(
     172             :         sal_uInt16 nPrefix,
     173             :         const OUString& rLName,
     174             :         const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
     175             : {
     176           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );
     177             : }
     178             : 
     179           0 : void ScXMLDetectiveHighlightedContext::EndElement()
     180             : {
     181           0 :     switch( aDetectiveObj.eObjType )
     182             :     {
     183             :         case SC_DETOBJ_ARROW:
     184             :         case SC_DETOBJ_TOOTHERTAB:
     185           0 :         break;
     186             :         case SC_DETOBJ_FROMOTHERTAB:
     187             :         case SC_DETOBJ_CIRCLE:
     188           0 :             bValid = true;
     189           0 :         break;
     190             :         default:
     191           0 :             bValid = false;
     192             :     }
     193           0 :     if( bValid )
     194           0 :         pDetectiveObjVec->push_back( aDetectiveObj );
     195           0 : }
     196             : 
     197             : 
     198             : //___________________________________________________________________
     199             : 
     200           0 : ScXMLDetectiveOperationContext::ScXMLDetectiveOperationContext(
     201             :         ScXMLImport& rImport,
     202             :         sal_uInt16 nPrfx,
     203             :         const OUString& rLName,
     204             :         const uno::Reference< xml::sax::XAttributeList >& xAttrList ) :
     205             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     206             :     aDetectiveOp(),
     207           0 :     bHasType( false )
     208             : {
     209           0 :     if( !xAttrList.is() ) return;
     210             : 
     211           0 :     sal_Int16               nAttrCount      = xAttrList->getLength();
     212           0 :     const SvXMLTokenMap&    rAttrTokenMap   = GetScImport().GetDetectiveOperationAttrTokenMap();
     213             : 
     214           0 :     for( sal_Int16 nIndex = 0; nIndex < nAttrCount; ++nIndex )
     215             :     {
     216           0 :         const rtl::OUString& sAttrName  (xAttrList->getNameByIndex( nIndex ));
     217           0 :         const rtl::OUString& sValue     (xAttrList->getValueByIndex( nIndex ));
     218           0 :         OUString aLocalName;
     219           0 :         sal_uInt16 nPrefix      = GetScImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     220             : 
     221           0 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
     222             :         {
     223             :             case XML_TOK_DETECTIVE_OPERATION_ATTR_NAME:
     224           0 :                 bHasType = ScXMLConverter::GetDetOpTypeFromString( aDetectiveOp.eOpType, sValue );
     225           0 :             break;
     226             :             case XML_TOK_DETECTIVE_OPERATION_ATTR_INDEX:
     227             :             {
     228             :                 sal_Int32 nValue;
     229           0 :                 if (::sax::Converter::convertNumber( nValue, sValue, 0 ))
     230           0 :                     aDetectiveOp.nIndex = nValue;
     231             :             }
     232           0 :             break;
     233             :         }
     234           0 :     }
     235           0 :     aDetectiveOp.aPosition =  rImport.GetTables().GetCurrentCellPos();
     236             : }
     237             : 
     238           0 : ScXMLDetectiveOperationContext::~ScXMLDetectiveOperationContext()
     239             : {
     240           0 : }
     241             : 
     242           0 : SvXMLImportContext *ScXMLDetectiveOperationContext::CreateChildContext(
     243             :         sal_uInt16 nPrefix,
     244             :         const OUString& rLName,
     245             :         const uno::Reference< xml::sax::XAttributeList>& /* xAttrList */ )
     246             : {
     247           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLName );
     248             : }
     249             : 
     250           0 : void ScXMLDetectiveOperationContext::EndElement()
     251             : {
     252           0 :     if( bHasType && (aDetectiveOp.nIndex >= 0) )
     253           0 :         GetScImport().GetDetectiveOpArray()->AddDetectiveOp( aDetectiveOp );
     254           0 : }
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10