bump product version to 7.6.3.2-android
[LibreOffice.git] / xmloff / source / script / xmlscripti.cxx
blob7da3607efa002857d9ff870ed0d194a1cacc3658
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
29 #include <com/sun/star/document/XEventsSupplier.hpp>
30 #include <com/sun/star/document/XEmbeddedScripts.hpp>
32 using namespace com::sun::star;
33 using namespace com::sun::star::uno;
34 using namespace com::sun::star::lang;
35 using namespace com::sun::star::frame;
36 using namespace com::sun::star::document;
37 using namespace com::sun::star::xml::sax;
38 using namespace ::xmloff::token;
40 // XMLScriptChildContext: context for <office:script> element
42 namespace {
44 class XMLScriptChildContext : public SvXMLImportContext
46 private:
47 css::uno::Reference< css::frame::XModel > m_xModel;
48 css::uno::Reference< css::document::XEmbeddedScripts > m_xDocumentScripts;
49 OUString m_aLanguage;
51 public:
52 XMLScriptChildContext( SvXMLImport& rImport,
53 const css::uno::Reference< css::frame::XModel>& rxModel,
54 OUString aLanguage );
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;
62 XMLScriptChildContext::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 ))
71 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptChildContext::createFastChildContext(
72 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
74 if ( m_xDocumentScripts.is() )
75 { // document supports embedding scripts/macros
76 OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) + ":Basic" );
78 if ( m_aLanguage == aBasic && nElement == XML_ELEMENT(OOO, XML_LIBRARIES) )
80 return new xmloff::BasicLibrariesElement( GetImport(), m_xModel );
84 return nullptr;
87 // XMLScriptContext: context for <office:scripts> element
89 XMLScriptContext::XMLScriptContext( SvXMLImport& rImport,
90 const Reference<XModel>& rDocModel )
91 :SvXMLImportContext( rImport )
92 ,m_xModel( rDocModel )
96 XMLScriptContext::~XMLScriptContext()
100 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::createFastChildContext(
101 sal_Int32 nElement,
102 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
104 if ( nElement == XML_ELEMENT(OFFICE, XML_SCRIPT) )
106 if ( m_xModel.is() )
108 OUString aLanguage = xAttrList->getValue( XML_ELEMENT(SCRIPT, XML_LANGUAGE) );
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 );
118 return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
121 else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
123 Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
124 return new XMLEventsImportContext( GetImport(), xSupplier );
127 return nullptr;
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */