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

Generated by: LCOV version 1.10