use of net.heartsome.cat.converter.ooconnect.OPException in project translationstudio8 by heartsome.
the class OpenOfficeDocumentConverter method convertInternal.
/**
* In this file-based implementation, streams are emulated using temporary files.
* @param inputStream
* the input stream
* @param inputFormat
* the input format
* @param outputStream
* the output stream
* @param outputFormat
* the output format
* @throws Exception
* the exception
*/
protected void convertInternal(InputStream inputStream, DocumentFormat inputFormat, OutputStream outputStream, DocumentFormat outputFormat) throws Exception {
File inputFile = null;
File outputFile = null;
try {
//$NON-NLS-1$ //$NON-NLS-2$
inputFile = File.createTempFile("document", "." + inputFormat.getFileExtension());
OutputStream inputFileStream = null;
try {
inputFileStream = new FileOutputStream(inputFile);
IOUtils.copy(inputStream, inputFileStream);
} finally {
IOUtils.closeQuietly(inputFileStream);
}
//$NON-NLS-1$ //$NON-NLS-2$
outputFile = File.createTempFile("document", "." + outputFormat.getFileExtension());
convert(inputFile, inputFormat, outputFile, outputFormat);
InputStream outputFileStream = null;
try {
outputFileStream = new FileInputStream(outputFile);
IOUtils.copy(outputFileStream, outputStream);
} finally {
IOUtils.closeQuietly(outputFileStream);
}
} catch (IOException ioException) {
//$NON-NLS-1$
throw new OPException(Messages.getString("ooconverter.OpenOfficeDocumentConverter.4"), ioException);
} finally {
if (inputFile != null) {
inputFile.delete();
}
if (outputFile != null) {
outputFile.delete();
}
}
}
use of net.heartsome.cat.converter.ooconnect.OPException in project translationstudio8 by heartsome.
the class OpenOfficeDocumentConverter method loadAndExport.
/**
* Load and export.
* @param inputUrl
* the input url
* @param loadProperties
* the load properties
* @param outputUrl
* the output url
* @param storeProperties
* the store properties
* @throws Exception
* the exception
*/
@SuppressWarnings("unchecked")
private void loadAndExport(String inputUrl, Map loadProperties, String outputUrl, Map storeProperties) throws Exception {
XComponent document;
// try {
document = loadDocument(inputUrl, loadProperties);
// }
if (document == null) {
//$NON-NLS-1$
throw new OPException(Messages.getString("ooconverter.OpenOfficeDocumentConverter.9"));
}
refreshDocument(document);
// try {
storeDocument(document, outputUrl, storeProperties);
// } catch (ErrorCodeIOException errorCodeIOException) {
// throw new
// OPException("conversion failed: could not save output document; OOo errorCode: "
// + errorCodeIOException.ErrCode, errorCodeIOException);
// } catch (Exception otherException) {
// throw new
// OPException("conversion failed: could not save output document",
// otherException);
// }
}
use of net.heartsome.cat.converter.ooconnect.OPException in project translationstudio8 by heartsome.
the class StreamOpenOfficeDocumentConverter method loadAndExport.
/**
* Load and export.
* @param inputStream
* the input stream
* @param importOptions
* the import options
* @param outputStream
* the output stream
* @param exportOptions
* the export options
* @throws Exception
* the exception
*/
@SuppressWarnings("unchecked")
private void loadAndExport(InputStream inputStream, Map importOptions, OutputStream outputStream, Map exportOptions) throws Exception {
XComponentLoader desktop = openOfficeConnection.getDesktopObject();
Map /* <String,Object> */
loadProperties = new HashMap();
loadProperties.putAll(getDefaultLoadProperties());
loadProperties.putAll(importOptions);
// doesn't work using InputStreamToXInputStreamAdapter; probably because
// it's not XSeekable
// property("InputStream", new
// InputStreamToXInputStreamAdapter(inputStream))
//$NON-NLS-1$
loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream)));
XComponent document = desktop.loadComponentFromURL("private:stream", "_blank", 0, //$NON-NLS-1$ //$NON-NLS-2$
toPropertyValues(loadProperties));
if (document == null) {
//$NON-NLS-1$
throw new OPException(Messages.getString("ooconverter.StreamOpenOfficeDocumentConverter.6"));
}
refreshDocument(document);
Map /* <String,Object> */
storeProperties = new HashMap();
storeProperties.putAll(exportOptions);
//$NON-NLS-1$
storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream));
try {
XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
//$NON-NLS-1$
storable.storeToURL("private:stream", toPropertyValues(storeProperties));
} finally {
document.dispose();
}
}
Aggregations