Search in sources :

Example 1 with XStorable

use of com.sun.star.frame.XStorable in project translationstudio8 by heartsome.

the class OpenOfficeDocumentConverter method storeDocument.

/**
	 * Store document.
	 * @param document
	 *            the document
	 * @param outputUrl
	 *            the output url
	 * @param storeProperties
	 *            the store properties
	 */
@SuppressWarnings("unchecked")
private void storeDocument(XComponent document, String outputUrl, Map storeProperties) throws com.sun.star.io.IOException {
    try {
        XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
        storable.storeToURL(outputUrl, toPropertyValues(storeProperties));
    } finally {
        XCloseable closeable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document);
        if (closeable != null) {
            try {
                closeable.close(true);
            } catch (CloseVetoException closeVetoException) {
                if (Converter.DEBUG_MODE) {
                    closeVetoException.printStackTrace();
                }
            }
        } else {
            document.dispose();
        }
    }
}
Also used : CloseVetoException(com.sun.star.util.CloseVetoException) XStorable(com.sun.star.frame.XStorable) XCloseable(com.sun.star.util.XCloseable)

Example 2 with XStorable

use of com.sun.star.frame.XStorable 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();
    }
}
Also used : HashMap(java.util.HashMap) XComponent(com.sun.star.lang.XComponent) OPException(net.heartsome.cat.converter.ooconnect.OPException) ByteArrayToXInputStreamAdapter(com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter) XComponentLoader(com.sun.star.frame.XComponentLoader) OutputStreamToXOutputStreamAdapter(com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter) HashMap(java.util.HashMap) Map(java.util.Map) XStorable(com.sun.star.frame.XStorable)

Aggregations

XStorable (com.sun.star.frame.XStorable)2 XComponentLoader (com.sun.star.frame.XComponentLoader)1 XComponent (com.sun.star.lang.XComponent)1 ByteArrayToXInputStreamAdapter (com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter)1 OutputStreamToXOutputStreamAdapter (com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter)1 CloseVetoException (com.sun.star.util.CloseVetoException)1 XCloseable (com.sun.star.util.XCloseable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OPException (net.heartsome.cat.converter.ooconnect.OPException)1