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 <xmloff/xmlscripti.hxx>
21 #include <xmloff/xmlnamespace.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/namespacemap.hxx>
26 #include "xmlbasicscript.hxx"
27 
28 #include <com/sun/star/document/XEventsSupplier.hpp>
29 #include <com/sun/star/document/XEmbeddedScripts.hpp>
30 
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;
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  const OUString& rLanguage );
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, const OUString& rLanguage )
63  :SvXMLImportContext( rImport )
64  ,m_xModel( rxModel )
65  ,m_xDocumentScripts( rxModel, UNO_QUERY )
66  ,m_aLanguage( rLanguage )
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 
89  const Reference<XModel>& rDocModel )
90  :SvXMLImportContext( rImport )
91  ,m_xModel( rDocModel )
92 {
93 }
94 
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  aMedDescr[nNewLen-1].Name = "BreakMacroSignature";
113  aMedDescr[nNewLen-1].Value <<= true;
114  m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
115 
116  return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage );
117  }
118  }
119  else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
120  {
121  Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
122  return new XMLEventsImportContext( GetImport(), xSupplier );
123  }
124 
125  return nullptr;
126 }
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~XMLScriptContext() override
Definition: xmlscripti.cxx:95
Reference< frame::XModel > m_xModel
XMLScriptContext(SvXMLImport &rImport, const css::uno::Reference< css::frame::XModel > &rDocModel)
Definition: xmlscripti.cxx:88
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
constexpr sal_uInt16 XML_NAMESPACE_OOO
css::uno::Reference< css::frame::XModel > m_xModel
Definition: xmlscripti.hxx:34
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
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:99