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