LCOV - code coverage report
Current view: top level - writerfilter/source/ooxml - OOXMLFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 118 124 95.2 %
Date: 2012-08-25 Functions: 22 26 84.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 147 276 53.3 %

           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                 :            : 
      22                 :            : #include <rtl/instance.hxx>
      23                 :            : #include <osl/mutex.hxx>
      24                 :            : #include "OOXMLFactory.hxx"
      25                 :            : #include "OOXMLFastHelper.hxx"
      26                 :            : 
      27                 :            : namespace writerfilter {
      28                 :            : namespace ooxml {
      29                 :            : 
      30                 :       1318 : AttributeInfo::AttributeInfo()
      31                 :       1318 : :m_nResource(RT_NoResource), m_nRef(0)
      32                 :            : {
      33                 :       1318 : }
      34                 :            : 
      35                 :       1333 : AttributeInfo::AttributeInfo(ResourceType_t nResource, Id nRef)
      36                 :       1333 :  :m_nResource(nResource), m_nRef(nRef)
      37                 :            : {
      38                 :       1333 : }
      39                 :            : 
      40                 :       7616 : CreateElement::CreateElement()
      41                 :       7616 : :m_nResource(RT_NoResource), m_nId(0)
      42                 :            : {
      43                 :       7616 : }
      44                 :            : 
      45                 :       6316 : CreateElement::CreateElement(ResourceType_t nResource, Id nId)
      46                 :       6316 : : m_nResource(nResource), m_nId(nId)
      47                 :            : {
      48                 :       6316 : }
      49                 :            : 
      50                 :            : // class OOXMLFactory_ns
      51                 :            : 
      52 [ +  - ][ +  - ]:        192 : OOXMLFactory_ns::~OOXMLFactory_ns()
                 [ +  - ]
      53                 :            : {
      54         [ -  + ]:        192 : }
      55                 :            : 
      56                 :      51761 : AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId)
      57                 :            : {
      58 [ +  - ][ +  + ]:      51761 :     if (m_AttributesMap.find(nId) == m_AttributesMap.end())
      59 [ +  - ][ +  - ]:        816 :         m_AttributesMap[nId] = createAttributeToResourceMap(nId);
      60                 :            : 
      61                 :      51761 :     return m_AttributesMap[nId];
      62                 :            : }
      63                 :            : 
      64                 :       9025 : ListValueMapPointer OOXMLFactory_ns::getListValueMap(Id nId)
      65                 :            : {
      66 [ +  - ][ +  + ]:       9025 :     if (m_ListValuesMap.find(nId) == m_ListValuesMap.end())
      67 [ +  - ][ +  - ]:        178 :         m_ListValuesMap[nId] = createListValueMap(nId);
      68                 :            : 
      69                 :       9025 :     return m_ListValuesMap[nId];
      70                 :            : }
      71                 :            : 
      72                 :      65302 : CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
      73                 :            : {
      74 [ +  - ][ +  + ]:      65302 :     if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end())
      75 [ +  - ][ +  - ]:        702 :         m_CreateElementsMap[nId] = createCreateElementMap(nId);
      76                 :            : 
      77                 :      65302 :     return m_CreateElementsMap[nId];
      78                 :            : }
      79                 :            : 
      80                 :     117063 : TokenToIdMapPointer OOXMLFactory_ns::getTokenToIdMap(Id nId)
      81                 :            : {
      82 [ +  - ][ +  + ]:     117063 :     if (m_TokenToIdsMap.find(nId) == m_TokenToIdsMap.end())
      83 [ +  - ][ +  - ]:       1092 :         m_TokenToIdsMap[nId] = createTokenToIdMap(nId);
      84                 :            : 
      85                 :     117063 :     return m_TokenToIdsMap[nId];
      86                 :            : }
      87                 :            : 
      88                 :          0 : string OOXMLFactory_ns::getDefineName(Id /*nId*/) const
      89                 :            : {
      90         [ #  # ]:          0 :     return "";
      91                 :            : }
      92                 :            : 
      93                 :            : // class OOXMLFactory
      94                 :            : 
      95                 :            : typedef rtl::Static< osl::Mutex, OOXMLFactory > OOXMLFactory_Mutex;
      96                 :            : 
      97                 :         20 : OOXMLFactory::Pointer_t OOXMLFactory::m_Instance;
      98                 :            : 
      99                 :          8 : OOXMLFactory::OOXMLFactory()
     100                 :            : {
     101                 :            :     // multi-thread-safe mutex for all platforms
     102                 :            : 
     103 [ +  - ][ +  - ]:          8 :     osl::MutexGuard aGuard(OOXMLFactory_Mutex::get());
                 [ +  - ]
     104                 :          8 : }
     105                 :            : 
     106                 :          8 : OOXMLFactory::~OOXMLFactory()
     107                 :            : {
     108         [ -  + ]:         16 : }
     109                 :            : 
     110                 :     191809 : OOXMLFactory::Pointer_t OOXMLFactory::getInstance()
     111                 :            : {
     112         [ +  + ]:     191809 :     if (m_Instance.get() == NULL)
     113         [ +  - ]:          8 :         m_Instance.reset(new OOXMLFactory());
     114                 :            : 
     115                 :     191809 :     return m_Instance;
     116                 :            : }
     117                 :            : 
     118                 :      51761 : void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
     119                 :            :                               const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     120                 :            : {
     121         [ +  - ]:      51761 :     Id nDefine = pHandler->getDefine();
     122         [ +  - ]:      51761 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     123                 :            : 
     124         [ +  - ]:      51761 :     if (pFactory.get() != NULL)
     125                 :            :     {
     126                 :            : #ifdef DEBUG_FACTORY
     127                 :            :         debug_logger->startElement("factory.attributes");
     128                 :            :         debug_logger->attribute("define", pFactory->getDefineName(nDefine));
     129                 :            :         char sBuffer[256];
     130                 :            :         snprintf(sBuffer, sizeof(sBuffer), "%08" SAL_PRIxUINT32, nDefine);
     131                 :            :         debug_logger->attribute("define-num", sBuffer);
     132                 :            : #endif
     133                 :            : 
     134         [ +  - ]:      51761 :         TokenToIdMapPointer pTokenToIdMap = pFactory->getTokenToIdMap(nDefine);
     135         [ +  - ]:      51761 :         AttributeToResourceMapPointer pMap = pFactory->getAttributeToResourceMap(nDefine);
     136                 :            : 
     137                 :      51761 :         AttributeToResourceMap::const_iterator aIt;
     138         [ +  - ]:      51761 :         AttributeToResourceMap::const_iterator aEndIt = pMap->end();
     139                 :            : 
     140 [ +  + ][ +  - ]:     133303 :         for (aIt = pMap->begin(); aIt != aEndIt; ++aIt)
     141                 :            :         {
     142 [ +  - ][ +  - ]:      81542 :             Id nId = (*pTokenToIdMap)[aIt->first];
     143                 :            : #ifdef DEBUG_FACTORY
     144                 :            :             debug_logger->startElement("factory.attribute");
     145                 :            :             debug_logger->attribute("name", fastTokenToId(aIt->first));
     146                 :            :             debug_logger->attribute("tokenid", (*QNameToString::Instance())(nId));
     147                 :            :             snprintf(sBuffer, sizeof(sBuffer), "%08" SAL_PRIxUINT32, nId);
     148                 :            :             debug_logger->attribute("tokenid-num", sBuffer);
     149                 :            : #endif
     150 [ +  - ][ +  - ]:      81542 :             if (Attribs->hasAttribute(aIt->first))
         [ +  - ][ +  + ]
     151                 :            :             {
     152 [ +  - ][ +  +  :      46611 :                 switch (aIt->second.m_nResource)
             +  +  +  - ]
     153                 :            :                 {
     154                 :            :                 case RT_Boolean:
     155                 :            :                     {
     156                 :            : #ifdef DEBUG_FACTORY
     157                 :            :                         debug_logger->element("boolean");
     158                 :            : #endif
     159 [ +  - ][ +  - ]:       1160 :                         OUString aValue(Attribs->getValue(aIt->first));
                 [ +  - ]
     160         [ +  - ]:       1160 :                         OOXMLFastHelper<OOXMLBooleanValue>::newProperty(pHandler, nId, aValue);
     161                 :            : 
     162 [ +  - ][ +  - ]:       1160 :                         OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(aValue));
                 [ +  - ]
     163 [ +  - ][ +  - ]:       1160 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
         [ +  - ][ +  - ]
                 [ +  - ]
     164                 :            :                     }
     165                 :       1160 :                     break;
     166                 :            :                 case RT_String:
     167                 :            :                     {
     168                 :            : #ifdef DEBUG_FACTORY
     169                 :            :                         debug_logger->element("string");
     170                 :            : #endif
     171 [ +  - ][ +  - ]:      19681 :                         OUString aValue(Attribs->getValue(aIt->first));
                 [ +  - ]
     172                 :            :                         OOXMLFastHelper<OOXMLStringValue>::newProperty
     173         [ +  - ]:      19681 :                             (pHandler, nId, aValue);
     174                 :            : 
     175 [ +  - ][ +  - ]:      19681 :                         OOXMLValue::Pointer_t pValue(new OOXMLStringValue(aValue));
                 [ +  - ]
     176 [ +  - ][ +  - ]:      19681 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
         [ +  - ][ +  - ]
                 [ +  - ]
     177                 :            :                     }
     178                 :      19681 :                     break;
     179                 :            :                 case RT_Integer:
     180                 :            :                     {
     181                 :            : #ifdef DEBUG_FACTORY
     182                 :            :                         debug_logger->element("integer");
     183                 :            : #endif
     184 [ +  - ][ +  - ]:      10057 :                         OUString aValue(Attribs->getValue(aIt->first));
                 [ +  - ]
     185                 :            :                         OOXMLFastHelper<OOXMLIntegerValue>::newProperty
     186         [ +  - ]:      10057 :                             (pHandler, nId, aValue);
     187                 :            : 
     188 [ +  - ][ +  - ]:      10057 :                         OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(aValue));
                 [ +  - ]
     189 [ +  - ][ +  - ]:      10057 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
         [ +  - ][ +  - ]
                 [ +  - ]
     190                 :            :                     }
     191                 :      10057 :                     break;
     192                 :            :                 case RT_Hex:
     193                 :            :                     {
     194                 :            : #ifdef DEBUG_FACTORY
     195                 :            :                         debug_logger->element("hex");
     196                 :            : #endif
     197 [ +  - ][ +  - ]:       6688 :                         OUString aValue(Attribs->getValue(aIt->first));
                 [ +  - ]
     198                 :            :                         OOXMLFastHelper<OOXMLHexValue>::newProperty
     199         [ +  - ]:       6688 :                             (pHandler, nId, aValue);
     200                 :            : 
     201 [ +  - ][ +  - ]:       6688 :                         OOXMLValue::Pointer_t pValue(new OOXMLHexValue(aValue));
                 [ +  - ]
     202 [ +  - ][ +  - ]:       6688 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
         [ +  - ][ +  - ]
                 [ +  - ]
     203                 :            :                     }
     204                 :       6688 :                     break;
     205                 :            :                 case RT_List:
     206                 :            :                     {
     207                 :            : #ifdef DEBUG_FACTORY
     208                 :            :                         debug_logger->startElement("list");
     209                 :            : #endif
     210                 :            :                         ListValueMapPointer pListValueMap =
     211 [ +  - ][ +  - ]:       9025 :                             pFactory->getListValueMap(aIt->second.m_nRef);
     212                 :            : 
     213         [ +  - ]:       9025 :                         if (pListValueMap.get() != NULL)
     214                 :            :                         {
     215 [ +  - ][ +  - ]:       9025 :                             OUString aValue(Attribs->getValue(aIt->first));
                 [ +  - ]
     216         [ +  - ]:       9025 :                             sal_uInt32 nValue = (*pListValueMap)[aValue];
     217                 :            : 
     218                 :            : #ifdef DEBUG_FACTORY
     219                 :            :                             debug_logger->attribute("value", aValue);
     220                 :            :                             debug_logger->attribute("value-num", nValue);
     221                 :            : #endif
     222                 :            : 
     223                 :            :                             OOXMLFastHelper<OOXMLIntegerValue>::newProperty
     224         [ +  - ]:       9025 :                                 (pHandler, nId, nValue);
     225                 :            : 
     226 [ +  - ][ +  - ]:       9025 :                             OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(nValue));
                 [ +  - ]
     227 [ +  - ][ +  - ]:       9025 :                             pFactory->attributeAction(pHandler, aIt->first, pValue);
         [ +  - ][ +  - ]
                 [ +  - ]
     228         [ +  - ]:       9025 :                         }
     229                 :            : #ifdef DEBUG_FACTORY
     230                 :            :                         debug_logger->endElement();
     231                 :            : #endif
     232                 :            :                     }
     233                 :       9025 :                     break;
     234                 :            :                 default:
     235                 :            : #ifdef DEBUG_FACTORY
     236                 :            :                     debug_logger->element("unknown-attribute-type");
     237                 :            : #endif
     238                 :      46611 :                     break;
     239                 :            :                 }
     240                 :            :             }
     241                 :            : #ifdef DEBUG_FACTORY
     242                 :            :             debug_logger->endElement();
     243                 :            : #endif
     244 [ +  - ][ +  - ]:      51761 :         }
     245                 :            : 
     246                 :            : #ifdef DEBUG_FACTORY
     247                 :            :         debug_logger->endElement();
     248                 :            : #endif
     249         [ +  - ]:      51761 :     }
     250                 :      51761 : }
     251                 :            : 
     252                 :            : uno::Reference< xml::sax::XFastContextHandler>
     253                 :      45587 : OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
     254                 :            :                                      Token_t Element)
     255                 :            : {
     256                 :            : #ifdef DEBUG_FACTORY
     257                 :            :     debug_logger->startElement("factory.createFastChildContext");
     258                 :            :     debug_logger->attribute("token", fastTokenToId(Element));
     259                 :            : #endif
     260                 :            : 
     261         [ +  - ]:      45587 :     Id nDefine = pHandler->getDefine();
     262                 :            : 
     263         [ +  - ]:      45587 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     264                 :            : 
     265                 :      45587 :     uno::Reference< xml::sax::XFastContextHandler> ret;
     266                 :            : 
     267                 :            :     //Avoid handling unknown tokens and recursing to death
     268         [ +  + ]:      45587 :     if ((Element & 0xffff) < OOXML_FAST_TOKENS_END)
     269 [ +  - ][ +  - ]:      45539 :         ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
         [ +  - ][ +  - ]
     270                 :            : 
     271                 :            : #ifdef DEBUG_FACTORY
     272                 :            :     debug_logger->endElement("factory.createFastChildContext");
     273                 :            : #endif
     274                 :            : 
     275         [ +  - ]:      45587 :     return ret;
     276                 :            : }
     277                 :            : 
     278                 :       4630 : void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
     279                 :            :                               const OUString & rString)
     280                 :            : {
     281                 :            : #ifdef DEBUG_FACTORY
     282                 :            :     debug_logger->startElement("factory.characters");
     283                 :            :     debug_logger->chars(rString);
     284                 :            : #endif
     285                 :            : 
     286         [ +  - ]:       4630 :     Id nDefine = pHandler->getDefine();
     287         [ +  - ]:       4630 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     288                 :            : 
     289         [ +  - ]:       4630 :     if (pFactory.get() != NULL)
     290                 :            :     {
     291         [ +  - ]:       4630 :         pFactory->charactersAction(pHandler, rString);
     292         [ +  - ]:       4630 :     }
     293                 :            : 
     294                 :            : #ifdef DEBUG_FACTORY
     295                 :            :     debug_logger->endElement("factory.characters");
     296                 :            : #endif
     297                 :       4630 : }
     298                 :            : 
     299                 :      44702 : void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
     300                 :            : {
     301         [ +  - ]:      44702 :     Id nDefine = pHandler->getDefine();
     302         [ +  - ]:      44702 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     303                 :            : 
     304         [ +  - ]:      44702 :     if (pFactory.get() != NULL)
     305                 :            :     {
     306                 :            : #ifdef DEBUG_ELEMENT
     307                 :            :         debug_logger->startElement("factory.startAction");
     308                 :            : #endif
     309         [ +  - ]:      44702 :         pFactory->startAction(pHandler);
     310                 :            : #ifdef DEBUG_ELEMENT
     311                 :            :         debug_logger->endElement();
     312                 :            : #endif
     313         [ +  - ]:      44702 :     }
     314                 :      44702 : }
     315                 :            : 
     316                 :      44234 : void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
     317                 :            : {
     318         [ +  - ]:      44234 :     Id nDefine = pHandler->getDefine();
     319         [ +  - ]:      44234 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     320                 :            : 
     321         [ +  - ]:      44234 :     if (pFactory.get() != NULL)
     322                 :            :     {
     323                 :            : #ifdef DEBUG_ELEMENT
     324                 :            :         debug_logger->startElement("factory.endAction");
     325                 :            : #endif
     326         [ +  - ]:      44234 :         pFactory->endAction(pHandler);
     327                 :            : #ifdef DEBUG_ELEMENT
     328                 :            :         debug_logger->endElement();
     329                 :            : #endif
     330         [ +  - ]:      44234 :     }
     331                 :      44234 : }
     332                 :            : 
     333                 :       7099 : void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
     334                 :            : {
     335                 :       7099 : }
     336                 :            : 
     337                 :       9637 : void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
     338                 :            : {
     339                 :       9637 : }
     340                 :            : 
     341                 :          0 : void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &)
     342                 :            : {
     343                 :          0 : }
     344                 :            : 
     345                 :          0 : void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, OOXMLValue::Pointer_t)
     346                 :            : {
     347                 :          0 : }
     348                 :            : 
     349                 :            : #ifdef DEBUG_FACTORY
     350                 :            : string OOXMLFactory_ns::getName() const
     351                 :            : {
     352                 :            :     return "noname";
     353                 :            : }
     354                 :            : #endif
     355                 :            : 
     356                 :            : }
     357 [ +  - ][ +  - ]:         60 : }
     358                 :            : 
     359                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10