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