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 .
21 #include <xmloff/xmlscripti.hxx>
22 #include "xmloff/xmlnmspe.hxx"
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include <xmloff/XMLEventsImportContext.hxx>
27 #include "xmlbasici.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
;
41 // =============================================================================
42 // XMLScriptChildContext: context for <office:script> element
43 // =============================================================================
45 class XMLScriptChildContext
: public SvXMLImportContext
48 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> m_xModel
;
49 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedScripts
> m_xDocumentScripts
;
53 XMLScriptChildContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
54 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& rxModel
,
55 const OUString
& rLanguage
);
56 virtual ~XMLScriptChildContext();
58 virtual SvXMLImportContext
* CreateChildContext( sal_uInt16 nPrefix
, const OUString
& rLocalName
,
59 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
61 virtual void EndElement();
64 // -----------------------------------------------------------------------------
66 XMLScriptChildContext::XMLScriptChildContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
67 const Reference
< frame::XModel
>& rxModel
, const OUString
& rLanguage
)
68 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
70 ,m_xDocumentScripts( rxModel
, UNO_QUERY
)
71 ,m_aLanguage( rLanguage
)
75 // -----------------------------------------------------------------------------
77 XMLScriptChildContext::~XMLScriptChildContext()
81 // -----------------------------------------------------------------------------
83 SvXMLImportContext
* XMLScriptChildContext::CreateChildContext(
84 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
85 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
87 SvXMLImportContext
* pContext
= NULL
;
89 if ( m_xDocumentScripts
.is() )
90 { // document supports embedding scripts/macros
91 OUString
aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO
) );
94 if ( m_aLanguage
== aBasic
&& nPrefix
== XML_NAMESPACE_OOO
&& IsXMLToken( rLocalName
, XML_LIBRARIES
) )
95 pContext
= new XMLBasicImportContext( GetImport(), nPrefix
, rLocalName
, m_xModel
);
99 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
104 // -----------------------------------------------------------------------------
106 void XMLScriptChildContext::EndElement()
110 // =============================================================================
111 // XMLScriptContext: context for <office:scripts> element
112 // =============================================================================
114 XMLScriptContext::XMLScriptContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
115 const Reference
<XModel
>& rDocModel
)
116 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
117 ,m_xModel( rDocModel
)
121 // -----------------------------------------------------------------------------
123 XMLScriptContext::~XMLScriptContext()
127 // -----------------------------------------------------------------------------
129 SvXMLImportContext
* XMLScriptContext::CreateChildContext(
130 sal_uInt16 nPrefix
, const OUString
& rLName
,
131 const Reference
<XAttributeList
>& xAttrList
)
133 SvXMLImportContext
* pContext
= NULL
;
135 if ( nPrefix
== XML_NAMESPACE_OFFICE
)
137 if ( IsXMLToken( rLName
, XML_EVENT_LISTENERS
) )
139 Reference
< XEventsSupplier
> xSupplier( GetImport().GetModel(), UNO_QUERY
);
140 pContext
= new XMLEventsImportContext( GetImport(), nPrefix
, rLName
, xSupplier
);
142 else if ( IsXMLToken( rLName
, XML_SCRIPT
) )
144 OUString
aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT
) );
145 aAttrName
+= ":language";
146 if ( xAttrList
.is() )
148 OUString aLanguage
= xAttrList
->getValueByName( aAttrName
);
152 uno::Sequence
< beans::PropertyValue
> aMedDescr
= m_xModel
->getArgs();
153 sal_Int32 nNewLen
= aMedDescr
.getLength() + 1;
154 aMedDescr
.realloc( nNewLen
);
155 aMedDescr
[nNewLen
-1].Name
= "BreakMacroSignature";
156 aMedDescr
[nNewLen
-1].Value
<<= (sal_Bool
)sal_True
;
157 m_xModel
->attachResource( m_xModel
->getURL(), aMedDescr
);
159 pContext
= new XMLScriptChildContext( GetImport(), nPrefix
, rLName
, m_xModel
, aLanguage
);
166 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLName
, xAttrList
);
171 // -----------------------------------------------------------------------------
173 void XMLScriptContext::EndElement()
177 // -----------------------------------------------------------------------------
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */