merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / plugin / base / manager.cxx
blobcd60034c18015bd3eb042d6e6e74caca87782416
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: manager.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #if STLPORT_VERSION>=321
35 #include <cstdarg>
36 #endif
38 #include "plugin/impl.hxx"
40 #include "osl/mutex.hxx"
41 #include "svtools/pathoptions.hxx"
42 #include "vcl/configsettings.hxx"
44 #include "com/sun/star/container/XEnumerationAccess.hpp"
45 #include "com/sun/star/container/XNameAccess.hpp"
46 #include "com/sun/star/container/XEnumeration.hpp"
47 #include "com/sun/star/container/XElementAccess.hpp"
48 #include "com/sun/star/container/XIndexAccess.hpp"
49 #include "com/sun/star/loader/XImplementationLoader.hpp"
50 #include "com/sun/star/loader/CannotActivateFactoryException.hpp"
52 PluginManager* PluginManager::pManager = NULL;
54 PluginManager& PluginManager::get()
56 if( ! pManager )
57 pManager = new PluginManager();
58 return *pManager;
61 void PluginManager::setServiceFactory( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
63 PluginManager& rManager = get();
64 if( ! rManager.m_xSMgr.is() )
65 rManager.m_xSMgr = xFactory;
68 PluginManager::PluginManager()
72 const Sequence< ::rtl::OUString >& PluginManager::getAdditionalSearchPaths()
74 static Sequence< ::rtl::OUString > aPaths;
76 if( ! aPaths.getLength() )
78 SvtPathOptions aOptions;
79 String aPluginPath( aOptions.GetPluginPath() );
80 if( aPluginPath.Len() )
82 USHORT nPaths = aPluginPath.GetTokenCount( ';' );
83 aPaths.realloc( nPaths );
84 for( USHORT i = 0; i < nPaths; i++ )
85 aPaths.getArray()[i] = aPluginPath.GetToken( i, ';' );
89 return aPaths;
92 //==================================================================================================
93 Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) throw( Exception )
95 Reference< XInterface > xService = *new XPluginManager_Impl( rSMgr );
96 return xService;
99 // ::com::sun::star::lang::XServiceInfo
100 ::rtl::OUString XPluginManager_Impl::getImplementationName() throw( )
103 return getImplementationName_Static();
107 // ::com::sun::star::lang::XServiceInfo
108 sal_Bool XPluginManager_Impl::supportsService(const ::rtl::OUString& ServiceName) throw( )
110 Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
111 const ::rtl::OUString * pArray = aSNL.getConstArray();
112 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
113 if( pArray[i] == ServiceName )
114 return sal_True;
115 return sal_False;
118 // ::com::sun::star::lang::XServiceInfo
119 Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames(void) throw( )
121 return getSupportedServiceNames_Static();
124 // XPluginManager_Impl
125 Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames_Static(void) throw( )
127 Sequence< ::rtl::OUString > aSNS( 1 );
128 aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginManager" );
129 return aSNS;
132 XPluginManager_Impl::XPluginManager_Impl( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr )
133 : m_xSMgr( rSMgr )
135 PluginManager::setServiceFactory( rSMgr );
138 XPluginManager_Impl::~XPluginManager_Impl()
142 XPlugin_Impl* XPluginManager_Impl::getXPluginFromNPP( NPP instance )
144 ::std::list<XPlugin_Impl*>::iterator iter;
145 for( iter = PluginManager::get().getPlugins().begin();
146 iter != PluginManager::get().getPlugins().end(); ++iter )
148 if( (*iter)->getNPPInstance() == instance )
149 return *iter;
152 return NULL;
155 XPlugin_Impl* XPluginManager_Impl::getPluginImplementation( const Reference< ::com::sun::star::plugin::XPlugin >& plugin )
157 ::std::list<XPlugin_Impl*>::iterator iter;
158 for( iter = PluginManager::get().getPlugins().begin();
159 iter != PluginManager::get().getPlugins().end(); ++iter )
161 if( plugin == Reference< ::com::sun::star::plugin::XPlugin >((*iter)) )
162 return *iter;
165 return NULL;
168 Sequence<com::sun::star::plugin::PluginDescription> XPluginManager_Impl::getPluginDescriptions() throw()
170 Sequence<com::sun::star::plugin::PluginDescription> aRet;
172 vcl::SettingsConfigItem* pCfg = vcl::SettingsConfigItem::get();
173 rtl::OUString aVal( pCfg->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BrowserPlugins" ) ),
174 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Disabled" ) ) ) );
175 if( ! aVal.toBoolean() )
177 aRet = impl_getPluginDescriptions();
179 return aRet;
182 Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPlugin( const Reference< ::com::sun::star::plugin::XPluginContext >& acontext, INT16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const ::com::sun::star::plugin::PluginDescription& plugintype)
183 throw( RuntimeException,::com::sun::star::plugin::PluginException )
185 XPlugin_Impl* pImpl = new XPlugin_Impl( m_xSMgr );
186 pImpl->setPluginContext( acontext );
188 PluginManager::get().getPlugins().push_back( pImpl );
190 pImpl->initInstance( plugintype,
191 argn,
192 argv,
193 mode );
195 return pImpl;
198 Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPluginFromURL( const Reference< ::com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const Reference< ::com::sun::star::awt::XToolkit > & toolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & parent, const ::rtl::OUString& url ) throw()
200 XPlugin_Impl* pImpl = new XPlugin_Impl( m_xSMgr );
201 Reference< ::com::sun::star::plugin::XPlugin > xRef = pImpl;
203 pImpl->setPluginContext( acontext );
205 PluginManager::get().getPlugins().push_back( pImpl );
208 pImpl->initInstance( url,
209 argn,
210 argv,
211 mode );
213 pImpl->createPeer( toolkit, parent );
215 pImpl->provideNewStream( pImpl->getDescription().Mimetype,
216 Reference< com::sun::star::io::XActiveDataSource >(),
217 url,
218 0, 0, (sal_Bool)(url.compareToAscii( "file:", 5 ) == 0) );
220 if( ! pImpl->getPluginComm() )
222 pImpl->dispose();
223 xRef = NULL;
226 return xRef;