Apache OpenOffice (AOO) Bugzilla – Issue 57047
XDocumentInsertable.insertDocumentFromURL() doesn't accept an InteractionHandler
Last modified: 2013-02-24 21:08:29 UTC
The method XDocumentInsertable.insertDocumentFromURL() expects an argument of type MediaDescriptor ([in] sequence< ::com::sun::star::beans::PropertyValue > insertProps). Trying to set the Value of insertProps.InteractionHandler to an own implementation of XInteractionHandler causes insertDocumentFromURL() to throw an InvalidArgumentException. The following code example demontrates this behaviour: import com.sun.star.beans.PropertyValue; import com.sun.star.comp.helper.Bootstrap; import com.sun.star.document.XDocumentInsertable; import com.sun.star.frame.FrameSearchFlag; import com.sun.star.frame.XComponentLoader; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.task.XInteractionHandler; import com.sun.star.task.XInteractionRequest; import com.sun.star.text.XText; import com.sun.star.text.XTextCursor; import com.sun.star.text.XTextDocument; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; public class InsertDocumentFromURLTest { public static void main(String[] args) throws Exception { PropertyValue[] insertProps; // bootstrap and create Desktop XComponentContext xContext = Bootstrap.bootstrap(); XMultiComponentFactory xMCF = xContext.getServiceManager(); Object desktop = xMCF.createInstanceWithContext( "com.sun.star.frame.Desktop", xContext); // create empty document XComponentLoader xLoader = (XComponentLoader) UnoRuntime .queryInterface(XComponentLoader.class, desktop); XComponent doc = xLoader.loadComponentFromURL( "private:factory/swriter", "_blank", FrameSearchFlag.CREATE, new PropertyValue[0]); // create insertion-textcursor XTextDocument xTextDoc = (XTextDocument) UnoRuntime.queryInterface( XTextDocument.class, doc); XText xText = xTextDoc.getText(); XTextCursor cursor = xText.createTextCursor(); XDocumentInsertable xInsert = (XDocumentInsertable) UnoRuntime .queryInterface(XDocumentInsertable.class, cursor); System.out.println("test 1"); // providing a non-empty MediaDescriptor throws an // IllegalArgumentException. insertProps = new PropertyValue[] { new PropertyValue() }; insertProps[0].Name = "InteractionHandler"; insertProps[0].Value = new XInteractionHandler() { public void handle(XInteractionRequest arg0) { // do something } }; xInsert.insertDocumentFromURL("file:///home/foo/aFile.odt", insertProps); System.out.println("finished!"); System.exit(0); } }
sw->tl: as far as I can see this is a writer-only Interface, so one for you
.
The whole MediaDescriptor should be passed to the InsertFile method. Inside this method you could do the following: #include <sfx2/sfxuno.hxx> pMed = new SfxMedium(rFileName, STREAM_READ, sal_True, 0, 0 ); TransformParameters( SID_OPENDOC, aMedium, *pMedium->GetItemSet() ); SFX_ITEMSET_ARG( pItem, SID_FILTERNAME, .... ); if ( pItem ) { SfxObjectFactory& rFact = pDocSh->GetFactory(); const SfxFilter* pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( pItem->GetValue() ); if ( pFilter ) { pMedium->SetFilter( pFilter ); } else DELETEZ(pMed); }
seems using insertProps[0] = new PropertyValue(); insertProps[0].Name = "InputStream"; insertProps[0].Value = new ByteArrayToXInputStreamAdapter(data); XDocumentInsertable insertable = (XDocumentInsertable) UnoRuntime.queryInterface(XDocumentInsertable.class, cursor); insertable.insertDocumentFromURL(url, insertProps); gives also an error. what is the status of this issue ?
->Laurent: Nothing new since the target is 2.x and I have still 2.3 issues to take care of.
If this issue also concerns input streams (which is also my problem), then I would suggest changing its summary to something like "XDocumentInsertable.insertDocumentFromURL() doesn't accept an InteractionHandler or a steam"
What's up with this bug? Will it be fixed in OOo 3.x?