LCOV - code coverage report
Current view: top level - xmloff/source/script - xmlscripti.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 48 95.8 %
Date: 2015-06-13 12:38:46 Functions: 10 10 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 <xmloff/xmlscripti.hxx>
      21             : #include <xmloff/xmlnmspe.hxx>
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include <xmloff/xmlimp.hxx>
      24             : #include <xmloff/nmspmap.hxx>
      25             : #include <xmloff/XMLEventsImportContext.hxx>
      26             : #include "xmlbasici.hxx"
      27             : 
      28             : #include <com/sun/star/document/XEventsSupplier.hpp>
      29             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      30             : 
      31             : using namespace com::sun::star;
      32             : using namespace com::sun::star::uno;
      33             : using namespace com::sun::star::lang;
      34             : using namespace com::sun::star::frame;
      35             : using namespace com::sun::star::document;
      36             : using namespace com::sun::star::xml::sax;
      37             : using namespace ::xmloff::token;
      38             : 
      39             : // XMLScriptChildContext: context for <office:script> element
      40             : 
      41             : class XMLScriptChildContext : public SvXMLImportContext
      42             : {
      43             : private:
      44             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >                 m_xModel;
      45             :     ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts >    m_xDocumentScripts;
      46             :     OUString m_aLanguage;
      47             : 
      48             : public:
      49             :     XMLScriptChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
      50             :         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel>& rxModel,
      51             :         const OUString& rLanguage );
      52             :     virtual ~XMLScriptChildContext();
      53             : 
      54             :     virtual SvXMLImportContext* CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
      55             :         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
      56             : 
      57             :     virtual void EndElement() SAL_OVERRIDE;
      58             : };
      59             : 
      60           1 : XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
      61             :         const Reference< frame::XModel >& rxModel, const OUString& rLanguage )
      62             :     :SvXMLImportContext( rImport, nPrfx, rLName )
      63             :     ,m_xModel( rxModel )
      64             :     ,m_xDocumentScripts( rxModel, UNO_QUERY )
      65           1 :     ,m_aLanguage( rLanguage )
      66             : {
      67           1 : }
      68             : 
      69           2 : XMLScriptChildContext::~XMLScriptChildContext()
      70             : {
      71           2 : }
      72             : 
      73           1 : SvXMLImportContext* XMLScriptChildContext::CreateChildContext(
      74             :     sal_uInt16 nPrefix, const OUString& rLocalName,
      75             :     const Reference< xml::sax::XAttributeList >& xAttrList )
      76             : {
      77           1 :     SvXMLImportContext* pContext = NULL;
      78             : 
      79           1 :     if ( m_xDocumentScripts.is() )
      80             :     {   // document supports embedding scripts/macros
      81           1 :         OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
      82           1 :         aBasic += ":Basic";
      83             : 
      84           1 :         if ( m_aLanguage == aBasic && nPrefix == XML_NAMESPACE_OOO && IsXMLToken( rLocalName, XML_LIBRARIES ) )
      85           1 :             pContext = new XMLBasicImportContext( GetImport(), nPrefix, rLocalName, m_xModel );
      86             :     }
      87             : 
      88           1 :     if ( !pContext )
      89           0 :         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
      90             : 
      91           1 :     return pContext;
      92             : }
      93             : 
      94           1 : void XMLScriptChildContext::EndElement()
      95             : {
      96           1 : }
      97             : 
      98             : // XMLScriptContext: context for <office:scripts> element
      99             : 
     100         512 : XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
     101             :         const Reference<XModel>& rDocModel )
     102             :     :SvXMLImportContext( rImport, nPrfx, rLName )
     103         512 :     ,m_xModel( rDocModel )
     104             : {
     105         512 : }
     106             : 
     107        1024 : XMLScriptContext::~XMLScriptContext()
     108             : {
     109        1024 : }
     110             : 
     111           6 : SvXMLImportContext* XMLScriptContext::CreateChildContext(
     112             :     sal_uInt16 nPrefix, const OUString& rLName,
     113             :     const Reference<XAttributeList>& xAttrList )
     114             : {
     115           6 :     SvXMLImportContext* pContext = NULL;
     116             : 
     117           6 :     if ( nPrefix == XML_NAMESPACE_OFFICE )
     118             :     {
     119           6 :         if ( IsXMLToken( rLName, XML_EVENT_LISTENERS ) )
     120             :         {
     121           5 :             Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
     122           5 :             pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName, xSupplier );
     123             :         }
     124           1 :         else if ( IsXMLToken( rLName, XML_SCRIPT ) )
     125             :         {
     126           1 :             OUString aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT ) );
     127           1 :             aAttrName += ":language";
     128           1 :             if ( xAttrList.is() )
     129             :             {
     130           1 :                 OUString aLanguage = xAttrList->getValueByName( aAttrName );
     131             : 
     132           1 :                 if ( m_xModel.is() )
     133             :                 {
     134           1 :                     uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs();
     135           1 :                     sal_Int32 nNewLen = aMedDescr.getLength() + 1;
     136           1 :                     aMedDescr.realloc( nNewLen );
     137           1 :                     aMedDescr[nNewLen-1].Name = "BreakMacroSignature";
     138           1 :                     aMedDescr[nNewLen-1].Value <<= true;
     139           1 :                     m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
     140             : 
     141           1 :                     pContext = new XMLScriptChildContext( GetImport(), nPrefix, rLName, m_xModel, aLanguage );
     142           1 :                 }
     143           1 :             }
     144             :         }
     145             :     }
     146             : 
     147           6 :     if ( !pContext )
     148           0 :         pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLName, xAttrList);
     149             : 
     150           6 :     return pContext;
     151             : }
     152             : 
     153         512 : void XMLScriptContext::EndElement()
     154             : {
     155         512 : }
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11