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 #ifndef INCLUDED_XMLSCRIPT_SOURCE_XMLFLAT_IMEXP_XMLBAS_IMPORT_HXX
21 #define INCLUDED_XMLSCRIPT_SOURCE_XMLFLAT_IMEXP_XMLBAS_IMPORT_HXX
23 #include <com/sun/star/document/XXMLOasisBasicImporter.hpp>
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/script/XLibraryContainer2.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/xml/input/XRoot.hpp>
29 #include <cppuhelper/implbase.hxx>
30 #include <osl/mutex.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <rtl/ref.hxx>
37 // class BasicElementBase
41 typedef ::cppu::WeakImplHelper
<
42 css::xml::input::XElement
> BasicElementBase_BASE
;
44 class BasicElementBase
: public BasicElementBase_BASE
47 rtl::Reference
<BasicImport
> m_xImport
;
49 rtl::Reference
<BasicElementBase
> m_xParent
;
50 OUString
const m_aLocalName
;
51 css::uno::Reference
< css::xml::input::XAttributes
> m_xAttributes
;
54 static bool getBoolAttr( bool* pRet
, const OUString
& rAttrName
,
55 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
,
59 BasicElementBase( const OUString
& rLocalName
,
60 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
,
61 BasicElementBase
* pParent
, BasicImport
* pImport
);
62 virtual ~BasicElementBase() override
;
65 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
getParent() override
;
66 virtual OUString SAL_CALL
getLocalName() override
;
67 virtual sal_Int32 SAL_CALL
getUid() override
;
68 virtual css::uno::Reference
< css::xml::input::XAttributes
> SAL_CALL
getAttributes() override
;
69 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
70 sal_Int32 nUid
, const OUString
& rLocalName
,
71 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
) override
;
72 virtual void SAL_CALL
characters( const OUString
& rChars
) override
;
73 virtual void SAL_CALL
ignorableWhitespace(
74 const OUString
& rWhitespaces
) override
;
75 virtual void SAL_CALL
processingInstruction(
76 const OUString
& rTarget
, const OUString
& rData
) override
;
77 virtual void SAL_CALL
endElement() override
;
80 // class BasicLibrariesElement
82 class BasicLibrariesElement
: public BasicElementBase
85 css::uno::Reference
< css::script::XLibraryContainer2
> m_xLibContainer
;
88 BasicLibrariesElement( const OUString
& rLocalName
,
89 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
,
91 const css::uno::Reference
< css::script::XLibraryContainer2
>& rxLibContainer
);
94 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
95 sal_Int32 nUid
, const OUString
& rLocalName
,
96 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
) override
;
97 virtual void SAL_CALL
endElement() override
;
100 // class BasicEmbeddedLibraryElement
102 class BasicEmbeddedLibraryElement
: public BasicElementBase
105 css::uno::Reference
< css::script::XLibraryContainer2
> m_xLibContainer
;
106 css::uno::Reference
< css::container::XNameContainer
> m_xLib
;
107 OUString
const m_aLibName
;
108 bool const m_bReadOnly
;
111 BasicEmbeddedLibraryElement( const OUString
& rLocalName
,
112 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
,
113 BasicElementBase
* pParent
, BasicImport
* pImport
,
114 const css::uno::Reference
< css::script::XLibraryContainer2
>& rxLibContainer
,
115 const OUString
& rLibName
, bool bReadOnly
);
118 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
119 sal_Int32 nUid
, const OUString
& rLocalName
,
120 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
) override
;
121 virtual void SAL_CALL
endElement() override
;
124 // class BasicModuleElement
126 class BasicModuleElement
: public BasicElementBase
129 css::uno::Reference
< css::container::XNameContainer
> m_xLib
;
130 OUString
const m_aName
;
133 BasicModuleElement( const OUString
& rLocalName
,
134 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
,
135 BasicElementBase
* pParent
, BasicImport
* pImport
,
136 const css::uno::Reference
< css::container::XNameContainer
>& rxLib
,
137 const OUString
& rName
);
140 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startChildElement(
141 sal_Int32 nUid
, const OUString
& rLocalName
,
142 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
) override
;
143 virtual void SAL_CALL
endElement() override
;
146 // class BasicSourceCodeElement
148 class BasicSourceCodeElement
: public BasicElementBase
151 css::uno::Reference
< css::container::XNameContainer
> m_xLib
;
152 OUString
const m_aName
;
153 OUStringBuffer m_aBuffer
;
156 BasicSourceCodeElement( const OUString
& rLocalName
,
157 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
,
158 BasicElementBase
* pParent
, BasicImport
* pImport
,
159 const css::uno::Reference
< css::container::XNameContainer
>& rxLib
,
160 const OUString
& rName
);
163 virtual void SAL_CALL
characters( const OUString
& rChars
) override
;
164 virtual void SAL_CALL
endElement() override
;
169 typedef ::cppu::WeakImplHelper
<
170 css::xml::input::XRoot
> BasicImport_BASE
;
172 class BasicImport
: public BasicImport_BASE
174 friend class BasicElementBase
;
175 friend class BasicLibrariesElement
;
176 friend class BasicEmbeddedLibraryElement
;
177 friend class BasicModuleElement
;
181 sal_Int32 XMLNS_XLINK_UID
;
182 css::uno::Reference
< css::frame::XModel
> m_xModel
;
186 BasicImport( const css::uno::Reference
< css::frame::XModel
>& rxModel
, bool bOasis
);
187 virtual ~BasicImport() override
;
190 virtual void SAL_CALL
startDocument(
191 const css::uno::Reference
< css::xml::input::XNamespaceMapping
>& xNamespaceMapping
) override
;
192 virtual void SAL_CALL
endDocument() override
;
193 virtual void SAL_CALL
processingInstruction(
194 const OUString
& rTarget
, const OUString
& rData
) override
;
195 virtual void SAL_CALL
setDocumentLocator(
196 const css::uno::Reference
< css::xml::sax::XLocator
>& xLocator
) override
;
197 virtual css::uno::Reference
< css::xml::input::XElement
> SAL_CALL
startRootElement(
198 sal_Int32 nUid
, const OUString
& rLocalName
,
199 const css::uno::Reference
< css::xml::input::XAttributes
>& xAttributes
) override
;
202 // class XMLBasicImporterBase
204 typedef ::cppu::WeakImplHelper
<
205 css::lang::XServiceInfo
,
206 css::document::XXMLOasisBasicImporter
> XMLBasicImporterBase_BASE
;
208 class XMLBasicImporterBase
: public XMLBasicImporterBase_BASE
211 ::osl::Mutex m_aMutex
;
212 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
213 css::uno::Reference
< css::xml::sax::XDocumentHandler
> m_xHandler
;
214 css::uno::Reference
< css::frame::XModel
> m_xModel
;
218 XMLBasicImporterBase(
219 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
, bool bOasis
);
220 virtual ~XMLBasicImporterBase() override
;
223 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
226 virtual void SAL_CALL
setTargetDocument( const css::uno::Reference
< css::lang::XComponent
>& rxDoc
) override
;
229 virtual void SAL_CALL
startDocument() override
;
230 virtual void SAL_CALL
endDocument() override
;
231 virtual void SAL_CALL
startElement( const OUString
& aName
,
232 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttribs
) override
;
233 virtual void SAL_CALL
endElement( const OUString
& aName
) override
;
234 virtual void SAL_CALL
characters( const OUString
& aChars
) override
;
235 virtual void SAL_CALL
ignorableWhitespace( const OUString
& aWhitespaces
) override
;
236 virtual void SAL_CALL
processingInstruction( const OUString
& aTarget
, const OUString
& aData
) override
;
237 virtual void SAL_CALL
setDocumentLocator( const css::uno::Reference
< css::xml::sax::XLocator
>& xLocator
) override
;
240 // class XMLBasicImporter
242 class XMLBasicImporter
: public XMLBasicImporterBase
245 explicit XMLBasicImporter(
246 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
247 virtual ~XMLBasicImporter() override
;
250 virtual OUString SAL_CALL
getImplementationName( ) override
;
251 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
254 // class XMLOasisBasicImporter
256 class XMLOasisBasicImporter
: public XMLBasicImporterBase
259 explicit XMLOasisBasicImporter(
260 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
261 virtual ~XMLOasisBasicImporter() override
;
264 virtual OUString SAL_CALL
getImplementationName( ) override
;
265 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
268 } // namespace xmlscript
270 #endif // INCLUDED_XMLSCRIPT_SOURCE_XMLFLAT_IMEXP_XMLBAS_IMPORT_HXX
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */