Line data Source code
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 :
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"
28 :
29 : #include <com/sun/star/document/XEventsSupplier.hpp>
30 : #include <com/sun/star/document/XEmbeddedScripts.hpp>
31 :
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;
39 :
40 :
41 : // =============================================================================
42 : // XMLScriptChildContext: context for <office:script> element
43 : // =============================================================================
44 :
45 : class XMLScriptChildContext : public SvXMLImportContext
46 : {
47 : private:
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;
50 : OUString m_aLanguage;
51 :
52 : public:
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();
57 :
58 : virtual SvXMLImportContext* CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
59 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
60 :
61 : virtual void EndElement();
62 : };
63 :
64 : // -----------------------------------------------------------------------------
65 :
66 0 : XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
67 : const Reference< frame::XModel >& rxModel, const OUString& rLanguage )
68 : :SvXMLImportContext( rImport, nPrfx, rLName )
69 : ,m_xModel( rxModel )
70 : ,m_xDocumentScripts( rxModel, UNO_QUERY )
71 0 : ,m_aLanguage( rLanguage )
72 : {
73 0 : }
74 :
75 : // -----------------------------------------------------------------------------
76 :
77 0 : XMLScriptChildContext::~XMLScriptChildContext()
78 : {
79 0 : }
80 :
81 : // -----------------------------------------------------------------------------
82 :
83 0 : SvXMLImportContext* XMLScriptChildContext::CreateChildContext(
84 : sal_uInt16 nPrefix, const OUString& rLocalName,
85 : const Reference< xml::sax::XAttributeList >& xAttrList )
86 : {
87 0 : SvXMLImportContext* pContext = NULL;
88 :
89 0 : if ( m_xDocumentScripts.is() )
90 : { // document supports embedding scripts/macros
91 0 : OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
92 0 : aBasic += ":Basic";
93 :
94 0 : if ( m_aLanguage == aBasic && nPrefix == XML_NAMESPACE_OOO && IsXMLToken( rLocalName, XML_LIBRARIES ) )
95 0 : pContext = new XMLBasicImportContext( GetImport(), nPrefix, rLocalName, m_xModel );
96 : }
97 :
98 0 : if ( !pContext )
99 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
100 :
101 0 : return pContext;
102 : }
103 :
104 : // -----------------------------------------------------------------------------
105 :
106 0 : void XMLScriptChildContext::EndElement()
107 : {
108 0 : }
109 :
110 : // =============================================================================
111 : // XMLScriptContext: context for <office:scripts> element
112 : // =============================================================================
113 :
114 141 : XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
115 : const Reference<XModel>& rDocModel )
116 : :SvXMLImportContext( rImport, nPrfx, rLName )
117 141 : ,m_xModel( rDocModel )
118 : {
119 141 : }
120 :
121 : // -----------------------------------------------------------------------------
122 :
123 282 : XMLScriptContext::~XMLScriptContext()
124 : {
125 282 : }
126 :
127 : // -----------------------------------------------------------------------------
128 :
129 0 : SvXMLImportContext* XMLScriptContext::CreateChildContext(
130 : sal_uInt16 nPrefix, const OUString& rLName,
131 : const Reference<XAttributeList>& xAttrList )
132 : {
133 0 : SvXMLImportContext* pContext = NULL;
134 :
135 0 : if ( nPrefix == XML_NAMESPACE_OFFICE )
136 : {
137 0 : if ( IsXMLToken( rLName, XML_EVENT_LISTENERS ) )
138 : {
139 0 : Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
140 0 : pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName, xSupplier );
141 : }
142 0 : else if ( IsXMLToken( rLName, XML_SCRIPT ) )
143 : {
144 0 : OUString aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT ) );
145 0 : aAttrName += ":language";
146 0 : if ( xAttrList.is() )
147 : {
148 0 : OUString aLanguage = xAttrList->getValueByName( aAttrName );
149 :
150 0 : if ( m_xModel.is() )
151 : {
152 0 : uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs();
153 0 : sal_Int32 nNewLen = aMedDescr.getLength() + 1;
154 0 : aMedDescr.realloc( nNewLen );
155 0 : aMedDescr[nNewLen-1].Name = "BreakMacroSignature";
156 0 : aMedDescr[nNewLen-1].Value <<= (sal_Bool)sal_True;
157 0 : m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
158 :
159 0 : pContext = new XMLScriptChildContext( GetImport(), nPrefix, rLName, m_xModel, aLanguage );
160 0 : }
161 0 : }
162 : }
163 : }
164 :
165 0 : if ( !pContext )
166 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLName, xAttrList);
167 :
168 0 : return pContext;
169 : }
170 :
171 : // -----------------------------------------------------------------------------
172 :
173 141 : void XMLScriptContext::EndElement()
174 : {
175 141 : }
176 :
177 : // -----------------------------------------------------------------------------
178 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|