1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoProvider.java,v $
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 ************************************************************************/
32 import com
.sun
.star
.comp
.helper
.Bootstrap
;
33 import com
.sun
.star
.lang
.XMultiComponentFactory
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XComponentContext
;
37 import java
.util
.Hashtable
;
38 import lib
.TestParameters
;
39 import util
.PropertyName
;
43 * Bootstrap UNO from a Java environment.
48 * <li>UNORC - complete path to the unorc file</li>
53 * <li>AppExecutionCommand - path to the soffice executable</li>
54 * <li>OS - the operating system in case it's Windows, because the
55 * unorc is called uno.ini</li>
60 public class UnoProvider
implements AppProvider
{
67 * Close existing office: calls disposeManager()
68 * @param param The test parameters.
69 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
70 * class in every case.
71 * @return True, if bootstrapping worked.
73 public boolean closeExistingOffice(TestParameters param
,
74 boolean closeIfPossible
) {
75 return disposeManager(param
);
79 * Dispose the UNO environment: just clears the bootstrapped
81 * @param param The test parameters.
82 * @return True, if bootstrapping worked.
84 public boolean disposeManager(TestParameters param
) {
85 XMultiServiceFactory xMSF
=
86 (XMultiServiceFactory
)param
.remove("ServiceManager");
92 catch(java
.lang
.InterruptedException e
) {}
97 * Bootstrap UNO and return the created MultiServiceFactory.
98 * @param param The test parameters.
99 * @return A created MultiServiceFactory.
101 public Object
getManager(TestParameters param
) {
102 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)param
.getMSF();
105 String unorcName
= getUnorcName(param
);
106 Hashtable env
= new Hashtable();
107 env
.put("SYSBINDIR", getSysBinDir(param
));
109 XComponentContext xContext
= null;
111 xContext
= Bootstrap
.defaultBootstrap_InitialComponentContext(
116 System
.out
.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
119 XMultiComponentFactory xMCF
= xContext
.getServiceManager();
120 xMSF
= (XMultiServiceFactory
)UnoRuntime
.queryInterface(
121 XMultiServiceFactory
.class, xMCF
);
126 private String
getUnorcName(TestParameters param
) {
127 String unorcName
= (String
)param
.get("UNORC");
128 if (unorcName
== null) {
129 String office
= (String
)param
.get("AppExecutionCommand");
130 // determine unorc name: unorc or uno.ini on windows
131 String opSystem
= (String
)param
.get(PropertyName
.OPERATING_SYSTEM
);
132 if ( opSystem
!= null && opSystem
.equalsIgnoreCase(PropertyName
.WNTMSCI
)) {
133 unorcName
= "uno.ini";
140 // use '/', because this will be a URL in any case.
141 unorcName
= office
.substring(0, office
.indexOf("program")+7) +
144 unorcName
= utils
.getFullURL(unorcName
);
145 if (param
.DebugIsActive
) {
146 System
.out
.println("UnoUcr: " + unorcName
);
151 private String
getSysBinDir(TestParameters param
) {
152 String base
= (String
)param
.get("AppExecutionCommand");
154 base
= (String
)param
.get("UNORC");
159 String sysbindir
= base
.substring(0,
160 base
.indexOf("program")+7);
162 sysbindir
= utils
.getFullURL(sysbindir
);
163 if (param
.DebugIsActive
) {
164 System
.out
.println("SysBinDir: " + sysbindir
);