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