com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter Java Examples
The following examples show how to use
com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamOpenOfficeDocumentConverter.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 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/* <String,Object> */importOptions, OutputStream outputStream, Map/* <String,Object> */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)) loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream))); //$NON-NLS-1$ XComponent document = desktop.loadComponentFromURL( "private:stream", "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$ //$NON-NLS-2$ if (document == null) { throw new OPException(Messages.getString("ooconverter.StreamOpenOfficeDocumentConverter.6")); //$NON-NLS-1$ } refreshDocument(document); Map/* <String,Object> */storeProperties = new HashMap(); storeProperties.putAll(exportOptions); storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream)); //$NON-NLS-1$ try { XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); storable.storeToURL("private:stream", toPropertyValues(storeProperties)); //$NON-NLS-1$ } finally { document.dispose(); } }
Example #2
Source File: PersistenceService.java From noa-libre with GNU Lesser General Public License v2.1 | 5 votes |
/** * Stored document in the submitted output stream. * * @param outputStream output stream to be used * * @throws Throwable if the document can not be stored * @author Alessandro Conte * @date 07.09.2006 */ private void storeInternal(OutputStream outputStream) throws Throwable { if (outputStream == null) return; OutputStreamToXOutputStreamAdapter stream = new OutputStreamToXOutputStreamAdapter(outputStream); PropertyValue[] initialPropertyValues = document.getInitialProperties(); String filterDefinition = null; for (int i = 0; i < initialPropertyValues.length; i++) { if (initialPropertyValues[i].Name.equalsIgnoreCase("FilterName")) filterDefinition = initialPropertyValues[i].Value.toString(); } boolean useFilter = filterDefinition != null && filterDefinition.length() > 0; int propCount = 2; if (useFilter) propCount = 3; PropertyValue[] propertyValues = new PropertyValue[propCount]; propertyValues[0] = new PropertyValue("OutputStream", -1, stream, PropertyState.DIRECT_VALUE); //$NON-NLS-1$ propertyValues[1] = new PropertyValue(); propertyValues[1].Name = "Hidden"; //$NON-NLS-1$ propertyValues[1].Value = new Boolean(true); if (useFilter) { propertyValues[2] = new PropertyValue(); propertyValues[2].Name = "FilterName"; //$NON-NLS-1$ propertyValues[2].Value = filterDefinition; } xStorable.storeToURL("private:stream", propertyValues); //$NON-NLS-1$ document.setModified(false); }
Example #3
Source File: StreamOpenOfficeDocumentConverter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * 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/* <String,Object> */importOptions, OutputStream outputStream, Map/* <String,Object> */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)) loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream))); //$NON-NLS-1$ XComponent document = desktop.loadComponentFromURL( "private:stream", "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$ //$NON-NLS-2$ if (document == null) { throw new OPException(Messages.getString("ooconverter.StreamOpenOfficeDocumentConverter.6")); //$NON-NLS-1$ } refreshDocument(document); Map/* <String,Object> */storeProperties = new HashMap(); storeProperties.putAll(exportOptions); storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream)); //$NON-NLS-1$ try { XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); storable.storeToURL("private:stream", toPropertyValues(storeProperties)); //$NON-NLS-1$ } finally { document.dispose(); } }
Example #4
Source File: PersistenceService.java From noa-libre with GNU Lesser General Public License v2.1 | 4 votes |
/** * Exports document into the output stream on the basis of the submitted filter. * * @param outputStream output stream to be used * @param filter filter to be used * * @throws NOAException if the document can not be exported * * @author Andreas Bröker * @date 25.08.2006 */ public void export(OutputStream outputStream, IFilter filter) throws NOAException { if (outputStream == null) throw new NOAException(Messages.getString("PersistenceService_error_message_invalid_output_stream")); //$NON-NLS-1$ if (filter == null || !filter.isSupported(document)) throw new NOAException(Messages.getString("PersistenceService.error_filter_invalid_message")); //$NON-NLS-1$ String filterDefinition = filter.getFilterDefinition(document); OutputStreamToXOutputStreamAdapter streamAdapter = new OutputStreamToXOutputStreamAdapter(outputStream); PropertyValue[] properties = filter instanceof PDFFilter ? new PropertyValue[3] : new PropertyValue[2]; properties[0] = new PropertyValue(); properties[0].Name = "FilterName"; //$NON-NLS-1$ properties[0].Value = filterDefinition; properties[1] = new PropertyValue("OutputStream", -1, streamAdapter, PropertyState.DIRECT_VALUE); //$NON-NLS-1$ if (filter instanceof PDFFilter) { properties[2] = new PropertyValue(); properties[2].Name = "FilterData"; properties[2].Value = ((PDFFilter) filter).getPDFFilterProperties().toPropertyValues(); } if (!filter.isExternalFilter()) document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS); try { xStorable.storeToURL("private:stream", properties); //$NON-NLS-1$ } catch (Throwable throwable) { String message = throwable.getMessage(); if (throwable instanceof ErrorCodeIOException) { message = ErrorCodeTranslator.getErrorCodeMessage(((ErrorCodeIOException) throwable).ErrCode); if (message == null) message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$ } else if (message == null || message.length() == 0) message = ERROR_MESSAGE; throw new NOAException(message, throwable); } if (!filter.isExternalFilter()) document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS_DONE); }