Document Links

From Apache OpenOffice Wiki
Jump to: navigation, search



Each data source can maintain an arbitrary number of document links. The primary purpose of this function is to provide a collection of database forms used with a database.

Template:Documentation/Note

The links are available at the com.sun.star.sdb.XBookmarksSupplier interface of a data source that has one method:

  com::sun::star::container::XNameAccess getBookmarks()

The returned service is a com.sun.star.sdb.DefinitionContainer. The DefinitionContainer is not only an XNameAccess, but a com.sun.star.container.XNameContainer, that is, new links are added using insertByName() as described in the chapter First Steps. Besides the name access, links are obtained through com.sun.star.container.XIndexAccess and com.sun.star.container.XEnumerationAccess.

The returned bookmarks are simple strings containing URLs. Usually forms are are stored at file:/// URLs. The following example adds a new document to the data source Bibliography:

  public static void addDocumentLink(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception {
      XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(
          XNameAccess.class,_rMSF.createInstance("com.sun.star.sdb.DatabaseContext"));
 
      // we use the predefined Bibliography data source
      XDataSource xDS = (XDataSource)UnoRuntime.queryInterface(
          XDataSource.class, xNameAccess.getByName("Bibliography"));
 
      // we need the XBookmarksSupplier interface of the data source
      XBookmarksSupplier xBookmarksSupplier = ( XBookmarksSupplier )UnoRuntime.queryInterface(
          XBookmarksSupplier.class, xDS);
 
      // get container with bookmark URLs
      XNameAccess xBookmarks = xBookmarksSupplier.getBookmarks();
      XNameContainer xBookmarksContainer = (XNameContainer)UnoRuntime.queryInterface(
          XNameContainer.class, xBookmarks);
 
      // insert new link
      xBookmarksContainer.insertByName("MyLink", "file:///home/ada01/Form_Ada01_DSADMIN.Table1.odt");
  }

To load a linked document, use the bookmark URL with the method loadComponentFromUrl() at the com.sun.star.frame.XComponentLoader interface of the com.sun.star.frame.Desktop singleton that is available at the global service manager. For details about the Desktop, see Office Development.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages