LCOV - code coverage report
Current view: top level - xmloff/source/script - XMLEventImportHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 59 0.0 %
Date: 2014-04-14 Functions: 0 7 0.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           0 : XMLEventImportHelper::XMLEventImportHelper() :
      33             :     aFactoryMap(),
      34           0 :     pEventNameMap(new NameMap()),
      35           0 :     aEventNameMapList()
      36             : {
      37           0 : }
      38             : 
      39             : 
      40           0 : XMLEventImportHelper::~XMLEventImportHelper()
      41             : {
      42             :     // delete factories
      43           0 :     FactoryMap::iterator aEnd = aFactoryMap.end();
      44           0 :     for(FactoryMap::iterator aIter = aFactoryMap.begin();
      45             :         aIter != aEnd;
      46             :         ++aIter)
      47             :     {
      48           0 :         delete aIter->second;
      49             :     }
      50           0 :     aFactoryMap.clear();
      51             : 
      52             :     // delete name map
      53           0 :     delete pEventNameMap;
      54           0 : }
      55             : 
      56           0 : void XMLEventImportHelper::RegisterFactory(
      57             :     const OUString& rLanguage,
      58             :     XMLEventContextFactory* pFactory )
      59             : {
      60             :     DBG_ASSERT(pFactory != NULL, "I need a factory.");
      61           0 :     if (NULL != pFactory)
      62             :     {
      63           0 :         aFactoryMap[rLanguage] = pFactory;
      64             :     }
      65           0 : }
      66             : 
      67           0 : void XMLEventImportHelper::AddTranslationTable(
      68             :     const XMLEventNameTranslation* pTransTable )
      69             : {
      70           0 :     if (NULL != pTransTable)
      71             :     {
      72             :         // put translation table into map
      73           0 :         for(const XMLEventNameTranslation* pTrans = pTransTable;
      74           0 :             pTrans->sAPIName != NULL;
      75             :             pTrans++)
      76             :         {
      77           0 :             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           0 :             (*pEventNameMap)[aName] =
      85           0 :                 OUString::createFromAscii(pTrans->sAPIName);
      86           0 :         }
      87             :     }
      88             :     // else? ignore!
      89           0 : }
      90             : 
      91           0 : void XMLEventImportHelper::PushTranslationTable()
      92             : {
      93             :     // save old map and install new one
      94           0 :     aEventNameMapList.push_back(pEventNameMap);
      95           0 :     pEventNameMap = new NameMap();
      96           0 : }
      97             : 
      98           0 : void XMLEventImportHelper::PopTranslationTable()
      99             : {
     100             :     DBG_ASSERT(aEventNameMapList.size() > 0,
     101             :                "no translation tables left to pop");
     102           0 :     if ( !aEventNameMapList.empty() )
     103             :     {
     104             :         // delete current and install old map
     105           0 :         delete pEventNameMap;
     106           0 :         pEventNameMap = aEventNameMapList.back();
     107           0 :         aEventNameMapList.pop_back();
     108             :     }
     109           0 : }
     110             : 
     111             : 
     112           0 : 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           0 :     SvXMLImportContext* pContext = NULL;
     122             : 
     123             :     // translate event name form xml to api
     124           0 :     OUString sMacroName;
     125             :     sal_uInt16 nMacroPrefix =
     126           0 :         rImport.GetNamespaceMap().GetKeyByAttrName( rXmlEventName,
     127           0 :                                                         &sMacroName );
     128           0 :     XMLEventName aEventName( nMacroPrefix, sMacroName );
     129           0 :     NameMap::iterator aNameIter = pEventNameMap->find(aEventName);
     130           0 :     if (aNameIter != pEventNameMap->end())
     131             :     {
     132           0 :         OUString aScriptLanguage;
     133           0 :         sal_uInt16 nScriptPrefix = rImport.GetNamespaceMap().
     134           0 :                 GetKeyByAttrName( rLanguage, &aScriptLanguage );
     135           0 :         if( XML_NAMESPACE_OOO != nScriptPrefix )
     136           0 :             aScriptLanguage = rLanguage ;
     137             : 
     138             :         // check for factory
     139             :         FactoryMap::iterator aFactoryIterator =
     140           0 :             aFactoryMap.find(aScriptLanguage);
     141           0 :         if (aFactoryIterator != aFactoryMap.end())
     142             :         {
     143             :             // delegate to factory
     144           0 :             pContext = aFactoryIterator->second->CreateContext(
     145             :                 rImport, nPrefix, rLocalName, xAttrList,
     146           0 :                 rEvents, aNameIter->second, aScriptLanguage);
     147           0 :         }
     148             :     }
     149             : 
     150             :     // default context (if no context was created above)
     151           0 :     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           0 :     return pContext;
     166             : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10