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