1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import com
.sun
.star
.comp
.helper
.Bootstrap
;
30 import com
.sun
.star
.lang
.XMultiComponentFactory
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XComponentContext
;
34 import java
.util
.Hashtable
;
35 import lib
.TestParameters
;
36 import util
.PropertyName
;
40 * Bootstrap UNO from a Java environment.
45 * <li>UNORC - complete path to the unorc file</li>
50 * <li>AppExecutionCommand - path to the soffice executable</li>
51 * <li>OS - the operating system in case it's Windows, because the
52 * unorc is called uno.ini</li>
57 public class UnoProvider
implements AppProvider
{
64 * Close existing office: calls disposeManager()
65 * @param param The test parameters.
66 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
67 * class in every case.
68 * @return True, if bootstrapping worked.
70 public boolean closeExistingOffice(TestParameters param
,
71 boolean closeIfPossible
) {
72 return disposeManager(param
);
76 * Dispose the UNO environment: just clears the bootstrapped
78 * @param param The test parameters.
79 * @return True, if bootstrapping worked.
81 public boolean disposeManager(TestParameters param
) {
82 XMultiServiceFactory xMSF
=
83 (XMultiServiceFactory
)param
.remove("ServiceManager");
89 catch(java
.lang
.InterruptedException e
) {}
94 * Bootstrap UNO and return the created MultiServiceFactory.
95 * @param param The test parameters.
96 * @return A created MultiServiceFactory.
98 public Object
getManager(TestParameters param
) {
99 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)param
.getMSF();
102 String unorcName
= getUnorcName(param
);
103 Hashtable env
= new Hashtable();
104 env
.put("SYSBINDIR", getSysBinDir(param
));
106 XComponentContext xContext
= null;
108 xContext
= Bootstrap
.defaultBootstrap_InitialComponentContext(
113 System
.out
.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
116 XMultiComponentFactory xMCF
= xContext
.getServiceManager();
117 xMSF
= (XMultiServiceFactory
)UnoRuntime
.queryInterface(
118 XMultiServiceFactory
.class, xMCF
);
123 private String
getUnorcName(TestParameters param
) {
124 String unorcName
= (String
)param
.get("UNORC");
125 if (unorcName
== null) {
126 String office
= (String
)param
.get("AppExecutionCommand");
127 // determine unorc name: unorc or uno.ini on windows
128 String opSystem
= (String
)param
.get(PropertyName
.OPERATING_SYSTEM
);
129 if ( opSystem
!= null && opSystem
.equalsIgnoreCase(PropertyName
.WNTMSCI
)) {
130 unorcName
= "uno.ini";
137 // use '/', because this will be a URL in any case.
138 unorcName
= office
.substring(0, office
.indexOf("program")+7) +
141 unorcName
= utils
.getFullURL(unorcName
);
142 if (param
.DebugIsActive
) {
143 System
.out
.println("UnoUcr: " + unorcName
);
148 private String
getSysBinDir(TestParameters param
) {
149 String base
= (String
)param
.get("AppExecutionCommand");
151 base
= (String
)param
.get("UNORC");
156 String sysbindir
= base
.substring(0,
157 base
.indexOf("program")+7);
159 sysbindir
= utils
.getFullURL(sysbindir
);
160 if (param
.DebugIsActive
) {
161 System
.out
.println("SysBinDir: " + sysbindir
);