LCOV - code coverage report
Current view: top level - xmloff/source/script - XMLEventImportHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 52 59 88.1 %
Date: 2015-06-13 12:38:46 Functions: 7 7 100.0 %
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             : 
      21             : #include "XMLEventImportHelper.hxx"
      22             : #include <tools/debug.hxx>
      23             : #include <xmloff/xmlimp.hxx>
      24             : #include <xmloff/nmspmap.hxx>
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmlerror.hxx>
      27             : 
      28             : using ::com::sun::star::xml::sax::XAttributeList;
      29             : using ::com::sun::star::uno::Reference;
      30             : using ::com::sun::star::uno::Sequence;
      31             : 
      32          20 : XMLEventImportHelper::XMLEventImportHelper() :
      33             :     aFactoryMap(),
      34           0 :     pEventNameMap(new NameMap()),
      35          20 :     aEventNameMapList()
      36             : {
      37          20 : }
      38             : 
      39             : 
      40          40 : XMLEventImportHelper::~XMLEventImportHelper()
      41             : {
      42             :     // delete factories
      43          20 :     FactoryMap::iterator aEnd = aFactoryMap.end();
      44          80 :     for(FactoryMap::iterator aIter = aFactoryMap.begin();
      45             :         aIter != aEnd;
      46             :         ++aIter)
      47             :     {
      48          60 :         delete aIter->second;
      49             :     }
      50          20 :     aFactoryMap.clear();
      51             : 
      52             :     // delete name map
      53          20 :     delete pEventNameMap;
      54          20 : }
      55             : 
      56          60 : void XMLEventImportHelper::RegisterFactory(
      57             :     const OUString& rLanguage,
      58             :     XMLEventContextFactory* pFactory )
      59             : {
      60             :     DBG_ASSERT(pFactory != NULL, "I need a factory.");
      61          60 :     if (NULL != pFactory)
      62             :     {
      63          60 :         aFactoryMap[rLanguage] = pFactory;
      64             :     }
      65          60 : }
      66             : 
      67          35 : void XMLEventImportHelper::AddTranslationTable(
      68             :     const XMLEventNameTranslation* pTransTable )
      69             : {
      70          35 :     if (NULL != pTransTable)
      71             :     {
      72             :         // put translation table into map
      73        3460 :         for(const XMLEventNameTranslation* pTrans = pTransTable;
      74        1730 :             pTrans->sAPIName != NULL;
      75             :             pTrans++)
      76             :         {
      77        1695 :             XMLEventName aName( pTrans->nPrefix, pTrans->sXMLName );
      78             : 
      79             :             // check for conflicting entries
      80             :             DBG_ASSERT(pEventNameMap->find(aName) == pEventNameMap->end(),
      81             :                        "conflicting event translations");
      82             : 
      83             :             // assign new translation
      84        3390 :             (*pEventNameMap)[aName] =
      85        1695 :                 OUString::createFromAscii(pTrans->sAPIName);
      86        1695 :         }
      87             :     }
      88             :     // else? ignore!
      89          35 : }
      90             : 
      91          15 : void XMLEventImportHelper::PushTranslationTable()
      92             : {
      93             :     // save old map and install new one
      94          15 :     aEventNameMapList.push_back(pEventNameMap);
      95          15 :     pEventNameMap = new NameMap();
      96          15 : }
      97             : 
      98          15 : void XMLEventImportHelper::PopTranslationTable()
      99             : {
     100             :     DBG_ASSERT(aEventNameMapList.size() > 0,
     101             :                "no translation tables left to pop");
     102          15 :     if ( !aEventNameMapList.empty() )
     103             :     {
     104             :         // delete current and install old map
     105          15 :         delete pEventNameMap;
     106          15 :         pEventNameMap = aEventNameMapList.back();
     107          15 :         aEventNameMapList.pop_back();
     108             :     }
     109          15 : }
     110             : 
     111             : 
     112          35 : SvXMLImportContext* XMLEventImportHelper::CreateContext(
     113             :     SvXMLImport& rImport,
     114             :     sal_uInt16 nPrefix,
     115             :     const OUString& rLocalName,
     116             :     const Reference<XAttributeList> & xAttrList,
     117             :     XMLEventsImportContext* rEvents,
     118             :     const OUString& rXmlEventName,
     119             :     const OUString& rLanguage)
     120             : {
     121          35 :     SvXMLImportContext* pContext = NULL;
     122             : 
     123             :     // translate event name form xml to api
     124          35 :     OUString sMacroName;
     125             :     sal_uInt16 nMacroPrefix =
     126          35 :         rImport.GetNamespaceMap().GetKeyByAttrName( rXmlEventName,
     127          35 :                                                         &sMacroName );
     128          70 :     XMLEventName aEventName( nMacroPrefix, sMacroName );
     129          35 :     NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
     130          35 :     if (aNameIter != pEventNameMap->end())
     131             :     {
     132          35 :         OUString aScriptLanguage;
     133          35 :         sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
     134          35 :                 GetKeyByAttrName( rLanguage, &aScriptLanguage );
     135          35 :         if( XML_NAMESPACE_OOO != nScriptPrefix )
     136           0 :             aScriptLanguage = rLanguage ;
     137             : 
     138             :         // check for factory
     139             :         FactoryMap::iterator aFactoryIterator =
     140          35 :             aFactoryMap.find(aScriptLanguage);
     141          35 :         if (aFactoryIterator != aFactoryMap.end())
     142             :         {
     143             :             // delegate to factory
     144          35 :             pContext = aFactoryIterator->second->CreateContext(
     145             :                 rImport, nPrefix, rLocalName, xAttrList,
     146          35 :                 rEvents, aNameIter->second, aScriptLanguage);
     147          35 :         }
     148             :     }
     149             : 
     150             :     // default context (if no context was created above)
     151          35 :     if( NULL == pContext )
     152             :     {
     153           0 :         pContext = new SvXMLImportContext(rImport, nPrefix, rLocalName);
     154             : 
     155           0 :         Sequence<OUString> aMsgParams(2);
     156             : 
     157           0 :         aMsgParams[0] = rXmlEventName;
     158           0 :         aMsgParams[1] = rLanguage;
     159             : 
     160             :         rImport.SetError(XMLERROR_FLAG_ERROR | XMLERROR_ILLEGAL_EVENT,
     161           0 :                          aMsgParams);
     162             : 
     163             :     }
     164             : 
     165          70 :     return pContext;
     166             : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11