0

基本的に、openoffice ソフトウェアに接続するためのドライバーとして機能する OfficeManger というクラスがあります。これは常に接続されている必要があるため、コンバーターを使用してドキュメントを変換できます。Web アプリケーションの開始時に OpenOfficeProcess を開始すると、正常に開始されます。しかし、init() で実行されているエグゼキュータが別のスレッドにあるように見え、OfficeManager の実行中のインスタンスを取得できませんでした。このインスタンスを別のクラスから呼び出してコンバーター メソッドを使用できるように、独自のスレッドで実行する方法を教えてください。

    OfficeDocumentConverter converter = OpenOfficeProcessor.getInstance().getDocumentConverter();

    converter.convert(inputFile, outputFile, pdf);

OpenOfficeプロセッサー

public class OpenOfficeProcessor  {

    private static final OpenOfficeProcessor INSTANCE = new OpenOfficeProcessor();
    static ExecutorService executor = Executors.newSingleThreadExecutor();
    private final OfficeManager officeManager;
    private final OfficeDocumentConverter documentConverter;

    public OpenOfficeProcessor(){
        DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
        String homePath = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_HOME_PATH);
        if(homePath != null){
            configuration.setOfficeHome(homePath);
        } else {
            LOG.error("OpenOffice.home.path is not set in the properties file");
            new Throwable("Please set OPENOFFICE.HOME.PATH parameter in the properties file");
        }
        String port = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_LISTENER_PORT);
        if( port != null){
            configuration.setPortNumber(Integer.parseInt(port));
        }else {
            LOG.error("openoffice.listener.port is not set in the properties file");
        }
        String executionTimeout = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_EXECUTION_TIMEOUT);
        if(executionTimeout != null){
            configuration.setTaskExecutionTimeout(Long.parseLong(executionTimeout));
        }
        String pipeNames = ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_PIPES_NAMES);
        if(ConfigurationManager.getApplicationProperty(ConfigurationManager.OPENOFFICE_PIPES_NAMES)!= null){
            configuration.setPipeNames(pipeNames);
        }

        officeManager = configuration.buildOfficeManager();
        documentConverter = new OfficeDocumentConverter(officeManager);
    }
    public static OpenOfficeProcessor getInstance()
    {
        return INSTANCE;
    }


    protected static void init() {
        LOG.debug("Starting the open office listener...");
        executor.submit(new Callable(){

            @Override
            public Object call() throws Exception {
                OpenOfficeProcessor.getInstance().officeManager.start();
                return null;
            }
        });

    }

    protected static void destroy() {
        LOG.debug("Stopping the open office listener...");
        OpenOfficeProcessor.getInstance().officeManager.stop();
    }

    public OfficeManager getOfficeManager() {
        return officeManager;
    }

    public OfficeDocumentConverter getDocumentConverter() {
        return documentConverter;
    }

}

事務長

public interface OfficeManager {

    void execute(OfficeTask task) throws OfficeException;

    void start() throws OfficeException;

    void stop() throws OfficeException;

    boolean isRunning();
}
4

0 に答える 0