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 : :
21 : : #include <cppuhelper/weakref.hxx>
22 : : #include <cppuhelper/implementationentry.hxx>
23 : : #include <cppuhelper/factory.hxx>
24 : : #include <cppuhelper/exc_hlp.hxx>
25 : : #include <cppuhelper/implbase1.hxx>
26 : : #include <comphelper/mediadescriptor.hxx>
27 : :
28 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 : : #include <com/sun/star/frame/XModel.hpp>
30 : : #include <com/sun/star/reflection/XProxyFactory.hpp>
31 : :
32 : : #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
33 : : #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
34 : : #include <com/sun/star/document/XScriptInvocationContext.hpp>
35 : :
36 : : #include <tools/diagnose_ex.h>
37 : :
38 : : #include "BrowseNodeFactoryImpl.hxx"
39 : : #include "ActiveMSPList.hxx"
40 : : #include <util/MiscUtils.hxx>
41 : : #include <util/util.hxx>
42 : :
43 : : #include <vector>
44 : : #include <algorithm>
45 : : using namespace ::com::sun::star;
46 : : using namespace ::com::sun::star::uno;
47 : : using namespace ::com::sun::star::script;
48 : : using namespace ::sf_misc;
49 : :
50 : : namespace browsenodefactory
51 : : {
52 : : class BrowseNodeAggregator :
53 : : public ::cppu::WeakImplHelper1< browse::XBrowseNode >
54 : : {
55 : : private:
56 : : ::rtl::OUString m_Name;
57 : : Sequence< Reference< browse::XBrowseNode > > m_Nodes;
58 : :
59 : : public:
60 : :
61 : 0 : BrowseNodeAggregator( const Reference< browse::XBrowseNode >& node )
62 [ # # ]: 0 : {
63 [ # # ][ # # ]: 0 : m_Name = node->getName();
64 [ # # ]: 0 : m_Nodes.realloc( 1 );
65 [ # # ][ # # ]: 0 : m_Nodes[ 0 ] = node;
66 : 0 : }
67 : :
68 : 0 : ~BrowseNodeAggregator()
69 [ # # ]: 0 : {
70 [ # # ]: 0 : }
71 : :
72 : 0 : void addBrowseNode( const Reference< browse::XBrowseNode>& node )
73 : : {
74 : 0 : sal_Int32 index = m_Nodes.getLength();
75 : :
76 : 0 : m_Nodes.realloc( index + 1 );
77 : 0 : m_Nodes[ index ] = node;
78 : 0 : }
79 : :
80 : : virtual ::rtl::OUString
81 : 0 : SAL_CALL getName()
82 : : throw ( RuntimeException )
83 : : {
84 : 0 : return m_Name;
85 : : }
86 : :
87 : : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
88 : 0 : getChildNodes()
89 : : throw ( RuntimeException )
90 : : {
91 [ # # ]: 0 : std::vector< Sequence< Reference < browse::XBrowseNode > > > seqs;
92 [ # # ]: 0 : seqs.reserve( m_Nodes.getLength() );
93 : :
94 : 0 : sal_Int32 numChildren = 0;
95 : :
96 [ # # ]: 0 : for ( sal_Int32 i = 0; i < m_Nodes.getLength(); i++ )
97 : : {
98 [ # # ]: 0 : Sequence< Reference < browse::XBrowseNode > > children;
99 : : try
100 : : {
101 [ # # ][ # # ]: 0 : children = m_Nodes[ i ]->getChildNodes();
[ # # ][ # # ]
[ # # # # ]
102 [ # # ]: 0 : seqs.push_back( children );
103 : 0 : numChildren += children.getLength();
104 : : }
105 [ # # ]: 0 : catch ( Exception& )
106 : : {
107 : : // some form of exception getting child nodes so they
108 : : // won't be displayed
109 : : }
110 [ # # ]: 0 : }
111 : :
112 [ # # ]: 0 : std::vector< Sequence< Reference < browse::XBrowseNode > > >::const_iterator it = seqs.begin();
113 [ # # ]: 0 : std::vector< Sequence< Reference < browse::XBrowseNode > > >::const_iterator it_end = seqs.end();
114 : :
115 [ # # ]: 0 : Sequence< Reference < browse::XBrowseNode > > result( numChildren );
116 [ # # ][ # # ]: 0 : for ( sal_Int32 index = 0; it != it_end && index < numChildren ; ++it )
[ # # ][ # # ]
117 : : {
118 [ # # ]: 0 : Sequence< Reference < browse::XBrowseNode > > children = *it;
119 [ # # ]: 0 : for ( sal_Int32 j = 0; j < children.getLength(); j++ )
120 : : {
121 [ # # ][ # # ]: 0 : result[ index++ ] = children[ j ];
[ # # ]
122 : : }
123 [ # # ]: 0 : }
124 : 0 : return result;
125 : : }
126 : :
127 : : virtual sal_Bool SAL_CALL
128 : 0 : hasChildNodes()
129 : : throw ( RuntimeException )
130 : : {
131 [ # # ]: 0 : if ( m_Nodes.getLength() != 0 )
132 : : {
133 [ # # ]: 0 : for ( sal_Int32 i = 0 ; i < m_Nodes.getLength(); i++ )
134 : : {
135 : : try
136 : : {
137 [ # # ][ # # ]: 0 : if ( m_Nodes[ i ]->hasChildNodes() )
[ # # ][ # # ]
138 : : {
139 : 0 : return sal_True;
140 : : }
141 : : }
142 : 0 : catch ( Exception& )
143 : : {
144 : : // some form of exception getting child nodes so move
145 : : // on to the next one
146 : : }
147 : : }
148 : : }
149 : :
150 [ # # ]: 0 : return sal_False;
151 : : }
152 : :
153 : 0 : virtual sal_Int16 SAL_CALL getType()
154 : : throw ( RuntimeException )
155 : : {
156 : 0 : return browse::BrowseNodeTypes::CONTAINER;
157 : : }
158 : : };
159 : :
160 : :
161 : : //typedef ::std::map< ::rtl::OUString, Reference< browse::XBrowseNode > >
162 : : typedef ::boost::unordered_map< ::rtl::OUString, Reference< browse::XBrowseNode >,
163 : : ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > >
164 : : BrowseNodeAggregatorHash;
165 : : typedef ::std::vector< ::rtl::OUString > vString;
166 : :
167 : :
168 : : struct alphaSort
169 : : {
170 : 0 : bool operator()( const ::rtl::OUString& a, const ::rtl::OUString& b )
171 : : {
172 : 0 : return a.compareTo( b ) < 0;
173 : : }
174 : : };
175 : : class LocationBrowseNode :
176 : : public ::cppu::WeakImplHelper1< browse::XBrowseNode >
177 : : {
178 : : private:
179 : : BrowseNodeAggregatorHash* m_hBNA;
180 : : vString m_vStr;
181 : : ::rtl::OUString m_sNodeName;
182 : : Reference< browse::XBrowseNode > m_origNode;
183 : :
184 : : public:
185 : :
186 : 0 : LocationBrowseNode( const Reference< browse::XBrowseNode >& node )
187 [ # # ]: 0 : {
188 [ # # ][ # # ]: 0 : m_sNodeName = node->getName();
189 : 0 : m_hBNA = NULL;
190 [ # # ]: 0 : m_origNode.set( node );
191 : 0 : }
192 : :
193 : 0 : ~LocationBrowseNode()
194 : 0 : {
195 [ # # ]: 0 : if (m_hBNA)
196 : : {
197 [ # # ][ # # ]: 0 : delete m_hBNA;
198 : : }
199 [ # # ]: 0 : }
200 : :
201 : : // -------------------------------------------------------------------------
202 : : // XBrowseNode
203 : : // -------------------------------------------------------------------------
204 : :
205 : 0 : virtual ::rtl::OUString SAL_CALL getName()
206 : : throw ( RuntimeException )
207 : : {
208 : 0 : return m_sNodeName;
209 : : }
210 : :
211 : : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
212 : 0 : getChildNodes()
213 : : throw ( RuntimeException )
214 : : {
215 [ # # ]: 0 : if ( m_hBNA == NULL )
216 : : {
217 [ # # ]: 0 : loadChildNodes();
218 : : }
219 : :
220 [ # # ]: 0 : Sequence< Reference< browse::XBrowseNode > > children( m_hBNA->size() );
221 : 0 : sal_Int32 index = 0;
222 : :
223 [ # # ]: 0 : vString::const_iterator it = m_vStr.begin();
224 : :
225 [ # # ][ # # ]: 0 : for ( ; it != m_vStr.end(); ++it, index++ )
226 : : {
227 [ # # ][ # # ]: 0 : children[ index ].set( m_hBNA->find( *it )->second );
[ # # ][ # # ]
228 : : }
229 : :
230 : 0 : return children;
231 : : }
232 : :
233 : 0 : virtual sal_Bool SAL_CALL hasChildNodes()
234 : : throw ( RuntimeException )
235 : : {
236 : 0 : return sal_True;
237 : : }
238 : :
239 : 0 : virtual sal_Int16 SAL_CALL getType()
240 : : throw ( RuntimeException )
241 : : {
242 : 0 : return browse::BrowseNodeTypes::CONTAINER;
243 : : }
244 : :
245 : : private:
246 : :
247 : 0 : void loadChildNodes()
248 : : {
249 [ # # ][ # # ]: 0 : m_hBNA = new BrowseNodeAggregatorHash();
250 : :
251 : : Sequence< Reference< browse::XBrowseNode > > langNodes =
252 [ # # ][ # # ]: 0 : m_origNode->getChildNodes();
253 : :
254 [ # # ]: 0 : for ( sal_Int32 i = 0; i < langNodes.getLength(); i++ )
255 : : {
256 : 0 : Reference< browse::XBrowseNode > xbn;
257 [ # # ][ # # ]: 0 : if ( langNodes[ i ]->getName() == "uno_packages" )
[ # # ][ # # ]
258 : : {
259 [ # # ][ # # ]: 0 : xbn.set( new LocationBrowseNode( langNodes[ i ] ) );
[ # # ][ # # ]
260 : : }
261 : : else
262 : : {
263 [ # # ][ # # ]: 0 : xbn.set( langNodes[ i ] );
264 : : }
265 : :
266 : : Sequence< Reference< browse::XBrowseNode > > grandchildren =
267 [ # # ][ # # ]: 0 : xbn->getChildNodes();
268 : :
269 [ # # ]: 0 : for ( sal_Int32 j = 0; j < grandchildren.getLength(); j++ )
270 : : {
271 [ # # ]: 0 : Reference< browse::XBrowseNode > grandchild(grandchildren[j]);
272 : :
273 : : BrowseNodeAggregatorHash::iterator h_it =
274 [ # # ][ # # ]: 0 : m_hBNA->find( grandchild->getName() );
[ # # ]
275 : :
276 [ # # ][ # # ]: 0 : if ( h_it != m_hBNA->end() )
277 : : {
278 [ # # ][ # # ]: 0 : BrowseNodeAggregator* bna = static_cast< BrowseNodeAggregator* >( h_it->second.get() );
[ # # ]
279 [ # # ]: 0 : bna->addBrowseNode( grandchild );
280 : : }
281 : : else
282 : : {
283 : : Reference< browse::XBrowseNode > bna(
284 [ # # ][ # # ]: 0 : new BrowseNodeAggregator( grandchild ) );
[ # # ]
285 [ # # ][ # # ]: 0 : (*m_hBNA)[ grandchild->getName() ].set( bna );
[ # # ][ # # ]
286 [ # # ][ # # ]: 0 : m_vStr.push_back( grandchild->getName() );
[ # # ]
287 : : }
288 : 0 : }
289 [ # # ]: 0 : }
290 : : // sort children alpahbetically
291 [ # # ][ # # ]: 0 : ::std::sort( m_vStr.begin(), m_vStr.end(), alphaSort() );
292 : 0 : }
293 : : };
294 : :
295 : : namespace
296 : : {
297 : :
298 : 0 : Sequence< Reference< browse::XBrowseNode > > getAllBrowseNodes( const Reference< XComponentContext >& xCtx )
299 : : {
300 : : Reference< lang::XMultiComponentFactory > mcf =
301 [ # # ][ # # ]: 0 : xCtx->getServiceManager();
302 : :
303 : : Sequence< ::rtl::OUString > openDocs =
304 [ # # ]: 0 : MiscUtils::allOpenTDocUrls( xCtx );
305 : :
306 : 0 : Reference< provider::XScriptProviderFactory > xFac;
307 : 0 : sal_Int32 initialSize = openDocs.getLength() + 2;
308 : 0 : sal_Int32 mspIndex = 0;
309 : :
310 [ # # ]: 0 : Sequence < Reference < browse::XBrowseNode > > locnBNs( initialSize );
311 : : try
312 : : {
313 : : xFac.set(
314 [ # # ]: 0 : xCtx->getValueByName(
315 [ # # ][ # # ]: 0 : OUSTR("/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY_THROW );
[ # # ]
316 : :
317 [ # # ][ # # ]: 0 : locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( ::rtl::OUString("user") ) ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ][ # # ]
318 [ # # ][ # # ]: 0 : locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( ::rtl::OUString("share") ) ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ][ # # ]
319 : : }
320 : : // TODO proper exception handling, should throw
321 [ # # # # ]: 0 : catch( const Exception& e )
322 : : {
323 : : (void)e;
324 : : OSL_TRACE("Caught Exception %s",
325 : : ::rtl::OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
326 [ # # ]: 0 : locnBNs.realloc( mspIndex );
327 [ # # ]: 0 : return locnBNs;
328 : : }
329 : :
330 [ # # ]: 0 : for ( sal_Int32 i = 0; i < openDocs.getLength(); i++ )
331 : : {
332 : : try
333 : : {
334 [ # # ][ # # ]: 0 : Reference< frame::XModel > model( MiscUtils::tDocUrlToModel( openDocs[ i ] ), UNO_QUERY_THROW );
[ # # ]
335 : :
336 : : // #i44599 Check if it's a real document or something special like Hidden/Preview
337 [ # # ][ # # ]: 0 : css::uno::Reference< css::frame::XController > xCurrentController = model->getCurrentController();
338 [ # # ]: 0 : if( xCurrentController.is() )
339 : : {
340 [ # # ][ # # ]: 0 : comphelper::MediaDescriptor aMD( model->getArgs() );
[ # # ][ # # ]
341 : 0 : sal_Bool bDefault = false;
342 [ # # ][ # # ]: 0 : sal_Bool bHidden = aMD.getUnpackedValueOrDefault( comphelper::MediaDescriptor::PROP_HIDDEN(), bDefault );
343 [ # # ][ # # ]: 0 : sal_Bool bPreview = aMD.getUnpackedValueOrDefault( comphelper::MediaDescriptor::PROP_PREVIEW(), bDefault );
344 [ # # ][ # # ]: 0 : if( !bHidden && !bPreview )
345 : : {
346 [ # # ]: 0 : Reference< document::XEmbeddedScripts > xScripts( model, UNO_QUERY );
347 [ # # ]: 0 : if ( xScripts.is() )
348 [ # # ]: 0 : locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >(
349 [ # # ][ # # ]: 0 : xFac->createScriptProvider( makeAny( model ) ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
350 [ # # ]: 0 : }
351 [ # # ]: 0 : }
352 : : }
353 [ # # ]: 0 : catch( const Exception& )
354 : : {
355 : : DBG_UNHANDLED_EXCEPTION();
356 : : }
357 : :
358 : : }
359 : :
360 [ # # ]: 0 : Sequence < Reference < browse::XBrowseNode > > locnBNs_Return( mspIndex );
361 [ # # ]: 0 : for ( sal_Int32 j = 0; j < mspIndex; j++ )
362 [ # # ][ # # ]: 0 : locnBNs_Return[j] = locnBNs[j];
[ # # ]
363 : :
364 [ # # ][ # # ]: 0 : return locnBNs_Return;
[ # # ][ # # ]
365 : : }
366 : :
367 : : } // namespace
368 : :
369 : : typedef ::std::vector< Reference< browse::XBrowseNode > > vXBrowseNodes;
370 : :
371 : : struct alphaSortForBNodes
372 : : {
373 : 0 : bool operator()( const Reference< browse::XBrowseNode >& a, const Reference< browse::XBrowseNode >& b )
374 : : {
375 [ # # ][ # # ]: 0 : return a->getName().compareTo( b->getName() ) < 0;
376 : : }
377 : : };
378 : :
379 : : typedef ::cppu::WeakImplHelper1< browse::XBrowseNode > t_BrowseNodeBase;
380 : : class DefaultBrowseNode :
381 : : public t_BrowseNodeBase
382 : : {
383 : :
384 : : private:
385 : : Reference< browse::XBrowseNode > m_xWrappedBrowseNode;
386 : : Reference< lang::XTypeProvider > m_xWrappedTypeProv;
387 : : Reference< XAggregation > m_xAggProxy;
388 : : Reference< XComponentContext > m_xCtx;
389 : :
390 : : DefaultBrowseNode();
391 : : public:
392 [ # # ][ # # ]: 0 : DefaultBrowseNode( const Reference< XComponentContext >& xCtx, const Reference< browse::XBrowseNode>& xNode ) : m_xWrappedBrowseNode( xNode ), m_xWrappedTypeProv( xNode, UNO_QUERY ), m_xCtx( xCtx, UNO_QUERY )
393 : : {
394 : : OSL_ENSURE( m_xWrappedBrowseNode.is(), "DefaultBrowseNode::DefaultBrowseNode(): No BrowseNode to wrap" );
395 : : OSL_ENSURE( m_xWrappedTypeProv.is(), "DefaultBrowseNode::DefaultBrowseNode(): No BrowseNode to wrap" );
396 : : OSL_ENSURE( m_xCtx.is(), "DefaultBrowseNode::DefaultBrowseNode(): No ComponentContext" );
397 : : // Use proxy factory service to create aggregatable proxy.
398 : : try
399 : : {
400 [ # # ][ # # ]: 0 : Reference< lang::XMultiComponentFactory > xMFac( m_xCtx->getServiceManager(), UNO_QUERY_THROW );
[ # # ]
401 : : Reference< reflection::XProxyFactory > xProxyFac(
402 [ # # ]: 0 : xMFac->createInstanceWithContext(
403 : : rtl::OUString( "com.sun.star.reflection.ProxyFactory" ),
404 [ # # ][ # # ]: 0 : m_xCtx ), UNO_QUERY_THROW );
405 [ # # ][ # # ]: 0 : m_xAggProxy = xProxyFac->createProxy( m_xWrappedBrowseNode );
[ # # ][ # # ]
406 : : }
407 [ # # ]: 0 : catch( uno::Exception& )
408 : : {
409 : : OSL_FAIL( "DefaultBrowseNode::DefaultBrowseNode: Caught exception!" );
410 : : }
411 : : OSL_ENSURE( m_xAggProxy.is(),
412 : : "DefaultBrowseNode::DefaultBrowseNode: Wrapped BrowseNode cannot be aggregated!" );
413 : :
414 [ # # ]: 0 : if ( m_xAggProxy.is() )
415 : : {
416 [ # # ]: 0 : osl_incrementInterlockedCount( &m_refCount );
417 : :
418 : : /* i35609 - Fix crash on Solaris. The setDelegator call needs
419 : : to be in its own block to ensure that all temporary Reference
420 : : instances that are acquired during the call are released
421 : : before m_refCount is decremented again */
422 : : {
423 [ # # ]: 0 : m_xAggProxy->setDelegator(
424 [ # # ][ # # ]: 0 : static_cast< cppu::OWeakObject * >( this ) );
425 : : }
426 : :
427 [ # # ]: 0 : osl_decrementInterlockedCount( &m_refCount );
428 : : }
429 : 0 : }
430 : :
431 : 0 : ~DefaultBrowseNode()
432 : 0 : {
433 [ # # ]: 0 : if ( m_xAggProxy.is() )
434 : : {
435 [ # # ][ # # ]: 0 : m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() );
436 : : }
437 [ # # ]: 0 : }
438 : :
439 : : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
440 : 0 : getChildNodes()
441 : : throw ( RuntimeException )
442 : : {
443 [ # # ]: 0 : if ( hasChildNodes() )
444 : : {
445 [ # # ]: 0 : vXBrowseNodes m_vNodes;
446 : : Sequence < Reference< browse::XBrowseNode > > nodes =
447 [ # # ][ # # ]: 0 : m_xWrappedBrowseNode->getChildNodes();
448 [ # # ]: 0 : for ( sal_Int32 i=0; i<nodes.getLength(); i++ )
449 : : {
450 [ # # ]: 0 : Reference< browse::XBrowseNode > xBrowseNode = nodes[ i ];
451 : : OSL_ENSURE( xBrowseNode.is(), "DefaultBrowseNode::getChildNodes(): Invalid BrowseNode" );
452 [ # # ]: 0 : if( xBrowseNode.is() )
453 [ # # ][ # # ]: 0 : m_vNodes.push_back( new DefaultBrowseNode( m_xCtx, xBrowseNode ) );
[ # # ][ # # ]
454 : 0 : }
455 : :
456 [ # # ]: 0 : ::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
457 [ # # ]: 0 : Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
458 [ # # ]: 0 : vXBrowseNodes::const_iterator it = m_vNodes.begin();
459 [ # # ][ # # ]: 0 : for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it )
[ # # ][ # # ]
[ # # # # ]
460 : : {
461 [ # # ][ # # ]: 0 : children[ i ].set( *it );
462 : : }
463 [ # # ][ # # ]: 0 : return children;
[ # # ]
464 : : }
465 : : else
466 : : {
467 : : // no nodes
468 : :
469 [ # # ]: 0 : Sequence < Reference< browse::XBrowseNode > > none;
470 [ # # ][ # # ]: 0 : return none;
471 : : }
472 : : }
473 : :
474 : 0 : virtual sal_Int16 SAL_CALL getType()
475 : : throw ( RuntimeException )
476 : : {
477 : 0 : return m_xWrappedBrowseNode->getType();
478 : : }
479 : :
480 : : virtual ::rtl::OUString
481 : 0 : SAL_CALL getName()
482 : : throw ( RuntimeException )
483 : : {
484 : 0 : return m_xWrappedBrowseNode->getName();
485 : : }
486 : :
487 : : virtual sal_Bool SAL_CALL
488 : 0 : hasChildNodes()
489 : : throw ( RuntimeException )
490 : : {
491 : 0 : return m_xWrappedBrowseNode->hasChildNodes();
492 : : }
493 : :
494 : : // XInterface
495 : 0 : virtual Any SAL_CALL queryInterface( const Type& aType )
496 : : throw ( com::sun::star::uno::RuntimeException )
497 : : {
498 [ # # ]: 0 : Any aRet = t_BrowseNodeBase::queryInterface( aType );
499 [ # # ]: 0 : if ( aRet.hasValue() )
500 : : {
501 : 0 : return aRet;
502 : : }
503 [ # # ]: 0 : if ( m_xAggProxy.is() )
504 : : {
505 [ # # ][ # # ]: 0 : return m_xAggProxy->queryAggregation( aType );
506 : : }
507 : : else
508 : : {
509 : 0 : return Any();
510 : 0 : }
511 : : }
512 : :
513 : 0 : virtual void SAL_CALL acquire()
514 : : throw ()
515 : :
516 : : {
517 : 0 : osl_incrementInterlockedCount( &m_refCount );
518 : 0 : }
519 : 0 : virtual void SAL_CALL release()
520 : : throw ()
521 : : {
522 [ # # ]: 0 : if ( osl_decrementInterlockedCount( &m_refCount ) == 0 )
523 : : {
524 [ # # ]: 0 : delete this;
525 : : }
526 : 0 : }
527 : : // XTypeProvider (implemnented by base, but needs to be overridden for
528 : : // delegating to aggregate)
529 : 0 : virtual Sequence< Type > SAL_CALL getTypes()
530 : : throw ( com::sun::star::uno::RuntimeException )
531 : : {
532 : 0 : return m_xWrappedTypeProv->getTypes();
533 : : }
534 : 0 : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId()
535 : : throw ( com::sun::star::uno::RuntimeException )
536 : : {
537 : 0 : return m_xWrappedTypeProv->getImplementationId();
538 : :
539 : : }
540 : : };
541 : :
542 : : class DefaultRootBrowseNode :
543 : : public ::cppu::WeakImplHelper1< browse::XBrowseNode >
544 : : {
545 : :
546 : : private:
547 : : vXBrowseNodes m_vNodes;
548 : : ::rtl::OUString m_Name;
549 : :
550 : : DefaultRootBrowseNode();
551 : : public:
552 : 0 : DefaultRootBrowseNode( const Reference< XComponentContext >& xCtx )
553 [ # # ]: 0 : {
554 : : Sequence < Reference< browse::XBrowseNode > > nodes =
555 [ # # ]: 0 : getAllBrowseNodes( xCtx );
556 : :
557 [ # # ]: 0 : for ( sal_Int32 i=0; i<nodes.getLength(); i++ )
558 : : {
559 [ # # ][ # # ]: 0 : m_vNodes.push_back( new DefaultBrowseNode( xCtx, nodes[ i ] ) );
[ # # ][ # # ]
[ # # ]
560 : : }
561 [ # # ]: 0 : m_Name = ::rtl::OUString("Root");
562 : 0 : }
563 : :
564 : 0 : ~DefaultRootBrowseNode()
565 : 0 : {
566 [ # # ]: 0 : }
567 : :
568 : : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
569 : 0 : getChildNodes()
570 : : throw ( RuntimeException )
571 : : {
572 : : // no need to sort user, share, doc1...docN
573 : : //::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
574 [ # # ]: 0 : Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
575 [ # # ]: 0 : vXBrowseNodes::const_iterator it = m_vNodes.begin();
576 [ # # ][ # # ]: 0 : for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it )
[ # # ][ # # ]
[ # # ][ # # ]
577 : : {
578 [ # # ][ # # ]: 0 : children[ i ].set( *it );
579 : : }
580 : 0 : return children;
581 : : }
582 : :
583 : 0 : virtual sal_Int16 SAL_CALL getType()
584 : : throw ( RuntimeException )
585 : : {
586 : 0 : return browse::BrowseNodeTypes::ROOT;
587 : : }
588 : :
589 : : virtual ::rtl::OUString
590 : 0 : SAL_CALL getName()
591 : : throw ( RuntimeException )
592 : : {
593 : 0 : return m_Name;
594 : : }
595 : :
596 : : virtual sal_Bool SAL_CALL
597 : 0 : hasChildNodes()
598 : : throw ( RuntimeException )
599 : : {
600 : 0 : sal_Bool result = sal_True;
601 [ # # ]: 0 : if ( !m_vNodes.size() )
602 : : {
603 : 0 : result = sal_False;
604 : : }
605 : 0 : return result;
606 : : }
607 : : };
608 : :
609 : :
610 : : class SelectorBrowseNode :
611 : : public ::cppu::WeakImplHelper1< browse::XBrowseNode >
612 : : {
613 : : private:
614 : : Reference< XComponentContext > m_xComponentContext;
615 : :
616 : : public:
617 : 0 : SelectorBrowseNode( const Reference< XComponentContext >& xContext )
618 : 0 : : m_xComponentContext( xContext )
619 : : {
620 : 0 : }
621 : :
622 : 0 : ~SelectorBrowseNode()
623 : 0 : {
624 [ # # ]: 0 : }
625 : :
626 : 0 : virtual ::rtl::OUString SAL_CALL getName()
627 : : throw ( RuntimeException )
628 : : {
629 : 0 : return ::rtl::OUString("Root");
630 : : }
631 : :
632 : : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
633 : 0 : getChildNodes()
634 : : throw ( RuntimeException )
635 : : {
636 : :
637 [ # # ]: 0 : Sequence < Reference < browse::XBrowseNode > > locnBNs = getAllBrowseNodes( m_xComponentContext );
638 : :
639 : : Sequence< Reference< browse::XBrowseNode > > children(
640 [ # # ]: 0 : locnBNs.getLength() );
641 : :
642 [ # # ]: 0 : for ( sal_Int32 j = 0; j < locnBNs.getLength(); j++ )
643 : : {
644 [ # # ][ # # ]: 0 : children[j] = new LocationBrowseNode( locnBNs[j] );
[ # # ][ # # ]
[ # # ]
645 : : }
646 : :
647 [ # # ]: 0 : return children;
648 : : }
649 : :
650 : 0 : virtual sal_Bool SAL_CALL hasChildNodes()
651 : : throw ( RuntimeException )
652 : : {
653 : 0 : return sal_True; // will always be user and share
654 : : }
655 : :
656 : 0 : virtual sal_Int16 SAL_CALL getType()
657 : : throw ( RuntimeException )
658 : : {
659 : 0 : return browse::BrowseNodeTypes::CONTAINER;
660 : : }
661 : : };
662 : :
663 : 0 : BrowseNodeFactoryImpl::BrowseNodeFactoryImpl(
664 : : Reference< XComponentContext > const & xComponentContext )
665 : 0 : : m_xComponentContext( xComponentContext )
666 : : {
667 : 0 : }
668 : :
669 : 0 : BrowseNodeFactoryImpl::~BrowseNodeFactoryImpl()
670 : : {
671 [ # # ]: 0 : }
672 : :
673 : :
674 : : //############################################################################
675 : : // Implementation of XBrowseNodeFactory
676 : : //############################################################################
677 : :
678 : : /*
679 : : * The selector hierarchy is the standard hierarchy for organizers with the
680 : : * language nodes removed.
681 : : */
682 : : Reference< browse::XBrowseNode > SAL_CALL
683 : 0 : BrowseNodeFactoryImpl::createView( sal_Int16 viewType )
684 : : throw (RuntimeException)
685 : : {
686 [ # # # ]: 0 : switch( viewType )
687 : : {
688 : : case browse::BrowseNodeFactoryViewTypes::MACROSELECTOR:
689 : 0 : return getSelectorHierarchy();
690 : : case browse::BrowseNodeFactoryViewTypes::MACROORGANIZER:
691 : 0 : return getOrganizerHierarchy();
692 : : default:
693 [ # # ][ # # ]: 0 : throw RuntimeException( OUSTR("Unknown view type" ), Reference< XInterface >() );
694 : : }
695 : : }
696 : :
697 : : Reference< browse::XBrowseNode >
698 : 0 : BrowseNodeFactoryImpl::getSelectorHierarchy()
699 : : throw (RuntimeException)
700 : : {
701 : : /*if ( !m_xSelectorBrowseNode.is() )
702 : : {
703 : : m_xSelectorBrowseNode = new SelectorBrowseNode( m_xComponentContext );
704 : : }*/
705 [ # # ][ # # ]: 0 : return new SelectorBrowseNode( m_xComponentContext );
706 : : }
707 : :
708 : : Reference< browse::XBrowseNode >
709 : 0 : BrowseNodeFactoryImpl::getOrganizerHierarchy()
710 : : throw (RuntimeException)
711 : : {
712 [ # # ][ # # ]: 0 : Reference< browse::XBrowseNode > xRet = new DefaultRootBrowseNode( m_xComponentContext );
[ # # ]
713 : 0 : return xRet;
714 : : }
715 : : //############################################################################
716 : : // Helper methods
717 : : //############################################################################
718 : :
719 : : //############################################################################
720 : : // Namespace global methods for setting up BrowseNodeFactory service
721 : : //############################################################################
722 : :
723 : : Sequence< ::rtl::OUString > SAL_CALL
724 : 0 : bnf_getSupportedServiceNames( )
725 : : SAL_THROW(())
726 : : {
727 : : ::rtl::OUString str_name(
728 : 0 : "com.sun.star.script.browse.BrowseNodeFactory");
729 : :
730 [ # # ]: 0 : return Sequence< ::rtl::OUString >( &str_name, 1 );
731 : : }
732 : :
733 : : ::rtl::OUString SAL_CALL
734 : 18 : bnf_getImplementationName( )
735 : : SAL_THROW(())
736 : : {
737 : : return ::rtl::OUString(
738 : 18 : "com.sun.star.script.browse.BrowseNodeFactory" );
739 : : }
740 : :
741 : : Reference< XInterface > SAL_CALL
742 : 0 : bnf_create( Reference< XComponentContext > const & xComponentContext )
743 : : SAL_THROW( (Exception) )
744 : : {
745 : : return static_cast< ::cppu::OWeakObject * >(
746 [ # # ]: 0 : new BrowseNodeFactoryImpl( xComponentContext ) );
747 : : }
748 : :
749 : : //############################################################################
750 : : // Implementation of XServiceInfo
751 : : //############################################################################
752 : :
753 : : ::rtl::OUString SAL_CALL
754 : 0 : BrowseNodeFactoryImpl::getImplementationName()
755 : : throw (RuntimeException)
756 : : {
757 : 0 : return bnf_getImplementationName();
758 : : }
759 : :
760 : : Sequence< ::rtl::OUString > SAL_CALL
761 : 0 : BrowseNodeFactoryImpl::getSupportedServiceNames()
762 : : throw (RuntimeException)
763 : : {
764 : 0 : return bnf_getSupportedServiceNames();
765 : : }
766 : :
767 : 0 : sal_Bool BrowseNodeFactoryImpl::supportsService(
768 : : ::rtl::OUString const & serviceName )
769 : : throw (RuntimeException)
770 : : {
771 : : // check();
772 : :
773 : : Sequence< ::rtl::OUString > supported_services(
774 [ # # ]: 0 : getSupportedServiceNames() );
775 : :
776 : 0 : ::rtl::OUString const * ar = supported_services.getConstArray();
777 : :
778 [ # # ]: 0 : for ( sal_Int32 pos = supported_services.getLength(); pos--; )
779 : : {
780 [ # # ]: 0 : if (ar[ pos ].equals( serviceName ))
781 : 0 : return sal_True;
782 : : }
783 [ # # ]: 0 : return sal_False;
784 : : }
785 : :
786 : : } // namespace browsenodefactory
787 : :
788 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|