tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / xmloff / source / script / xmlscripti.cxx
blobbb0e950b0659e93ccdffd9dfaaea112e65016996
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::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 OUString aLanguage );
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, OUString aLanguage )
63 :SvXMLImportContext( rImport )
64 ,m_xModel( rxModel )
65 ,m_xDocumentScripts( rxModel, UNO_QUERY )
66 ,m_aLanguage(std::move( aLanguage ))
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 auto pMedDescr = aMedDescr.getArray();
113 pMedDescr[nNewLen-1].Name = "BreakMacroSignature";
114 pMedDescr[nNewLen-1].Value <<= true;
115 m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
117 return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
120 else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
122 Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
123 return new XMLEventsImportContext( GetImport(), xSupplier );
126 return nullptr;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */