LCOV - code coverage report
Current view: top level - sc/source/filter/oox - commentsfragment.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 64 42.2 %
Date: 2014-11-03 Functions: 6 11 54.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             : #include "commentsfragment.hxx"
      21             : 
      22             : #include "richstringcontext.hxx"
      23             : 
      24             : namespace oox {
      25             : namespace xls {
      26             : 
      27             : using namespace ::oox::core;
      28             : 
      29           4 : CommentsFragment::CommentsFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
      30           4 :     WorksheetFragmentBase( rHelper, rFragmentPath )
      31             : {
      32           4 : }
      33             : 
      34          32 : ContextHandlerRef CommentsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      35             : {
      36          32 :     switch( getCurrentElement() )
      37             :     {
      38             :         case XML_ROOT_CONTEXT:
      39           4 :             if( nElement == XLS_TOKEN( comments ) ) return this;
      40           0 :         break;
      41             :         case XLS_TOKEN( comments ):
      42           8 :             if( nElement == XLS_TOKEN( authors ) ) return this;
      43           4 :             if( nElement == XLS_TOKEN( commentList ) ) return this;
      44           0 :         break;
      45             :         case XLS_TOKEN( authors ):
      46           4 :             if( nElement == XLS_TOKEN( author ) ) return this;  // collect author in onCharacters()
      47           0 :         break;
      48             :         case XLS_TOKEN( commentList ):
      49           4 :             if( nElement == XLS_TOKEN( comment ) ) { importComment( rAttribs ); return this; }
      50           0 :         break;
      51             :         case XLS_TOKEN( commentPr ):
      52           2 :             if( nElement == XLS_TOKEN( anchor ) )
      53           2 :                 return this;
      54           0 :             break;
      55             :         case XLS_TOKEN( anchor ):
      56           4 :             if( nElement == XDR_TOKEN( from ) || nElement == XDR_TOKEN( to ) )
      57           0 :                 return this;
      58           4 :             break;
      59             :         case XDR_TOKEN( from ):
      60             :         case XDR_TOKEN( to ):
      61           0 :             return this;
      62             :         case XLS_TOKEN( comment ):
      63           6 :             if( (nElement == XLS_TOKEN( text )) && mxComment.get() )
      64           4 :                 return new RichStringContext( *this, mxComment->createText() );
      65           2 :             if( nElement == XLS_TOKEN( commentPr ) ) { mxComment->importCommentPr( rAttribs ); return this; }
      66           0 :         break;
      67             :     }
      68           4 :     return 0;
      69             : }
      70             : 
      71           0 : void CommentsFragment::onCharacters( const OUString& rChars )
      72             : {
      73           0 :     if( isCurrentElement( XLS_TOKEN( author ) ) )
      74           0 :         getComments().appendAuthor( rChars );
      75           0 : }
      76             : 
      77          32 : void CommentsFragment::onEndElement()
      78             : {
      79          32 :     if( isCurrentElement( XLS_TOKEN( comment ) ) )
      80          12 :         mxComment.reset();
      81          32 : }
      82             : 
      83           0 : ContextHandlerRef CommentsFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
      84             : {
      85           0 :     switch( getCurrentElement() )
      86             :     {
      87             :         case XML_ROOT_CONTEXT:
      88           0 :             if( nRecId == BIFF12_ID_COMMENTS ) return this;
      89           0 :         break;
      90             :         case BIFF12_ID_COMMENTS:
      91           0 :             if( nRecId == BIFF12_ID_COMMENTAUTHORS ) return this;
      92           0 :             if( nRecId == BIFF12_ID_COMMENTLIST ) return this;
      93           0 :         break;
      94             :         case BIFF12_ID_COMMENTAUTHORS:
      95           0 :             if( nRecId == BIFF12_ID_COMMENTAUTHOR ) getComments().appendAuthor( BiffHelper::readString( rStrm ) );
      96           0 :         break;
      97             :         case BIFF12_ID_COMMENTLIST:
      98           0 :             if( nRecId == BIFF12_ID_COMMENT ) { importComment( rStrm ); return this; }
      99           0 :         break;
     100             :         case BIFF12_ID_COMMENT:
     101           0 :             if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment.get() )
     102           0 :                 mxComment->createText()->importString( rStrm, true );
     103           0 :         break;
     104             :     }
     105           0 :     return 0;
     106             : }
     107             : 
     108           0 : void CommentsFragment::onEndRecord()
     109             : {
     110           0 :     if( isCurrentElement( BIFF12_ID_COMMENT ) )
     111           0 :         mxComment.reset();
     112           0 : }
     113             : 
     114           0 : const RecordInfo* CommentsFragment::getRecordInfos() const
     115             : {
     116             :     static const RecordInfo spRecInfos[] =
     117             :     {
     118             :         { BIFF12_ID_COMMENT,        BIFF12_ID_COMMENT + 1           },
     119             :         { BIFF12_ID_COMMENTAUTHORS, BIFF12_ID_COMMENTAUTHORS + 1    },
     120             :         { BIFF12_ID_COMMENTLIST,    BIFF12_ID_COMMENTLIST + 1       },
     121             :         { BIFF12_ID_COMMENTS,       BIFF12_ID_COMMENTS + 1          },
     122             :         { -1,                       -1                              }
     123             :     };
     124           0 :     return spRecInfos;
     125             : }
     126             : 
     127             : // private --------------------------------------------------------------------
     128             : 
     129           4 : void CommentsFragment::importComment( const AttributeList& rAttribs )
     130             : {
     131           4 :     mxComment = getComments().createComment();
     132           4 :     mxComment->importComment( rAttribs );
     133           4 : }
     134             : 
     135           0 : void CommentsFragment::importComment( SequenceInputStream& rStrm )
     136             : {
     137           0 :     mxComment = getComments().createComment();
     138           0 :     mxComment->importComment( rStrm );
     139           0 : }
     140             : 
     141             : } // namespace xls
     142          48 : } // namespace oox
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10