1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlscripti.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <xmloff/xmlscripti.hxx>
35 #include "xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmlimp.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/XMLEventsImportContext.hxx>
40 #include "xmlbasici.hxx"
42 #include <com/sun/star/document/XEventsSupplier.hpp>
43 #include <com/sun/star/document/XEmbeddedScripts.hpp>
45 using ::rtl::OUString
;
46 using namespace com::sun::star
;
47 using namespace com::sun::star::uno
;
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::frame
;
50 using namespace com::sun::star::document
;
51 using namespace com::sun::star::xml::sax
;
52 using namespace ::xmloff::token
;
55 // =============================================================================
56 // XMLScriptChildContext: context for <office:script> element
57 // =============================================================================
59 class XMLScriptChildContext
: public SvXMLImportContext
62 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> m_xModel
;
63 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedScripts
> m_xDocumentScripts
;
64 ::rtl::OUString m_aLanguage
;
67 XMLScriptChildContext( SvXMLImport
& rImport
, USHORT nPrfx
, const ::rtl::OUString
& rLName
,
68 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& rxModel
,
69 const ::rtl::OUString
& rLanguage
);
70 virtual ~XMLScriptChildContext();
72 virtual SvXMLImportContext
* CreateChildContext( USHORT nPrefix
, const ::rtl::OUString
& rLocalName
,
73 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
75 virtual void EndElement();
78 // -----------------------------------------------------------------------------
80 XMLScriptChildContext::XMLScriptChildContext( SvXMLImport
& rImport
, USHORT nPrfx
, const ::rtl::OUString
& rLName
,
81 const Reference
< frame::XModel
>& rxModel
, const ::rtl::OUString
& rLanguage
)
82 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
84 ,m_xDocumentScripts( rxModel
, UNO_QUERY
)
85 ,m_aLanguage( rLanguage
)
89 // -----------------------------------------------------------------------------
91 XMLScriptChildContext::~XMLScriptChildContext()
95 // -----------------------------------------------------------------------------
97 SvXMLImportContext
* XMLScriptChildContext::CreateChildContext(
98 USHORT nPrefix
, const ::rtl::OUString
& rLocalName
,
99 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
101 SvXMLImportContext
* pContext
= NULL
;
103 if ( m_xDocumentScripts
.is() )
104 { // document supports embedding scripts/macros
105 ::rtl::OUString
aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO
) );
106 aBasic
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":Basic" ) );
108 if ( m_aLanguage
== aBasic
&& nPrefix
== XML_NAMESPACE_OOO
&& IsXMLToken( rLocalName
, XML_LIBRARIES
) )
109 pContext
= new XMLBasicImportContext( GetImport(), nPrefix
, rLocalName
, m_xModel
);
113 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
118 // -----------------------------------------------------------------------------
120 void XMLScriptChildContext::EndElement()
124 // =============================================================================
125 // XMLScriptContext: context for <office:scripts> element
126 // =============================================================================
128 XMLScriptContext::XMLScriptContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
129 const Reference
<XModel
>& rDocModel
)
130 :SvXMLImportContext( rImport
, nPrfx
, rLName
)
131 ,m_xModel( rDocModel
)
135 // -----------------------------------------------------------------------------
137 XMLScriptContext::~XMLScriptContext()
141 // -----------------------------------------------------------------------------
143 SvXMLImportContext
* XMLScriptContext::CreateChildContext(
144 sal_uInt16 nPrefix
, const OUString
& rLName
,
145 const Reference
<XAttributeList
>& xAttrList
)
147 SvXMLImportContext
* pContext
= NULL
;
149 if ( nPrefix
== XML_NAMESPACE_OFFICE
)
151 if ( IsXMLToken( rLName
, XML_EVENT_LISTENERS
) )
153 Reference
< XEventsSupplier
> xSupplier( GetImport().GetModel(), UNO_QUERY
);
154 pContext
= new XMLEventsImportContext( GetImport(), nPrefix
, rLName
, xSupplier
);
156 else if ( IsXMLToken( rLName
, XML_SCRIPT
) )
158 ::rtl::OUString
aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT
) );
159 aAttrName
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":language" ) );
160 if ( xAttrList
.is() )
162 ::rtl::OUString aLanguage
= xAttrList
->getValueByName( aAttrName
);
166 uno::Sequence
< beans::PropertyValue
> aMedDescr
= m_xModel
->getArgs();
167 sal_Int32 nNewLen
= aMedDescr
.getLength() + 1;
168 aMedDescr
.realloc( nNewLen
);
169 aMedDescr
[nNewLen
-1].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BreakMacroSignature" ) );
170 aMedDescr
[nNewLen
-1].Value
<<= (sal_Bool
)sal_True
;
171 m_xModel
->attachResource( m_xModel
->getURL(), aMedDescr
);
173 pContext
= new XMLScriptChildContext( GetImport(), nPrefix
, rLName
, m_xModel
, aLanguage
);
180 pContext
= SvXMLImportContext::CreateChildContext( nPrefix
, rLName
, xAttrList
);
185 // -----------------------------------------------------------------------------
187 void XMLScriptContext::EndElement()
191 // -----------------------------------------------------------------------------