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 : #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"
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 : class XMLScriptChildContext : public SvXMLImportContext
42 : {
43 : private:
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;
46 : OUString m_aLanguage;
47 :
48 : public:
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();
53 :
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;
56 :
57 : virtual void EndElement() SAL_OVERRIDE;
58 : };
59 :
60 2 : XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
61 : const Reference< frame::XModel >& rxModel, const OUString& rLanguage )
62 : :SvXMLImportContext( rImport, nPrfx, rLName )
63 : ,m_xModel( rxModel )
64 : ,m_xDocumentScripts( rxModel, UNO_QUERY )
65 2 : ,m_aLanguage( rLanguage )
66 : {
67 2 : }
68 :
69 4 : XMLScriptChildContext::~XMLScriptChildContext()
70 : {
71 4 : }
72 :
73 2 : SvXMLImportContext* XMLScriptChildContext::CreateChildContext(
74 : sal_uInt16 nPrefix, const OUString& rLocalName,
75 : const Reference< xml::sax::XAttributeList >& xAttrList )
76 : {
77 2 : SvXMLImportContext* pContext = NULL;
78 :
79 2 : if ( m_xDocumentScripts.is() )
80 : { // document supports embedding scripts/macros
81 2 : OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) );
82 2 : aBasic += ":Basic";
83 :
84 2 : if ( m_aLanguage == aBasic && nPrefix == XML_NAMESPACE_OOO && IsXMLToken( rLocalName, XML_LIBRARIES ) )
85 2 : pContext = new XMLBasicImportContext( GetImport(), nPrefix, rLocalName, m_xModel );
86 : }
87 :
88 2 : if ( !pContext )
89 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
90 :
91 2 : return pContext;
92 : }
93 :
94 2 : void XMLScriptChildContext::EndElement()
95 : {
96 2 : }
97 :
98 : // XMLScriptContext: context for <office:scripts> element
99 :
100 644 : XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
101 : const Reference<XModel>& rDocModel )
102 : :SvXMLImportContext( rImport, nPrfx, rLName )
103 644 : ,m_xModel( rDocModel )
104 : {
105 644 : }
106 :
107 1288 : XMLScriptContext::~XMLScriptContext()
108 : {
109 1288 : }
110 :
111 8 : SvXMLImportContext* XMLScriptContext::CreateChildContext(
112 : sal_uInt16 nPrefix, const OUString& rLName,
113 : const Reference<XAttributeList>& xAttrList )
114 : {
115 8 : SvXMLImportContext* pContext = NULL;
116 :
117 8 : if ( nPrefix == XML_NAMESPACE_OFFICE )
118 : {
119 8 : if ( IsXMLToken( rLName, XML_EVENT_LISTENERS ) )
120 : {
121 6 : Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY );
122 6 : pContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName, xSupplier );
123 : }
124 2 : else if ( IsXMLToken( rLName, XML_SCRIPT ) )
125 : {
126 2 : OUString aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT ) );
127 2 : aAttrName += ":language";
128 2 : if ( xAttrList.is() )
129 : {
130 2 : OUString aLanguage = xAttrList->getValueByName( aAttrName );
131 :
132 2 : if ( m_xModel.is() )
133 : {
134 2 : uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs();
135 2 : sal_Int32 nNewLen = aMedDescr.getLength() + 1;
136 2 : aMedDescr.realloc( nNewLen );
137 2 : aMedDescr[nNewLen-1].Name = "BreakMacroSignature";
138 2 : aMedDescr[nNewLen-1].Value <<= true;
139 2 : m_xModel->attachResource( m_xModel->getURL(), aMedDescr );
140 :
141 2 : pContext = new XMLScriptChildContext( GetImport(), nPrefix, rLName, m_xModel, aLanguage );
142 2 : }
143 2 : }
144 : }
145 : }
146 :
147 8 : if ( !pContext )
148 0 : pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLName, xAttrList);
149 :
150 8 : return pContext;
151 : }
152 :
153 644 : void XMLScriptContext::EndElement()
154 : {
155 644 : }
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|