LibreOffice Module xmloff (master) 1
xmlscripti.cxx
Go to the documentation of this file.
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>
23#include <xmloff/xmltoken.hxx>
24#include <xmloff/xmlimp.hxx>
27#include "xmlbasicscript.hxx"
28
29#include <com/sun/star/document/XEventsSupplier.hpp>
30#include <com/sun/star/document/XEmbeddedScripts.hpp>
31
32using namespace com::sun::star;
33using namespace com::sun::star::uno;
34using namespace com::sun::star::lang;
35using namespace com::sun::star::frame;
36using namespace com::sun::star::document;
37using namespace com::sun::star::xml::sax;
38using namespace ::xmloff::token;
39
40// XMLScriptChildContext: context for <office:script> element
41
42namespace {
43
44class XMLScriptChildContext : public SvXMLImportContext
45{
46private:
47 css::uno::Reference< css::frame::XModel > m_xModel;
48 css::uno::Reference< css::document::XEmbeddedScripts > m_xDocumentScripts;
49 OUString m_aLanguage;
50
51public:
52 XMLScriptChildContext( SvXMLImport& rImport,
53 const css::uno::Reference< css::frame::XModel>& rxModel,
54 OUString aLanguage );
55
56 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
57 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
58};
59
60}
61
62XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport,
63 const Reference< frame::XModel >& rxModel, OUString aLanguage )
64 :SvXMLImportContext( rImport )
65 ,m_xModel( rxModel )
66 ,m_xDocumentScripts( rxModel, UNO_QUERY )
67 ,m_aLanguage(std::move( aLanguage ))
68{
69}
70
71css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptChildContext::createFastChildContext(
72 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
73{
74 if ( m_xDocumentScripts.is() )
75 { // document supports embedding scripts/macros
76 OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) + ":Basic" );
77
78 if ( m_aLanguage == aBasic && nElement == XML_ELEMENT(OOO, XML_LIBRARIES) )
79 {
80 return new xmloff::BasicLibrariesElement( GetImport(), m_xModel );
81 }
82 }
83
84 return nullptr;
85}
86
87// XMLScriptContext: context for <office:scripts> element
88
90 const Reference<XModel>& rDocModel )
91 :SvXMLImportContext( rImport )
92 ,m_xModel( rDocModel )
93{
94}
95
97{
98}
99
100css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::createFastChildContext(
101 sal_Int32 nElement,
102 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
103{
104 if ( nElement == XML_ELEMENT(OFFICE, XML_SCRIPT) )
105 {
106 if ( m_xModel.is() )
107 {
108 OUString aLanguage = xAttrList->getValue( XML_ELEMENT(SCRIPT, XML_LANGUAGE) );
109
110 uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs();
111 sal_Int32 nNewLen = aMedDescr.getLength() + 1;
112 aMedDescr.realloc( nNewLen );
113 auto pMedDescr = aMedDescr.getArray();
114 pMedDescr[nNewLen-1].Name = "BreakMacroSignature";
115 pMedDescr[nNewLen-1].Value <<= true;
116 m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
117
118 return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
119 }
120 }
121 else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
122 {
123 Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
124 return new XMLEventsImportContext( GetImport(), xSupplier );
125 }
126
127 return nullptr;
128}
129
130/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:59
Import <script:events> element.
css::uno::Reference< css::frame::XModel > m_xModel
Definition: xmlscripti.hxx:34
XMLScriptContext(SvXMLImport &rImport, const css::uno::Reference< css::frame::XModel > &rDocModel)
Definition: xmlscripti.cxx:89
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: xmlscripti.cxx:100
virtual ~XMLScriptContext() override
Definition: xmlscripti.cxx:96
Reference< frame::XModel > m_xModel
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
constexpr sal_uInt16 XML_NAMESPACE_OOO