Issue 57047 - XDocumentInsertable.insertDocumentFromURL() doesn't accept an InteractionHandler
Summary: XDocumentInsertable.insertDocumentFromURL() doesn't accept an InteractionHandler
Status: ACCEPTED
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-31 14:11 UTC by clutz
Modified: 2013-02-24 21:08 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description clutz 2005-10-31 14:11:00 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);
    }
}
Comment 1 stephan.wunderlich 2005-11-02 13:04:58 UTC
sw->tl: as far as I can see this is a writer-only Interface, so one for you
Comment 2 thomas.lange 2006-06-20 14:24:54 UTC
.
Comment 3 Mathias_Bauer 2006-07-10 11:04:12 UTC
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);
    }

Comment 4 maison.godard 2007-06-28 14:23:59 UTC
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 ?
Comment 5 thomas.lange 2007-06-28 15:05:45 UTC
->Laurent: Nothing new since the target is 2.x and I have still 2.3 issues to
take care of.
Comment 6 sebdotv 2007-09-20 11:19:07 UTC
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"
Comment 7 thomas.lange 2007-12-03 15:57:49 UTC
.
Comment 8 elliot2extreme 2008-08-18 09:56:58 UTC
What's up with this bug? Will it be fixed in OOo 3.x?