xref: /aoo41x/main/desktop/source/app/appinit.cxx (revision 85c309d6)
12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
102722ceddSAndrew Rist  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
192722ceddSAndrew Rist  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "app.hxx"
30cdf0e10cSrcweir #include "cmdlineargs.hxx"
31cdf0e10cSrcweir #include "desktopresid.hxx"
32cdf0e10cSrcweir #include "desktop.hrc"
33cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
36cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
37cdf0e10cSrcweir #include <com/sun/star/uno/XCurrentContext.hpp>
38cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipIOException.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
43cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderManager.hpp>
44cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProviderFactory.hpp>
45cdf0e10cSrcweir #include <uno/current_context.hxx>
46cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
47cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
48cdf0e10cSrcweir #include <osl/file.hxx>
49cdf0e10cSrcweir #include <osl/module.h>
50cdf0e10cSrcweir #include <vos/process.hxx>
51cdf0e10cSrcweir #include <rtl/uri.hxx>
52cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
53cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
54cdf0e10cSrcweir #include <comphelper/regpathhelper.hxx>
55cdf0e10cSrcweir #include <tools/debug.hxx>
56cdf0e10cSrcweir #include <tools/tempfile.hxx>
57cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
60cdf0e10cSrcweir #include <tools/urlobj.hxx>
61cdf0e10cSrcweir #include <tools/rcid.h>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <rtl/logfile.hxx>
64cdf0e10cSrcweir #include <rtl/instance.hxx>
65cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
66cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
67cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
68cdf0e10cSrcweir #include <unotools/tempfile.hxx>
69cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
70cdf0e10cSrcweir #include <vcl/svapp.hxx>
71cdf0e10cSrcweir #include <unotools/startoptions.hxx>
72cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
73cdf0e10cSrcweir #include <unotools/internaloptions.hxx>
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir #define	DEFINE_CONST_OUSTRING(CONSTASCII)		OUString(RTL_CONSTASCII_USTRINGPARAM(CONSTASCII))
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #define DESKTOP_TEMPDIRNAME						"soffice.tmp"
79cdf0e10cSrcweir 
80cdf0e10cSrcweir using namespace rtl;
81cdf0e10cSrcweir using namespace vos;
82cdf0e10cSrcweir using namespace desktop;
83cdf0e10cSrcweir using namespace ::com::sun::star::uno;
84cdf0e10cSrcweir using namespace ::com::sun::star::lang;
85cdf0e10cSrcweir using namespace ::com::sun::star::beans;
86cdf0e10cSrcweir using namespace ::com::sun::star::registry;
87cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir namespace desktop
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // -----------------------------------------------------------------------------
93cdf0e10cSrcweir 
configureUcb(bool bServer,rtl::OUString const & rPortalConnect)94cdf0e10cSrcweir static bool configureUcb(bool bServer, rtl::OUString const & rPortalConnect)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "desktop (sb93797) ::configureUcb" );
97cdf0e10cSrcweir 	Reference< XMultiServiceFactory >
98cdf0e10cSrcweir         xServiceFactory( comphelper::getProcessServiceFactory() );
99cdf0e10cSrcweir 	if (!xServiceFactory.is())
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		DBG_ERROR("configureUcb(): No XMultiServiceFactory");
102cdf0e10cSrcweir 		return false;
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	rtl::OUString aPipe;
106cdf0e10cSrcweir 	vos::OSecurity().getUserIdent(aPipe);
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	rtl::OUStringBuffer aPortal;
109cdf0e10cSrcweir 	if (rPortalConnect.getLength() != 0)
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		aPortal.append(sal_Unicode(','));
112cdf0e10cSrcweir 		aPortal.append(rPortalConnect);
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	Sequence< Any > aArgs(6);
116cdf0e10cSrcweir 	aArgs[0]
117cdf0e10cSrcweir 		<<= rtl::OUString::createFromAscii(bServer ?
118cdf0e10cSrcweir 										       UCB_CONFIGURATION_KEY1_SERVER :
119cdf0e10cSrcweir 										       UCB_CONFIGURATION_KEY1_LOCAL);
120cdf0e10cSrcweir 	aArgs[1]
121cdf0e10cSrcweir 		<<= rtl::OUString::createFromAscii(UCB_CONFIGURATION_KEY2_OFFICE);
122cdf0e10cSrcweir 	aArgs[2] <<= rtl::OUString::createFromAscii("PIPE");
123cdf0e10cSrcweir 	aArgs[3] <<= aPipe;
124cdf0e10cSrcweir 	aArgs[4] <<= rtl::OUString::createFromAscii("PORTAL");
125cdf0e10cSrcweir 	aArgs[5] <<= aPortal.makeStringAndClear();
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     bool ret =
128cdf0e10cSrcweir         ::ucbhelper::ContentBroker::initialize( xServiceFactory, aArgs ) != false;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #ifdef GNOME_VFS_ENABLED
131cdf0e10cSrcweir     // register GnomeUCP if necessary
132cdf0e10cSrcweir     ::ucbhelper::ContentBroker* cb = ::ucbhelper::ContentBroker::get();
133cdf0e10cSrcweir     if(cb) {
134cdf0e10cSrcweir         try {
135cdf0e10cSrcweir             Reference< XCurrentContext > xCurrentContext(
136cdf0e10cSrcweir                 getCurrentContext());
137cdf0e10cSrcweir             if (xCurrentContext.is())
138cdf0e10cSrcweir             {
139cdf0e10cSrcweir                 Any aValue = xCurrentContext->getValueByName(
140cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
141cdf0e10cSrcweir                                        "system.desktop-environment" ) )
142cdf0e10cSrcweir                 );
143cdf0e10cSrcweir                 rtl::OUString aDesktopEnvironment;
144cdf0e10cSrcweir                 if ((aValue >>= aDesktopEnvironment)
145cdf0e10cSrcweir                     && aDesktopEnvironment.equalsAscii("GNOME"))
146cdf0e10cSrcweir                 {
147cdf0e10cSrcweir                     Reference<XContentProviderManager> xCPM =
148cdf0e10cSrcweir                         cb->getContentProviderManagerInterface();
149cdf0e10cSrcweir #if 0
150cdf0e10cSrcweir                     try
151cdf0e10cSrcweir                     {
152cdf0e10cSrcweir 
153cdf0e10cSrcweir                         Reference<XContentProviderFactory> xCPF(
154cdf0e10cSrcweir                             xServiceFactory->createInstance(
155cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
156cdf0e10cSrcweir                                     "com.sun.star.ucb.ContentProviderProxyFactory")),
157cdf0e10cSrcweir                             UNO_QUERY);
158cdf0e10cSrcweir                         if(xCPF.is())
159cdf0e10cSrcweir                             xCPM->registerContentProvider(
160cdf0e10cSrcweir                                 xCPF->createContentProvider(
161cdf0e10cSrcweir                                     rtl::OUString::createFromAscii(
162cdf0e10cSrcweir                                         "com.sun.star.ucb.GnomeVFSContentProvider"
163cdf0e10cSrcweir                                     )
164cdf0e10cSrcweir                                 ),
165cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(".*"),
166cdf0e10cSrcweir                                 false);
167cdf0e10cSrcweir                     } catch (...)
168cdf0e10cSrcweir                     {
169cdf0e10cSrcweir                     }
170cdf0e10cSrcweir #else
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 		    // Workaround for P1 #124597#.  Instanciate GNOME-VFS-UCP in the thread that initialized
173cdf0e10cSrcweir  		    // GNOME in order to avoid a deadlock that may occure in case UCP gets initialized from
174cdf0e10cSrcweir 		    // a different thread. The latter may happen when calling the Office remotely via UNO.
175cdf0e10cSrcweir 		    // THIS IS NOT A FIX, JUST A WORKAROUND!
176cdf0e10cSrcweir 
177cdf0e10cSrcweir                     try
178cdf0e10cSrcweir                     {
179cdf0e10cSrcweir                         Reference<XContentProvider> xCP(
180cdf0e10cSrcweir                             xServiceFactory->createInstance(
181cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(
182cdf0e10cSrcweir                                     "com.sun.star.ucb.GnomeVFSContentProvider")),
183cdf0e10cSrcweir                             UNO_QUERY);
184cdf0e10cSrcweir                         if(xCP.is())
185cdf0e10cSrcweir                             xCPM->registerContentProvider(
186cdf0e10cSrcweir                                 xCP,
187cdf0e10cSrcweir                                 rtl::OUString::createFromAscii(".*"),
188cdf0e10cSrcweir                                 false);
189cdf0e10cSrcweir                     } catch (...)
190cdf0e10cSrcweir                     {
191cdf0e10cSrcweir                     }
192cdf0e10cSrcweir                 }
193cdf0e10cSrcweir #endif
194cdf0e10cSrcweir             }
195cdf0e10cSrcweir         } catch (RuntimeException e) {
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir #endif // GNOME_VFS_ENABLED
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     return ret;;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
CreateApplicationServiceManager()203cdf0e10cSrcweir Reference< XMultiServiceFactory > Desktop::CreateApplicationServiceManager()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::createApplicationServiceManager" );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	try
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		Reference<XComponentContext> xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext();
210cdf0e10cSrcweir 		Reference<XMultiServiceFactory> xMS(xComponentContext->getServiceManager(), UNO_QUERY);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 		return xMS;
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir 	catch( ::com::sun::star::uno::Exception& )
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 	}
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	return Reference< XMultiServiceFactory >();
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
DestroyApplicationServiceManager(Reference<XMultiServiceFactory> & xSMgr)221cdf0e10cSrcweir void Desktop::DestroyApplicationServiceManager( Reference< XMultiServiceFactory >& xSMgr )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     Reference< XPropertySet > xProps( xSMgr, UNO_QUERY );
224cdf0e10cSrcweir     if ( xProps.is() )
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         try
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             Reference< XComponent > xComp;
229cdf0e10cSrcweir             if (xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComp )
230cdf0e10cSrcweir             {
231cdf0e10cSrcweir                 xComp->dispose();
232cdf0e10cSrcweir             }
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir         catch ( UnknownPropertyException& )
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
RegisterServices(Reference<XMultiServiceFactory> & xSMgr)240cdf0e10cSrcweir void Desktop::RegisterServices( Reference< XMultiServiceFactory >& xSMgr )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir     if( !m_bServicesRegistered )
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir 	    RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::registerServices" );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	    // read command line parameters
247cdf0e10cSrcweir 	    ::rtl::OUString conDcp;
248cdf0e10cSrcweir 	    ::rtl::OUString aClientDisplay;
249cdf0e10cSrcweir 	    ::rtl::OUString aTmpString;
250cdf0e10cSrcweir 	    sal_Bool		bHeadlessMode = sal_False;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	    // interpret command line arguments
253cdf0e10cSrcweir 	    CommandLineArgs* pCmdLine = GetCommandLineArgs();
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	    // read accept string from configuration
256cdf0e10cSrcweir 	    conDcp = SvtStartOptions().GetConnectionURL();
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	    if ( pCmdLine->GetAcceptString( aTmpString ))
259cdf0e10cSrcweir 		    conDcp = aTmpString;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	    // Headless mode for FAT Office
262cdf0e10cSrcweir 	    bHeadlessMode	= pCmdLine->IsHeadless();
263cdf0e10cSrcweir 	    if ( bHeadlessMode )
264cdf0e10cSrcweir 		    Application::EnableHeadlessMode();
265cdf0e10cSrcweir 
266*85c309d6SJürgen Schmidt 	    // ConversionMode
267*85c309d6SJürgen Schmidt 	    if ( pCmdLine->IsConversionMode() )
268*85c309d6SJürgen Schmidt 		    Application::EnableConversionMode();
269*85c309d6SJürgen Schmidt 
270*85c309d6SJürgen Schmidt         if ( conDcp.getLength() > 0 )
271cdf0e10cSrcweir 	    {
272cdf0e10cSrcweir 		    // accept incoming connections (scripting and one rvp)
273cdf0e10cSrcweir 		    RTL_LOGFILE_CONTEXT( aLog, "desktop (lo119109) desktop::Desktop::createAcceptor()" );
274cdf0e10cSrcweir 		    createAcceptor(conDcp);
275cdf0e10cSrcweir 	    }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	    // improves parallel processing on Sun ONE Webtop
278cdf0e10cSrcweir 	    // servicemanager up -> copy user installation
279cdf0e10cSrcweir 	    if ( pCmdLine->IsServer() )
280cdf0e10cSrcweir 	    {
281cdf0e10cSrcweir 		    // Check some mandatory environment states if "-server" is possible. Otherwise ignore
282cdf0e10cSrcweir 		    // this parameter.
283cdf0e10cSrcweir 		    Reference< com::sun::star::container::XContentEnumerationAccess > rContent( xSMgr , UNO_QUERY );
284cdf0e10cSrcweir 		    if( rContent.is() )
285cdf0e10cSrcweir 		    {
286cdf0e10cSrcweir 			    OUString sPortalService = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.portal.InstallUser" ) );
287cdf0e10cSrcweir 			    Reference < com::sun::star::container::XEnumeration > rEnum = rContent->createContentEnumeration( sPortalService );
288cdf0e10cSrcweir 			    if ( !rEnum.is() )
289cdf0e10cSrcweir 			    {
290cdf0e10cSrcweir 				    // Reset server parameter so it is ignored in the furthermore startup process
291cdf0e10cSrcweir 				    pCmdLine->SetBoolParam( CommandLineArgs::CMD_BOOLPARAM_SERVER, sal_False );
292cdf0e10cSrcweir 			    }
293cdf0e10cSrcweir 		    }
294cdf0e10cSrcweir 	    }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         ::rtl::OUString	aPortalConnect;
297cdf0e10cSrcweir         bool bServer = (bool)pCmdLine->IsServer();
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	    pCmdLine->GetPortalConnectString( aPortalConnect );
300cdf0e10cSrcweir         if ( !configureUcb( bServer, aPortalConnect ) )
301cdf0e10cSrcweir 	    {
302cdf0e10cSrcweir             DBG_ERROR( "Can't configure UCB" );
303cdf0e10cSrcweir 		    throw com::sun::star::uno::Exception(rtl::OUString::createFromAscii("RegisterServices, configureUcb"), NULL);
304cdf0e10cSrcweir 	    }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 	    CreateTemporaryDirectory();
307cdf0e10cSrcweir 	    m_bServicesRegistered = true;
308cdf0e10cSrcweir     }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir namespace
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     struct acceptorMap : public rtl::Static< AcceptorMap, acceptorMap > {};
314cdf0e10cSrcweir     struct CurrentTempURL : public rtl::Static< String, CurrentTempURL > {};
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir static sal_Bool bAccept = sal_False;
318cdf0e10cSrcweir 
createAcceptor(const OUString & aAcceptString)319cdf0e10cSrcweir void Desktop::createAcceptor(const OUString& aAcceptString)
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	// check whether the requested acceptor already exists
322cdf0e10cSrcweir 	AcceptorMap &rMap = acceptorMap::get();
323cdf0e10cSrcweir 	AcceptorMap::const_iterator pIter = rMap.find(aAcceptString);
324cdf0e10cSrcweir 	if (pIter == rMap.end() ) {
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 		Sequence< Any > aSeq( 2 );
327cdf0e10cSrcweir 		aSeq[0] <<= aAcceptString;
328cdf0e10cSrcweir 		aSeq[1] <<= bAccept;
329cdf0e10cSrcweir 		Reference<XInitialization> rAcceptor(
330cdf0e10cSrcweir 			::comphelper::getProcessServiceFactory()->createInstance(
331cdf0e10cSrcweir 			OUString::createFromAscii( "com.sun.star.office.Acceptor" )), UNO_QUERY );
332cdf0e10cSrcweir 		if ( rAcceptor.is() ) {
333cdf0e10cSrcweir 			try{
334cdf0e10cSrcweir 				rAcceptor->initialize( aSeq );
335cdf0e10cSrcweir 				rMap.insert(AcceptorMap::value_type(aAcceptString, rAcceptor));
336cdf0e10cSrcweir 			} catch (com::sun::star::uno::Exception&) {
337cdf0e10cSrcweir 			// no error handling needed...
338cdf0e10cSrcweir 			// acceptor just won't come up
339cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "Acceptor could not be created.");
340cdf0e10cSrcweir 		}
341cdf0e10cSrcweir 	} else {
342cdf0e10cSrcweir 		// there is already an acceptor with this description
343cdf0e10cSrcweir 		OSL_ENSURE(sal_False, "Acceptor already exists.");
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	}
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir class enable
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	private:
352cdf0e10cSrcweir 	Sequence<Any> m_aSeq;
353cdf0e10cSrcweir 	public:
enable()354cdf0e10cSrcweir 	enable() : m_aSeq(1) {
355cdf0e10cSrcweir 		m_aSeq[0] <<= sal_True;
356cdf0e10cSrcweir 	}
operator ()(const AcceptorMap::value_type & val)357cdf0e10cSrcweir 	void operator() (const AcceptorMap::value_type& val) {
358cdf0e10cSrcweir 		if (val.second.is()) {
359cdf0e10cSrcweir 			val.second->initialize(m_aSeq);
360cdf0e10cSrcweir 		}
361cdf0e10cSrcweir 	}
362cdf0e10cSrcweir };
363cdf0e10cSrcweir 
enableAcceptors()364cdf0e10cSrcweir void Desktop::enableAcceptors()
365cdf0e10cSrcweir {
366cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT(aLog, "desktop (lo119109) Desktop::enableAcceptors");
367cdf0e10cSrcweir 	if (!bAccept)
368cdf0e10cSrcweir 	{
369cdf0e10cSrcweir 		// from now on, all new acceptors are enabled
370cdf0e10cSrcweir 		bAccept = sal_True;
371cdf0e10cSrcweir 		// enable existing acceptors by calling initialize(true)
372cdf0e10cSrcweir 		// on all existing acceptors
373cdf0e10cSrcweir 	    AcceptorMap &rMap = acceptorMap::get();
374cdf0e10cSrcweir 		std::for_each(rMap.begin(), rMap.end(), enable());
375cdf0e10cSrcweir 	}
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
destroyAcceptor(const OUString & aAcceptString)378cdf0e10cSrcweir void Desktop::destroyAcceptor(const OUString& aAcceptString)
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	// special case stop all acceptors
381cdf0e10cSrcweir 	AcceptorMap &rMap = acceptorMap::get();
382cdf0e10cSrcweir 	if (aAcceptString.compareToAscii("all") == 0) {
383cdf0e10cSrcweir 		rMap.clear();
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	} else {
386cdf0e10cSrcweir 		// try to remove acceptor from map
387cdf0e10cSrcweir 		AcceptorMap::const_iterator pIter = rMap.find(aAcceptString);
388cdf0e10cSrcweir 		if (pIter != rMap.end() ) {
389cdf0e10cSrcweir 			// remove reference from map
390cdf0e10cSrcweir 			// this is the last reference and the acceptor will be destructed
391cdf0e10cSrcweir 			rMap.erase(aAcceptString);
392cdf0e10cSrcweir 		} else {
393cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "Found no acceptor to remove");
394cdf0e10cSrcweir 		}
395cdf0e10cSrcweir 	}
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 
DeregisterServices()399cdf0e10cSrcweir void Desktop::DeregisterServices()
400cdf0e10cSrcweir {
401cdf0e10cSrcweir 	// stop all acceptors by clearing the map
402cdf0e10cSrcweir 	acceptorMap::get().clear();
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
CreateTemporaryDirectory()405cdf0e10cSrcweir void Desktop::CreateTemporaryDirectory()
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::createTemporaryDirectory" );
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     ::rtl::OUString aTempBaseURL;
410cdf0e10cSrcweir     try
411cdf0e10cSrcweir     {
412cdf0e10cSrcweir         SvtPathOptions aOpt;
413cdf0e10cSrcweir 	    aTempBaseURL = aOpt.GetTempPath();
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir     catch ( RuntimeException& e )
416cdf0e10cSrcweir     {
417cdf0e10cSrcweir         // Catch runtime exception here: We have to add language dependent info
418cdf0e10cSrcweir         // to the exception message. Fallback solution uses hard coded string.
419cdf0e10cSrcweir         OUString aMsg;
420cdf0e10cSrcweir         DesktopResId aResId( STR_BOOTSTRAP_ERR_NO_PATHSET_SERVICE );
421cdf0e10cSrcweir         aResId.SetRT( RSC_STRING );
422cdf0e10cSrcweir         if ( aResId.GetResMgr()->IsAvailable( aResId ))
423cdf0e10cSrcweir             aMsg = String( aResId );
424cdf0e10cSrcweir         else
425cdf0e10cSrcweir             aMsg = OUString( RTL_CONSTASCII_USTRINGPARAM( "The path manager is not available.\n" ));
426cdf0e10cSrcweir         e.Message = aMsg + e.Message;
427cdf0e10cSrcweir         throw e;
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     // remove possible old directory and base directory
431cdf0e10cSrcweir 	SvtInternalOptions	aInternalOpt;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	// set temp base directory
434cdf0e10cSrcweir 	sal_Int32 nLength = aTempBaseURL.getLength();
435cdf0e10cSrcweir 	if ( aTempBaseURL.matchAsciiL( "/", 1, nLength-1 ) )
436cdf0e10cSrcweir 		aTempBaseURL = aTempBaseURL.copy( 0, nLength - 1 );
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	String aOldTempURL = aInternalOpt.GetCurrentTempURL();
439cdf0e10cSrcweir 	if ( aOldTempURL.Len() > 0 )
440cdf0e10cSrcweir 	{
441cdf0e10cSrcweir 		// remove old temporary directory
442cdf0e10cSrcweir 	    ::utl::UCBContentHelper::Kill( aOldTempURL );
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     String aRet;
446cdf0e10cSrcweir 	::rtl::OUString aTempPath( aTempBaseURL );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 	// create new current temporary directory
449cdf0e10cSrcweir 	::utl::LocalFileHelper::ConvertURLToPhysicalName( aTempBaseURL, aRet );
450cdf0e10cSrcweir 	::osl::FileBase::getFileURLFromSystemPath( aRet, aTempPath );
451cdf0e10cSrcweir 	aTempPath = ::utl::TempFile::SetTempNameBaseDirectory( aTempPath );
452cdf0e10cSrcweir     if ( !aTempPath.getLength() )
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir 		::osl::File::getTempDirURL( aTempBaseURL );
455cdf0e10cSrcweir 
456cdf0e10cSrcweir         nLength = aTempBaseURL.getLength();
457cdf0e10cSrcweir 		if ( aTempBaseURL.matchAsciiL( "/", 1, nLength-1 ) )
458cdf0e10cSrcweir 			aTempBaseURL = aTempBaseURL.copy( 0, nLength - 1 );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir         aTempPath = aTempBaseURL;
461cdf0e10cSrcweir         ::osl::FileBase::getFileURLFromSystemPath( aRet, aTempPath );
462cdf0e10cSrcweir         aTempPath = ::utl::TempFile::SetTempNameBaseDirectory( aTempPath );
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 	// set new current temporary directory
466cdf0e10cSrcweir     ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aTempPath, aRet );
467cdf0e10cSrcweir 	aInternalOpt.SetCurrentTempURL( aRet );
468cdf0e10cSrcweir 	CurrentTempURL::get() = aRet;
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
RemoveTemporaryDirectory()471cdf0e10cSrcweir void Desktop::RemoveTemporaryDirectory()
472cdf0e10cSrcweir {
473cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::removeTemporaryDirectory" );
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	// remove current temporary directory
476cdf0e10cSrcweir 	String &rCurrentTempURL = CurrentTempURL::get();
477cdf0e10cSrcweir 	if ( rCurrentTempURL.Len() > 0 )
478cdf0e10cSrcweir 	{
479cdf0e10cSrcweir 		if ( ::utl::UCBContentHelper::Kill( rCurrentTempURL ) )
480cdf0e10cSrcweir 			SvtInternalOptions().SetCurrentTempURL( String() );
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir } // namespace desktop
485