Reference Marks

From Apache OpenOffice Wiki
Jump to: navigation, search

A reference mark is a text content that is used as a target for text fields. These text fields show the contents of reference marks in a text document and allows the user to jump to the reference mark. Reference marks support the and interfaces. They can be accessed by using the text document's interface that defines a single method getReferenceMarks().

The returned collection is a service which has a and a interface.

 /** This method demonstrates how to create and insert reference marks, and GetReference Text Fields
 protected void ReferenceExample () {
     try {
         // Go to the end of the document
         // Insert a paragraph break
             mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false);
         // Get the Paragraph cursor
         XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface(
             XParagraphCursor.class, mxDocCursor);
         // Move the cursor into the new paragraph
         // Create a new ReferenceMark and get it's XNamed interface
         XNamed xRefMark = (XNamed) UnoRuntime.queryInterface(XNamed.class, 
         // Set the name to TableHeader
         // Get the TextTablesSupplier interface of the document
         XTextTablesSupplier xTableSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(
             XTextTablesSupplier.class, mxDoc);
         // Get an XIndexAccess of TextTables
         XIndexAccess xTables = (XIndexAccess) UnoRuntime.queryInterface(
             XIndexAccess.class, xTableSupplier.getTextTables());
         // We've only inserted one table, so get the first one from index zero
         XTextTable xTable = (XTextTable) UnoRuntime.queryInterface(
             XTextTable.class, xTables.getByIndex(0));
         // Get the first cell from the table
         XText xTableText = (XText) UnoRuntime.queryInterface(
             XText.class, xTable.getCellByName("A1"));
         // Get a text cursor for the first cell
         XTextCursor xTableCursor = xTableText.createTextCursor();
         // Get the XTextContent interface of the reference mark so we can insert it
         XTextContent xContent = (XTextContent) UnoRuntime.queryInterface(
             XTextContent.class, xRefMark);
         // Insert the reference mark into the first cell of the table
         xTableText.insertTextContent (xTableCursor, xContent, false);
         // Create a 'GetReference' text field to refer to the reference mark we just inserted,
         // and get it's XPropertySet interface
         XPropertySet xFieldProps = (XPropertySet) UnoRuntime.queryInterface(
             XPropertySet.class, mxDocFactory.createInstance(
         // Get the XReferenceMarksSupplier interface of the document
         XReferenceMarksSupplier xRefSupplier = (XReferenceMarksSupplier) UnoRuntime.queryInterface(
             XReferenceMarksSupplier.class, mxDoc);
         // Get an XNameAccess which refers to all inserted reference marks
         XNameAccess xMarks = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
         // Put the names of each reference mark into an array of strings
         String[] aNames = xMarks.getElementNames();
         // Make sure that at least 1 reference mark actually exists 
         // (well, we just inserted one!)
         if (aNames.length > 0) {
             // Output the name of the first reference mark ('TableHeader')
             System.out.println ("GetReference text field inserted for ReferenceMark : " 
                 + aNames[0]);
             // Set the SourceName of the GetReference text field to 'TableHeader'
             xFieldProps.setPropertyValue("SourceName", aNames[0]);
             // specify that the source is a reference mark (could also be a footnote,
             // bookmark or sequence field)
             xFieldProps.setPropertyValue ("ReferenceFieldSource", new Short(
             // We want the reference displayed as 'above' or 'below'
                 new Short (ReferenceFieldPart.UP_DOWN));
             // Get the XTextContent interface of the GetReference text field
             XTextContent xRefContent = (XTextContent) UnoRuntime.queryInterface(
                 XTextContent.class, xFieldProps);
             // Go to the end of the document
             // Make some text to precede the reference
             mxDocText.insertString(mxDocText.getEnd(), "The table ", false);
             // Insert the text field
             mxDocText.insertTextContent(mxDocText.getEnd(), xRefContent, false);
             // And some text after the reference..
             mxDocText.insertString( mxDocText.getEnd(), 
                 " contains the sum of some random numbers.", false);
             // Refresh the document
             XRefreshable xRefresh = (XRefreshable) UnoRuntime.queryInterface(
                 XRefreshable.class, mxDoc);
     } catch (Exception e) {

The name of a reference mark can be used in a text field to refer to the position of the reference mark.

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