Branch data 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 "xmlbas_import.hxx"
21 : : #include "xmlscript/xmlns.h"
22 : : #include "xmlscript/xml_helper.hxx"
23 : : #include <com/sun/star/beans/XPropertySet.hpp>
24 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
25 : : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
26 : : #include <com/sun/star/document/XEmbeddedScripts.hpp>
27 : : #include <cppuhelper/implementationentry.hxx>
28 : :
29 : : using namespace ::com::sun::star;
30 : : using namespace ::com::sun::star::lang;
31 : : using namespace ::com::sun::star::uno;
32 : :
33 : :
34 : : //.........................................................................
35 : : namespace xmlscript
36 : : {
37 : : //.........................................................................
38 : :
39 : : // =============================================================================
40 : : // BasicElementBase
41 : : // =============================================================================
42 : :
43 : 0 : BasicElementBase::BasicElementBase( const ::rtl::OUString& rLocalName,
44 : : const Reference< xml::input::XAttributes >& xAttributes,
45 : : BasicElementBase* pParent, BasicImport* pImport )
46 : : :m_pImport( pImport )
47 : : ,m_pParent( pParent )
48 : : ,m_aLocalName( rLocalName )
49 : 0 : ,m_xAttributes( xAttributes )
50 : : {
51 [ # # ]: 0 : if ( m_pImport )
52 : 0 : m_pImport->acquire();
53 [ # # ]: 0 : if ( m_pParent )
54 : 0 : m_pParent->acquire();
55 : 0 : }
56 : :
57 : : // -----------------------------------------------------------------------------
58 : :
59 : 0 : BasicElementBase::~BasicElementBase()
60 : : {
61 [ # # ]: 0 : if ( m_pImport )
62 : 0 : m_pImport->release();
63 [ # # ]: 0 : if ( m_pParent )
64 : 0 : m_pParent->release();
65 [ # # ]: 0 : }
66 : :
67 : : // -----------------------------------------------------------------------------
68 : :
69 : 0 : bool BasicElementBase::getBoolAttr( sal_Bool* pRet, const ::rtl::OUString& rAttrName,
70 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
71 : : sal_Int32 nUid )
72 : : {
73 [ # # ]: 0 : if ( xAttributes.is() )
74 : : {
75 [ # # ][ # # ]: 0 : ::rtl::OUString aValue( xAttributes->getValueByUidName( nUid, rAttrName ) );
76 [ # # ]: 0 : if ( !aValue.isEmpty() )
77 : : {
78 [ # # ]: 0 : if ( aValue == "true" )
79 : : {
80 : 0 : *pRet = sal_True;
81 : 0 : return true;
82 : : }
83 [ # # ]: 0 : else if ( aValue == "false" )
84 : : {
85 : 0 : *pRet = sal_False;
86 : 0 : return true;
87 : : }
88 : : else
89 : : {
90 : : throw xml::sax::SAXException(
91 : : rAttrName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": no boolean value (true|false)!" ) ),
92 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
93 : : }
94 [ # # ]: 0 : }
95 : : }
96 : 0 : return false;
97 : : }
98 : :
99 : : // -----------------------------------------------------------------------------
100 : : // XElement
101 : : // -----------------------------------------------------------------------------
102 : :
103 : 0 : Reference< xml::input::XElement > BasicElementBase::getParent()
104 : : throw (RuntimeException)
105 : : {
106 [ # # ]: 0 : return static_cast< xml::input::XElement* >( m_pParent );
107 : : }
108 : :
109 : : // -----------------------------------------------------------------------------
110 : :
111 : 0 : ::rtl::OUString BasicElementBase::getLocalName()
112 : : throw (RuntimeException)
113 : : {
114 : 0 : return m_aLocalName;
115 : : }
116 : :
117 : : // -----------------------------------------------------------------------------
118 : :
119 : 0 : sal_Int32 BasicElementBase::getUid()
120 : : throw (RuntimeException)
121 : : {
122 : 0 : sal_Int32 nId = -1;
123 [ # # ]: 0 : if ( m_pImport )
124 : 0 : nId = m_pImport->XMLNS_UID;
125 : 0 : return nId;
126 : : }
127 : :
128 : : // -----------------------------------------------------------------------------
129 : :
130 : 0 : Reference< xml::input::XAttributes > BasicElementBase::getAttributes()
131 : : throw (RuntimeException)
132 : : {
133 : 0 : return m_xAttributes;
134 : : }
135 : :
136 : : // -----------------------------------------------------------------------------
137 : :
138 : 0 : Reference< xml::input::XElement > BasicElementBase::startChildElement(
139 : : sal_Int32 /*nUid*/, const ::rtl::OUString& /*rLocalName*/,
140 : : const Reference< xml::input::XAttributes >& /*xAttributes*/ )
141 : : throw (xml::sax::SAXException, RuntimeException)
142 : : {
143 : : throw xml::sax::SAXException(
144 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unexpected element!" ) ),
145 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
146 : : }
147 : :
148 : : // -----------------------------------------------------------------------------
149 : :
150 : 0 : void BasicElementBase::characters( const ::rtl::OUString& /*rChars*/ )
151 : : throw (xml::sax::SAXException, RuntimeException)
152 : : {
153 : : // not used, all characters ignored
154 : 0 : }
155 : :
156 : : // -----------------------------------------------------------------------------
157 : :
158 : 0 : void BasicElementBase::ignorableWhitespace( const ::rtl::OUString& /*rWhitespaces*/ )
159 : : throw (xml::sax::SAXException, RuntimeException)
160 : : {
161 : 0 : }
162 : :
163 : : // -----------------------------------------------------------------------------
164 : :
165 : 0 : void BasicElementBase::processingInstruction( const ::rtl::OUString& /*rTarget*/, const ::rtl::OUString& /*rData*/ )
166 : : throw (xml::sax::SAXException, RuntimeException)
167 : : {
168 : 0 : }
169 : :
170 : : // -----------------------------------------------------------------------------
171 : :
172 : 0 : void BasicElementBase::endElement()
173 : : throw (xml::sax::SAXException, RuntimeException)
174 : : {
175 : 0 : }
176 : :
177 : :
178 : : // =============================================================================
179 : : // BasicLibrariesElement
180 : : // =============================================================================
181 : :
182 : 0 : BasicLibrariesElement::BasicLibrariesElement( const ::rtl::OUString& rLocalName,
183 : : const Reference< xml::input::XAttributes >& xAttributes,
184 : : BasicElementBase* pParent, BasicImport* pImport,
185 : : const Reference< script::XLibraryContainer2 >& rxLibContainer )
186 : : :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
187 : 0 : ,m_xLibContainer( rxLibContainer )
188 : : {
189 : 0 : }
190 : :
191 : : // -----------------------------------------------------------------------------
192 : : // XElement
193 : : // -----------------------------------------------------------------------------
194 : :
195 : 0 : Reference< xml::input::XElement > BasicLibrariesElement::startChildElement(
196 : : sal_Int32 nUid, const ::rtl::OUString& rLocalName,
197 : : const Reference< xml::input::XAttributes >& xAttributes )
198 : : throw (xml::sax::SAXException, RuntimeException)
199 : : {
200 : 0 : Reference< xml::input::XElement > xElement;
201 : :
202 [ # # ]: 0 : if ( nUid != m_pImport->XMLNS_UID )
203 : : {
204 : : throw xml::sax::SAXException(
205 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
206 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
207 : : }
208 [ # # ]: 0 : else if ( rLocalName == "library-linked" )
209 : : {
210 [ # # ]: 0 : if ( xAttributes.is() )
211 : : {
212 [ # # ]: 0 : ::rtl::OUString aName = xAttributes->getValueByUidName(
213 : : m_pImport->XMLNS_UID,
214 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
215 : :
216 [ # # ]: 0 : ::rtl::OUString aStorageURL = xAttributes->getValueByUidName(
217 : : m_pImport->XMLNS_XLINK_UID,
218 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "href" ) ) );
219 : :
220 : 0 : sal_Bool bReadOnly = sal_False;
221 : : getBoolAttr( &bReadOnly,
222 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
223 [ # # ][ # # ]: 0 : xAttributes, m_pImport->XMLNS_UID );
224 : :
225 [ # # ]: 0 : if ( m_xLibContainer.is() )
226 : : {
227 : : try
228 : : {
229 : : Reference< container::XNameAccess > xLib(
230 [ # # ][ # # ]: 0 : m_xLibContainer->createLibraryLink( aName, aStorageURL, bReadOnly ) );
231 [ # # ]: 0 : if ( xLib.is() )
232 [ # # ][ # # ]: 0 : xElement.set( new BasicElementBase( rLocalName, xAttributes, this, m_pImport ) );
[ # # ]
[ # # # ]
233 : : }
234 [ # # ]: 0 : catch ( const container::ElementExistException& e )
235 : : {
236 : : OSL_TRACE( "BasicLibrariesElement::startChildElement: caught ElementExceptionExist reason %s",
237 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
238 : : }
239 [ # # ]: 0 : catch ( const lang::IllegalArgumentException& e )
240 : : {
241 : : OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
242 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
243 : : }
244 : 0 : }
245 : : }
246 : : }
247 [ # # ]: 0 : else if ( rLocalName == "library-embedded" )
248 : : {
249 : : // TODO: create password protected libraries
250 : :
251 [ # # ]: 0 : if ( xAttributes.is() )
252 : : {
253 [ # # ]: 0 : ::rtl::OUString aName = xAttributes->getValueByUidName(
254 : : m_pImport->XMLNS_UID,
255 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
256 : :
257 : 0 : sal_Bool bReadOnly = sal_False;
258 : : getBoolAttr( &bReadOnly,
259 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
260 [ # # ][ # # ]: 0 : xAttributes, m_pImport->XMLNS_UID );
261 : :
262 [ # # ]: 0 : if ( m_xLibContainer.is() )
263 : : {
264 : : try
265 : : {
266 : 0 : Reference< container::XNameContainer > xLib;
267 [ # # ][ # # ]: 0 : if ( m_xLibContainer->hasByName( aName ) )
[ # # ]
268 : : {
269 : : // Standard library
270 [ # # ][ # # ]: 0 : m_xLibContainer->getByName( aName ) >>= xLib;
[ # # ]
271 : : }
272 : : else
273 : : {
274 [ # # ][ # # ]: 0 : xLib.set( m_xLibContainer->createLibrary( aName ) );
[ # # ]
275 : : }
276 : :
277 [ # # ]: 0 : if ( xLib.is() )
278 [ # # ][ # # ]: 0 : xElement.set( new BasicEmbeddedLibraryElement( rLocalName, xAttributes, this, m_pImport, m_xLibContainer, aName, bReadOnly ) );
[ # # ][ # # ]
279 : : }
280 [ # # ]: 0 : catch ( const lang::IllegalArgumentException& e )
281 : : {
282 : : OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
283 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
284 : : }
285 : 0 : }
286 : : }
287 : : }
288 : : else
289 : : {
290 : : throw xml::sax::SAXException(
291 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected library-linked or library-embedded element!" ) ),
292 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
293 : : }
294 : :
295 : 0 : return xElement;
296 : : }
297 : :
298 : : // -----------------------------------------------------------------------------
299 : :
300 : 0 : void BasicLibrariesElement::endElement()
301 : : throw (xml::sax::SAXException, RuntimeException)
302 : : {
303 : 0 : }
304 : :
305 : :
306 : : // =============================================================================
307 : : // BasicEmbeddedLibraryElement
308 : : // =============================================================================
309 : :
310 : 0 : BasicEmbeddedLibraryElement::BasicEmbeddedLibraryElement( const ::rtl::OUString& rLocalName,
311 : : const Reference< xml::input::XAttributes >& xAttributes,
312 : : BasicElementBase* pParent, BasicImport* pImport,
313 : : const Reference< script::XLibraryContainer2 >& rxLibContainer,
314 : : const ::rtl::OUString& rLibName, bool bReadOnly )
315 : : :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
316 : : ,m_xLibContainer( rxLibContainer )
317 : : ,m_aLibName( rLibName )
318 : 0 : ,m_bReadOnly( bReadOnly )
319 : : {
320 : : try
321 : : {
322 [ # # ][ # # ]: 0 : if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_aLibName ) )
[ # # ][ # # ]
[ # # ]
323 [ # # ][ # # ]: 0 : m_xLibContainer->getByName( m_aLibName ) >>= m_xLib;
[ # # ][ # # ]
324 : : }
325 [ # # ]: 0 : catch ( const lang::WrappedTargetException& e )
326 : : {
327 : : OSL_TRACE( "BasicEmbeddedLibraryElement CTOR: caught WrappedTargetException reason %s",
328 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
329 : : }
330 : 0 : }
331 : :
332 : : // -----------------------------------------------------------------------------
333 : : // XElement
334 : : // -----------------------------------------------------------------------------
335 : :
336 : 0 : Reference< xml::input::XElement > BasicEmbeddedLibraryElement::startChildElement(
337 : : sal_Int32 nUid, const ::rtl::OUString& rLocalName,
338 : : const Reference< xml::input::XAttributes >& xAttributes )
339 : : throw (xml::sax::SAXException, RuntimeException)
340 : : {
341 : 0 : Reference< xml::input::XElement > xElement;
342 : :
343 [ # # ]: 0 : if ( nUid != m_pImport->XMLNS_UID )
344 : : {
345 : : throw xml::sax::SAXException(
346 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
347 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
348 : : }
349 [ # # ]: 0 : else if ( rLocalName == "module" )
350 : : {
351 [ # # ]: 0 : if ( xAttributes.is() )
352 : : {
353 [ # # ]: 0 : ::rtl::OUString aName = xAttributes->getValueByUidName(
354 : : m_pImport->XMLNS_UID,
355 [ # # ][ # # ]: 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
356 : :
357 [ # # ][ # # ]: 0 : if ( m_xLib.is() && !aName.isEmpty() )
[ # # ]
358 [ # # ][ # # ]: 0 : xElement.set( new BasicModuleElement( rLocalName, xAttributes, this, m_pImport, m_xLib, aName ) );
[ # # ]
359 : : }
360 : : }
361 : : else
362 : : {
363 : : throw xml::sax::SAXException(
364 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected module element!" ) ),
365 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
366 : : }
367 : :
368 : 0 : return xElement;
369 : : }
370 : :
371 : : // -----------------------------------------------------------------------------
372 : :
373 : 0 : void BasicEmbeddedLibraryElement::endElement()
374 : : throw (xml::sax::SAXException, RuntimeException)
375 : : {
376 [ # # ][ # # ]: 0 : if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_aLibName ) && m_bReadOnly )
[ # # ][ # # ]
377 : 0 : m_xLibContainer->setLibraryReadOnly( m_aLibName, m_bReadOnly );
378 : 0 : }
379 : :
380 : :
381 : : // =============================================================================
382 : : // BasicModuleElement
383 : : // =============================================================================
384 : :
385 : 0 : BasicModuleElement::BasicModuleElement( const ::rtl::OUString& rLocalName,
386 : : const Reference< xml::input::XAttributes >& xAttributes,
387 : : BasicElementBase* pParent, BasicImport* pImport,
388 : : const Reference< container::XNameContainer >& rxLib, const ::rtl::OUString& rName )
389 : : :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
390 : : ,m_xLib( rxLib )
391 : 0 : ,m_aName( rName )
392 : : {
393 : 0 : }
394 : :
395 : : // -----------------------------------------------------------------------------
396 : : // XElement
397 : : // -----------------------------------------------------------------------------
398 : :
399 : 0 : Reference< xml::input::XElement > BasicModuleElement::startChildElement(
400 : : sal_Int32 nUid, const ::rtl::OUString& rLocalName,
401 : : const Reference< xml::input::XAttributes >& xAttributes )
402 : : throw (xml::sax::SAXException, RuntimeException)
403 : : {
404 : : // TODO: <byte-code>
405 : :
406 : 0 : Reference< xml::input::XElement > xElement;
407 : :
408 [ # # ]: 0 : if ( nUid != m_pImport->XMLNS_UID )
409 : : {
410 : : throw xml::sax::SAXException(
411 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
412 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
413 : : }
414 [ # # ]: 0 : else if ( rLocalName == "source-code" )
415 : : {
416 : : // TODO: password protected libraries
417 : :
418 [ # # ]: 0 : if ( xAttributes.is() )
419 : : {
420 [ # # ][ # # ]: 0 : if ( m_xLib.is() && !m_aName.isEmpty() )
[ # # ]
421 [ # # ][ # # ]: 0 : xElement.set( new BasicSourceCodeElement( rLocalName, xAttributes, this, m_pImport, m_xLib, m_aName ) );
[ # # ]
422 : : }
423 : : }
424 : : else
425 : : {
426 : : throw xml::sax::SAXException(
427 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected source-code element!" ) ),
428 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
429 : : }
430 : :
431 : 0 : return xElement;
432 : : }
433 : :
434 : : // -----------------------------------------------------------------------------
435 : :
436 : 0 : void BasicModuleElement::endElement()
437 : : throw (xml::sax::SAXException, RuntimeException)
438 : : {
439 : 0 : }
440 : :
441 : :
442 : : // =============================================================================
443 : : // BasicSourceCodeElement
444 : : // =============================================================================
445 : :
446 : 0 : BasicSourceCodeElement::BasicSourceCodeElement( const ::rtl::OUString& rLocalName,
447 : : const Reference< xml::input::XAttributes >& xAttributes,
448 : : BasicElementBase* pParent, BasicImport* pImport,
449 : : const Reference< container::XNameContainer >& rxLib, const ::rtl::OUString& rName )
450 : : :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
451 : : ,m_xLib( rxLib )
452 : 0 : ,m_aName( rName )
453 : : {
454 : 0 : }
455 : :
456 : : // -----------------------------------------------------------------------------
457 : : // XElement
458 : : // -----------------------------------------------------------------------------
459 : :
460 : 0 : void BasicSourceCodeElement::characters( const ::rtl::OUString& rChars )
461 : : throw (xml::sax::SAXException, RuntimeException)
462 : : {
463 : 0 : m_aBuffer.append( rChars );
464 : 0 : }
465 : :
466 : : // -----------------------------------------------------------------------------
467 : :
468 : 0 : void BasicSourceCodeElement::endElement()
469 : : throw (xml::sax::SAXException, RuntimeException)
470 : : {
471 : : try
472 : : {
473 [ # # ][ # # ]: 0 : if ( m_xLib.is() && !m_aName.isEmpty() )
[ # # ]
474 : : {
475 : 0 : Any aElement;
476 [ # # ][ # # ]: 0 : aElement <<= m_aBuffer.makeStringAndClear();
477 [ # # ]: 0 : m_xLib->insertByName( m_aName, aElement );
[ # # # # ]
[ # # ]
478 : : }
479 : : }
480 : 0 : catch ( const container::ElementExistException& e )
481 : : {
482 : : OSL_TRACE( "BasicSourceCodeElement::endElement: caught ElementExceptionExist reason %s",
483 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
484 : : }
485 : 0 : catch ( const lang::IllegalArgumentException& e )
486 : : {
487 : : OSL_TRACE( "BasicSourceCodeElement::endElement: caught IllegalArgumentException reason %s",
488 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
489 : : }
490 : 0 : catch ( const lang::WrappedTargetException& e )
491 : : {
492 : : OSL_TRACE( "BasicSourceCodeElement::endElement: caught WrappedTargetException reason %s",
493 : : ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
494 : : }
495 : 0 : }
496 : :
497 : :
498 : : // =============================================================================
499 : : // BasicImport
500 : : // =============================================================================
501 : :
502 : 0 : BasicImport::BasicImport( const Reference< frame::XModel >& rxModel, sal_Bool bOasis )
503 : : :m_xModel( rxModel )
504 : 0 : ,m_bOasis( bOasis )
505 : : {
506 : 0 : }
507 : :
508 : : // -----------------------------------------------------------------------------
509 : :
510 : 0 : BasicImport::~BasicImport()
511 : : {
512 [ # # ]: 0 : }
513 : :
514 : : // -----------------------------------------------------------------------------
515 : : // XRoot
516 : : // -----------------------------------------------------------------------------
517 : :
518 : 0 : void BasicImport::startDocument( const Reference< xml::input::XNamespaceMapping >& xNamespaceMapping )
519 : : throw (xml::sax::SAXException, RuntimeException)
520 : : {
521 [ # # ]: 0 : if ( xNamespaceMapping.is() )
522 : : {
523 : 0 : ::rtl::OUString aURI;
524 [ # # ]: 0 : if ( m_bOasis )
525 [ # # ]: 0 : aURI = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_OOO_URI ) );
526 : : else
527 [ # # ]: 0 : aURI = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_SCRIPT_URI ) );
528 [ # # ][ # # ]: 0 : XMLNS_UID = xNamespaceMapping->getUidByUri( aURI );
529 [ # # ][ # # ]: 0 : XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_URI ) ) );
[ # # ]
530 : : }
531 : 0 : }
532 : :
533 : : // -----------------------------------------------------------------------------
534 : :
535 : 0 : void BasicImport::endDocument()
536 : : throw (xml::sax::SAXException, RuntimeException)
537 : : {
538 : 0 : }
539 : :
540 : : // -----------------------------------------------------------------------------
541 : :
542 : 0 : void BasicImport::processingInstruction( const ::rtl::OUString& /*rTarget*/, const ::rtl::OUString& /*rData*/ )
543 : : throw (xml::sax::SAXException, RuntimeException)
544 : : {
545 : 0 : }
546 : :
547 : : // -----------------------------------------------------------------------------
548 : :
549 : 0 : void BasicImport::setDocumentLocator( const Reference< xml::sax::XLocator >& /*xLocator*/ )
550 : : throw (xml::sax::SAXException, RuntimeException)
551 : : {
552 : 0 : }
553 : :
554 : : // -----------------------------------------------------------------------------
555 : :
556 : 0 : Reference< xml::input::XElement > BasicImport::startRootElement( sal_Int32 nUid, const ::rtl::OUString& rLocalName,
557 : : Reference< xml::input::XAttributes > const & xAttributes )
558 : : throw (xml::sax::SAXException, RuntimeException)
559 : : {
560 : 0 : Reference< xml::input::XElement > xElement;
561 : :
562 [ # # ]: 0 : if ( nUid != XMLNS_UID )
563 : : {
564 : : throw xml::sax::SAXException(
565 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
566 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
567 : : }
568 [ # # ]: 0 : else if ( rLocalName == "libraries" )
569 : : {
570 : 0 : Reference< script::XLibraryContainer2 > xLibContainer;
571 : :
572 : : // try the XEmbeddedScripts interface
573 [ # # ]: 0 : Reference< document::XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
574 [ # # ]: 0 : if ( xDocumentScripts.is() )
575 [ # # ][ # # ]: 0 : xLibContainer.set( xDocumentScripts->getBasicLibraries().get() );
[ # # ][ # # ]
[ # # ]
576 : :
577 [ # # ]: 0 : if ( !xLibContainer.is() )
578 : : {
579 : : // try the "BasicLibraries" property (old-style, for compatibility)
580 [ # # ]: 0 : Reference< beans::XPropertySet > xPSet( m_xModel, UNO_QUERY );
581 [ # # ]: 0 : if ( xPSet.is() )
582 [ # # ][ # # ]: 0 : xPSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ) >>= xLibContainer;
[ # # ][ # # ]
583 : : }
584 : :
585 : : OSL_ENSURE( xLibContainer.is(), "BasicImport::startRootElement: nowhere to import to!" );
586 : :
587 [ # # ]: 0 : if ( xLibContainer.is() )
588 : : {
589 [ # # ][ # # ]: 0 : xElement.set( new BasicLibrariesElement( rLocalName, xAttributes, 0, this, xLibContainer ) );
[ # # ]
590 : 0 : }
591 : : }
592 : : else
593 : : {
594 : : throw xml::sax::SAXException(
595 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal root element (expected libraries) given: " ) ) +
596 [ # # ][ # # ]: 0 : rLocalName, Reference< XInterface >(), Any() );
597 : : }
598 : :
599 : 0 : return xElement;
600 : : }
601 : :
602 : :
603 : : // =============================================================================
604 : : // component operations
605 : : // =============================================================================
606 : :
607 : 2 : ::rtl::OUString getImplementationName_XMLBasicImporter()
608 : : {
609 : : static ::rtl::OUString* pImplName = 0;
610 [ + - ]: 2 : if ( !pImplName )
611 : : {
612 [ + - ][ + - ]: 2 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
613 [ + - ]: 2 : if ( !pImplName )
614 : : {
615 [ + - ][ + - ]: 2 : static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLBasicImporter" ) );
[ + - ][ # # ]
616 : 2 : pImplName = &aImplName;
617 [ + - ]: 2 : }
618 : : }
619 : 2 : return *pImplName;
620 : : }
621 : :
622 : : // -----------------------------------------------------------------------------
623 : :
624 : 0 : Sequence< ::rtl::OUString > getSupportedServiceNames_XMLBasicImporter()
625 : : {
626 : : static Sequence< ::rtl::OUString >* pNames = 0;
627 [ # # ]: 0 : if ( !pNames )
628 : : {
629 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
630 [ # # ]: 0 : if ( !pNames )
631 : : {
632 [ # # ][ # # ]: 0 : static Sequence< ::rtl::OUString > aNames(1);
[ # # ][ # # ]
633 [ # # ][ # # ]: 0 : aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLBasicImporter" ) );
634 : 0 : pNames = &aNames;
635 [ # # ]: 0 : }
636 : : }
637 : 0 : return *pNames;
638 : : }
639 : :
640 : : // -----------------------------------------------------------------------------
641 : :
642 : 2 : ::rtl::OUString getImplementationName_XMLOasisBasicImporter()
643 : : {
644 : : static ::rtl::OUString* pImplName = 0;
645 [ + - ]: 2 : if ( !pImplName )
646 : : {
647 [ + - ][ + - ]: 2 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
648 [ + - ]: 2 : if ( !pImplName )
649 : : {
650 [ + - ][ + - ]: 2 : static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLOasisBasicImporter" ) );
[ + - ][ # # ]
651 : 2 : pImplName = &aImplName;
652 [ + - ]: 2 : }
653 : : }
654 : 2 : return *pImplName;
655 : : }
656 : :
657 : : // -----------------------------------------------------------------------------
658 : :
659 : 0 : Sequence< ::rtl::OUString > getSupportedServiceNames_XMLOasisBasicImporter()
660 : : {
661 : : static Sequence< ::rtl::OUString >* pNames = 0;
662 [ # # ]: 0 : if ( !pNames )
663 : : {
664 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
665 [ # # ]: 0 : if ( !pNames )
666 : : {
667 [ # # ][ # # ]: 0 : static Sequence< ::rtl::OUString > aNames(1);
[ # # ][ # # ]
668 [ # # ][ # # ]: 0 : aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) );
669 : 0 : pNames = &aNames;
670 [ # # ]: 0 : }
671 : : }
672 : 0 : return *pNames;
673 : : }
674 : :
675 : :
676 : : // =============================================================================
677 : : // XMLBasicImporterBase
678 : : // =============================================================================
679 : :
680 : 0 : XMLBasicImporterBase::XMLBasicImporterBase( const Reference< XComponentContext >& rxContext, sal_Bool bOasis )
681 : : :m_xContext( rxContext )
682 [ # # ]: 0 : ,m_bOasis( bOasis )
683 : : {
684 : 0 : }
685 : :
686 : : // -----------------------------------------------------------------------------
687 : :
688 [ # # ]: 0 : XMLBasicImporterBase::~XMLBasicImporterBase()
689 : : {
690 [ # # ]: 0 : }
691 : :
692 : : // -----------------------------------------------------------------------------
693 : : // XServiceInfo
694 : : // -----------------------------------------------------------------------------
695 : :
696 : 0 : sal_Bool XMLBasicImporterBase::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
697 : : {
698 [ # # ]: 0 : Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
699 : 0 : const ::rtl::OUString* pNames = aNames.getConstArray();
700 : 0 : const ::rtl::OUString* pEnd = pNames + aNames.getLength();
701 [ # # ][ # # ]: 0 : for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
[ # # ]
702 : : ;
703 : :
704 [ # # ]: 0 : return pNames != pEnd;
705 : : }
706 : :
707 : : // -----------------------------------------------------------------------------
708 : : // XImporter
709 : : // -----------------------------------------------------------------------------
710 : :
711 : 0 : void XMLBasicImporterBase::setTargetDocument( const Reference< XComponent >& rxDoc )
712 : : throw (IllegalArgumentException, RuntimeException)
713 : : {
714 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
715 : :
716 [ # # ]: 0 : m_xModel.set( rxDoc, UNO_QUERY );
717 : :
718 [ # # ]: 0 : if ( !m_xModel.is() )
719 : : {
720 : : throw IllegalArgumentException(
721 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporter::setTargetDocument: no document model!" ) ),
722 [ # # ][ # # ]: 0 : Reference< XInterface >(), 1 );
723 : : }
724 : :
725 [ # # ]: 0 : if ( m_xContext.is() )
726 : : {
727 [ # # ][ # # ]: 0 : Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
728 [ # # ]: 0 : if ( xSMgr.is() )
729 : : {
730 [ # # ][ # # ]: 0 : Reference < xml::input::XRoot > xRoot( new BasicImport( m_xModel, m_bOasis ) );
[ # # ]
731 [ # # ]: 0 : Sequence < Any > aArgs( 1 );
732 [ # # ][ # # ]: 0 : aArgs[0] <<= xRoot;
733 [ # # ]: 0 : m_xHandler.set( xSMgr->createInstanceWithArgumentsAndContext(
734 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.input.SaxDocumentHandler" ) ),
735 [ # # ][ # # ]: 0 : aArgs, m_xContext ), UNO_QUERY );
[ # # ][ # # ]
736 : 0 : }
737 [ # # ]: 0 : }
738 : 0 : }
739 : :
740 : : // -----------------------------------------------------------------------------
741 : : // XDocumentHandler
742 : : // -----------------------------------------------------------------------------
743 : :
744 : 0 : void XMLBasicImporterBase::startDocument()
745 : : throw (xml::sax::SAXException, RuntimeException)
746 : : {
747 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
748 : :
749 [ # # ]: 0 : if ( m_xHandler.is() )
750 [ # # ][ # # ]: 0 : m_xHandler->startDocument();
[ # # ]
751 : 0 : }
752 : :
753 : : // -----------------------------------------------------------------------------
754 : :
755 : 0 : void XMLBasicImporterBase::endDocument()
756 : : throw (xml::sax::SAXException, RuntimeException)
757 : : {
758 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
759 : :
760 [ # # ]: 0 : if ( m_xHandler.is() )
761 [ # # ][ # # ]: 0 : m_xHandler->endDocument();
[ # # ]
762 : 0 : }
763 : :
764 : : // -----------------------------------------------------------------------------
765 : :
766 : 0 : void XMLBasicImporterBase::startElement( const ::rtl::OUString& aName,
767 : : const Reference< xml::sax::XAttributeList >& xAttribs )
768 : : throw (xml::sax::SAXException, RuntimeException)
769 : : {
770 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
771 : :
772 [ # # ]: 0 : if ( m_xHandler.is() )
773 [ # # ][ # # ]: 0 : m_xHandler->startElement( aName, xAttribs );
[ # # ]
774 : 0 : }
775 : :
776 : : // -----------------------------------------------------------------------------
777 : :
778 : 0 : void XMLBasicImporterBase::endElement( const ::rtl::OUString& aName )
779 : : throw (xml::sax::SAXException, RuntimeException)
780 : : {
781 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
782 : :
783 [ # # ]: 0 : if ( m_xHandler.is() )
784 [ # # ][ # # ]: 0 : m_xHandler->endElement( aName );
[ # # ]
785 : 0 : }
786 : :
787 : : // -----------------------------------------------------------------------------
788 : :
789 : 0 : void XMLBasicImporterBase::characters( const ::rtl::OUString& aChars )
790 : : throw (xml::sax::SAXException, RuntimeException)
791 : : {
792 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
793 : :
794 [ # # ]: 0 : if ( m_xHandler.is() )
795 [ # # ][ # # ]: 0 : m_xHandler->characters( aChars );
[ # # ]
796 : 0 : }
797 : :
798 : : // -----------------------------------------------------------------------------
799 : :
800 : 0 : void XMLBasicImporterBase::ignorableWhitespace( const ::rtl::OUString& aWhitespaces )
801 : : throw (xml::sax::SAXException, RuntimeException)
802 : : {
803 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
804 : :
805 [ # # ]: 0 : if ( m_xHandler.is() )
806 [ # # ][ # # ]: 0 : m_xHandler->ignorableWhitespace( aWhitespaces );
[ # # ]
807 : 0 : }
808 : :
809 : : // -----------------------------------------------------------------------------
810 : :
811 : 0 : void XMLBasicImporterBase::processingInstruction( const ::rtl::OUString& aTarget,
812 : : const ::rtl::OUString& aData )
813 : : throw (xml::sax::SAXException, RuntimeException)
814 : : {
815 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
816 : :
817 [ # # ]: 0 : if ( m_xHandler.is() )
818 [ # # ][ # # ]: 0 : m_xHandler->processingInstruction( aTarget, aData );
[ # # ]
819 : 0 : }
820 : :
821 : : // -----------------------------------------------------------------------------
822 : :
823 : 0 : void XMLBasicImporterBase::setDocumentLocator( const Reference< xml::sax::XLocator >& xLocator )
824 : : throw (xml::sax::SAXException, RuntimeException)
825 : : {
826 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
827 : :
828 [ # # ]: 0 : if ( m_xHandler.is() )
829 [ # # ][ # # ]: 0 : m_xHandler->setDocumentLocator( xLocator );
[ # # ]
830 : 0 : }
831 : :
832 : :
833 : : // =============================================================================
834 : : // XMLBasicImporter
835 : : // =============================================================================
836 : :
837 : 0 : XMLBasicImporter::XMLBasicImporter( const Reference< XComponentContext >& rxContext )
838 : 0 : :XMLBasicImporterBase( rxContext, sal_False )
839 : : {
840 : 0 : }
841 : :
842 : : // -----------------------------------------------------------------------------
843 : :
844 : 0 : XMLBasicImporter::~XMLBasicImporter()
845 : : {
846 [ # # ]: 0 : }
847 : :
848 : : // -----------------------------------------------------------------------------
849 : : // XServiceInfo
850 : : // -----------------------------------------------------------------------------
851 : :
852 : 0 : ::rtl::OUString XMLBasicImporter::getImplementationName( ) throw (RuntimeException)
853 : : {
854 : 0 : return getImplementationName_XMLBasicImporter();
855 : : }
856 : :
857 : : // -----------------------------------------------------------------------------
858 : :
859 : 0 : Sequence< ::rtl::OUString > XMLBasicImporter::getSupportedServiceNames( ) throw (RuntimeException)
860 : : {
861 : 0 : return getSupportedServiceNames_XMLBasicImporter();
862 : : }
863 : :
864 : :
865 : : // =============================================================================
866 : : // XMLOasisBasicImporter
867 : : // =============================================================================
868 : :
869 : 0 : XMLOasisBasicImporter::XMLOasisBasicImporter( const Reference< XComponentContext >& rxContext )
870 : 0 : :XMLBasicImporterBase( rxContext, sal_True )
871 : : {
872 : 0 : }
873 : :
874 : : // -----------------------------------------------------------------------------
875 : :
876 : 0 : XMLOasisBasicImporter::~XMLOasisBasicImporter()
877 : : {
878 [ # # ]: 0 : }
879 : :
880 : : // -----------------------------------------------------------------------------
881 : : // XServiceInfo
882 : : // -----------------------------------------------------------------------------
883 : :
884 : 0 : ::rtl::OUString XMLOasisBasicImporter::getImplementationName( ) throw (RuntimeException)
885 : : {
886 : 0 : return getImplementationName_XMLOasisBasicImporter();
887 : : }
888 : :
889 : : // -----------------------------------------------------------------------------
890 : :
891 : 0 : Sequence< ::rtl::OUString > XMLOasisBasicImporter::getSupportedServiceNames( ) throw (RuntimeException)
892 : : {
893 : 0 : return getSupportedServiceNames_XMLOasisBasicImporter();
894 : : }
895 : :
896 : :
897 : : // =============================================================================
898 : : // component operations
899 : : // =============================================================================
900 : :
901 : 0 : Reference< XInterface > SAL_CALL create_XMLBasicImporter(
902 : : Reference< XComponentContext > const & xContext )
903 : : SAL_THROW(())
904 : : {
905 [ # # ][ # # ]: 0 : return static_cast< lang::XTypeProvider * >( new XMLBasicImporter( xContext ) );
906 : : }
907 : :
908 : : // -----------------------------------------------------------------------------
909 : :
910 : 0 : Reference< XInterface > SAL_CALL create_XMLOasisBasicImporter(
911 : : Reference< XComponentContext > const & xContext )
912 : : SAL_THROW(())
913 : : {
914 [ # # ][ # # ]: 0 : return static_cast< lang::XTypeProvider * >( new XMLOasisBasicImporter( xContext ) );
915 : : }
916 : :
917 : : // -----------------------------------------------------------------------------
918 : :
919 : : //.........................................................................
920 : : } // namespace xmlscript
921 : : //.........................................................................
922 : :
923 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|