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

Generated by: LCOV version 1.10