nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / script / xmlscripti.cxx
blob16bcfaee7281e651f3288b9b464c70e35d8fb60b
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 <xmloff/xmlscripti.hxx>
21 #include <xmloff/xmlnamespace.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/XMLEventsImportContext.hxx>
26 #include "xmlbasicscript.hxx"
28 #include <com/sun/star/document/XEventsSupplier.hpp>
29 #include <com/sun/star/document/XEmbeddedScripts.hpp>
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;
39 // XMLScriptChildContext: context for <office:script> element
41 namespace {
43 class XMLScriptChildContext : public SvXMLImportContext
45 private:
46 css::uno::Reference< css::frame::XModel > m_xModel;
47 css::uno::Reference< css::document::XEmbeddedScripts > m_xDocumentScripts;
48 OUString m_aLanguage;
50 public:
51 XMLScriptChildContext( SvXMLImport& rImport,
52 const css::uno::Reference< css::frame::XModel>& rxModel,
53 const OUString& rLanguage );
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;
61 XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport,
62 const Reference< frame::XModel >& rxModel, const OUString& rLanguage )
63 :SvXMLImportContext( rImport )
64 ,m_xModel( rxModel )
65 ,m_xDocumentScripts( rxModel, UNO_QUERY )
66 ,m_aLanguage( rLanguage )
70 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptChildContext::createFastChildContext(
71 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
73 if ( m_xDocumentScripts.is() )
74 { // document supports embedding scripts/macros
75 OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) + ":Basic" );
77 if ( m_aLanguage == aBasic && nElement == XML_ELEMENT(OOO, XML_LIBRARIES) )
79 return new xmloff::BasicLibrariesElement( GetImport(), m_xModel );
83 return nullptr;
86 // XMLScriptContext: context for <office:scripts> element
88 XMLScriptContext::XMLScriptContext( SvXMLImport& rImport,
89 const Reference<XModel>& rDocModel )
90 :SvXMLImportContext( rImport )
91 ,m_xModel( rDocModel )
95 XMLScriptContext::~XMLScriptContext()
99 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::createFastChildContext(
100 sal_Int32 nElement,
101 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
103 if ( nElement == XML_ELEMENT(OFFICE, XML_SCRIPT) )
105 if ( m_xModel.is() )
107 OUString aLanguage = xAttrList->getValue( XML_ELEMENT(SCRIPT, XML_LANGUAGE) );
109 uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs();
110 sal_Int32 nNewLen = aMedDescr.getLength() + 1;
111 aMedDescr.realloc( nNewLen );
112 aMedDescr[nNewLen-1].Name = "BreakMacroSignature";
113 aMedDescr[nNewLen-1].Value <<= true;
114 m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
116 return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
119 else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
121 Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
122 return new XMLEventsImportContext( GetImport(), xSupplier );
125 return nullptr;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */