Search in sources :

Example 1 with DefaultOfficeManagerConfiguration

use of org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration in project openmeetings by apache.

the class DocumentConverter method createOfficeManager.

public static void createOfficeManager(String officePath, Consumer<OfficeManager> consumer) {
    OfficeManager manager = null;
    try {
        DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
        if (!Strings.isEmpty(officePath)) {
            configuration.setOfficeHome(officePath);
        }
        manager = configuration.buildOfficeManager();
        manager.start();
        if (consumer != null) {
            consumer.accept(manager);
        }
    } finally {
        if (manager != null) {
            manager.stop();
        }
    }
}
Also used : OfficeManager(org.artofsolving.jodconverter.office.OfficeManager) DefaultOfficeManagerConfiguration(org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration)

Example 2 with DefaultOfficeManagerConfiguration

use of org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration in project fess-crawler by codelibs.

the class JodExtractorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    StandardCrawlerContainer container = new StandardCrawlerContainer().singleton("officeManagerConfiguration", // 
    DefaultOfficeManagerConfiguration.class).singleton("jodExtractor", JodExtractor.class);
    jodExtractor = container.getComponent("jodExtractor");
    DefaultOfficeManagerConfiguration officeManagerConfiguration = container.getComponent("officeManagerConfiguration");
    jodExtractor.officeManager = officeManagerConfiguration.setPortNumber(12002).buildOfficeManager();
}
Also used : StandardCrawlerContainer(org.codelibs.fess.crawler.container.StandardCrawlerContainer) DefaultOfficeManagerConfiguration(org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration)

Example 3 with DefaultOfficeManagerConfiguration

use of org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration 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);
}
Also used : JsonDocumentFormatRegistry(org.artofsolving.jodconverter.document.JsonDocumentFormatRegistry) DefaultOfficeConverter(org.xwiki.officeimporter.internal.converter.DefaultOfficeConverter) OfficeServerException(org.xwiki.officeimporter.server.OfficeServerException) InputStream(java.io.InputStream) ExternalOfficeManagerConfiguration(org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration) File(java.io.File) DefaultOfficeManagerConfiguration(org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration) OfficeServerException(org.xwiki.officeimporter.server.OfficeServerException) OfficeDocumentConverter(org.artofsolving.jodconverter.OfficeDocumentConverter)

Aggregations

DefaultOfficeManagerConfiguration (org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration)3 File (java.io.File)1 InputStream (java.io.InputStream)1 OfficeDocumentConverter (org.artofsolving.jodconverter.OfficeDocumentConverter)1 JsonDocumentFormatRegistry (org.artofsolving.jodconverter.document.JsonDocumentFormatRegistry)1 ExternalOfficeManagerConfiguration (org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration)1 OfficeManager (org.artofsolving.jodconverter.office.OfficeManager)1 StandardCrawlerContainer (org.codelibs.fess.crawler.container.StandardCrawlerContainer)1 DefaultOfficeConverter (org.xwiki.officeimporter.internal.converter.DefaultOfficeConverter)1 OfficeServerException (org.xwiki.officeimporter.server.OfficeServerException)1