2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.util
.HashMap
;
22 import lib
.TestParameters
;
23 import util
.PropertyName
;
26 import com
.sun
.star
.comp
.helper
.Bootstrap
;
27 import com
.sun
.star
.lang
.XMultiComponentFactory
;
28 import com
.sun
.star
.lang
.XMultiServiceFactory
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
30 import com
.sun
.star
.uno
.XComponentContext
;
33 * Bootstrap UNO from a Java environment.
38 * <li>UNORC - complete path to the unorc file</li>
43 * <li>AppExecutionCommand - path to the soffice executable</li>
44 * <li>OS - the operating system in case it's Windows, because the
45 * unorc is called uno.ini</li>
50 public class UnoProvider
implements AppProvider
{
57 * Close existing office: calls disposeManager()
58 * @param param The test parameters.
59 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
60 * class in every case.
61 * @return True, if bootstrapping worked.
63 public boolean closeExistingOffice(TestParameters param
,
64 boolean closeIfPossible
) {
65 return disposeManager(param
);
69 * Dispose the UNO environment: just clears the bootstrapped
71 * @param param The test parameters.
72 * @return True, if bootstrapping worked.
74 public boolean disposeManager(TestParameters param
) {
75 param
.remove("ServiceManager");
80 catch(java
.lang
.InterruptedException e
) {}
85 * Bootstrap UNO and return the created MultiServiceFactory.
86 * @param param The test parameters.
87 * @return A created MultiServiceFactory.
89 public Object
getManager(TestParameters param
) {
90 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)param
.getMSF();
93 String unorcName
= getUnorcName(param
);
94 HashMap
<String
,String
> env
= new HashMap
<String
,String
>();
95 env
.put("SYSBINDIR", getSysBinDir(param
));
97 XComponentContext xContext
= null;
99 xContext
= Bootstrap
.defaultBootstrap_InitialComponentContext(
104 System
.out
.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
107 XMultiComponentFactory xMCF
= xContext
.getServiceManager();
108 xMSF
= UnoRuntime
.queryInterface(
109 XMultiServiceFactory
.class, xMCF
);
114 private String
getUnorcName(TestParameters param
) {
115 String unorcName
= (String
)param
.get("UNORC");
116 if (unorcName
== null) {
117 String office
= (String
)param
.get("AppExecutionCommand");
118 // determine unorc name: unorc or uno.ini on windows
119 String opSystem
= (String
)param
.get(PropertyName
.OPERATING_SYSTEM
);
120 if ( opSystem
!= null && opSystem
.equalsIgnoreCase(PropertyName
.WNTMSCI
)) {
121 unorcName
= "uno.ini";
128 // use '/', because this will be a URL in any case.
129 unorcName
= office
.substring(0, office
.indexOf("program")+7) +
132 unorcName
= utils
.getFullURL(unorcName
);
133 if (param
.DebugIsActive
) {
134 System
.out
.println("UnoUcr: " + unorcName
);
139 private String
getSysBinDir(TestParameters param
) {
140 String base
= (String
)param
.get("AppExecutionCommand");
142 base
= (String
)param
.get("UNORC");
147 String sysbindir
= base
.substring(0,
148 base
.indexOf("program")+7);
150 sysbindir
= utils
.getFullURL(sysbindir
);
151 if (param
.DebugIsActive
) {
152 System
.out
.println("SysBinDir: " + sysbindir
);