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 <com/sun/star/lang/XSingleServiceFactory.hpp>
22 : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
23 : #include <com/sun/star/beans/PropertyValue.hpp>
24 : #include "tvfactory.hxx"
25 : #include "tvread.hxx"
26 :
27 :
28 : using namespace treeview;
29 : using namespace com::sun::star;
30 : using namespace com::sun::star::uno;
31 : using namespace com::sun::star::lang;
32 : using namespace com::sun::star::beans;
33 : using namespace com::sun::star::container;
34 :
35 :
36 :
37 0 : TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF )
38 0 : : m_xMSF( xMSF )
39 : {
40 0 : }
41 :
42 :
43 0 : TVFactory::~TVFactory()
44 : {
45 0 : }
46 :
47 :
48 : //////////////////////////////////////////////////////////////////////////
49 : // XInterface
50 : //////////////////////////////////////////////////////////////////////////
51 :
52 : void SAL_CALL
53 0 : TVFactory::acquire(
54 : void )
55 : throw()
56 : {
57 0 : OWeakObject::acquire();
58 0 : }
59 :
60 :
61 : void SAL_CALL
62 0 : TVFactory::release(
63 : void )
64 : throw()
65 : {
66 0 : OWeakObject::release();
67 0 : }
68 :
69 :
70 : Any SAL_CALL
71 0 : TVFactory::queryInterface(
72 : const Type& rType )
73 : throw( RuntimeException )
74 : {
75 : Any aRet = cppu::queryInterface( rType,
76 : (static_cast< XServiceInfo* >(this)),
77 : (static_cast< XTypeProvider* >(this)),
78 0 : (static_cast< XMultiServiceFactory* >(this)) );
79 :
80 0 : return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
81 : }
82 :
83 :
84 : ////////////////////////////////////////////////////////////////////////////////
85 : //
86 : // XTypeProvider methods.
87 :
88 0 : XTYPEPROVIDER_IMPL_3( TVFactory,
89 : XServiceInfo,
90 : XTypeProvider,
91 : XMultiServiceFactory );
92 :
93 :
94 :
95 : ////////////////////////////////////////////////////////////////////////////////
96 :
97 : // XServiceInfo methods.
98 :
99 : rtl::OUString SAL_CALL
100 0 : TVFactory::getImplementationName()
101 : throw( RuntimeException )
102 : {
103 0 : return TVFactory::getImplementationName_static();
104 : }
105 :
106 :
107 : sal_Bool SAL_CALL
108 0 : TVFactory::supportsService(
109 : const rtl::OUString& ServiceName )
110 : throw( RuntimeException )
111 : {
112 : return
113 0 : ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
114 0 : ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
115 : }
116 :
117 :
118 : Sequence< rtl::OUString > SAL_CALL
119 0 : TVFactory::getSupportedServiceNames( void )
120 : throw( RuntimeException )
121 : {
122 0 : return TVFactory::getSupportedServiceNames_static();
123 : }
124 :
125 :
126 :
127 : // XMultiServiceFactory
128 :
129 : Reference< XInterface > SAL_CALL
130 0 : TVFactory::createInstance(
131 : const rtl::OUString& aServiceSpecifier )
132 : throw( Exception,
133 : RuntimeException )
134 : {
135 0 : Any aAny;
136 0 : aAny <<= rtl::OUString();
137 0 : Sequence< Any > seq( 1 );
138 0 : seq[0] <<= PropertyValue(
139 : rtl::OUString( "nodepath" ),
140 : -1,
141 : aAny,
142 0 : PropertyState_DIRECT_VALUE );
143 :
144 : return createInstanceWithArguments( aServiceSpecifier,
145 0 : seq );
146 : }
147 :
148 :
149 : Reference< XInterface > SAL_CALL
150 0 : TVFactory::createInstanceWithArguments(
151 : const rtl::OUString& ServiceSpecifier,
152 : const Sequence< Any >& Arguments )
153 : throw( Exception,
154 : RuntimeException )
155 : {
156 : (void)ServiceSpecifier;
157 :
158 0 : if( ! m_xHDS.is() )
159 : {
160 0 : cppu::OWeakObject* p = new TVChildTarget( m_xMSF );
161 0 : m_xHDS = Reference< XInterface >( p );
162 : }
163 :
164 0 : Reference< XInterface > ret = m_xHDS;
165 :
166 0 : rtl::OUString hierview;
167 0 : for( int i = 0; i < Arguments.getLength(); ++i )
168 : {
169 0 : PropertyValue pV;
170 0 : if( ! ( Arguments[i] >>= pV ) )
171 0 : continue;
172 :
173 0 : if( pV.Name.compareToAscii( "nodepath" ) )
174 0 : continue;
175 :
176 0 : if( ! ( pV.Value >>= hierview ) )
177 0 : continue;
178 :
179 : break;
180 0 : }
181 :
182 0 : if( !hierview.isEmpty() )
183 : {
184 0 : Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
185 0 : Any aAny = xhieraccess->getByHierarchicalName( hierview );
186 0 : Reference< XInterface > xInterface;
187 0 : aAny >>= xInterface;
188 0 : return xInterface;
189 : }
190 : else
191 0 : return m_xHDS;
192 : }
193 :
194 :
195 : Sequence< rtl::OUString > SAL_CALL
196 0 : TVFactory::getAvailableServiceNames( )
197 : throw( RuntimeException )
198 : {
199 0 : Sequence< rtl::OUString > seq( 1 );
200 0 : seq[0] = rtl::OUString( "com.sun.star.ucb.HierarchyDataReadAccess" );
201 0 : return seq;
202 : }
203 :
204 :
205 :
206 : // static
207 :
208 :
209 : rtl::OUString SAL_CALL
210 0 : TVFactory::getImplementationName_static()
211 : {
212 0 : return rtl::OUString( "com.sun.star.help.TreeViewImpl" );
213 : }
214 :
215 :
216 : Sequence< rtl::OUString > SAL_CALL
217 0 : TVFactory::getSupportedServiceNames_static()
218 : {
219 0 : Sequence< rtl::OUString > seq( 2 );
220 0 : seq[0] = rtl::OUString( "com.sun.star.help.TreeView" );
221 0 : seq[1] = rtl::OUString( "com.sun.star.ucb.HiearchyDataSource" );
222 0 : return seq;
223 : }
224 :
225 :
226 : Reference< XSingleServiceFactory > SAL_CALL
227 0 : TVFactory::createServiceFactory(
228 : const Reference< XMultiServiceFactory >& rxServiceMgr )
229 : {
230 : return Reference< XSingleServiceFactory > (
231 : cppu::createSingleFactory(
232 : rxServiceMgr,
233 : TVFactory::getImplementationName_static(),
234 : TVFactory::CreateInstance,
235 0 : TVFactory::getSupportedServiceNames_static() ) );
236 : }
237 :
238 :
239 :
240 : Reference< XInterface > SAL_CALL
241 0 : TVFactory::CreateInstance(
242 : const Reference< XMultiServiceFactory >& xMultiServiceFactory )
243 : {
244 0 : XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory );
245 0 : return Reference< XInterface >::query( xP );
246 : }
247 :
248 : //=========================================================================
249 0 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
250 : const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey )
251 : {
252 : (void)pRegistryKey;
253 :
254 0 : void * pRet = 0;
255 :
256 : Reference< XMultiServiceFactory > xSMgr(
257 0 : reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
258 :
259 0 : Reference< XSingleServiceFactory > xFactory;
260 :
261 : //////////////////////////////////////////////////////////////////////
262 : // File Content Provider.
263 : //////////////////////////////////////////////////////////////////////
264 :
265 0 : if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 )
266 : {
267 0 : xFactory = TVFactory::createServiceFactory( xSMgr );
268 : }
269 :
270 : //////////////////////////////////////////////////////////////////////
271 :
272 0 : if ( xFactory.is() )
273 : {
274 0 : xFactory->acquire();
275 0 : pRet = xFactory.get();
276 : }
277 :
278 0 : return pRet;
279 : }
280 :
281 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|