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 "imp_share.hxx"
21 : : #include "xml_import.hxx"
22 : :
23 : : namespace xmlscript
24 : : {
25 : :
26 : : //##################################################################################################
27 : :
28 : : //__________________________________________________________________________________________________
29 : 0 : Reference< xml::input::XElement > LibElementBase::getParent()
30 : : throw (RuntimeException)
31 : : {
32 [ # # ]: 0 : return static_cast< xml::input::XElement * >( _pParent );
33 : : }
34 : : //__________________________________________________________________________________________________
35 : 0 : OUString LibElementBase::getLocalName()
36 : : throw (RuntimeException)
37 : : {
38 : 0 : return _aLocalName;
39 : : }
40 : : //__________________________________________________________________________________________________
41 : 0 : sal_Int32 LibElementBase::getUid()
42 : : throw (RuntimeException)
43 : : {
44 : 0 : return _pImport->XMLNS_LIBRARY_UID;
45 : : }
46 : : //__________________________________________________________________________________________________
47 : 0 : Reference< xml::input::XAttributes > LibElementBase::getAttributes()
48 : : throw (RuntimeException)
49 : : {
50 : 0 : return _xAttributes;
51 : : }
52 : : //__________________________________________________________________________________________________
53 : 0 : void LibElementBase::ignorableWhitespace(
54 : : OUString const & /*rWhitespaces*/ )
55 : : throw (xml::sax::SAXException, RuntimeException)
56 : : {
57 : 0 : }
58 : : //__________________________________________________________________________________________________
59 : 12824 : void LibElementBase::characters( OUString const & /*rChars*/ )
60 : : throw (xml::sax::SAXException, RuntimeException)
61 : : {
62 : : // not used, all characters ignored
63 : 12824 : }
64 : :
65 : : //__________________________________________________________________________________________________
66 : 0 : void LibElementBase::processingInstruction(
67 : : OUString const & /*rTarget*/, OUString const & /*rData*/ )
68 : : throw (xml::sax::SAXException, RuntimeException)
69 : : {
70 : 0 : }
71 : :
72 : : //__________________________________________________________________________________________________
73 : 4416 : void LibElementBase::endElement()
74 : : throw (xml::sax::SAXException, RuntimeException)
75 : : {
76 : 4416 : }
77 : : //__________________________________________________________________________________________________
78 : 0 : Reference< xml::input::XElement > LibElementBase::startChildElement(
79 : : sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
80 : : Reference< xml::input::XAttributes > const & /*xAttributes*/ )
81 : : throw (xml::sax::SAXException, RuntimeException)
82 : : {
83 : : throw xml::sax::SAXException(
84 : : OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected element!") ),
85 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
86 : : }
87 : :
88 : : //__________________________________________________________________________________________________
89 : 7286 : LibElementBase::LibElementBase(
90 : : OUString const & rLocalName,
91 : : Reference< xml::input::XAttributes > const & xAttributes,
92 : : LibElementBase * pParent, LibraryImport * pImport )
93 : : SAL_THROW(())
94 : : : _pImport( pImport )
95 : : , _pParent( pParent )
96 : : , _aLocalName( rLocalName )
97 : 7286 : , _xAttributes( xAttributes )
98 : : {
99 : 7286 : _pImport->acquire();
100 : :
101 [ + + ]: 7286 : if (_pParent)
102 : : {
103 : 5538 : _pParent->acquire();
104 : : }
105 : 7286 : }
106 : : //__________________________________________________________________________________________________
107 : 7286 : LibElementBase::~LibElementBase()
108 : : SAL_THROW(())
109 : : {
110 : 7286 : _pImport->release();
111 : :
112 [ + + ]: 7286 : if (_pParent)
113 : : {
114 : 5538 : _pParent->release();
115 : : }
116 : :
117 : : #if OSL_DEBUG_LEVEL > 1
118 : : OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
119 : : OSL_TRACE( "LibElementBase::~LibElementBase(): %s", aStr.getStr() );
120 : : #endif
121 [ - + ]: 11702 : }
122 : :
123 : : //##################################################################################################
124 : :
125 : : // XRoot
126 : :
127 : : //______________________________________________________________________________
128 : 1748 : void LibraryImport::startDocument(
129 : : Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
130 : : throw (xml::sax::SAXException, RuntimeException)
131 : : {
132 : 1748 : XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri(
133 [ + - ]: 1748 : OUSTR(XMLNS_LIBRARY_URI) );
134 : 1748 : XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri(
135 [ + - ]: 1748 : OUSTR(XMLNS_XLINK_URI) );
136 : 1748 : }
137 : : //__________________________________________________________________________________________________
138 : 1748 : void LibraryImport::endDocument()
139 : : throw (xml::sax::SAXException, RuntimeException)
140 : : {
141 : 1748 : }
142 : : //__________________________________________________________________________________________________
143 : 0 : void LibraryImport::processingInstruction(
144 : : OUString const & /*rTarget*/, OUString const & /*rData*/ )
145 : : throw (xml::sax::SAXException, RuntimeException)
146 : : {
147 : 0 : }
148 : : //__________________________________________________________________________________________________
149 : 1748 : void LibraryImport::setDocumentLocator(
150 : : Reference< xml::sax::XLocator > const & /*xLocator*/ )
151 : : throw (xml::sax::SAXException, RuntimeException)
152 : : {
153 : 1748 : }
154 : : //__________________________________________________________________________________________________
155 : 1748 : Reference< xml::input::XElement > LibraryImport::startRootElement(
156 : : sal_Int32 nUid, OUString const & rLocalName,
157 : : Reference< xml::input::XAttributes > const & xAttributes )
158 : : throw (xml::sax::SAXException, RuntimeException)
159 : : {
160 [ - + ]: 1748 : if (XMLNS_LIBRARY_UID != nUid)
161 : : {
162 : : throw xml::sax::SAXException(
163 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
164 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
165 : : }
166 [ + + ][ + - ]: 1748 : else if ( mpLibArray && rLocalName == "libraries" )
[ + + ]
167 : : {
168 [ + - ][ + - ]: 254 : return new LibrariesElement( rLocalName, xAttributes, 0, this );
169 : : }
170 [ + - ][ + - ]: 1494 : else if ( mpLibDesc && rLocalName == "library" )
[ + - ]
171 : : {
172 : 1494 : LibDescriptor& aDesc = *mpLibDesc;
173 : 1494 : aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = sal_False;
174 : :
175 : 1494 : aDesc.aName = xAttributes->getValueByUidName(
176 [ + - ]: 1494 : XMLNS_LIBRARY_UID, OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
177 : : getBoolAttr(
178 : : &aDesc.bReadOnly,
179 : : OUString( RTL_CONSTASCII_USTRINGPARAM("readonly") ), xAttributes,
180 [ + - ]: 1494 : XMLNS_LIBRARY_UID );
181 : : getBoolAttr(
182 : : &aDesc.bPasswordProtected,
183 : : OUString( RTL_CONSTASCII_USTRINGPARAM("passwordprotected") ),
184 [ + - ]: 1494 : xAttributes, XMLNS_LIBRARY_UID );
185 : : getBoolAttr(
186 : : &aDesc.bPreload,
187 : : OUString( RTL_CONSTASCII_USTRINGPARAM("preload") ),
188 [ + - ]: 1494 : xAttributes, XMLNS_LIBRARY_UID );
189 : :
190 [ + - ][ + - ]: 1494 : return new LibraryElement( rLocalName, xAttributes, 0, this );
191 : : }
192 : : else
193 : : {
194 : : throw xml::sax::SAXException(
195 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal root element (expected libraries) given: ") ) +
196 [ # # ][ # # ]: 1748 : rLocalName, Reference< XInterface >(), Any() );
197 : : }
198 : : }
199 : : //__________________________________________________________________________________________________
200 : 1748 : LibraryImport::~LibraryImport()
201 : : SAL_THROW(())
202 : : {
203 : : #if OSL_DEBUG_LEVEL > 1
204 : : OSL_TRACE( "LibraryImport::~LibraryImport()." );
205 : : #endif
206 [ - + ]: 3496 : }
207 : :
208 : : //##################################################################################################
209 : :
210 : :
211 : : // libraries
212 : : //__________________________________________________________________________________________________
213 : 1122 : Reference< xml::input::XElement > LibrariesElement::startChildElement(
214 : : sal_Int32 nUid, OUString const & rLocalName,
215 : : Reference< xml::input::XAttributes > const & xAttributes )
216 : : throw (xml::sax::SAXException, RuntimeException)
217 : : {
218 [ - + ]: 1122 : if (_pImport->XMLNS_LIBRARY_UID != nUid)
219 : : {
220 : : throw xml::sax::SAXException(
221 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
222 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
223 : : }
224 : : // library
225 [ + - ]: 1122 : else if ( rLocalName == "library" )
226 : : {
227 [ + - ]: 1122 : LibDescriptor aDesc;
228 : 1122 : aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = sal_False;
229 : :
230 [ + - ]: 1122 : aDesc.aName = xAttributes->getValueByUidName(
231 : : _pImport->XMLNS_LIBRARY_UID,
232 [ + - ][ + - ]: 1122 : OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
233 [ + - ]: 1122 : aDesc.aStorageURL = xAttributes->getValueByUidName(
234 : : _pImport->XMLNS_XLINK_UID,
235 [ + - ][ + - ]: 1122 : OUString( RTL_CONSTASCII_USTRINGPARAM("href") ) );
236 : : getBoolAttr(
237 : : &aDesc.bLink,
238 : : OUString( RTL_CONSTASCII_USTRINGPARAM("link") ),
239 [ + - ][ + - ]: 1122 : xAttributes, _pImport->XMLNS_LIBRARY_UID );
240 : : getBoolAttr(
241 : : &aDesc.bReadOnly,
242 : : OUString( RTL_CONSTASCII_USTRINGPARAM("readonly") ),
243 [ + - ][ + - ]: 1122 : xAttributes, _pImport->XMLNS_LIBRARY_UID );
244 : : getBoolAttr(
245 : : &aDesc.bPasswordProtected,
246 : : OUString( RTL_CONSTASCII_USTRINGPARAM("passwordprotected") ),
247 [ + - ][ + - ]: 1122 : xAttributes, _pImport->XMLNS_LIBRARY_UID );
248 : :
249 [ + - ]: 1122 : mLibDescriptors.push_back( aDesc );
250 [ + - ][ + - ]: 1122 : return new LibraryElement( rLocalName, xAttributes, this, _pImport );
[ + - ][ + - ]
251 : : }
252 : : else
253 : : {
254 : : throw xml::sax::SAXException(
255 : : OUString( RTL_CONSTASCII_USTRINGPARAM("expected styles ot bulletinboard element!") ),
256 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
257 : : }
258 : : }
259 : : //__________________________________________________________________________________________________
260 : 254 : void LibrariesElement::endElement()
261 : : throw (xml::sax::SAXException, RuntimeException)
262 : : {
263 : 254 : sal_Int32 nLibCount = _pImport->mpLibArray->mnLibCount = (sal_Int32)mLibDescriptors.size();
264 [ + - ][ + + : 1376 : _pImport->mpLibArray->mpLibs = new LibDescriptor[ nLibCount ];
# # # # ]
265 : :
266 [ + + ]: 1376 : for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
267 : : {
268 : 1122 : const LibDescriptor& rLib = mLibDescriptors[i];
269 : 1122 : _pImport->mpLibArray->mpLibs[i] = rLib;
270 : : }
271 : 254 : }
272 : :
273 : : // library
274 : : //__________________________________________________________________________________________________
275 : 4416 : Reference< xml::input::XElement > LibraryElement::startChildElement(
276 : : sal_Int32 nUid, OUString const & rLocalName,
277 : : Reference< xml::input::XAttributes > const & xAttributes )
278 : : throw (xml::sax::SAXException, RuntimeException)
279 : : {
280 [ - + ]: 4416 : if (_pImport->XMLNS_LIBRARY_UID != nUid)
281 : : {
282 : : throw xml::sax::SAXException(
283 : : OUString( RTL_CONSTASCII_USTRINGPARAM("illegal namespace!") ),
284 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
285 : : }
286 : : // library
287 [ + - ]: 4416 : else if ( rLocalName == "element" )
288 : : {
289 [ + - ]: 4416 : OUString aValue( xAttributes->getValueByUidName(
290 : : _pImport->XMLNS_LIBRARY_UID,
291 [ + - ][ + - ]: 4416 : OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) ) );
292 [ + - ]: 4416 : if (!aValue.isEmpty())
293 [ + - ]: 4416 : mElements.push_back( aValue );
294 : :
295 [ + - ][ + - ]: 4416 : return new LibElementBase( rLocalName, xAttributes, this, _pImport );
[ + - ]
296 : : }
297 : : else
298 : : {
299 : : throw xml::sax::SAXException(
300 : : OUString( RTL_CONSTASCII_USTRINGPARAM("expected styles ot bulletinboard element!") ),
301 [ # # ][ # # ]: 0 : Reference< XInterface >(), Any() );
302 : : }
303 : : }
304 : : //__________________________________________________________________________________________________
305 : 2616 : void LibraryElement::endElement()
306 : : throw (xml::sax::SAXException, RuntimeException)
307 : : {
308 : 2616 : sal_Int32 nElementCount = mElements.size();
309 [ + - ]: 2616 : Sequence< OUString > aElementNames( nElementCount );
310 [ + - ]: 2616 : OUString* pElementNames = aElementNames.getArray();
311 [ + + ]: 7032 : for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
312 : 4416 : pElementNames[i] = mElements[i];
313 : :
314 : 2616 : LibDescriptor* pLib = _pImport->mpLibDesc;
315 [ + + ]: 2616 : if( !pLib )
316 [ + - ]: 1122 : pLib = &static_cast< LibrariesElement* >( _pParent )->mLibDescriptors.back();
317 [ + - ][ + - ]: 2616 : pLib->aElementNames = aElementNames;
318 : 2616 : }
319 : :
320 : :
321 : : //##################################################################################################
322 : :
323 : : Reference< ::com::sun::star::xml::sax::XDocumentHandler >
324 : 254 : SAL_CALL importLibraryContainer( LibDescriptorArray* pLibArray )
325 : : SAL_THROW( (Exception) )
326 : : {
327 : : return ::xmlscript::createDocumentHandler(
328 [ + - ][ + - ]: 254 : static_cast< xml::input::XRoot * >( new LibraryImport( pLibArray ) ) );
[ + - ]
329 : : }
330 : :
331 : : //##################################################################################################
332 : :
333 : : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >
334 : 1494 : SAL_CALL importLibrary( LibDescriptor& rLib )
335 : : SAL_THROW( (::com::sun::star::uno::Exception) )
336 : : {
337 : : return ::xmlscript::createDocumentHandler(
338 [ + - ][ + - ]: 1494 : static_cast< xml::input::XRoot * >( new LibraryImport( &rLib ) ) );
[ + - ]
339 : : }
340 : :
341 : :
342 : : //##################################################################################################
343 : :
344 : 180 : LibDescriptorArray::LibDescriptorArray( sal_Int32 nLibCount )
345 : : {
346 : 180 : mnLibCount = nLibCount;
347 [ + - ][ + + : 360 : mpLibs = new LibDescriptor[ mnLibCount ];
# # # # ]
348 : 180 : }
349 : :
350 : 434 : LibDescriptorArray::~LibDescriptorArray()
351 : : {
352 [ + - ][ + + ]: 1736 : delete[] mpLibs;
353 : 434 : }
354 : :
355 : : }
356 : :
357 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|