1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xmlnmspe.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include <xmloff/XMLEventsImportContext.hxx>
26 #include "xmlbasici.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 class XMLScriptChildContext
: public SvXMLImportContext
44 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> m_xModel
;
45 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedScripts
> m_xDocumentScripts
;
49 XMLScriptChildContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
50 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& rxModel
,
51 const OUString
& rLanguage
);
52 virtual ~XMLScriptChildContext();
54 virtual SvXMLImportContext
* CreateChildContext( sal_uInt16 nPrefix
, const OUString
& rLocalName
,
55 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
) SAL_OVERRIDE
;
57 virtual void EndElement() SAL_OVERRIDE
;
60 XMLScriptChildContext::XMLScriptChildContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
61 const Reference
< frame::XModel
>& rxModel
, const OUString
& rLanguage
)
62 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
64 ,m_xDocumentScripts( rxModel
, UNO_QUERY
)
65 ,m_aLanguage( rLanguage
)
69 XMLScriptChildContext::~XMLScriptChildContext()
73 SvXMLImportContext
* XMLScriptChildContext::CreateChildContext(
74 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
75 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
77 SvXMLImportContext
* pContext
= NULL
;
79 if ( m_xDocumentScripts
.is() )
80 { // document supports embedding scripts/macros
81 OUString
aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO
) );
84 if ( m_aLanguage
== aBasic
&& nPrefix
== XML_NAMESPACE_OOO
&& IsXMLToken( rLocalName
, XML_LIBRARIES
) )
85 pContext
= new XMLBasicImportContext( GetImport(), nPrefix
, rLocalName
, m_xModel
);
89 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
94 void XMLScriptChildContext::EndElement()
98 // XMLScriptContext: context for <office:scripts> element
100 XMLScriptContext::XMLScriptContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
101 const Reference
<XModel
>& rDocModel
)
102 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
103 ,m_xModel( rDocModel
)
107 XMLScriptContext::~XMLScriptContext()
111 SvXMLImportContext
* XMLScriptContext::CreateChildContext(
112 sal_uInt16 nPrefix
, const OUString
& rLName
,
113 const Reference
<XAttributeList
>& xAttrList
)
115 SvXMLImportContext
* pContext
= NULL
;
117 if ( nPrefix
== XML_NAMESPACE_OFFICE
)
119 if ( IsXMLToken( rLName
, XML_EVENT_LISTENERS
) )
121 Reference
< XEventsSupplier
> xSupplier( GetImport().GetModel(), UNO_QUERY
);
122 pContext
= new XMLEventsImportContext( GetImport(), nPrefix
, rLName
, xSupplier
);
124 else if ( IsXMLToken( rLName
, XML_SCRIPT
) )
126 OUString
aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT
) );
127 aAttrName
+= ":language";
128 if ( xAttrList
.is() )
130 OUString aLanguage
= xAttrList
->getValueByName( aAttrName
);
134 uno::Sequence
< beans::PropertyValue
> aMedDescr
= m_xModel
->getArgs();
135 sal_Int32 nNewLen
= aMedDescr
.getLength() + 1;
136 aMedDescr
.realloc( nNewLen
);
137 aMedDescr
[nNewLen
-1].Name
= "BreakMacroSignature";
138 aMedDescr
[nNewLen
-1].Value
<<= true;
139 m_xModel
->attachResource( m_xModel
->getURL(), aMedDescr
);
141 pContext
= new XMLScriptChildContext( GetImport(), nPrefix
, rLName
, m_xModel
, aLanguage
);
148 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLName
, xAttrList
);
153 void XMLScriptContext::EndElement()
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */