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 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
21 : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
22 : #include <com/sun/star/beans/PropertyValue.hpp>
23 : #include <comphelper/processfactory.hxx>
24 : #include <cppuhelper/supportsservice.hxx>
25 : #include "tvfactory.hxx"
26 : #include "tvread.hxx"
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 0 : TVFactory::TVFactory( const uno::Reference< XComponentContext >& xContext )
36 0 : : m_xContext( xContext )
37 : {
38 0 : }
39 :
40 0 : TVFactory::~TVFactory()
41 : {
42 0 : }
43 :
44 : // XServiceInfo methods.
45 :
46 : OUString SAL_CALL
47 0 : TVFactory::getImplementationName()
48 : throw( RuntimeException, std::exception )
49 : {
50 0 : return TVFactory::getImplementationName_static();
51 : }
52 :
53 0 : sal_Bool SAL_CALL TVFactory::supportsService( const OUString& ServiceName )
54 : throw( RuntimeException, std::exception )
55 : {
56 0 : return cppu::supportsService( this, ServiceName );
57 : }
58 :
59 : Sequence< OUString > SAL_CALL
60 0 : TVFactory::getSupportedServiceNames( void )
61 : throw( RuntimeException, std::exception )
62 : {
63 0 : return TVFactory::getSupportedServiceNames_static();
64 : }
65 :
66 : // XMultiServiceFactory
67 :
68 : Reference< XInterface > SAL_CALL
69 0 : TVFactory::createInstance(
70 : const OUString& aServiceSpecifier )
71 : throw( Exception,
72 : RuntimeException, std::exception )
73 : {
74 0 : Any aAny;
75 0 : aAny <<= OUString();
76 0 : Sequence< Any > seq( 1 );
77 0 : seq[0] <<= PropertyValue(
78 : OUString( "nodepath" ),
79 : -1,
80 : aAny,
81 0 : PropertyState_DIRECT_VALUE );
82 :
83 : return createInstanceWithArguments( aServiceSpecifier,
84 0 : seq );
85 : }
86 :
87 : Reference< XInterface > SAL_CALL
88 0 : TVFactory::createInstanceWithArguments(
89 : const OUString& ServiceSpecifier,
90 : const Sequence< Any >& Arguments )
91 : throw( Exception,
92 : RuntimeException, std::exception )
93 : {
94 : (void)ServiceSpecifier;
95 :
96 0 : if( ! m_xHDS.is() )
97 : {
98 0 : cppu::OWeakObject* p = new TVChildTarget( m_xContext );
99 0 : m_xHDS = Reference< XInterface >( p );
100 : }
101 :
102 0 : Reference< XInterface > ret = m_xHDS;
103 :
104 0 : OUString hierview;
105 0 : for( int i = 0; i < Arguments.getLength(); ++i )
106 : {
107 0 : PropertyValue pV;
108 0 : if( ! ( Arguments[i] >>= pV ) )
109 0 : continue;
110 :
111 0 : if( pV.Name.compareToAscii( "nodepath" ) )
112 0 : continue;
113 :
114 0 : if( ! ( pV.Value >>= hierview ) )
115 0 : continue;
116 :
117 0 : break;
118 0 : }
119 :
120 0 : if( !hierview.isEmpty() )
121 : {
122 0 : Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
123 0 : Any aAny = xhieraccess->getByHierarchicalName( hierview );
124 0 : Reference< XInterface > xInterface;
125 0 : aAny >>= xInterface;
126 0 : return xInterface;
127 : }
128 : else
129 0 : return m_xHDS;
130 : }
131 :
132 : Sequence< OUString > SAL_CALL
133 0 : TVFactory::getAvailableServiceNames( )
134 : throw( RuntimeException, std::exception )
135 : {
136 0 : Sequence< OUString > seq( 1 );
137 0 : seq[0] = "com.sun.star.ucb.HierarchyDataReadAccess";
138 0 : return seq;
139 : }
140 :
141 : // static
142 :
143 : OUString SAL_CALL
144 0 : TVFactory::getImplementationName_static()
145 : {
146 0 : return OUString( "com.sun.star.help.TreeViewImpl" );
147 : }
148 :
149 : Sequence< OUString > SAL_CALL
150 0 : TVFactory::getSupportedServiceNames_static()
151 : {
152 0 : Sequence< OUString > seq( 2 );
153 0 : seq[0] = "com.sun.star.help.TreeView";
154 0 : seq[1] = "com.sun.star.ucb.HiearchyDataSource";
155 0 : return seq;
156 : }
157 :
158 : Reference< XSingleServiceFactory > SAL_CALL
159 0 : TVFactory::createServiceFactory(
160 : const Reference< XMultiServiceFactory >& rxServiceMgr )
161 : {
162 : return Reference< XSingleServiceFactory > (
163 : cppu::createSingleFactory(
164 : rxServiceMgr,
165 : TVFactory::getImplementationName_static(),
166 : TVFactory::CreateInstance,
167 0 : TVFactory::getSupportedServiceNames_static() ) );
168 : }
169 :
170 : Reference< XInterface > SAL_CALL
171 0 : TVFactory::CreateInstance(
172 : const Reference< XMultiServiceFactory >& xMultiServiceFactory )
173 : {
174 0 : XServiceInfo* xP = (XServiceInfo*) new TVFactory( comphelper::getComponentContext(xMultiServiceFactory) );
175 0 : return Reference< XInterface >::query( xP );
176 : }
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|