LCOV - code coverage report
Current view: top level - xmloff/source/script - XMLStarBasicContextFactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 35 38 92.1 %
Date: 2015-06-13 12:38:46 Functions: 4 4 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             : #include "XMLStarBasicContextFactory.hxx"
      21             : #include <xmloff/XMLEventsImportContext.hxx>
      22             : #include <xmloff/xmlimp.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/xmltoken.hxx>
      26             : 
      27             : 
      28             : using namespace ::xmloff::token;
      29             : 
      30             : using ::com::sun::star::xml::sax::XAttributeList;
      31             : using ::com::sun::star::beans::PropertyValue;
      32             : using ::com::sun::star::uno::Reference;
      33             : using ::com::sun::star::uno::Sequence;
      34             : using ::com::sun::star::uno::Any;
      35             : 
      36             : 
      37          40 : XMLStarBasicContextFactory::XMLStarBasicContextFactory() :
      38             :     sEventType("EventType"),
      39             :     sLibrary("Library"),
      40             :     sMacroName("MacroName"),
      41          40 :     sStarBasic("StarBasic")
      42             : {
      43          40 : }
      44             : 
      45          80 : XMLStarBasicContextFactory::~XMLStarBasicContextFactory()
      46             : {
      47          80 : }
      48             : 
      49           3 : SvXMLImportContext* XMLStarBasicContextFactory::CreateContext(
      50             :     SvXMLImport& rImport,
      51             :     sal_uInt16 p_nPrefix,
      52             :     const OUString& rLocalName,
      53             :     const Reference<XAttributeList> & xAttrList,
      54             :     XMLEventsImportContext* rEvents,
      55             :     const OUString& rApiEventName,
      56             :     const OUString& /*rApiLanguage*/)
      57             : {
      58           3 :     OUString sLibraryVal;
      59           6 :     OUString sMacroNameVal;
      60             : 
      61           3 :     sal_Int16 nCount = xAttrList->getLength();
      62          12 :     for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
      63             :     {
      64           9 :         OUString sLocalName;
      65           9 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().
      66          18 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), &sLocalName );
      67             : 
      68           9 :         if (XML_NAMESPACE_SCRIPT == nPrefix)
      69             :         {
      70           9 :             if (IsXMLToken(sLocalName, XML_MACRO_NAME))
      71             :             {
      72           3 :                 sMacroNameVal = xAttrList->getValueByIndex(nAttr);
      73             :             }
      74             :             // else: ingore
      75             :         }
      76             :         // else: ignore
      77           9 :     }
      78             : 
      79           3 :     const OUString& rApp = GetXMLToken( XML_APPLICATION );
      80           3 :     const OUString& rDoc = GetXMLToken( XML_DOCUMENT );
      81          15 :     if( sMacroNameVal.getLength() > rApp.getLength()+1 &&
      82          15 :         sMacroNameVal.copy(0,rApp.getLength()).equalsIgnoreAsciiCase( rApp ) &&
      83           0 :         ':' == sMacroNameVal[rApp.getLength()] )
      84             :     {
      85           0 :         sLibraryVal = "StarOffice";
      86           0 :         sMacroNameVal = sMacroNameVal.copy( rApp.getLength()+1 );
      87             :     }
      88          15 :     else if( sMacroNameVal.getLength() > rDoc.getLength()+1 &&
      89          18 :         sMacroNameVal.copy(0,rDoc.getLength()).equalsIgnoreAsciiCase( rDoc ) &&
      90           3 :         ':' == sMacroNameVal[rDoc.getLength()] )
      91             :     {
      92           3 :         sLibraryVal = rDoc;
      93           3 :         sMacroNameVal = sMacroNameVal.copy( rDoc.getLength()+1 );
      94             :     }
      95             : 
      96           6 :     Sequence<PropertyValue> aValues(3);
      97             : 
      98             :     // EventType
      99           3 :     aValues[0].Name = sEventType;
     100           3 :     aValues[0].Value <<= sStarBasic;
     101             : 
     102             :     // library name
     103           3 :     aValues[1].Name = sLibrary;
     104           3 :     aValues[1].Value <<= sLibraryVal;
     105             : 
     106             :     // macro name
     107           3 :     aValues[2].Name = sMacroName;
     108           3 :     aValues[2].Value <<= sMacroNameVal;
     109             : 
     110             :     // add values for event now
     111           3 :     rEvents->AddEventValues(rApiEventName, aValues);
     112             : 
     113             :     // return dummy context
     114           6 :     return new SvXMLImportContext(rImport, p_nPrefix, rLocalName);
     115             : }
     116             : 
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11