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
{
53 * Close existing office: calls disposeManager()
54 * @param param The test parameters.
55 * @param closeIfPossible Not needed, since UNO is bootstrapped by this
56 * class in every case.
57 * @return True, if bootstrapping worked.
59 public boolean closeExistingOffice(TestParameters param
,
60 boolean closeIfPossible
) {
61 return disposeManager(param
);
65 * Dispose the UNO environment: just clears the bootstrapped
67 * @param param The test parameters.
68 * @return True, if bootstrapping worked.
70 public boolean disposeManager(TestParameters param
) {
71 param
.remove("ServiceManager");
73 util
.utils
.pause(1000);
78 * Bootstrap UNO and return the created MultiServiceFactory.
79 * @param param The test parameters.
80 * @return A created MultiServiceFactory.
82 public Object
getManager(TestParameters param
) {
83 XMultiServiceFactory xMSF
= param
.getMSF();
86 String unorcName
= getUnorcName(param
);
87 HashMap
<String
,String
> env
= new HashMap
<String
,String
>();
88 env
.put("SYSBINDIR", getSysBinDir(param
));
90 XComponentContext xContext
= null;
92 xContext
= Bootstrap
.defaultBootstrap_InitialComponentContext(
97 System
.out
.println("Could not get XComponentContext. Maybe you must add program folder to LD_LIBRARY_PATH");
100 XMultiComponentFactory xMCF
= xContext
.getServiceManager();
101 xMSF
= UnoRuntime
.queryInterface(
102 XMultiServiceFactory
.class, xMCF
);
107 private String
getUnorcName(TestParameters param
) {
108 String unorcName
= (String
)param
.get("UNORC");
109 if (unorcName
== null) {
110 String office
= (String
)param
.get("AppExecutionCommand");
111 // determine unorc name: unorc or uno.ini on windows
112 unorcName
= (String
)param
.get(PropertyName
.UNORC_NAME
);
113 // use '/', because this will be a URL in any case.
114 unorcName
= office
.substring(0, office
.indexOf("program")+7) +
117 unorcName
= utils
.getFullURL(unorcName
);
118 if (param
.getBool(PropertyName
.DEBUG_IS_ACTIVE
)) {
119 System
.out
.println("UnoUcr: " + unorcName
);
124 private String
getSysBinDir(TestParameters param
) {
125 String base
= (String
)param
.get("AppExecutionCommand");
127 base
= (String
)param
.get("UNORC");
132 String sysbindir
= base
.substring(0,
133 base
.indexOf("program")+7);
135 sysbindir
= utils
.getFullURL(sysbindir
);
136 if (param
.getBool(PropertyName
.DEBUG_IS_ACTIVE
)) {
137 System
.out
.println("SysBinDir: " + sysbindir
);