use of org.xwiki.officeimporter.server.OfficeServerException in project xwiki-platform by xwiki.
the class DefaultOfficeServer method start.
@Override
public void start() throws OfficeServerException {
// If the office server is running then stop it in order to restart the connection.
stop();
initialize();
try {
this.jodManager.start();
setState(ServerState.CONNECTED);
this.logger.info("Open Office instance started.");
} catch (Exception e) {
setState(ServerState.ERROR);
throw new OfficeServerException("Error while connecting / starting the office server.", e);
}
}
use of org.xwiki.officeimporter.server.OfficeServerException in project xwiki-platform by xwiki.
the class DefaultOfficeServer method stop.
@Override
public void stop() throws OfficeServerException {
// We should try stopping the office server even if the status is not connected but we should not raise an
// error if there is a failure to stop.
boolean connected = checkState(ServerState.CONNECTED);
try {
this.jodManager.stop();
setState(ServerState.NOT_CONNECTED);
this.logger.info("Open Office instance stopped.");
} catch (Exception e) {
if (connected) {
setState(ServerState.ERROR);
throw new OfficeServerException("Error while disconnecting / shutting down the office server.", e);
}
}
}
use of org.xwiki.officeimporter.server.OfficeServerException in project xwiki-platform by xwiki.
the class DefaultOfficeServer method initialize.
/**
* Initialize JodConverter.
*
* @throws OfficeServerException when failed to initialize
*/
public void initialize() throws OfficeServerException {
if (this.config.getServerType() == OfficeServerConfiguration.SERVER_TYPE_INTERNAL) {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
configuration.setPortNumber(this.config.getServerPort());
String homePath = this.config.getHomePath();
if (homePath != null) {
configuration.setOfficeHome(homePath);
}
String profilePath = this.config.getProfilePath();
if (profilePath != null) {
configuration.setTemplateProfileDir(new File(profilePath));
}
configuration.setMaxTasksPerProcess(this.config.getMaxTasksPerProcess());
configuration.setTaskExecutionTimeout(this.config.getTaskExecutionTimeout());
try {
this.jodManager = configuration.buildOfficeManager();
} catch (Exception e) {
// We wrap this in an OfficeServerException in order to display some nicer message to the user.
throw new OfficeServerException("Failed to start Office server. Reason: " + e.getMessage(), e);
}
} else if (this.config.getServerType() == OfficeServerConfiguration.SERVER_TYPE_EXTERNAL_LOCAL) {
ExternalOfficeManagerConfiguration externalProcessOfficeManager = new ExternalOfficeManagerConfiguration();
externalProcessOfficeManager.setPortNumber(this.config.getServerPort());
externalProcessOfficeManager.setConnectOnStart(true);
this.jodManager = externalProcessOfficeManager.buildOfficeManager();
} else {
setState(ServerState.CONF_ERROR);
throw new OfficeServerException("Invalid office server configuration.");
}
this.jodConverter = null;
// Try to use the JSON document format registry to configure the office document conversion.
InputStream input = getClass().getResourceAsStream(DOCUMENT_FORMATS_PATH);
if (input != null) {
try {
this.jodConverter = new OfficeDocumentConverter(this.jodManager, new JsonDocumentFormatRegistry(input));
} catch (Exception e) {
this.logger.warn("Failed to parse {} . The default document format registry will be used instead.", DOCUMENT_FORMATS_PATH, e);
}
} else {
this.logger.debug("{} is missing. The default document format registry will be used instead.", DOCUMENT_FORMATS_PATH);
}
if (this.jodConverter == null) {
// Use the default document format registry.
this.jodConverter = new OfficeDocumentConverter(this.jodManager);
}
File workDir = this.environment.getTemporaryDirectory();
this.converter = new DefaultOfficeConverter(this.jodConverter, workDir);
}
Aggregations