| 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 <utility> |
| 21 |
#include <xmloff/xmlscripti.hxx> |
| 22 |
#include <xmloff/xmlnamespace.hxx> |
| 23 |
#include <xmloff/xmltoken.hxx> |
| 24 |
#include <xmloff/xmlimp.hxx> |
| 25 |
#include <xmloff/namespacemap.hxx> |
| 26 |
#include <xmloff/XMLEventsImportContext.hxx> |
| 27 |
#include "xmlbasicscript.hxx" |
| 28 |
|
| 29 |
#include <com/sun/star/document/XEventsSupplier.hpp> |
| 30 |
#include <com/sun/star/document/XEmbeddedScripts.hpp> |
| 31 |
|
| 32 |
using namespace com::sun::star; |
| 33 |
using namespace com::sun::star::uno; |
| 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 |
namespace { |
| 42 |
|
| 43 |
class XMLScriptChildContext : public SvXMLImportContext |
| 44 |
{ |
| 45 |
private: |
| 46 |
css::uno::Reference< css::frame::XModel > m_xModel; |
| 47 |
css::uno::Reference< css::document::XEmbeddedScripts > m_xDocumentScripts; |
| 48 |
OUString m_aLanguage; |
| 49 |
|
| 50 |
public: |
| 51 |
XMLScriptChildContext( SvXMLImport& rImport, |
| 52 |
const css::uno::Reference< css::frame::XModel>& rxModel, |
| 53 |
OUString aLanguage ); |
| 54 |
|
| 55 |
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
| 56 |
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; |
| 57 |
}; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, |
| 62 |
const Reference< frame::XModel >& rxModel, OUString aLanguage ) |
| 63 |
:SvXMLImportContext( rImport ) |
| 64 |
,m_xModel( rxModel ) |
| 65 |
,m_xDocumentScripts( rxModel, UNO_QUERY ) |
| 66 |
,m_aLanguage(std::move( aLanguage )) |
| 67 |
{ |
| 68 |
} |
| 69 |
|
| 70 |
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptChildContext::createFastChildContext( |
| 71 |
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) |
| 72 |
{ |
| 73 |
if ( m_xDocumentScripts.is() ) |
| 74 |
{ // document supports embedding scripts/macros |
| 75 |
OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) + ":Basic" ); |
| 76 |
|
| 77 |
if ( m_aLanguage == aBasic && nElement == XML_ELEMENT(OOO, XML_LIBRARIES) ) |
| 78 |
{ |
| 79 |
return new xmloff::BasicLibrariesElement( GetImport(), m_xModel ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
return nullptr; |
| 84 |
} |
| 85 |
|
| 86 |
// XMLScriptContext: context for <office:scripts> element |
| 87 |
|
| 88 |
XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, |
| 89 |
const Reference<XModel>& rDocModel ) |
| 90 |
:SvXMLImportContext( rImport ) |
| 91 |
,m_xModel( rDocModel ) |
| 92 |
{ |
| 93 |
} |
| 94 |
|
| 95 |
XMLScriptContext::~XMLScriptContext() |
| 96 |
{ |
| 97 |
} |
| 98 |
|
| 99 |
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::createFastChildContext( |
| 100 |
sal_Int32 nElement, |
| 101 |
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
| 102 |
{ |
| 103 |
if ( nElement == XML_ELEMENT(OFFICE, XML_SCRIPT) ) |
| 104 |
{ |
| 105 |
if ( m_xModel.is() ) |
| 106 |
{ |
| 107 |
OUString aLanguage = xAttrList->getValue( XML_ELEMENT(SCRIPT, XML_LANGUAGE) ); |
| 108 |
|
| 109 |
uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs(); |
| 110 |
sal_Int32 nNewLen = aMedDescr.getLength() + 1; |
| 111 |
aMedDescr.realloc( nNewLen ); |
| 112 |
auto pMedDescr = aMedDescr.getArray(); |
| 113 |
pMedDescr[nNewLen-1].Name = "BreakMacroSignature"; |
| 114 |
pMedDescr[nNewLen-1].Value <<= true; |
| 115 |
m_xModel->attachResource( m_xModel->getURL(), aMedDescr ); |
| 116 |
|
| 117 |
return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage ); |
| 118 |
} |
| 119 |
} |
| 120 |
else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) ) |
| 121 |
{ |
| 122 |
Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY ); |
| 123 |
return new XMLEventsImportContext( GetImport(), xSupplier ); |
| 124 |
} |
| 125 |
|
| 126 |
return nullptr; |
| 127 |
} |
| 128 |
|
| 129 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |