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 <cppuhelper/supportsservice.hxx>
27 : #include <unotools/mediadescriptor.hxx>
28 :
29 : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
30 : #include <com/sun/star/frame/XModel.hpp>
31 : #include <com/sun/star/reflection/ProxyFactory.hpp>
32 :
33 : #include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
34 : #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
35 : #include <com/sun/star/document/XScriptInvocationContext.hpp>
36 :
37 : #include <tools/diagnose_ex.h>
38 :
39 : #include "BrowseNodeFactoryImpl.hxx"
40 : #include "ActiveMSPList.hxx"
41 : #include <util/MiscUtils.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 : 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 : virtual ~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 OUString
81 0 : SAL_CALL getName()
82 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
83 : {
84 0 : return m_Name;
85 : }
86 :
87 : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
88 0 : getChildNodes()
89 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
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, std::exception ) SAL_OVERRIDE
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, std::exception ) SAL_OVERRIDE
155 : {
156 0 : return browse::BrowseNodeTypes::CONTAINER;
157 : }
158 : };
159 :
160 :
161 : //typedef ::std::map< OUString, Reference< browse::XBrowseNode > >
162 : typedef ::boost::unordered_map< OUString, Reference< browse::XBrowseNode >,
163 : OUStringHash, ::std::equal_to< OUString > >
164 : BrowseNodeAggregatorHash;
165 : typedef ::std::vector< OUString > vString;
166 :
167 :
168 : struct alphaSort
169 : {
170 0 : bool operator()( const OUString& a, const 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 : 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 : virtual ~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 OUString SAL_CALL getName()
206 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
207 : {
208 0 : return m_sNodeName;
209 : }
210 :
211 : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
212 0 : getChildNodes()
213 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
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, std::exception ) SAL_OVERRIDE
235 : {
236 0 : return sal_True;
237 : }
238 :
239 0 : virtual sal_Int16 SAL_CALL getType()
240 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
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 : Sequence< OUString > openDocs =
301 0 : MiscUtils::allOpenTDocUrls( xCtx );
302 :
303 0 : Reference< provider::XScriptProviderFactory > xFac;
304 0 : sal_Int32 initialSize = openDocs.getLength() + 2;
305 0 : sal_Int32 mspIndex = 0;
306 :
307 0 : Sequence < Reference < browse::XBrowseNode > > locnBNs( initialSize );
308 : try
309 : {
310 0 : xFac = provider::theMasterScriptProviderFactory::get( xCtx );
311 :
312 0 : locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( OUString("user") ) ), UNO_QUERY_THROW );
313 0 : locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( OUString("share") ) ), UNO_QUERY_THROW );
314 : }
315 : // TODO proper exception handling, should throw
316 0 : catch( const Exception& e )
317 : {
318 : (void)e;
319 : OSL_TRACE("Caught Exception %s",
320 : OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
321 0 : locnBNs.realloc( mspIndex );
322 0 : return locnBNs;
323 : }
324 :
325 0 : for ( sal_Int32 i = 0; i < openDocs.getLength(); i++ )
326 : {
327 : try
328 : {
329 0 : Reference< frame::XModel > model( MiscUtils::tDocUrlToModel( openDocs[ i ] ), UNO_QUERY_THROW );
330 :
331 : // #i44599 Check if it's a real document or something special like Hidden/Preview
332 0 : css::uno::Reference< css::frame::XController > xCurrentController = model->getCurrentController();
333 0 : if( xCurrentController.is() )
334 : {
335 0 : utl::MediaDescriptor aMD( model->getArgs() );
336 0 : sal_Bool bDefault = false;
337 0 : sal_Bool bHidden = aMD.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_HIDDEN(), bDefault );
338 0 : sal_Bool bPreview = aMD.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_PREVIEW(), bDefault );
339 0 : if( !bHidden && !bPreview )
340 : {
341 0 : Reference< document::XEmbeddedScripts > xScripts( model, UNO_QUERY );
342 0 : if ( xScripts.is() )
343 0 : locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >(
344 0 : xFac->createScriptProvider( makeAny( model ) ), UNO_QUERY_THROW );
345 0 : }
346 0 : }
347 : }
348 0 : catch( const Exception& )
349 : {
350 : DBG_UNHANDLED_EXCEPTION();
351 : }
352 :
353 : }
354 :
355 0 : Sequence < Reference < browse::XBrowseNode > > locnBNs_Return( mspIndex );
356 0 : for ( sal_Int32 j = 0; j < mspIndex; j++ )
357 0 : locnBNs_Return[j] = locnBNs[j];
358 :
359 0 : return locnBNs_Return;
360 : }
361 :
362 : } // namespace
363 :
364 : typedef ::std::vector< Reference< browse::XBrowseNode > > vXBrowseNodes;
365 :
366 : struct alphaSortForBNodes
367 : {
368 0 : bool operator()( const Reference< browse::XBrowseNode >& a, const Reference< browse::XBrowseNode >& b )
369 : {
370 0 : return a->getName().compareTo( b->getName() ) < 0;
371 : }
372 : };
373 :
374 : typedef ::cppu::WeakImplHelper1< browse::XBrowseNode > t_BrowseNodeBase;
375 : class DefaultBrowseNode :
376 : public t_BrowseNodeBase
377 : {
378 :
379 : private:
380 : Reference< browse::XBrowseNode > m_xWrappedBrowseNode;
381 : Reference< lang::XTypeProvider > m_xWrappedTypeProv;
382 : Reference< XAggregation > m_xAggProxy;
383 : Reference< XComponentContext > m_xCtx;
384 :
385 : DefaultBrowseNode();
386 : public:
387 0 : DefaultBrowseNode( const Reference< XComponentContext >& xCtx, const Reference< browse::XBrowseNode>& xNode ) : m_xWrappedBrowseNode( xNode ), m_xWrappedTypeProv( xNode, UNO_QUERY ), m_xCtx( xCtx )
388 : {
389 : OSL_ENSURE( m_xWrappedBrowseNode.is(), "DefaultBrowseNode::DefaultBrowseNode(): No BrowseNode to wrap" );
390 : OSL_ENSURE( m_xWrappedTypeProv.is(), "DefaultBrowseNode::DefaultBrowseNode(): No BrowseNode to wrap" );
391 : OSL_ENSURE( m_xCtx.is(), "DefaultBrowseNode::DefaultBrowseNode(): No ComponentContext" );
392 : // Use proxy factory service to create aggregatable proxy.
393 : try
394 : {
395 : Reference< reflection::XProxyFactory > xProxyFac =
396 0 : reflection::ProxyFactory::create( m_xCtx );
397 0 : m_xAggProxy = xProxyFac->createProxy( m_xWrappedBrowseNode );
398 : }
399 0 : catch( uno::Exception& )
400 : {
401 : OSL_FAIL( "DefaultBrowseNode::DefaultBrowseNode: Caught exception!" );
402 : }
403 : OSL_ENSURE( m_xAggProxy.is(),
404 : "DefaultBrowseNode::DefaultBrowseNode: Wrapped BrowseNode cannot be aggregated!" );
405 :
406 0 : if ( m_xAggProxy.is() )
407 : {
408 0 : osl_atomic_increment( &m_refCount );
409 :
410 : /* i35609 - Fix crash on Solaris. The setDelegator call needs
411 : to be in its own block to ensure that all temporary Reference
412 : instances that are acquired during the call are released
413 : before m_refCount is decremented again */
414 : {
415 0 : m_xAggProxy->setDelegator(
416 0 : static_cast< cppu::OWeakObject * >( this ) );
417 : }
418 :
419 0 : osl_atomic_decrement( &m_refCount );
420 : }
421 0 : }
422 :
423 0 : virtual ~DefaultBrowseNode()
424 0 : {
425 0 : if ( m_xAggProxy.is() )
426 : {
427 0 : m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() );
428 : }
429 0 : }
430 :
431 : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
432 0 : getChildNodes()
433 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
434 : {
435 0 : if ( hasChildNodes() )
436 : {
437 0 : vXBrowseNodes m_vNodes;
438 : Sequence < Reference< browse::XBrowseNode > > nodes =
439 0 : m_xWrappedBrowseNode->getChildNodes();
440 0 : for ( sal_Int32 i=0; i<nodes.getLength(); i++ )
441 : {
442 0 : Reference< browse::XBrowseNode > xBrowseNode = nodes[ i ];
443 : OSL_ENSURE( xBrowseNode.is(), "DefaultBrowseNode::getChildNodes(): Invalid BrowseNode" );
444 0 : if( xBrowseNode.is() )
445 0 : m_vNodes.push_back( new DefaultBrowseNode( m_xCtx, xBrowseNode ) );
446 0 : }
447 :
448 0 : ::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
449 0 : Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
450 0 : vXBrowseNodes::const_iterator it = m_vNodes.begin();
451 0 : for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it )
452 : {
453 0 : children[ i ].set( *it );
454 : }
455 0 : return children;
456 : }
457 : else
458 : {
459 : // no nodes
460 :
461 0 : Sequence < Reference< browse::XBrowseNode > > none;
462 0 : return none;
463 : }
464 : }
465 :
466 0 : virtual sal_Int16 SAL_CALL getType()
467 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
468 : {
469 0 : return m_xWrappedBrowseNode->getType();
470 : }
471 :
472 : virtual OUString
473 0 : SAL_CALL getName()
474 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
475 : {
476 0 : return m_xWrappedBrowseNode->getName();
477 : }
478 :
479 : virtual sal_Bool SAL_CALL
480 0 : hasChildNodes()
481 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
482 : {
483 0 : return m_xWrappedBrowseNode->hasChildNodes();
484 : }
485 :
486 : // XInterface
487 0 : virtual Any SAL_CALL queryInterface( const Type& aType )
488 : throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
489 : {
490 0 : Any aRet = t_BrowseNodeBase::queryInterface( aType );
491 0 : if ( aRet.hasValue() )
492 : {
493 0 : return aRet;
494 : }
495 0 : if ( m_xAggProxy.is() )
496 : {
497 0 : return m_xAggProxy->queryAggregation( aType );
498 : }
499 : else
500 : {
501 0 : return Any();
502 0 : }
503 : }
504 :
505 0 : virtual void SAL_CALL acquire()
506 : throw () SAL_OVERRIDE
507 :
508 : {
509 0 : osl_atomic_increment( &m_refCount );
510 0 : }
511 0 : virtual void SAL_CALL release()
512 : throw () SAL_OVERRIDE
513 : {
514 0 : if ( osl_atomic_decrement( &m_refCount ) == 0 )
515 : {
516 0 : delete this;
517 : }
518 0 : }
519 : // XTypeProvider (implemnented by base, but needs to be overridden for
520 : // delegating to aggregate)
521 0 : virtual Sequence< Type > SAL_CALL getTypes()
522 : throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
523 : {
524 0 : return m_xWrappedTypeProv->getTypes();
525 : }
526 0 : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId()
527 : throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
528 : {
529 0 : return css::uno::Sequence<sal_Int8>();
530 : }
531 : };
532 :
533 : class DefaultRootBrowseNode :
534 : public ::cppu::WeakImplHelper1< browse::XBrowseNode >
535 : {
536 :
537 : private:
538 : vXBrowseNodes m_vNodes;
539 : OUString m_Name;
540 :
541 : DefaultRootBrowseNode();
542 : public:
543 0 : DefaultRootBrowseNode( const Reference< XComponentContext >& xCtx )
544 0 : {
545 : Sequence < Reference< browse::XBrowseNode > > nodes =
546 0 : getAllBrowseNodes( xCtx );
547 :
548 0 : for ( sal_Int32 i=0; i<nodes.getLength(); i++ )
549 : {
550 0 : m_vNodes.push_back( new DefaultBrowseNode( xCtx, nodes[ i ] ) );
551 : }
552 0 : m_Name = "Root";
553 0 : }
554 :
555 0 : virtual ~DefaultRootBrowseNode()
556 0 : {
557 0 : }
558 :
559 : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
560 0 : getChildNodes()
561 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
562 : {
563 : // no need to sort user, share, doc1...docN
564 : //::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
565 0 : Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
566 0 : vXBrowseNodes::const_iterator it = m_vNodes.begin();
567 0 : for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it )
568 : {
569 0 : children[ i ].set( *it );
570 : }
571 0 : return children;
572 : }
573 :
574 0 : virtual sal_Int16 SAL_CALL getType()
575 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
576 : {
577 0 : return browse::BrowseNodeTypes::ROOT;
578 : }
579 :
580 : virtual OUString
581 0 : SAL_CALL getName()
582 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
583 : {
584 0 : return m_Name;
585 : }
586 :
587 : virtual sal_Bool SAL_CALL
588 0 : hasChildNodes()
589 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
590 : {
591 0 : sal_Bool result = sal_True;
592 0 : if ( !m_vNodes.size() )
593 : {
594 0 : result = sal_False;
595 : }
596 0 : return result;
597 : }
598 : };
599 :
600 :
601 : class SelectorBrowseNode :
602 : public ::cppu::WeakImplHelper1< browse::XBrowseNode >
603 : {
604 : private:
605 : Reference< XComponentContext > m_xComponentContext;
606 :
607 : public:
608 0 : SelectorBrowseNode( const Reference< XComponentContext >& xContext )
609 0 : : m_xComponentContext( xContext )
610 : {
611 0 : }
612 :
613 0 : virtual ~SelectorBrowseNode()
614 0 : {
615 0 : }
616 :
617 0 : virtual OUString SAL_CALL getName()
618 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
619 : {
620 0 : return OUString("Root");
621 : }
622 :
623 : virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
624 0 : getChildNodes()
625 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
626 : {
627 :
628 0 : Sequence < Reference < browse::XBrowseNode > > locnBNs = getAllBrowseNodes( m_xComponentContext );
629 :
630 : Sequence< Reference< browse::XBrowseNode > > children(
631 0 : locnBNs.getLength() );
632 :
633 0 : for ( sal_Int32 j = 0; j < locnBNs.getLength(); j++ )
634 : {
635 0 : children[j] = new LocationBrowseNode( locnBNs[j] );
636 : }
637 :
638 0 : return children;
639 : }
640 :
641 0 : virtual sal_Bool SAL_CALL hasChildNodes()
642 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
643 : {
644 0 : return sal_True; // will always be user and share
645 : }
646 :
647 0 : virtual sal_Int16 SAL_CALL getType()
648 : throw ( RuntimeException, std::exception ) SAL_OVERRIDE
649 : {
650 0 : return browse::BrowseNodeTypes::CONTAINER;
651 : }
652 : };
653 :
654 0 : BrowseNodeFactoryImpl::BrowseNodeFactoryImpl(
655 : Reference< XComponentContext > const & xComponentContext )
656 0 : : m_xComponentContext( xComponentContext )
657 : {
658 0 : }
659 :
660 0 : BrowseNodeFactoryImpl::~BrowseNodeFactoryImpl()
661 : {
662 0 : }
663 :
664 :
665 :
666 : // Implementation of XBrowseNodeFactory
667 :
668 :
669 : /*
670 : * The selector hierarchy is the standard hierarchy for organizers with the
671 : * language nodes removed.
672 : */
673 : Reference< browse::XBrowseNode > SAL_CALL
674 0 : BrowseNodeFactoryImpl::createView( sal_Int16 viewType )
675 : throw (RuntimeException, std::exception)
676 : {
677 0 : switch( viewType )
678 : {
679 : case browse::BrowseNodeFactoryViewTypes::MACROSELECTOR:
680 0 : return getSelectorHierarchy();
681 : case browse::BrowseNodeFactoryViewTypes::MACROORGANIZER:
682 0 : return getOrganizerHierarchy();
683 : default:
684 0 : throw RuntimeException( "Unknown view type", Reference< XInterface >() );
685 : }
686 : }
687 :
688 : Reference< browse::XBrowseNode >
689 0 : BrowseNodeFactoryImpl::getSelectorHierarchy()
690 : throw (RuntimeException)
691 : {
692 : /*if ( !m_xSelectorBrowseNode.is() )
693 : {
694 : m_xSelectorBrowseNode = new SelectorBrowseNode( m_xComponentContext );
695 : }*/
696 0 : return new SelectorBrowseNode( m_xComponentContext );
697 : }
698 :
699 : Reference< browse::XBrowseNode >
700 0 : BrowseNodeFactoryImpl::getOrganizerHierarchy()
701 : throw (RuntimeException)
702 : {
703 0 : Reference< browse::XBrowseNode > xRet = new DefaultRootBrowseNode( m_xComponentContext );
704 0 : return xRet;
705 : }
706 :
707 : // Helper methods
708 :
709 :
710 :
711 : // Namespace global methods for setting up BrowseNodeFactory service
712 :
713 :
714 : Sequence< OUString > SAL_CALL
715 0 : bnf_getSupportedServiceNames( )
716 : SAL_THROW(())
717 : {
718 : OUString str_name(
719 0 : "com.sun.star.script.browse.BrowseNodeFactory");
720 :
721 0 : return Sequence< OUString >( &str_name, 1 );
722 : }
723 :
724 : OUString SAL_CALL
725 0 : bnf_getImplementationName( )
726 : SAL_THROW(())
727 : {
728 : return OUString(
729 0 : "com.sun.star.script.browse.BrowseNodeFactory" );
730 : }
731 :
732 : Reference< XInterface > SAL_CALL
733 0 : bnf_create( Reference< XComponentContext > const & xComponentContext )
734 : SAL_THROW( (Exception) )
735 : {
736 : return static_cast< ::cppu::OWeakObject * >(
737 0 : new BrowseNodeFactoryImpl( xComponentContext ) );
738 : }
739 :
740 :
741 : // Implementation of XServiceInfo
742 :
743 :
744 : OUString SAL_CALL
745 0 : BrowseNodeFactoryImpl::getImplementationName()
746 : throw (RuntimeException, std::exception)
747 : {
748 0 : return bnf_getImplementationName();
749 : }
750 :
751 : Sequence< OUString > SAL_CALL
752 0 : BrowseNodeFactoryImpl::getSupportedServiceNames()
753 : throw (RuntimeException, std::exception)
754 : {
755 0 : return bnf_getSupportedServiceNames();
756 : }
757 :
758 0 : sal_Bool BrowseNodeFactoryImpl::supportsService(OUString const & serviceName )
759 : throw (RuntimeException, std::exception)
760 : {
761 0 : return cppu::supportsService(this, serviceName);
762 : }
763 :
764 : } // namespace browsenodefactory
765 :
766 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|