LCOV - code coverage report
Current view: top level - xmloff/source/script - XMLEventImportHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 58 87.9 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 60 41.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "XMLEventImportHelper.hxx"
      31                 :            : #include <tools/debug.hxx>
      32                 :            : #include <xmloff/xmlimp.hxx>
      33                 :            : #include <xmloff/nmspmap.hxx>
      34                 :            : #include "xmloff/xmlnmspe.hxx"
      35                 :            : #include "xmloff/xmlerror.hxx"
      36                 :            : 
      37                 :            : using ::rtl::OUString;
      38                 :            : using ::com::sun::star::xml::sax::XAttributeList;
      39                 :            : using ::com::sun::star::uno::Reference;
      40                 :            : using ::com::sun::star::uno::Sequence;
      41                 :            : 
      42                 :         12 : XMLEventImportHelper::XMLEventImportHelper() :
      43                 :            :     aFactoryMap(),
      44                 :          0 :     pEventNameMap(new NameMap()),
      45 [ +  - ][ +  - ]:         12 :     aEventNameMapList()
                 [ +  - ]
      46                 :            : {
      47                 :         12 : }
      48                 :            : 
      49                 :            : 
      50                 :         12 : XMLEventImportHelper::~XMLEventImportHelper()
      51                 :            : {
      52                 :            :     // delete factories
      53                 :         12 :     FactoryMap::iterator aEnd = aFactoryMap.end();
      54         [ +  + ]:         48 :     for(FactoryMap::iterator aIter = aFactoryMap.begin();
      55                 :            :         aIter != aEnd;
      56                 :            :         ++aIter)
      57                 :            :     {
      58 [ +  - ][ +  - ]:         36 :         delete aIter->second;
      59                 :            :     }
      60                 :         12 :     aFactoryMap.clear();
      61                 :            : 
      62                 :            :     // delete name map
      63         [ +  - ]:         12 :     delete pEventNameMap;
      64                 :         12 : }
      65                 :            : 
      66                 :         36 : void XMLEventImportHelper::RegisterFactory(
      67                 :            :     const OUString& rLanguage,
      68                 :            :     XMLEventContextFactory* pFactory )
      69                 :            : {
      70                 :            :     DBG_ASSERT(pFactory != NULL, "I need a factory.");
      71         [ +  - ]:         36 :     if (NULL != pFactory)
      72                 :            :     {
      73                 :         36 :         aFactoryMap[rLanguage] = pFactory;
      74                 :            :     }
      75                 :         36 : }
      76                 :            : 
      77                 :         24 : void XMLEventImportHelper::AddTranslationTable(
      78                 :            :     const XMLEventNameTranslation* pTransTable )
      79                 :            : {
      80         [ +  - ]:         24 :     if (NULL != pTransTable)
      81                 :            :     {
      82                 :            :         // put translation table into map
      83         [ +  + ]:       1140 :         for(const XMLEventNameTranslation* pTrans = pTransTable;
      84                 :            :             pTrans->sAPIName != NULL;
      85                 :            :             pTrans++)
      86                 :            :         {
      87                 :       1116 :             XMLEventName aName( pTrans->nPrefix, pTrans->sXMLName );
      88                 :            : 
      89                 :            :             // check for conflicting entries
      90                 :            :             DBG_ASSERT(pEventNameMap->find(aName) == pEventNameMap->end(),
      91                 :            :                        "conflicting event translations");
      92                 :            : 
      93                 :            :             // assign new translation
      94         [ +  - ]:       1116 :             (*pEventNameMap)[aName] =
      95                 :       2232 :                 OUString::createFromAscii(pTrans->sAPIName);
      96                 :       1116 :         }
      97                 :            :     }
      98                 :            :     // else? ignore!
      99                 :         24 : }
     100                 :            : 
     101                 :         12 : void XMLEventImportHelper::PushTranslationTable()
     102                 :            : {
     103                 :            :     // save old map and install new one
     104                 :         12 :     aEventNameMapList.push_back(pEventNameMap);
     105         [ +  - ]:         12 :     pEventNameMap = new NameMap();
     106                 :         12 : }
     107                 :            : 
     108                 :         12 : void XMLEventImportHelper::PopTranslationTable()
     109                 :            : {
     110                 :            :     DBG_ASSERT(aEventNameMapList.size() > 0,
     111                 :            :                "no translation tables left to pop");
     112         [ +  - ]:         12 :     if ( !aEventNameMapList.empty() )
     113                 :            :     {
     114                 :            :         // delete current and install old map
     115         [ +  - ]:         12 :         delete pEventNameMap;
     116                 :         12 :         pEventNameMap = aEventNameMapList.back();
     117                 :         12 :         aEventNameMapList.pop_back();
     118                 :            :     }
     119                 :         12 : }
     120                 :            : 
     121                 :            : 
     122                 :         14 : SvXMLImportContext* XMLEventImportHelper::CreateContext(
     123                 :            :     SvXMLImport& rImport,
     124                 :            :     sal_uInt16 nPrefix,
     125                 :            :     const OUString& rLocalName,
     126                 :            :     const Reference<XAttributeList> & xAttrList,
     127                 :            :     XMLEventsImportContext* rEvents,
     128                 :            :     const OUString& rXmlEventName,
     129                 :            :     const OUString& rLanguage)
     130                 :            : {
     131                 :         14 :     SvXMLImportContext* pContext = NULL;
     132                 :            : 
     133                 :            :     // translate event name form xml to api
     134                 :         14 :     OUString sMacroName;
     135                 :            :     sal_uInt16 nMacroPrefix =
     136                 :         14 :         rImport.GetNamespaceMap().GetKeyByAttrName( rXmlEventName,
     137         [ +  - ]:         14 :                                                         &sMacroName );
     138                 :         14 :     XMLEventName aEventName( nMacroPrefix, sMacroName );
     139         [ +  - ]:         14 :     NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
     140         [ +  - ]:         14 :     if (aNameIter != pEventNameMap->end())
     141                 :            :     {
     142                 :         14 :         OUString aScriptLanguage;
     143                 :         14 :         sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
     144         [ +  - ]:         14 :                 GetKeyByAttrName( rLanguage, &aScriptLanguage );
     145         [ -  + ]:         14 :         if( XML_NAMESPACE_OOO != nScriptPrefix )
     146                 :          0 :             aScriptLanguage = rLanguage ;
     147                 :            : 
     148                 :            :         // check for factory
     149                 :            :         FactoryMap::iterator aFactoryIterator =
     150         [ +  - ]:         14 :             aFactoryMap.find(aScriptLanguage);
     151         [ +  - ]:         14 :         if (aFactoryIterator != aFactoryMap.end())
     152                 :            :         {
     153                 :            :             // delegate to factory
     154                 :         14 :             pContext = aFactoryIterator->second->CreateContext(
     155                 :            :                 rImport, nPrefix, rLocalName, xAttrList,
     156         [ +  - ]:         14 :                 rEvents, aNameIter->second, aScriptLanguage);
     157                 :         14 :         }
     158                 :            :     }
     159                 :            : 
     160                 :            :     // default context (if no context was created above)
     161         [ -  + ]:         14 :     if( NULL == pContext )
     162                 :            :     {
     163 [ #  # ][ #  # ]:          0 :         pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
     164                 :            : 
     165         [ #  # ]:          0 :         Sequence<OUString> aMsgParams(2);
     166                 :            : 
     167         [ #  # ]:          0 :         aMsgParams[0] = rXmlEventName;
     168         [ #  # ]:          0 :         aMsgParams[1] = rLanguage;
     169                 :            : 
     170                 :            :         rImport.SetError(XMLERROR_FLAG_ERROR | XMLERROR_ILLEGAL_EVENT,
     171 [ #  # ][ #  # ]:          0 :                          aMsgParams);
     172                 :            : 
     173                 :            :     }
     174                 :            : 
     175                 :         14 :     return pContext;
     176                 :            : }
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10