LCOV - code coverage report
Current view: top level - scripting/source/provider - BrowseNodeFactoryImpl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 257 0.8 %
Date: 2014-11-03 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 <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             : 
     162             : //typedef ::std::map< OUString, Reference< browse::XBrowseNode > >
     163             : typedef ::boost::unordered_map< OUString, Reference< browse::XBrowseNode >,
     164             :     OUStringHash, ::std::equal_to< OUString > >
     165             :         BrowseNodeAggregatorHash;
     166             : typedef ::std::vector< OUString > vString;
     167             : 
     168             : 
     169             : struct alphaSort
     170             : {
     171           0 :     bool operator()( const OUString& a, const OUString& b )
     172             :     {
     173           0 :         return a.compareTo( b ) < 0;
     174             :     }
     175             : };
     176             : class LocationBrowseNode :
     177             :     public ::cppu::WeakImplHelper1< browse::XBrowseNode >
     178             : {
     179             : private:
     180             :     BrowseNodeAggregatorHash* m_hBNA;
     181             :     vString m_vStr;
     182             :     OUString m_sNodeName;
     183             :     Reference< browse::XBrowseNode > m_origNode;
     184             : 
     185             : public:
     186             : 
     187           0 :     LocationBrowseNode( const Reference< browse::XBrowseNode >& node )
     188           0 :     {
     189           0 :         m_sNodeName = node->getName();
     190           0 :         m_hBNA = NULL;
     191           0 :         m_origNode.set( node );
     192           0 :     }
     193             : 
     194           0 :     virtual ~LocationBrowseNode()
     195           0 :     {
     196           0 :         if (m_hBNA)
     197             :         {
     198           0 :             delete m_hBNA;
     199             :         }
     200           0 :     }
     201             : 
     202             : 
     203             :     // XBrowseNode
     204             : 
     205             : 
     206           0 :     virtual OUString SAL_CALL getName()
     207             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     208             :     {
     209           0 :         return m_sNodeName;
     210             :     }
     211             : 
     212             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     213           0 :     getChildNodes()
     214             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     215             :     {
     216           0 :         if ( m_hBNA == NULL )
     217             :         {
     218           0 :             loadChildNodes();
     219             :         }
     220             : 
     221           0 :         Sequence<  Reference< browse::XBrowseNode > > children( m_hBNA->size() );
     222           0 :         sal_Int32 index = 0;
     223             : 
     224           0 :         vString::const_iterator it = m_vStr.begin();
     225             : 
     226           0 :         for ( ; it != m_vStr.end(); ++it, index++ )
     227             :         {
     228           0 :             children[ index ].set( m_hBNA->find( *it )->second );
     229             :         }
     230             : 
     231           0 :         return children;
     232             :     }
     233             : 
     234           0 :     virtual sal_Bool SAL_CALL hasChildNodes()
     235             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     236             :     {
     237           0 :         return sal_True;
     238             :     }
     239             : 
     240           0 :     virtual sal_Int16 SAL_CALL getType()
     241             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     242             :     {
     243           0 :         return browse::BrowseNodeTypes::CONTAINER;
     244             :     }
     245             : 
     246             : private:
     247             : 
     248           0 :     void loadChildNodes()
     249             :     {
     250           0 :         m_hBNA = new BrowseNodeAggregatorHash();
     251             : 
     252             :         Sequence< Reference< browse::XBrowseNode > > langNodes =
     253           0 :             m_origNode->getChildNodes();
     254             : 
     255           0 :         for ( sal_Int32 i = 0; i < langNodes.getLength(); i++ )
     256             :         {
     257           0 :             Reference< browse::XBrowseNode > xbn;
     258           0 :             if ( langNodes[ i ]->getName() == "uno_packages" )
     259             :             {
     260           0 :                 xbn.set( new LocationBrowseNode( langNodes[ i ] ) );
     261             :             }
     262             :             else
     263             :             {
     264           0 :                 xbn.set( langNodes[ i ] );
     265             :             }
     266             : 
     267             :             Sequence< Reference< browse::XBrowseNode > > grandchildren =
     268           0 :                 xbn->getChildNodes();
     269             : 
     270           0 :             for ( sal_Int32 j = 0; j < grandchildren.getLength(); j++ )
     271             :             {
     272           0 :                 Reference< browse::XBrowseNode > grandchild(grandchildren[j]);
     273             : 
     274             :                 BrowseNodeAggregatorHash::iterator h_it =
     275           0 :                     m_hBNA->find( grandchild->getName() );
     276             : 
     277           0 :                 if ( h_it != m_hBNA->end() )
     278             :                 {
     279           0 :                     BrowseNodeAggregator* bna = static_cast< BrowseNodeAggregator* >( h_it->second.get() );
     280           0 :                     bna->addBrowseNode( grandchild );
     281             :                 }
     282             :                 else
     283             :                 {
     284             :                     Reference< browse::XBrowseNode > bna(
     285           0 :                         new BrowseNodeAggregator( grandchild ) );
     286           0 :                     (*m_hBNA)[ grandchild->getName() ].set( bna );
     287           0 :                     m_vStr.push_back( grandchild->getName() );
     288             :                 }
     289           0 :             }
     290           0 :         }
     291             :         // sort children alpahbetically
     292           0 :         ::std::sort( m_vStr.begin(), m_vStr.end(), alphaSort() );
     293           0 :     }
     294             : };
     295             : 
     296             : namespace
     297             : {
     298             : 
     299           0 : Sequence< Reference< browse::XBrowseNode > > getAllBrowseNodes( const Reference< XComponentContext >& xCtx )
     300             : {
     301             :     Sequence< OUString > openDocs =
     302           0 :         MiscUtils::allOpenTDocUrls( xCtx );
     303             : 
     304           0 :     Reference< provider::XScriptProviderFactory > xFac;
     305           0 :     sal_Int32 initialSize = openDocs.getLength() + 2;
     306           0 :     sal_Int32 mspIndex = 0;
     307             : 
     308           0 :     Sequence < Reference < browse::XBrowseNode > > locnBNs( initialSize );
     309             :     try
     310             :     {
     311           0 :         xFac = provider::theMasterScriptProviderFactory::get( xCtx );
     312             : 
     313           0 :         locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( OUString("user") ) ), UNO_QUERY_THROW );
     314           0 :         locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( OUString("share") ) ), UNO_QUERY_THROW );
     315             :     }
     316             :     // TODO proper exception handling, should throw
     317           0 :     catch( const Exception& e )
     318             :     {
     319             :         (void)e;
     320             :         OSL_TRACE("Caught Exception %s",
     321             :             OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     322           0 :         locnBNs.realloc( mspIndex );
     323           0 :         return locnBNs;
     324             :     }
     325             : 
     326           0 :     for ( sal_Int32 i = 0; i < openDocs.getLength(); i++ )
     327             :     {
     328             :         try
     329             :         {
     330           0 :             Reference< frame::XModel > model( MiscUtils::tDocUrlToModel( openDocs[ i ] ), UNO_QUERY_THROW );
     331             : 
     332             :             // #i44599 Check if it's a real document or something special like Hidden/Preview
     333           0 :             css::uno::Reference< css::frame::XController > xCurrentController = model->getCurrentController();
     334           0 :             if( xCurrentController.is() )
     335             :             {
     336           0 :                 utl::MediaDescriptor aMD( model->getArgs() );
     337           0 :                 bool bDefault = false;
     338           0 :                 bool bHidden  = aMD.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_HIDDEN(),  bDefault );
     339           0 :                 bool bPreview = aMD.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_PREVIEW(), bDefault );
     340           0 :                 if( !bHidden && !bPreview )
     341             :                 {
     342           0 :                     Reference< document::XEmbeddedScripts > xScripts( model, UNO_QUERY );
     343           0 :                     if ( xScripts.is() )
     344           0 :                         locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >(
     345           0 :                             xFac->createScriptProvider( makeAny( model ) ), UNO_QUERY_THROW );
     346           0 :                 }
     347           0 :             }
     348             :         }
     349           0 :         catch( const Exception& )
     350             :         {
     351             :             DBG_UNHANDLED_EXCEPTION();
     352             :         }
     353             : 
     354             :     }
     355             : 
     356           0 :     Sequence < Reference < browse::XBrowseNode > > locnBNs_Return( mspIndex );
     357           0 :     for ( sal_Int32 j = 0; j < mspIndex; j++ )
     358           0 :         locnBNs_Return[j] = locnBNs[j];
     359             : 
     360           0 :     return locnBNs_Return;
     361             : }
     362             : 
     363             : } // namespace
     364             : 
     365             : typedef ::std::vector< Reference< browse::XBrowseNode > > vXBrowseNodes;
     366             : 
     367             : struct alphaSortForBNodes
     368             : {
     369           0 :     bool operator()( const Reference< browse::XBrowseNode >& a, const Reference< browse::XBrowseNode >& b )
     370             :     {
     371           0 :         return a->getName().compareTo( b->getName() ) < 0;
     372             :     }
     373             : };
     374             : 
     375             : typedef ::cppu::WeakImplHelper1< browse::XBrowseNode > t_BrowseNodeBase;
     376             : class DefaultBrowseNode :
     377             :     public t_BrowseNodeBase
     378             : {
     379             : 
     380             : private:
     381             :     Reference< browse::XBrowseNode > m_xWrappedBrowseNode;
     382             :     Reference< lang::XTypeProvider > m_xWrappedTypeProv;
     383             :     Reference< XAggregation >        m_xAggProxy;
     384             :     Reference< XComponentContext >   m_xCtx;
     385             : 
     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             : public:
     542           0 :     DefaultRootBrowseNode( const Reference< XComponentContext >& xCtx )
     543           0 :     {
     544             :         Sequence < Reference< browse::XBrowseNode > > nodes =
     545           0 :             getAllBrowseNodes( xCtx );
     546             : 
     547           0 :         for ( sal_Int32 i=0; i<nodes.getLength(); i++ )
     548             :         {
     549           0 :             m_vNodes.push_back( new DefaultBrowseNode( xCtx, nodes[ i ] ) );
     550             :         }
     551           0 :         m_Name = "Root";
     552           0 :     }
     553             : 
     554           0 :     virtual ~DefaultRootBrowseNode()
     555           0 :     {
     556           0 :     }
     557             : 
     558             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     559           0 :                 getChildNodes()
     560             :     throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     561             :     {
     562             :         // no need to sort user, share, doc1...docN
     563             :         //::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
     564           0 :         Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
     565           0 :         vXBrowseNodes::const_iterator it = m_vNodes.begin();
     566           0 :         for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it )
     567             :         {
     568           0 :             children[ i ].set( *it );
     569             :         }
     570           0 :         return children;
     571             :     }
     572             : 
     573           0 :     virtual sal_Int16 SAL_CALL getType()
     574             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     575             :     {
     576           0 :         return browse::BrowseNodeTypes::ROOT;
     577             :     }
     578             : 
     579             :     virtual OUString
     580           0 :     SAL_CALL getName()
     581             :     throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     582             :     {
     583           0 :         return m_Name;
     584             :     }
     585             : 
     586             :     virtual sal_Bool SAL_CALL
     587           0 :     hasChildNodes()
     588             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     589             :     {
     590           0 :         bool result = true;
     591           0 :         if ( !m_vNodes.size() )
     592             :         {
     593           0 :             result = false;
     594             :         }
     595           0 :         return result;
     596             :     }
     597             : };
     598             : 
     599             : 
     600             : class SelectorBrowseNode :
     601             :     public ::cppu::WeakImplHelper1< browse::XBrowseNode >
     602             : {
     603             : private:
     604             :     Reference< XComponentContext > m_xComponentContext;
     605             : 
     606             : public:
     607           0 :     SelectorBrowseNode( const Reference< XComponentContext >& xContext )
     608           0 :       : m_xComponentContext( xContext )
     609             :     {
     610           0 :     }
     611             : 
     612           0 :     virtual ~SelectorBrowseNode()
     613           0 :     {
     614           0 :     }
     615             : 
     616           0 :     virtual OUString SAL_CALL getName()
     617             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     618             :     {
     619           0 :         return OUString("Root");
     620             :     }
     621             : 
     622             :     virtual Sequence< Reference< browse::XBrowseNode > > SAL_CALL
     623           0 :     getChildNodes()
     624             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     625             :     {
     626             : 
     627           0 :         Sequence < Reference < browse::XBrowseNode > > locnBNs = getAllBrowseNodes( m_xComponentContext );
     628             : 
     629             :         Sequence<  Reference< browse::XBrowseNode > > children(
     630           0 :             locnBNs.getLength() );
     631             : 
     632           0 :         for ( sal_Int32 j = 0; j < locnBNs.getLength(); j++ )
     633             :         {
     634           0 :             children[j] = new LocationBrowseNode( locnBNs[j] );
     635             :         }
     636             : 
     637           0 :         return children;
     638             :     }
     639             : 
     640           0 :     virtual sal_Bool SAL_CALL hasChildNodes()
     641             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     642             :     {
     643           0 :         return sal_True; // will always be user and share
     644             :     }
     645             : 
     646           0 :     virtual sal_Int16 SAL_CALL getType()
     647             :         throw ( RuntimeException, std::exception ) SAL_OVERRIDE
     648             :     {
     649           0 :         return browse::BrowseNodeTypes::CONTAINER;
     650             :     }
     651             : };
     652             : 
     653           0 : BrowseNodeFactoryImpl::BrowseNodeFactoryImpl(
     654             :     Reference< XComponentContext > const & xComponentContext )
     655           0 :     : m_xComponentContext( xComponentContext )
     656             : {
     657           0 : }
     658             : 
     659           0 : BrowseNodeFactoryImpl::~BrowseNodeFactoryImpl()
     660             : {
     661           0 : }
     662             : 
     663             : 
     664             : 
     665             : // Implementation of XBrowseNodeFactory
     666             : 
     667             : 
     668             : /*
     669             :  * The selector hierarchy is the standard hierarchy for organizers with the
     670             :  * language nodes removed.
     671             :  */
     672             : Reference< browse::XBrowseNode > SAL_CALL
     673           0 : BrowseNodeFactoryImpl::createView( sal_Int16 viewType )
     674             :     throw (RuntimeException, std::exception)
     675             : {
     676           0 :     switch( viewType )
     677             :     {
     678             :         case browse::BrowseNodeFactoryViewTypes::MACROSELECTOR:
     679           0 :             return getSelectorHierarchy();
     680             :         case browse::BrowseNodeFactoryViewTypes::MACROORGANIZER:
     681           0 :             return getOrganizerHierarchy();
     682             :         default:
     683           0 :             throw RuntimeException( "Unknown view type" );
     684             :     }
     685             : }
     686             : 
     687             : Reference< browse::XBrowseNode >
     688           0 : BrowseNodeFactoryImpl::getSelectorHierarchy()
     689             :     throw (RuntimeException)
     690             : {
     691             :     /*if ( !m_xSelectorBrowseNode.is() )
     692             :     {
     693             :         m_xSelectorBrowseNode = new SelectorBrowseNode( m_xComponentContext );
     694             :     }*/
     695           0 :     return new SelectorBrowseNode( m_xComponentContext );
     696             : }
     697             : 
     698             : Reference< browse::XBrowseNode >
     699           0 : BrowseNodeFactoryImpl::getOrganizerHierarchy()
     700             :     throw (RuntimeException)
     701             : {
     702           0 :     Reference< browse::XBrowseNode > xRet = new  DefaultRootBrowseNode( m_xComponentContext );
     703           0 :     return xRet;
     704             : }
     705             : 
     706             : // Helper methods
     707             : 
     708             : 
     709             : 
     710             : // Namespace global methods for setting up BrowseNodeFactory service
     711             : 
     712             : 
     713             : Sequence< OUString > SAL_CALL
     714           0 : bnf_getSupportedServiceNames( )
     715             : {
     716             :     OUString str_name(
     717           0 :         "com.sun.star.script.browse.BrowseNodeFactory");
     718             : 
     719           0 :     return Sequence< OUString >( &str_name, 1 );
     720             : }
     721             : 
     722             : OUString SAL_CALL
     723          18 : bnf_getImplementationName( )
     724             : {
     725             :     return OUString(
     726          18 :         "com.sun.star.script.browse.BrowseNodeFactory" );
     727             : }
     728             : 
     729             : Reference< XInterface > SAL_CALL
     730           0 : bnf_create( Reference< XComponentContext > const & xComponentContext )
     731             : {
     732             :     return static_cast< ::cppu::OWeakObject * >(
     733           0 :         new BrowseNodeFactoryImpl( xComponentContext ) );
     734             : }
     735             : 
     736             : 
     737             : // Implementation of XServiceInfo
     738             : 
     739             : 
     740             : OUString SAL_CALL
     741           0 : BrowseNodeFactoryImpl::getImplementationName()
     742             :     throw (RuntimeException, std::exception)
     743             : {
     744           0 :     return bnf_getImplementationName();
     745             : }
     746             : 
     747             : Sequence< OUString > SAL_CALL
     748           0 : BrowseNodeFactoryImpl::getSupportedServiceNames()
     749             :     throw (RuntimeException, std::exception)
     750             : {
     751           0 :     return bnf_getSupportedServiceNames();
     752             : }
     753             : 
     754           0 : sal_Bool BrowseNodeFactoryImpl::supportsService(OUString const & serviceName )
     755             :     throw (RuntimeException, std::exception)
     756             : {
     757           0 :     return cppu::supportsService(this, serviceName);
     758             : }
     759             : 
     760             : } // namespace browsenodefactory
     761             : 
     762             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10