LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerfilter/source/ooxml - OOXMLFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 117 124 94.4 %
Date: 2013-07-09 Functions: 22 26 84.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 <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         979 : AttributeInfo::AttributeInfo()
      31         979 : :m_nResource(RT_NoResource), m_nRef(0)
      32             : {
      33         979 : }
      34             : 
      35         984 : AttributeInfo::AttributeInfo(ResourceType_t nResource, Id nRef)
      36         984 :  :m_nResource(nResource), m_nRef(nRef)
      37             : {
      38         984 : }
      39             : 
      40        5052 : CreateElement::CreateElement()
      41        5052 : :m_nResource(RT_NoResource), m_nId(0)
      42             : {
      43        5052 : }
      44             : 
      45        4064 : CreateElement::CreateElement(ResourceType_t nResource, Id nId)
      46        4064 : : m_nResource(nResource), m_nId(nId)
      47             : {
      48        4064 : }
      49             : 
      50             : // class OOXMLFactory_ns
      51             : 
      52         125 : OOXMLFactory_ns::~OOXMLFactory_ns()
      53             : {
      54         125 : }
      55             : 
      56       62906 : AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId)
      57             : {
      58       62906 :     if (m_AttributesMap.find(nId) == m_AttributesMap.end())
      59         560 :         m_AttributesMap[nId] = createAttributeToResourceMap(nId);
      60             : 
      61       62906 :     return m_AttributesMap[nId];
      62             : }
      63             : 
      64       13219 : ListValueMapPointer OOXMLFactory_ns::getListValueMap(Id nId)
      65             : {
      66       13219 :     if (m_ListValuesMap.find(nId) == m_ListValuesMap.end())
      67         135 :         m_ListValuesMap[nId] = createListValueMap(nId);
      68             : 
      69       13219 :     return m_ListValuesMap[nId];
      70             : }
      71             : 
      72       81216 : CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
      73             : {
      74       81216 :     if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end())
      75         513 :         m_CreateElementsMap[nId] = createCreateElementMap(nId);
      76             : 
      77       81216 :     return m_CreateElementsMap[nId];
      78             : }
      79             : 
      80      144122 : TokenToIdMapPointer OOXMLFactory_ns::getTokenToIdMap(Id nId)
      81             : {
      82      144122 :     if (m_TokenToIdsMap.find(nId) == m_TokenToIdsMap.end())
      83         793 :         m_TokenToIdsMap[nId] = createTokenToIdMap(nId);
      84             : 
      85      144122 :     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           8 : OOXMLFactory::Pointer_t OOXMLFactory::m_Instance;
      98             : 
      99           5 : OOXMLFactory::OOXMLFactory()
     100             : {
     101             :     // multi-thread-safe mutex for all platforms
     102             : 
     103           5 :     osl::MutexGuard aGuard(OOXMLFactory_Mutex::get());
     104           5 : }
     105             : 
     106          10 : OOXMLFactory::~OOXMLFactory()
     107             : {
     108          10 : }
     109             : 
     110      258813 : OOXMLFactory::Pointer_t OOXMLFactory::getInstance()
     111             : {
     112      258813 :     if (m_Instance.get() == NULL)
     113           5 :         m_Instance.reset(new OOXMLFactory());
     114             : 
     115      258813 :     return m_Instance;
     116             : }
     117             : 
     118       62906 : void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
     119             :                               const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     120             : {
     121       62906 :     Id nDefine = pHandler->getDefine();
     122       62906 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     123             : 
     124       62906 :     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       62906 :         TokenToIdMapPointer pTokenToIdMap = pFactory->getTokenToIdMap(nDefine);
     135      125812 :         AttributeToResourceMapPointer pMap = pFactory->getAttributeToResourceMap(nDefine);
     136             : 
     137       62906 :         AttributeToResourceMap::const_iterator aIt;
     138       62906 :         AttributeToResourceMap::const_iterator aEndIt = pMap->end();
     139             : 
     140      185170 :         for (aIt = pMap->begin(); aIt != aEndIt; ++aIt)
     141             :         {
     142      122264 :             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      122264 :             if (Attribs->hasAttribute(aIt->first))
     151             :             {
     152       66736 :                 switch (aIt->second.m_nResource)
     153             :                 {
     154             :                 case RT_Boolean:
     155             :                     {
     156             : #ifdef DEBUG_FACTORY
     157             :                         debug_logger->element("boolean");
     158             : #endif
     159        1549 :                         OUString aValue(Attribs->getValue(aIt->first));
     160        1549 :                         OOXMLFastHelper<OOXMLBooleanValue>::newProperty(pHandler, nId, aValue);
     161             : 
     162        3098 :                         OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(aValue));
     163        3098 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
     164             :                     }
     165        1549 :                     break;
     166             :                 case RT_String:
     167             :                     {
     168             : #ifdef DEBUG_FACTORY
     169             :                         debug_logger->element("string");
     170             : #endif
     171       24083 :                         OUString aValue(Attribs->getValue(aIt->first));
     172             :                         OOXMLFastHelper<OOXMLStringValue>::newProperty
     173       24083 :                             (pHandler, nId, aValue);
     174             : 
     175       48166 :                         OOXMLValue::Pointer_t pValue(new OOXMLStringValue(aValue));
     176       48166 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
     177             :                     }
     178       24083 :                     break;
     179             :                 case RT_Integer:
     180             :                     {
     181             : #ifdef DEBUG_FACTORY
     182             :                         debug_logger->element("integer");
     183             : #endif
     184       15517 :                         OUString aValue(Attribs->getValue(aIt->first));
     185             :                         OOXMLFastHelper<OOXMLIntegerValue>::newProperty
     186       15517 :                             (pHandler, nId, aValue);
     187             : 
     188       31034 :                         OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(aValue));
     189       31034 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
     190             :                     }
     191       15517 :                     break;
     192             :                 case RT_Hex:
     193             :                     {
     194             : #ifdef DEBUG_FACTORY
     195             :                         debug_logger->element("hex");
     196             : #endif
     197       12368 :                         OUString aValue(Attribs->getValue(aIt->first));
     198             :                         OOXMLFastHelper<OOXMLHexValue>::newProperty
     199       12368 :                             (pHandler, nId, aValue);
     200             : 
     201       24736 :                         OOXMLValue::Pointer_t pValue(new OOXMLHexValue(aValue));
     202       24736 :                         pFactory->attributeAction(pHandler, aIt->first, pValue);
     203             :                     }
     204       12368 :                     break;
     205             :                 case RT_List:
     206             :                     {
     207             : #ifdef DEBUG_FACTORY
     208             :                         debug_logger->startElement("list");
     209             : #endif
     210             :                         ListValueMapPointer pListValueMap =
     211       13219 :                             pFactory->getListValueMap(aIt->second.m_nRef);
     212             : 
     213       13219 :                         if (pListValueMap.get() != NULL)
     214             :                         {
     215       13219 :                             OUString aValue(Attribs->getValue(aIt->first));
     216       13219 :                             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       13219 :                                 (pHandler, nId, nValue);
     225             : 
     226       26438 :                             OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(nValue));
     227       26438 :                             pFactory->attributeAction(pHandler, aIt->first, pValue);
     228       13219 :                         }
     229             : #ifdef DEBUG_FACTORY
     230             :                         debug_logger->endElement();
     231             : #endif
     232             :                     }
     233       13219 :                     break;
     234             :                 default:
     235             : #ifdef DEBUG_FACTORY
     236             :                     debug_logger->element("unknown-attribute-type");
     237             : #endif
     238           0 :                     break;
     239             :                 }
     240             :             }
     241             : #ifdef DEBUG_FACTORY
     242             :             debug_logger->endElement();
     243             : #endif
     244       62906 :         }
     245             : 
     246             : #ifdef DEBUG_FACTORY
     247             :         debug_logger->endElement();
     248             : #endif
     249       62906 :     }
     250       62906 : }
     251             : 
     252             : uno::Reference< xml::sax::XFastContextHandler>
     253       61418 : 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       61418 :     Id nDefine = pHandler->getDefine();
     262             : 
     263       61418 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     264             : 
     265       61418 :     uno::Reference< xml::sax::XFastContextHandler> ret;
     266             : 
     267             :     //Avoid handling unknown tokens and recursing to death
     268       61418 :     if ((Element & 0xffff) < OOXML_FAST_TOKENS_END)
     269       61306 :         ret = createFastChildContextFromFactory(pHandler, pFactory, Element);
     270             : 
     271             : #ifdef DEBUG_FACTORY
     272             :     debug_logger->endElement("factory.createFastChildContext");
     273             : #endif
     274             : 
     275       61418 :     return ret;
     276             : }
     277             : 
     278       13156 : 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       13156 :     Id nDefine = pHandler->getDefine();
     287       13156 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     288             : 
     289       13156 :     if (pFactory.get() != NULL)
     290             :     {
     291       13156 :         pFactory->charactersAction(pHandler, rString);
     292       13156 :     }
     293             : 
     294             : #ifdef DEBUG_FACTORY
     295             :     debug_logger->endElement("factory.characters");
     296             : #endif
     297       13156 : }
     298             : 
     299       60436 : void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
     300             : {
     301       60436 :     Id nDefine = pHandler->getDefine();
     302       60436 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     303             : 
     304       60436 :     if (pFactory.get() != NULL)
     305             :     {
     306             : #ifdef DEBUG_ELEMENT
     307             :         debug_logger->startElement("factory.startAction");
     308             : #endif
     309       60436 :         pFactory->startAction(pHandler);
     310             : #ifdef DEBUG_ELEMENT
     311             :         debug_logger->endElement();
     312             : #endif
     313       60436 :     }
     314       60436 : }
     315             : 
     316       60020 : void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
     317             : {
     318       60020 :     Id nDefine = pHandler->getDefine();
     319       60020 :     OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
     320             : 
     321       60020 :     if (pFactory.get() != NULL)
     322             :     {
     323             : #ifdef DEBUG_ELEMENT
     324             :         debug_logger->startElement("factory.endAction");
     325             : #endif
     326       60020 :         pFactory->endAction(pHandler);
     327             : #ifdef DEBUG_ELEMENT
     328             :         debug_logger->endElement();
     329             : #endif
     330       60020 :     }
     331       60020 : }
     332             : 
     333        7653 : void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
     334             : {
     335        7653 : }
     336             : 
     337       10410 : void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
     338             : {
     339       10410 : }
     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          24 : }
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10