
de.devsurf.components.converter.openoffice.OOoConverter Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2010 Daniel Manzke
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.devsurf.components.converter.openoffice;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.annotation.PostConstruct;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.document.DocumentFormatRegistry;
import org.artofsolving.jodconverter.document.JsonDocumentFormatRegistry;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeConnectionProtocol;
import org.artofsolving.jodconverter.office.OfficeException;
import org.artofsolving.jodconverter.office.OfficeManager;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import de.devsurf.components.converter.Converter;
import de.devsurf.components.converter.ConverterFormat;
import de.devsurf.components.converter.ConverterFormat.InputFormat;
import de.devsurf.components.converter.ConverterFormat.OutputFormat;
import de.devsurf.tools.io.NamedInputStream;
import de.devsurf.tools.io.StreamUtil;
@Singleton
public class OOoConverter implements Converter {
private OfficeManager officeManager;
private DocumentFormatRegistry formatRegistry;
private OfficeDocumentConverter converter;
private TempCleaner cleaner;
@Inject(optional=true) @Named("converter.pipe.name")
private String pipeName = "saOOPipe";
@Inject(optional=true) @Named("converter.pipe.count")
private int pipes = 3;
@Inject(optional=true) @Named("converter.pipe.executionTimeOut")
private long executionTimeOut = 120000;
@Inject(optional=true) @Named("converter.pipe.killTimeOut")
private long killTimeOut = 5000L;
@Inject(optional=true) @Named("converter.pipe.cleanerTimeOut")
private long cleanerTimeOut = 1L;
@Override
@PostConstruct
public void initialize() throws Exception{
DefaultOfficeManagerConfiguration converterConfiguration = new DefaultOfficeManagerConfiguration();
converterConfiguration.setConnectionProtocol(OfficeConnectionProtocol.PIPE);
String[] pipeNames = new String[pipes];
for(int i=0;i getSupportedFormats() {
return new HashSet(Arrays.asList(new OutputFormat("Portable Document Format", "pdf", "application/pdf")));
}
@Override
public boolean supports(ConverterFormat format) {
return true;
}
@Override
public void shutdown() throws Exception {
officeManager.stop();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy