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

Generated by: LCOV version 1.10