merge the formfield patch from ooo-build
[ooovba.git] / xmlscript / source / xmlflat_imexp / xmlbas_import.hxx
blob543b4f1a1e6b8d85920c93a8dbb6762d7d2a682c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlbas_import.hxx,v $
10 * $Revision: 1.4 $
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 #ifndef XMLSCRIPT_XMLBAS_IMPORT_HXX
32 #define XMLSCRIPT_XMLBAS_IMPORT_HXX
34 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
35 #include <com/sun/star/document/XImporter.hpp>
36 #include <com/sun/star/frame/XModel.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
39 #include <com/sun/star/script/XLibraryContainer2.hpp>
40 #endif
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #include <com/sun/star/xml/input/XRoot.hpp>
43 #include <cppuhelper/implbase1.hxx>
44 #include <cppuhelper/implbase3.hxx>
45 #include <osl/mutex.hxx>
46 #include <rtl/ustrbuf.hxx>
49 //.........................................................................
50 namespace xmlscript
52 //.........................................................................
54 // =============================================================================
55 // class BasicElementBase
56 // =============================================================================
58 class BasicImport;
60 typedef ::cppu::WeakImplHelper1<
61 ::com::sun::star::xml::input::XElement > BasicElementBase_BASE;
63 class BasicElementBase : public BasicElementBase_BASE
65 protected:
66 BasicImport* m_pImport;
67 BasicElementBase* m_pParent;
68 ::rtl::OUString m_aLocalName;
69 ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes > m_xAttributes;
71 bool getBoolAttr( sal_Bool* pRet, const ::rtl::OUString& rAttrName,
72 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
73 sal_Int32 nUid );
75 public:
76 BasicElementBase( const ::rtl::OUString& rLocalName,
77 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
78 BasicElementBase* pParent, BasicImport* pImport );
79 virtual ~BasicElementBase();
81 // XElement
82 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XElement > SAL_CALL getParent()
83 throw (::com::sun::star::uno::RuntimeException);
84 virtual ::rtl::OUString SAL_CALL getLocalName()
85 throw (::com::sun::star::uno::RuntimeException);
86 virtual sal_Int32 SAL_CALL getUid()
87 throw (::com::sun::star::uno::RuntimeException);
88 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes > SAL_CALL getAttributes()
89 throw (::com::sun::star::uno::RuntimeException);
90 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XElement > SAL_CALL startChildElement(
91 sal_Int32 nUid, const ::rtl::OUString& rLocalName,
92 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes )
93 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
94 virtual void SAL_CALL characters( const ::rtl::OUString& rChars )
95 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
96 virtual void SAL_CALL ignorableWhitespace(
97 const ::rtl::OUString& rWhitespaces )
98 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
99 virtual void SAL_CALL processingInstruction(
100 const ::rtl::OUString& rTarget, const ::rtl::OUString& rData )
101 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
102 virtual void SAL_CALL endElement()
103 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
107 // =============================================================================
108 // class BasicLibrariesElement
109 // =============================================================================
111 class BasicLibrariesElement : public BasicElementBase
113 private:
114 ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer2 > m_xLibContainer;
116 public:
117 BasicLibrariesElement( const ::rtl::OUString& rLocalName,
118 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
119 BasicElementBase* pParent, BasicImport* pImport,
120 const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer2 >& rxLibContainer );
122 // XElement
123 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XElement > SAL_CALL startChildElement(
124 sal_Int32 nUid, const ::rtl::OUString& rLocalName,
125 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes )
126 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
127 virtual void SAL_CALL endElement()
128 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
132 // =============================================================================
133 // class BasicEmbeddedLibraryElement
134 // =============================================================================
136 class BasicEmbeddedLibraryElement : public BasicElementBase
138 private:
139 ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer2 > m_xLibContainer;
140 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xLib;
141 ::rtl::OUString m_aLibName;
142 bool m_bReadOnly;
144 public:
145 BasicEmbeddedLibraryElement( const ::rtl::OUString& rLocalName,
146 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
147 BasicElementBase* pParent, BasicImport* pImport,
148 const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer2 >& rxLibContainer,
149 const ::rtl::OUString& rLibName, bool bReadOnly );
151 // XElement
152 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XElement > SAL_CALL startChildElement(
153 sal_Int32 nUid, const ::rtl::OUString& rLocalName,
154 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes )
155 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
156 virtual void SAL_CALL endElement()
157 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
161 // =============================================================================
162 // class BasicModuleElement
163 // =============================================================================
165 class BasicModuleElement : public BasicElementBase
167 private:
168 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xLib;
169 ::rtl::OUString m_aName;
171 public:
172 BasicModuleElement( const ::rtl::OUString& rLocalName,
173 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
174 BasicElementBase* pParent, BasicImport* pImport,
175 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxLib,
176 const ::rtl::OUString& rName );
178 // XElement
179 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XElement > SAL_CALL startChildElement(
180 sal_Int32 nUid, const ::rtl::OUString& rLocalName,
181 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes )
182 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
183 virtual void SAL_CALL endElement()
184 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
188 // =============================================================================
189 // class BasicSourceCodeElement
190 // =============================================================================
192 class BasicSourceCodeElement : public BasicElementBase
194 private:
195 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xLib;
196 ::rtl::OUString m_aName;
197 ::rtl::OUStringBuffer m_aBuffer;
199 public:
200 BasicSourceCodeElement( const ::rtl::OUString& rLocalName,
201 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
202 BasicElementBase* pParent, BasicImport* pImport,
203 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxLib,
204 const ::rtl::OUString& rName );
206 // XElement
207 virtual void SAL_CALL characters( const ::rtl::OUString& rChars )
208 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
209 virtual void SAL_CALL endElement()
210 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
214 // =============================================================================
215 // class BasicImport
216 // =============================================================================
218 typedef ::cppu::WeakImplHelper1<
219 ::com::sun::star::xml::input::XRoot > BasicImport_BASE;
221 class BasicImport : public BasicImport_BASE
223 friend class BasicElementBase;
224 friend class BasicLibrariesElement;
225 friend class BasicEmbeddedLibraryElement;
226 friend class BasicModuleElement;
228 private:
229 sal_Int32 XMLNS_UID;
230 sal_Int32 XMLNS_XLINK_UID;
231 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
232 sal_Bool m_bOasis;
234 public:
235 BasicImport( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel, sal_Bool bOasis );
236 virtual ~BasicImport();
238 // XRoot
239 virtual void SAL_CALL startDocument(
240 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XNamespaceMapping >& xNamespaceMapping )
241 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
242 virtual void SAL_CALL endDocument()
243 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
244 virtual void SAL_CALL processingInstruction(
245 const ::rtl::OUString& rTarget, const ::rtl::OUString& rData )
246 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
247 virtual void SAL_CALL setDocumentLocator(
248 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator )
249 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
250 virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XElement > SAL_CALL startRootElement(
251 sal_Int32 nUid, const ::rtl::OUString& rLocalName,
252 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes )
253 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
257 // =============================================================================
258 // class XMLBasicImporterBase
259 // =============================================================================
261 typedef ::cppu::WeakImplHelper3<
262 ::com::sun::star::lang::XServiceInfo,
263 ::com::sun::star::document::XImporter,
264 ::com::sun::star::xml::sax::XDocumentHandler > XMLBasicImporterBase_BASE;
266 class XMLBasicImporterBase : public XMLBasicImporterBase_BASE
268 private:
269 ::osl::Mutex m_aMutex;
270 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
271 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xHandler;
272 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel;
273 sal_Bool m_bOasis;
275 public:
276 XMLBasicImporterBase(
277 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, sal_Bool bOasis );
278 virtual ~XMLBasicImporterBase();
280 // XServiceInfo
281 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
282 throw (::com::sun::star::uno::RuntimeException);
284 // XImporter
285 virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxDoc )
286 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
288 // XDocumentHandler
289 virtual void SAL_CALL startDocument()
290 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
291 virtual void SAL_CALL endDocument()
292 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
293 virtual void SAL_CALL startElement( const ::rtl::OUString& aName,
294 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs )
295 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
296 virtual void SAL_CALL endElement( const ::rtl::OUString& aName )
297 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
298 virtual void SAL_CALL characters( const ::rtl::OUString& aChars )
299 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
300 virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces )
301 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
302 virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData )
303 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
304 virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator )
305 throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
309 // =============================================================================
310 // class XMLBasicImporter
311 // =============================================================================
313 class XMLBasicImporter : public XMLBasicImporterBase
315 public:
316 XMLBasicImporter(
317 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
318 virtual ~XMLBasicImporter();
320 // XServiceInfo
321 virtual ::rtl::OUString SAL_CALL getImplementationName( )
322 throw (::com::sun::star::uno::RuntimeException);
323 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
324 throw (::com::sun::star::uno::RuntimeException);
328 // =============================================================================
329 // class XMLOasisBasicImporter
330 // =============================================================================
332 class XMLOasisBasicImporter : public XMLBasicImporterBase
334 public:
335 XMLOasisBasicImporter(
336 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
337 virtual ~XMLOasisBasicImporter();
339 // XServiceInfo
340 virtual ::rtl::OUString SAL_CALL getImplementationName( )
341 throw (::com::sun::star::uno::RuntimeException);
342 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
343 throw (::com::sun::star::uno::RuntimeException);
346 //.........................................................................
347 } // namespace xmlscript
348 //.........................................................................
350 #endif // XMLSCRIPT_XMLBAS_IMPORT_HXX