LCOV - code coverage report
Current view: top level - writerfilter/source/ooxml - OOXMLParserState.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 134 134 100.0 %
Date: 2012-08-25 Functions: 35 35 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 63 112 56.2 %

           Branch data     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 <stdio.h>
      21                 :            : #include <iostream>
      22                 :            : #include "OOXMLParserState.hxx"
      23                 :            : #include "ooxmlLoggers.hxx"
      24                 :            : 
      25                 :            : namespace writerfilter {
      26                 :            : namespace ooxml
      27                 :            : {
      28                 :            : /*
      29                 :            :   class OOXMLParserState
      30                 :            : */
      31                 :            : 
      32                 :        859 : OOXMLParserState::OOXMLParserState() :
      33                 :            :     mbInSectionGroup(false),
      34                 :            :     mbInParagraphGroup(false),
      35                 :            :     mbInCharacterGroup(false),
      36                 :            :     mbLastParagraphInSection(false),
      37                 :            :     mbForwardEvents(true),
      38                 :            :     mnContexts(0),
      39                 :            :     mnHandle(0),
      40                 :            :     mpDocument(NULL),
      41                 :            :     inTxbxContent(false),
      42                 :            :     savedInSectionGroup(false),
      43                 :            :     savedInParagraphGroup(false),
      44                 :            :     savedInCharacterGroup(false),
      45 [ +  - ][ +  - ]:        859 :     savedLastParagraphInSection(false)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      46                 :            : {
      47                 :        859 : }
      48                 :            : 
      49         [ +  - ]:        859 : OOXMLParserState::~OOXMLParserState()
      50                 :            : {
      51         [ -  + ]:       1718 : }
      52                 :            : 
      53                 :        233 : void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection)
      54                 :            : {
      55                 :        233 :     mbLastParagraphInSection = bLastParagraphInSection;
      56                 :        233 : }
      57                 :            : 
      58                 :        748 : bool OOXMLParserState::isLastParagraphInSection() const
      59                 :            : {
      60                 :        748 :     return mbLastParagraphInSection;
      61                 :            : }
      62                 :            : 
      63                 :       1472 : bool OOXMLParserState::isInSectionGroup() const
      64                 :            : {
      65                 :       1472 :     return mbInSectionGroup;
      66                 :            : }
      67                 :            : 
      68                 :        666 : void OOXMLParserState::setInSectionGroup(bool bInSectionGroup)
      69                 :            : {
      70                 :        666 :     mbInSectionGroup = bInSectionGroup;
      71                 :        666 : }
      72                 :            : 
      73                 :       3848 : bool OOXMLParserState::isInParagraphGroup() const
      74                 :            : {
      75                 :       3848 :     return mbInParagraphGroup;
      76                 :            : }
      77                 :            : 
      78                 :       1591 : void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup)
      79                 :            : {
      80                 :       1591 :     mbInParagraphGroup = bInParagraphGroup;
      81                 :       1591 : }
      82                 :            : 
      83                 :       5172 : bool OOXMLParserState::isInCharacterGroup() const
      84                 :            : {
      85                 :       5172 :     return mbInCharacterGroup;
      86                 :            : }
      87                 :            : 
      88                 :       2421 : void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup)
      89                 :            : {
      90                 :       2421 :     mbInCharacterGroup = bInCharacterGroup;
      91                 :       2421 : }
      92                 :            : 
      93                 :        871 : void OOXMLParserState::setForwardEvents(bool bForwardEvents)
      94                 :            : {
      95                 :        871 :     mbForwardEvents = bForwardEvents;
      96                 :        871 : }
      97                 :            : 
      98                 :       8370 : bool OOXMLParserState::isForwardEvents() const
      99                 :            : {
     100                 :       8370 :     return mbForwardEvents;
     101                 :            : }
     102                 :            : 
     103                 :        969 : const string OOXMLParserState::getHandle() const
     104                 :            : {
     105                 :            :     char sBuffer[256];
     106                 :            : 
     107                 :        969 :     snprintf(sBuffer, sizeof(sBuffer), "%d", mnHandle);
     108                 :            : 
     109         [ +  - ]:        969 :     return sBuffer;
     110                 :            : }
     111                 :            : 
     112                 :        748 : void OOXMLParserState::setHandle()
     113                 :            : {
     114                 :        748 :     mnHandle = mnContexts;
     115                 :        748 : }
     116                 :            : 
     117                 :        859 : void OOXMLParserState::setDocument(OOXMLDocument * pDocument)
     118                 :            : {
     119                 :        859 :     mpDocument = pDocument;
     120                 :        859 : }
     121                 :            : 
     122                 :        297 : OOXMLDocument * OOXMLParserState::getDocument() const
     123                 :            : {
     124                 :        297 :     return mpDocument;
     125                 :            : }
     126                 :            : 
     127                 :        859 : void OOXMLParserState::setXNoteId(const sal_Int32 nId)
     128                 :            : {
     129                 :        859 :     mpDocument->setXNoteId(nId);
     130                 :        859 : }
     131                 :            : 
     132                 :          6 : sal_Int32 OOXMLParserState::getXNoteId() const
     133                 :            : {
     134                 :          6 :     return mpDocument->getXNoteId();
     135                 :            : }
     136                 :            : 
     137                 :         57 : const OUString & OOXMLParserState::getTarget() const
     138                 :            : {
     139                 :         57 :     return mpDocument->getTarget();
     140                 :            : }
     141                 :            : 
     142                 :       1227 : void OOXMLParserState::resolveCharacterProperties(Stream & rStream)
     143                 :            : {
     144         [ +  + ]:       1227 :     if (mpCharacterProps.get() != NULL)
     145                 :            :     {
     146                 :            : #ifdef DEBUG_PROPERTIES
     147                 :            :         debug_logger->startElement("resolveCharacterProperties");
     148                 :            : #endif
     149                 :            : 
     150 [ +  - ][ +  - ]:        337 :         rStream.props(mpCharacterProps);
                 [ +  - ]
     151         [ +  - ]:        337 :         mpCharacterProps.reset(new OOXMLPropertySetImpl());
     152                 :            : 
     153                 :            : #ifdef DEBUG_PROPERTIES
     154                 :            :         debug_logger->endElement();
     155                 :            : #endif
     156                 :            :     }
     157                 :       1227 : }
     158                 :            : 
     159                 :         39 : void OOXMLParserState::setCharacterProperties
     160                 :            : (OOXMLPropertySet::Pointer_t pProps)
     161                 :            : {
     162         [ +  + ]:         39 :     if (mpCharacterProps.get() == NULL)
     163                 :         14 :         mpCharacterProps = pProps;
     164                 :            :     else
     165         [ +  - ]:         25 :         mpCharacterProps->add(pProps);
     166                 :         39 : }
     167                 :            : 
     168                 :        229 : void OOXMLParserState::setCellProperties
     169                 :            : (OOXMLPropertySet::Pointer_t pProps)
     170                 :            : {
     171         [ +  - ]:        229 :     if (!mCellProps.empty())
     172                 :            :     {
     173                 :        229 :         OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
     174                 :            : 
     175         [ +  + ]:        229 :         if (rCellProps.get() == NULL)
     176                 :         36 :             rCellProps = pProps;
     177                 :            :         else
     178         [ +  - ]:        193 :             rCellProps->add(pProps);
     179                 :            :     }
     180                 :        229 : }
     181                 :            : 
     182                 :         12 : void OOXMLParserState::setRowProperties
     183                 :            : (OOXMLPropertySet::Pointer_t pProps)
     184                 :            : {
     185         [ +  - ]:         12 :     if (!mRowProps.empty())
     186                 :            :     {
     187                 :         12 :         OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
     188                 :            : 
     189         [ +  + ]:         12 :         if (rRowProps.get() == NULL)
     190                 :         10 :             rRowProps = pProps;
     191                 :            :         else
     192         [ +  - ]:          2 :             rRowProps->add(pProps);
     193                 :            :     }
     194                 :         12 : }
     195                 :            : 
     196                 :        229 : void OOXMLParserState::resolveCellProperties(Stream & rStream)
     197                 :            : {
     198         [ +  - ]:        229 :     if (!mCellProps.empty())
     199                 :            :     {
     200                 :        229 :         OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top();
     201                 :            : 
     202         [ +  - ]:        229 :         if (rCellProps.get() != NULL)
     203                 :            :         {
     204 [ +  - ][ +  - ]:        229 :             rStream.props(rCellProps);
                 [ +  - ]
     205         [ +  - ]:        229 :             rCellProps.reset(new OOXMLPropertySetImpl());
     206                 :            :         }
     207                 :            :     }
     208                 :        229 : }
     209                 :            : 
     210                 :         40 : void OOXMLParserState::resolveRowProperties(Stream & rStream)
     211                 :            : {
     212         [ +  - ]:         40 :     if (!mRowProps.empty())
     213                 :            :     {
     214                 :         40 :         OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top();
     215                 :            : 
     216         [ +  + ]:         40 :         if (rRowProps.get() != NULL)
     217                 :            :         {
     218 [ +  - ][ +  - ]:         14 :             rStream.props(rRowProps);
                 [ +  - ]
     219         [ +  - ]:         14 :             rRowProps.reset(new OOXMLPropertySetImpl());
     220                 :            :         }
     221                 :            :     }
     222                 :         40 : }
     223                 :            : 
     224                 :         40 : void OOXMLParserState::resolveTableProperties(Stream & rStream)
     225                 :            : {
     226         [ +  - ]:         40 :     if (!mTableProps.empty())
     227                 :            :     {
     228                 :         40 :         OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
     229                 :            : 
     230         [ +  - ]:         40 :         if (rTableProps.get() != NULL)
     231                 :            :         {
     232 [ +  - ][ +  - ]:         40 :             rStream.props(rTableProps);
                 [ +  - ]
     233         [ +  - ]:         40 :             rTableProps.reset(new OOXMLPropertySetImpl());
     234                 :            :         }
     235                 :            :     }
     236                 :         40 : }
     237                 :            : 
     238                 :        108 : void OOXMLParserState::setTableProperties
     239                 :            : (OOXMLPropertySet::Pointer_t pProps)
     240                 :            : {
     241         [ +  + ]:        108 :     if (!mTableProps.empty())
     242                 :            :     {
     243                 :         72 :         OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top();
     244         [ +  + ]:         72 :         if (rTableProps.get() == NULL)
     245                 :         36 :             rTableProps = pProps;
     246                 :            :         else
     247         [ +  - ]:         36 :             rTableProps->add(pProps);
     248                 :            :     }
     249                 :        108 : }
     250                 :            : 
     251                 :         36 : void OOXMLParserState::startTable()
     252                 :            : {
     253         [ +  - ]:         36 :     OOXMLPropertySet::Pointer_t pCellProps;
     254         [ +  - ]:         36 :     OOXMLPropertySet::Pointer_t pRowProps;
     255         [ +  - ]:         36 :     OOXMLPropertySet::Pointer_t pTableProps;
     256                 :            : 
     257         [ +  - ]:         36 :     mCellProps.push(pCellProps);
     258         [ +  - ]:         36 :     mRowProps.push(pRowProps);
     259 [ +  - ][ +  - ]:         36 :     mTableProps.push(pTableProps);
         [ +  - ][ +  - ]
     260                 :         36 : }
     261                 :            : 
     262                 :         36 : void OOXMLParserState::endTable()
     263                 :            : {
     264                 :         36 :     mCellProps.pop();
     265                 :         36 :     mRowProps.pop();
     266                 :         36 :     mTableProps.pop();
     267                 :         36 : }
     268                 :            : 
     269                 :      46233 : void OOXMLParserState::incContextCount()
     270                 :            : {
     271                 :      46233 :     mnContexts++;
     272                 :      46233 : }
     273                 :            : 
     274                 :         24 : void OOXMLParserState::startTxbxContent()
     275                 :            : {
     276                 :         24 :     if( inTxbxContent )
     277                 :            :         SAL_WARN( "writerfilter", "Nested w:txbxContent" );
     278                 :         24 :     inTxbxContent = true;
     279                 :            :     // Do not save and reset section group state, it'd cause a new page.
     280                 :            : //    savedInSectionGroup = mbInSectionGroup;
     281                 :         24 :     savedInParagraphGroup = mbInParagraphGroup;
     282                 :         24 :     savedInCharacterGroup = mbInCharacterGroup;
     283                 :         24 :     savedLastParagraphInSection = mbLastParagraphInSection;
     284                 :            : //    mbInSectionGroup = false;
     285                 :         24 :     mbInParagraphGroup = false;
     286                 :         24 :     mbInCharacterGroup = false;
     287                 :         24 :     mbLastParagraphInSection = false;
     288                 :         24 : }
     289                 :            : 
     290                 :         24 : void OOXMLParserState::endTxbxContent()
     291                 :            : {
     292         [ -  + ]:         24 :     if( !inTxbxContent )
     293                 :            :     {
     294                 :            :         SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" );
     295                 :         24 :         return;
     296                 :            :     }
     297                 :            : //    mbInSectionGroup = savedInSectionGroup;
     298                 :         24 :     mbInParagraphGroup = savedInParagraphGroup;
     299                 :         24 :     mbInCharacterGroup = savedInCharacterGroup;
     300                 :         24 :     mbLastParagraphInSection = savedLastParagraphInSection;
     301                 :         24 :     inTxbxContent = false;
     302                 :            : }
     303                 :            : 
     304                 :            : #if OSL_DEBUG_LEVEL > 1
     305                 :            : void OOXMLParserState::dumpXml( const TagLogger::Pointer_t& pLogger )
     306                 :            : {
     307                 :            :     pLogger->startElement("parserstate");
     308                 :            : 
     309                 :            :     string sTmp;
     310                 :            : 
     311                 :            :     if (isInSectionGroup())
     312                 :            :         sTmp += "s";
     313                 :            :     else
     314                 :            :         sTmp += "-";
     315                 :            : 
     316                 :            :     if (isInParagraphGroup())
     317                 :            :         sTmp += "p";
     318                 :            :     else
     319                 :            :         sTmp += "-";
     320                 :            : 
     321                 :            :     if (isInCharacterGroup())
     322                 :            :         sTmp += "c";
     323                 :            :     else
     324                 :            :         sTmp += "-";
     325                 :            : 
     326                 :            :     if (isForwardEvents())
     327                 :            :         sTmp += "f";
     328                 :            :     else
     329                 :            :         sTmp += "-";
     330                 :            : 
     331                 :            :     pLogger->attribute("state", sTmp);
     332                 :            :     pLogger->attribute("XNoteId", getXNoteId() );
     333                 :            :     if (mpCharacterProps != OOXMLPropertySet::Pointer_t())
     334                 :            :         pLogger->chars(mpCharacterProps->toString());
     335                 :            : 
     336                 :            :     pLogger->endElement();
     337                 :            :  }
     338                 :            : 
     339                 :            : XPathLogger & OOXMLParserState::getXPathLogger()
     340                 :            : {
     341                 :            :     return m_xPathLogger;
     342                 :            : }
     343                 :            : #endif
     344                 :            : 
     345 [ +  - ][ +  - ]:         60 : }}
     346                 :            : 
     347                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10