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

Generated by: LCOV version 1.10