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

Generated by: LCOV version 1.10