Hi,
in the following example-code I found some bugs in the
XDocumentInsertable.insertDocumentFromURL() method. Can you confirm
these bugs, so I can report an issue?
Are there known workarounds?
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.IllegalArgumentException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
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");
// Bug 1:
// providing a non-empty MediaDescriptor throws an
// IllegalArgumentException.
try {
insertProps = new PropertyValue[] { new PropertyValue() };
insertProps[0].Name = "Author";
insertProps[0].Value = "itsMe";
xInsert.insertDocumentFromURL(
"file:///W:/aFolder/thisFileDoesNotExist", insertProps);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
System.out.println("test 2");
// Bug ?:
// trying to insert a document with a non-existing file-URL
// does nothing (not even an exception)
insertProps = new PropertyValue[] {};
xInsert.insertDocumentFromURL(
"file:///aFolder/thisFileDoesNotExist", insertProps);
System.out.println("test 3");
// Bug 2:
// trying to insert a document with a non-existing file-URL
// causes OOo to freeze IF the URL start with a drive letter "c:"
insertProps = new PropertyValue[] {};
xInsert.insertDocumentFromURL(
"file:///c:/aFolder/aNonExistingFile", insertProps);
System.out.println("test 4");
// trying to insert a document with a non-existing file-URL
// causes OOo to freeze IF the URL is an unresolved http-url.
insertProps = new PropertyValue[] {};
xInsert.insertDocumentFromURL(
"http://www.michgibtswirklichnichtglaubichauchnicht.de/index.odt",
insertProps);
System.out.println("finished!");
System.exit(0);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]