Writer/Smart Tags

From Apache OpenOffice Wiki
< Writer
Revision as of 09:35, 30 January 2007 by Jlechner (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Developing Smart Tag Components for Openoffice.org

Introduction

Smart Tags were introduced in Microsoft Office XP and allow to recognize words that have a special meaning to the user and futhermore allow to execute certain actions for a recognized word. Support for smart tags is included in the Openoffice 2.2 release as a new feature. In order to use this feature external UNO components (so-called smart tag libraries) have to be installed. This document explains how to write own smart tag libraries and how to integrate them into your Openoffice. The necessary interfaces for smart tag libraries currently have the status "unpublished" because there are still some minor enhancements planned. Nevertheless smart tag libraries are fully supported in Openoffice Writer 2.2. Just be aware that you have may have to modify the code of your components if you want to use them with the next release of Openoffice.org.

Basic functionality of Smart Tags

Basically smart tags UNO components consist of two parts: 1. A recognizer 2. An action library.

If a recognizer component is installed in openoffice its recognize() method will be invoked by Openoffice.org Writer for every word found in the opened document. The recognize method then decides if the word has some specific meaning and returns true or false. Recognized words will be underlined violet in Openoffice.org Writer. If the control key is pressed and the mouse is moved over a underlined word the mouse cursor changes to a hand. When you click on the word with the left mouse button (still holding the control key) a context menu is opened. This is where action libraries come into play. An action library provides actions for recognized words. The captions of available actions are displayed in the context menu. When you click on one entry in the context menu the invokeAction() method of the action library component is called. This method subsequently executes the appropriate action (a simple action might be opening some URL in the browser).

Here is a sceenshot of an example smart tag component which recognizes document property keywords like author, subject, title etc. There is only one action defined. This action inserts the value of the recognized document property into the text document.

Stag screenshot1.gif

The Services

For supporting external smart tag components two new service definitions have been added to offapi: - com.sun.star.smarttags.SmartTagRecognizer - com.sun.star.smarttags.SmartTagAction

The SmartTagRecognizer service exports the interface XSmartTagRecognizer. Accordingly the service SmartTagAction exports the interface XSmartTagAction.

The Interfaces

Recognizer and action components are collections of smart tags. This means a smart tag component can contain recognizers or actions for different topics, e.g. a smart tag for recognizing email addresses and another one for recognizing dates and times can be packed into one single recognizer component (accordingly actions for both the email and the date smart tag can be combined in one action component).

Personal tools