LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/scripting/source/provider - BrowseNodeFactoryImpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 262 0.8 %
Date: 2013-07-09 Functions: 1 57 1.8 %
Legend: Lines: hit not hit

          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/ProxyFactory.hpp>
      31             : 
      32             : #include <com/sun/star/script/provider/theMasterScriptProviderFactory.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             : 
      42             : #include <vector>
      43             : #include <algorithm>
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::uno;
      46             : using namespace ::com::sun::star::script;
      47             : using namespace ::sf_misc;
      48             : 
      49             : namespace browsenodefactory
      50             : {
      51             : class BrowseNodeAggregator :
      52             :     public ::cppu::WeakImplHelper1< browse::XBrowseNode >
      53             : {
      54             : private:
      55             :     OUString m_Name;
      56             :     Sequence< Reference< browse::XBrowseNode > > m_Nodes;
      57             : 
      58             : public:
      59             : 
      60           0 :     BrowseNodeAggregator( const Reference< browse::XBrowseNode >& node )
      61           0 :     {
      62           0 :         m_Name = node->getName();
      63           0 :         m_Nodes.realloc( 1 );
      64           0 :         m_Nodes[ 0 ] = node;
      65           0 :     }
      66             : 
      67           0 :     ~BrowseNodeAggregator()
      68           0 :     {
      69           0 :     }
      70             : 
      71           0 :     void addBrowseNode( const Reference< browse::XBrowseNode>& node )
      72             :     {
      73           0 :         sal_Int32 index = m_Nodes.getLength();
      74             : 
      75           0 :         m_Nodes.realloc( index + 1 );
      76           0 :         m_Nodes[ index ] = node;
      77           0 :     }
      78             : 
      79             :     virtual OUString
      80           0 :     SAL_CALL getName()
      81             :             throw ( RuntimeException )
      82             :     {
      83           0 :         return m_Name;
      84             :     }
      85             : 
      86             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
      87           0 :     getChildNodes()
      88             :         throw ( RuntimeException )
      89             :     {
      90           0 :         std::vector<  Sequence< Reference < browse::XBrowseNode > > > seqs;
      91           0 :         seqs.reserve( m_Nodes.getLength() );
      92             : 
      93           0 :         sal_Int32 numChildren = 0;
      94             : 
      95           0 :         for ( sal_Int32 i = 0; i < m_Nodes.getLength(); i++ )
      96             :         {
      97           0 :             Sequence< Reference < browse::XBrowseNode > > children;
      98             :             try
      99             :             {
     100           0 :                 children = m_Nodes[ i ]->getChildNodes();
     101           0 :                 seqs.push_back( children );
     102           0 :                 numChildren += children.getLength();
     103             :             }
     104           0 :             catch ( Exception& )
     105             :             {
     106             :                 // some form of exception getting child nodes so they
     107             :                 // won't be displayed
     108             :             }
     109           0 :         }
     110             : 
     111           0 :         std::vector<  Sequence< Reference < browse::XBrowseNode > > >::const_iterator it = seqs.begin();
     112           0 :         std::vector<  Sequence< Reference < browse::XBrowseNode > > >::const_iterator it_end = seqs.end();
     113             : 
     114           0 :         Sequence< Reference < browse::XBrowseNode > > result( numChildren );
     115           0 :         for ( sal_Int32 index = 0; it != it_end && index < numChildren ; ++it )
     116             :         {
     117           0 :             Sequence< Reference < browse::XBrowseNode > > children = *it;
     118           0 :             for ( sal_Int32 j = 0; j < children.getLength(); j++ )
     119             :             {
     120           0 :                 result[ index++ ] = children[ j ];
     121             :             }
     122           0 :         }
     123           0 :         return result;
     124             :     }
     125             : 
     126             :     virtual sal_Bool SAL_CALL
     127           0 :     hasChildNodes()
     128             :         throw ( RuntimeException )
     129             :     {
     130           0 :         if ( m_Nodes.getLength() != 0 )
     131             :         {
     132           0 :             for ( sal_Int32 i = 0 ; i < m_Nodes.getLength(); i++ )
     133             :             {
     134             :                 try
     135             :                 {
     136           0 :                     if ( m_Nodes[ i ]->hasChildNodes() )
     137             :                     {
     138           0 :                         return sal_True;
     139             :                     }
     140             :                 }
     141           0 :                 catch ( Exception& )
     142             :                 {
     143             :                     // some form of exception getting child nodes so move
     144             :                     // on to the next one
     145             :                 }
     146             :             }
     147             :         }
     148             : 
     149           0 :         return sal_False;
     150             :     }
     151             : 
     152           0 :     virtual sal_Int16 SAL_CALL getType()
     153             :         throw ( RuntimeException )
     154             :     {
     155           0 :         return browse::BrowseNodeTypes::CONTAINER;
     156             :     }
     157             : };
     158             : 
     159             : 
     160             : //typedef ::std::map< OUString, Reference< browse::XBrowseNode > >
     161             : typedef ::boost::unordered_map< OUString, Reference< browse::XBrowseNode >,
     162             :     OUStringHash, ::std::equal_to< OUString > >
     163             :         BrowseNodeAggregatorHash;
     164             : typedef ::std::vector< OUString > vString;
     165             : 
     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 :     ~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 )
     206             :     {
     207           0 :         return m_sNodeName;
     208             :     }
     209             : 
     210             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     211           0 :     getChildNodes()
     212             :         throw ( RuntimeException )
     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 )
     234             :     {
     235           0 :         return sal_True;
     236             :     }
     237             : 
     238           0 :     virtual sal_Int16 SAL_CALL getType()
     239             :         throw ( RuntimeException )
     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 :                 comphelper::MediaDescriptor aMD( model->getArgs() );
     335           0 :                 sal_Bool bDefault = false;
     336           0 :                 sal_Bool bHidden  = aMD.getUnpackedValueOrDefault( comphelper::MediaDescriptor::PROP_HIDDEN(),  bDefault );
     337           0 :                 sal_Bool bPreview = aMD.getUnpackedValueOrDefault( comphelper::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             :     DefaultBrowseNode();
     385             : public:
     386           0 :     DefaultBrowseNode( const Reference< XComponentContext >& xCtx, const Reference< browse::XBrowseNode>& xNode ) : m_xWrappedBrowseNode( xNode ), m_xWrappedTypeProv( xNode, UNO_QUERY ), m_xCtx( xCtx )
     387             :     {
     388             :         OSL_ENSURE( m_xWrappedBrowseNode.is(), "DefaultBrowseNode::DefaultBrowseNode(): No BrowseNode to wrap" );
     389             :         OSL_ENSURE( m_xWrappedTypeProv.is(), "DefaultBrowseNode::DefaultBrowseNode(): No BrowseNode to wrap" );
     390             :         OSL_ENSURE( m_xCtx.is(), "DefaultBrowseNode::DefaultBrowseNode(): No ComponentContext" );
     391             :     // Use proxy factory service to create aggregatable proxy.
     392             :         try
     393             :         {
     394             :             Reference< reflection::XProxyFactory > xProxyFac =
     395           0 :                 reflection::ProxyFactory::create( m_xCtx );
     396           0 :             m_xAggProxy = xProxyFac->createProxy( m_xWrappedBrowseNode );
     397             :         }
     398           0 :         catch(  uno::Exception& )
     399             :         {
     400             :             OSL_FAIL( "DefaultBrowseNode::DefaultBrowseNode: Caught exception!" );
     401             :         }
     402             :         OSL_ENSURE( m_xAggProxy.is(),
     403             :             "DefaultBrowseNode::DefaultBrowseNode: Wrapped BrowseNode cannot be aggregated!" );
     404             : 
     405           0 :         if ( m_xAggProxy.is() )
     406             :         {
     407           0 :             osl_atomic_increment( &m_refCount );
     408             : 
     409             :             /* i35609 - Fix crash on Solaris. The setDelegator call needs
     410             :                to be in its own block to ensure that all temporary Reference
     411             :                instances that are acquired during the call are released
     412             :                before m_refCount is decremented again */
     413             :             {
     414           0 :                 m_xAggProxy->setDelegator(
     415           0 :                     static_cast< cppu::OWeakObject * >( this ) );
     416             :             }
     417             : 
     418           0 :             osl_atomic_decrement( &m_refCount );
     419             :         }
     420           0 :     }
     421             : 
     422           0 :     ~DefaultBrowseNode()
     423           0 :     {
     424           0 :         if ( m_xAggProxy.is() )
     425             :         {
     426           0 :             m_xAggProxy->setDelegator( uno::Reference< uno::XInterface >() );
     427             :         }
     428           0 :     }
     429             : 
     430             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     431           0 :                 getChildNodes()
     432             :     throw ( RuntimeException )
     433             :     {
     434           0 :         if ( hasChildNodes() )
     435             :         {
     436           0 :             vXBrowseNodes m_vNodes;
     437             :             Sequence < Reference< browse::XBrowseNode > > nodes =
     438           0 :                 m_xWrappedBrowseNode->getChildNodes();
     439           0 :             for ( sal_Int32 i=0; i<nodes.getLength(); i++ )
     440             :             {
     441           0 :                 Reference< browse::XBrowseNode > xBrowseNode = nodes[ i ];
     442             :                 OSL_ENSURE( xBrowseNode.is(), "DefaultBrowseNode::getChildNodes(): Invalid BrowseNode" );
     443           0 :                 if( xBrowseNode.is() )
     444           0 :                     m_vNodes.push_back( new DefaultBrowseNode( m_xCtx, xBrowseNode ) );
     445           0 :             }
     446             : 
     447           0 :             ::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
     448           0 :             Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
     449           0 :             vXBrowseNodes::const_iterator it = m_vNodes.begin();
     450           0 :             for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it )
     451             :             {
     452           0 :                 children[ i ].set( *it );
     453             :             }
     454           0 :             return children;
     455             :         }
     456             :         else
     457             :         {
     458             :             // no nodes
     459             : 
     460           0 :             Sequence < Reference< browse::XBrowseNode > > none;
     461           0 :             return none;
     462             :         }
     463             :     }
     464             : 
     465           0 :     virtual sal_Int16 SAL_CALL getType()
     466             :         throw ( RuntimeException )
     467             :     {
     468           0 :         return m_xWrappedBrowseNode->getType();
     469             :     }
     470             : 
     471             :     virtual OUString
     472           0 :     SAL_CALL getName()
     473             :     throw ( RuntimeException )
     474             :     {
     475           0 :         return m_xWrappedBrowseNode->getName();
     476             :     }
     477             : 
     478             :     virtual sal_Bool SAL_CALL
     479           0 :     hasChildNodes()
     480             :         throw ( RuntimeException )
     481             :     {
     482           0 :         return m_xWrappedBrowseNode->hasChildNodes();
     483             :     }
     484             : 
     485             :     // XInterface
     486           0 :     virtual Any SAL_CALL queryInterface( const Type& aType )
     487             :         throw ( com::sun::star::uno::RuntimeException )
     488             :     {
     489           0 :         Any aRet = t_BrowseNodeBase::queryInterface( aType );
     490           0 :         if ( aRet.hasValue() )
     491             :         {
     492           0 :             return aRet;
     493             :         }
     494           0 :         if ( m_xAggProxy.is() )
     495             :         {
     496           0 :             return m_xAggProxy->queryAggregation( aType );
     497             :         }
     498             :         else
     499             :         {
     500           0 :             return Any();
     501           0 :         }
     502             :     }
     503             : 
     504           0 :     virtual void SAL_CALL acquire()
     505             :         throw ()
     506             : 
     507             :     {
     508           0 :         osl_atomic_increment( &m_refCount );
     509           0 :     }
     510           0 :     virtual void SAL_CALL release()
     511             :         throw ()
     512             :     {
     513           0 :         if ( osl_atomic_decrement( &m_refCount ) == 0 )
     514             :         {
     515           0 :             delete this;
     516             :         }
     517           0 :     }
     518             :     // XTypeProvider (implemnented by base, but needs to be overridden for
     519             :     //                delegating to aggregate)
     520           0 :     virtual Sequence< Type > SAL_CALL getTypes()
     521             :         throw ( com::sun::star::uno::RuntimeException )
     522             :     {
     523           0 :         return m_xWrappedTypeProv->getTypes();
     524             :     }
     525           0 :     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId()
     526             :         throw ( com::sun::star::uno::RuntimeException )
     527             :     {
     528           0 :         return m_xWrappedTypeProv->getImplementationId();
     529             : 
     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 = OUString("Root");
     553           0 :     }
     554             : 
     555           0 :     ~DefaultRootBrowseNode()
     556           0 :     {
     557           0 :     }
     558             : 
     559             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     560           0 :                 getChildNodes()
     561             :     throw ( RuntimeException )
     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 )
     576             :     {
     577           0 :         return browse::BrowseNodeTypes::ROOT;
     578             :     }
     579             : 
     580             :     virtual OUString
     581           0 :     SAL_CALL getName()
     582             :     throw ( RuntimeException )
     583             :     {
     584           0 :         return m_Name;
     585             :     }
     586             : 
     587             :     virtual sal_Bool SAL_CALL
     588           0 :     hasChildNodes()
     589             :         throw ( RuntimeException )
     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 :     ~SelectorBrowseNode()
     614           0 :     {
     615           0 :     }
     616             : 
     617           0 :     virtual OUString SAL_CALL getName()
     618             :         throw ( RuntimeException )
     619             :     {
     620           0 :         return OUString("Root");
     621             :     }
     622             : 
     623             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     624           0 :     getChildNodes()
     625             :         throw ( RuntimeException )
     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 )
     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 )
     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)
     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           8 : bnf_getImplementationName( )
     726             :     SAL_THROW(())
     727             : {
     728             :     return OUString(
     729           8 :         "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)
     747             : {
     748           0 :     return bnf_getImplementationName();
     749             : }
     750             : 
     751             : Sequence< OUString > SAL_CALL
     752           0 : BrowseNodeFactoryImpl::getSupportedServiceNames()
     753             :     throw (RuntimeException)
     754             : {
     755           0 :     return bnf_getSupportedServiceNames();
     756             : }
     757             : 
     758           0 : sal_Bool BrowseNodeFactoryImpl::supportsService(
     759             :     OUString const & serviceName )
     760             :     throw (RuntimeException)
     761             : {
     762             : //     check();
     763             : 
     764             :     Sequence< OUString > supported_services(
     765           0 :         getSupportedServiceNames() );
     766             : 
     767           0 :     OUString const * ar = supported_services.getConstArray();
     768             : 
     769           0 :     for ( sal_Int32 pos = supported_services.getLength(); pos--; )
     770             :     {
     771           0 :         if (ar[ pos ].equals( serviceName ))
     772           0 :             return sal_True;
     773             :     }
     774           0 :     return sal_False;
     775             : }
     776             : 
     777             : } // namespace browsenodefactory
     778             : 
     779             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10