/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ package helper;
/** * This class will connect the office and start it if possible *
*/ publicclass OfficeProvider implements AppProvider
{
privateboolean debug = false;
/** * copy the user layer to a safe place, usually to $TMP/user_backup$USER
*/ privatevoid backupUserLayer(TestParameters param, XMultiServiceFactory msf)
{ try
{ final XStringSubstitution sts = createStringSubstitution(msf);
debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
dbg(" copy '" + userLayer + "' ->" + copyLayer + "'"); // Slow machines the copy job could spend some time. To avoid activating of OfficeWatcher it must be pinged
OfficeWatcherPing owp = new OfficeWatcherPing((OfficeWatcher) param.get(PropertyName.OFFICE_WATCHER));
owp.start();
deleteFilesAndDirector (new File(copyLayer));
FileTools.copyDirectory(new File(userLayer), new File(copyLayer), new String[]
{ "temp"
});
/** * Dispose the office. * This method can only be used, if the office was connected in the first * place: getManager() was called first. * @return return true if desktop is terminates, else false
*/ publicboolean disposeManager(lib.TestParameters param)
{
/** * Method to get the ServiceManager of an Office
*/ public Object getManager(lib.TestParameters param) throws UnsupportedEncodingException
{
String errorMessage = null; boolean bAppExecutionHasWarning = false;
debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
System.out.println("Connecting the Office with " + cncstr);
XMultiServiceFactory msf = connectOffice(cncstr);
// if the office is running and the office crashes while testing it could // be useful to restart the office if possible and continue the tests. // Example: the UNO-API-Tests in the projects will be executed by calling // 'dmake'. if ((param.getBool(util.PropertyName.AUTO_RESTART)) && (msf != null))
{
makeAppExecCommand(msf, param);
}
if (isAppKnown)
{
dbg("Local Connection trying to start the Office");
//ensure that a pending officewatcher gets finished before a new //office is started final OfficeWatcher ow_old = (OfficeWatcher) param.get("Watcher");
if (ow_old != null)
{
ow_old.finish = true;
}
final String cmd = (String) param.get("AppExecutionCommand");
dbg("AppExecutionCommand: " + cmd); // validate the AppExecutionCommand, but try it out anyway. // keep the error message for later.
errorMessage =
util.utils.validateAppExecutionCommand(cmd, (String) param.get("OperatingSystem")); if (errorMessage.startsWith("Error"))
{
System.out.println(errorMessage); returnnull;
}
bAppExecutionHasWarning = !errorMessage.equals("OK");
final DynamicClassLoader dcl = new DynamicClassLoader(); final LogWriter log = (LogWriter) dcl.getInstance(
(String) param.get("LogWriter"));
// Get component context final XComponentContext xcomponentcontext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
// initial serviceManager final XMultiComponentFactory xLocalServiceManager = xcomponentcontext.getServiceManager();
// create a connector, so that it can contact the office final Object xUrlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xcomponentcontext); final XUnoUrlResolver urlResolver = UnoRuntime.queryInterface(XUnoUrlResolver.class, xUrlResolver);
final Object rInitialObject = urlResolver.resolve(connectStr);
/** * Close an office. * @param param The test parameters. * @param closeIfPossible If true, close even if * it was running before the test
*/ publicboolean closeExistingOffice(lib.TestParameters param, boolean closeIfPossible)
{
/** * If the office is connected but the <CODE>AppExecutionCommand</CODE> is not set, * this function asks the office for its location and fill the * <CODE>AppExecutionCommand</CODE> with valid content. * This function was only called if parameter <CODE>AutoRestart</CODE> is set. * @param msf the <CODE>MultiServiceFactory</CODE> * @param param the <CODE>TestParameters</CODE>
*/ privatevoid makeAppExecCommand(XMultiServiceFactory msf, TestParameters param)
{
debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
// get existing AppExecutionCommand if available, else empty string
String command = (String) param.get(util.PropertyName.APP_EXECUTION_COMMAND);
String connectionString; if (param.getBool(util.PropertyName.USE_PIPE_CONNECTION))
{ // This is the default behaviour
connectionString = (String) param.get(util.PropertyName.PIPE_CONNECTION_STRING);
} else
{ // is used if UsePipeConnection=false
connectionString = (String) param.get(util.PropertyName.CONNECTION_STRING);
}
String sysBinDir = "";
try
{
sysBinDir = utils.getSystemURL(utils.expandMacro(msf, "$SYSBINDIR"));
} catch (java.lang.Exception e)
{
dbg("could not get system binary directory"); return;
}
// does the existing command show to the connected office? if (command.indexOf(sysBinDir) == -1)
{
command = sysBinDir + System.getProperty("file.separator") + "soffice" + " --norestore --accept=" + connectionString + ";urp;";
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.