url current document Tom Schindl How does one get the URL of the active document

I tried using the {@link com.sun.star.document.MediaDescriptor} but got a com.sun.star.beans.UnknownPropertyException

XPropertySet documentProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,document); System.out.println(documentProps.getPropertyValue("URL"));

The URL-Property is marked OPTIONAL in the IDL. You are better of using the XModel to get the URL

import com.sun.star.beans.XPropertySet; import com.sun.star.frame.XDesktop; import com.sun.star.frame.XModel; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; public class Snippet { public void snippet(XMultiComponentFactory xmcf, XComponentContext ctx) throws Exception { Object desktop = xmcf.createInstanceWithContext("com.sun.star.frame.Desktop", ctx); XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop); XComponent document = xDesktop.getCurrentComponent(); XModel xmodel = (XModel) UnoRuntime.queryInterface(XModel.class, document); if (xmodel != null) { System.out.println(xmodel.getURL()); } } }
Removed unneeded code Initial version