Search in sources :

Example 1 with XComponent

use of com.sun.star.lang.XComponent 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);
// }
}
Also used : XComponent(com.sun.star.lang.XComponent) OPException(net.heartsome.cat.converter.ooconnect.OPException)

Example 2 with XComponent

use of com.sun.star.lang.XComponent 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)

Example 3 with XComponent

use of com.sun.star.lang.XComponent in project translationstudio8 by heartsome.

the class TerminationOpenoffice method getCurrentComponent.

/**
	 * Gets the current component.
	 * @return the current component
	 * @throws Exception
	 *             the exception
	 */
public static XComponent getCurrentComponent() throws Exception {
    XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
    // XComponentContext xRemoteContext =
    // com.sun.star.comp.helper.Bootstrap.bootstrap();
    XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();
    //$NON-NLS-1$
    Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext);
    XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
    XComponent currentComponent = xDesktop.getCurrentComponent();
    return currentComponent;
}
Also used : XComponentContext(com.sun.star.uno.XComponentContext) XComponent(com.sun.star.lang.XComponent) XDesktop(com.sun.star.frame.XDesktop) XMultiComponentFactory(com.sun.star.lang.XMultiComponentFactory)

Example 4 with XComponent

use of com.sun.star.lang.XComponent in project jabref by JabRef.

the class OOBibBase method getTextDocuments.

private List<XTextDocument> getTextDocuments() throws NoSuchElementException, WrappedTargetException {
    List<XTextDocument> result = new ArrayList<>();
    XEnumerationAccess enumAccess = xDesktop.getComponents();
    XEnumeration componentEnumeration = enumAccess.createEnumeration();
    while (componentEnumeration.hasMoreElements()) {
        Object nextElement = componentEnumeration.nextElement();
        XComponent component = UnoRuntime.queryInterface(XComponent.class, nextElement);
        XTextDocument document = UnoRuntime.queryInterface(XTextDocument.class, component);
        if (document != null) {
            result.add(document);
        }
    }
    return result;
}
Also used : XTextDocument(com.sun.star.text.XTextDocument) XComponent(com.sun.star.lang.XComponent) ArrayList(java.util.ArrayList) XEnumeration(com.sun.star.container.XEnumeration) XEnumerationAccess(com.sun.star.container.XEnumerationAccess)

Aggregations

XComponent (com.sun.star.lang.XComponent)4 OPException (net.heartsome.cat.converter.ooconnect.OPException)2 XEnumeration (com.sun.star.container.XEnumeration)1 XEnumerationAccess (com.sun.star.container.XEnumerationAccess)1 XComponentLoader (com.sun.star.frame.XComponentLoader)1 XDesktop (com.sun.star.frame.XDesktop)1 XStorable (com.sun.star.frame.XStorable)1 XMultiComponentFactory (com.sun.star.lang.XMultiComponentFactory)1 ByteArrayToXInputStreamAdapter (com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter)1 OutputStreamToXOutputStreamAdapter (com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter)1 XTextDocument (com.sun.star.text.XTextDocument)1 XComponentContext (com.sun.star.uno.XComponentContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1