Difference between revisions of "Writer/Smart Tags"
Line 1: | Line 1: | ||
=Introduction= | =Introduction= | ||
− | Smart Tags were introduced in Microsoft Office XP and allow to recognize words that have a special meaning to the user and furthermore allow to execute certain actions for a recognized word. | + | Smart Tags were introduced in Microsoft Office XP and allow to recognize words that have a special meaning to the user and furthermore allow to execute certain actions for a recognized word. The OpenOffice.org smart tag project has been initiated by Jakob Lechner/[http://www.fabalabs.org Fabalabs Software GmbH]. OpenOffice.org 2.2 included a first draft of the new smart tag API, for OpenOffice.org 2.3 this API has been enhanced significantly. In order to use this functionality, 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 installation of OpenOffice.org. The necessary interfaces for smart tag libraries currently have the status "unpublished" because will most likely be published in the next version of OpenOffice.org. |
=Basic functionality of Smart Tags= | =Basic functionality of Smart Tags= | ||
Line 7: | Line 7: | ||
Basically smart tags UNO components consist of two parts: | Basically smart tags UNO components consist of two parts: | ||
− | * A recognizer | + | * A recognizer component |
− | * An action | + | * An action component |
− | If a recognizer component is installed in OpenOffice.org its recognize() method will be invoked by OpenOffice.org Writer for every | + | If a recognizer component is installed in OpenOffice.org its recognize() method will be invoked by OpenOffice.org Writer for every paragraph found in the opened document. The recognize method then decides if any of the words has some specific meaning. Recognized words will be underlined violet in OpenOffice.org Writer. Ctrl-click on a recognized smart tag opens the smart tag menu. 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 smart tag 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. | 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. | ||
Line 35: | Line 35: | ||
For a look at the recognizer interface definition go to this [http://go-ooo.org/lxr/source/api/offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl page]. | For a look at the recognizer interface definition go to this [http://go-ooo.org/lxr/source/api/offapi/com/sun/star/smarttags/XSmartTagRecognizer.idl page]. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{| border=1 cellspacing=0 cellpadding=5 style="width:75%" | {| border=1 cellspacing=0 cellpadding=5 style="width:75%" | ||
Line 846: | Line 167: | ||
|} | |} | ||
− | ==The Action Interface== | + | |
+ | ==The Action Library Interface== | ||
+ | |||
+ | For a look at the action library interface definition go to this [http://go-ooo.org/lxr/source/api/offapi/com/sun/star/smarttags/XSmartTagAction.idl page]. | ||
{| border=1 cellspacing=0 cellpadding=5 style="width:75%" | {| border=1 cellspacing=0 cellpadding=5 style="width:75%" | ||
Line 1,064: | Line 388: | ||
| a boolean indicating whether the smart tag indicator should be visible. | | a boolean indicating whether the smart tag indicator should be visible. | ||
|} | |} | ||
+ | |||
+ | |||
+ | =Example implementations= | ||
+ | |||
+ | ==Document Properties Smart Tag== | ||
+ | |||
+ | ===Recognizer=== | ||
+ | |||
+ | |||
+ | As described above the recognizer matches document property keywords like title, author, description etc. The matching of scanned words of the current document is done by the Recognize() method as you can see below. This recognizer component contains just one smart tag type. Thus the getSmartTagCount() method returns 1. The name of this recognizer ("Document Properties Recognizer") is returned by the method getSmartTagName(). | ||
+ | |||
+ | |||
+ | <code>[java] | ||
+ | |||
+ | |||
+ | </code> | ||
+ | |||
+ | |||
+ | ===Action Library=== | ||
+ | |||
+ | |||
+ | Implementing an action library is quite similar to implementing the recognizer. Of course you have to support the action service instead of the recongizer service. Since this component just provides actions for one smart tag type the getSmartTagCount() method returns 1. And for this single smart tag the component just provides one action, as you can see in the invokeAction() method. This action retrieves the document properties value and inserts it into the document. | ||
+ | |||
+ | <code>[cpp] | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==XML based Smart Tags== | ||
+ | |||
+ | In some cases you just want to match a list of words or regular expressions and open some URL associated with these words. For such simple smart tag components Microsoft Office provides the possiblity to define a recognizer or an action library with a XML schema. These simple smart tag descriptions are called "Microsoft Office Smart Tag Lists" (MOSTL). Below you can find an example XML description which defines some OOo related terms and some actions involving OOo websites. The XML description is pretty self-explanatory. As mentioned it is also possible to specify regular expressions in order to recognize certain word patterns. If you want to see how regular expressions are defined have a look at this [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta/html/odc_regex_smarttags_2003.asp site]. | ||
+ | |||
+ | <code>[xml] | ||
+ | <FL:smarttaglist xmlns:FL="http://schemas.microsoft.com/office/smarttags/2003/mostl"> | ||
+ | <FL:name>OOo Smart Tags</FL:name> | ||
+ | <FL:lcid>1033</FL:lcid> | ||
+ | <FL:description>OOo Smart Tags</FL:description> | ||
+ | <FL:smarttag type="urn:schemas-openoffice-org:smarttags#ooo"> | ||
+ | |||
+ | <FL:caption>OOo Smart Tags</FL:caption> | ||
+ | <FL:terms> | ||
+ | <FL:termlist>OpenOffice.org, Writer, OOo, UNO</FL:termlist> | ||
+ | </FL:terms> | ||
+ | |||
+ | <FL:actions> | ||
+ | <FL:action id="ooo1"> | ||
+ | <FL:caption>OpenOffice.org Homepage</FL:caption> | ||
+ | <FL:url>http://www.openoffice.org</FL:url> | ||
+ | </FL:action> | ||
+ | <FL:action id="ooo2"> | ||
+ | <FL:caption>Download OpenOffice.org</FL:caption> | ||
+ | <FL:url>http://download.openoffice.org/index.html</FL:url> | ||
+ | </FL:action> | ||
+ | <FL:action id="ooo3"> | ||
+ | <FL:caption>Search in OOo Wiki</FL:caption> | ||
+ | <FL:url>http://wiki.services.openoffice.org/wiki/Special:Search?search={TEXT}&fulltext=Search</FL:url> | ||
+ | </FL:action> | ||
+ | </FL:actions> | ||
+ | |||
+ | </FL:smarttag> | ||
+ | </FL:smarttaglist> | ||
+ | </code> | ||
+ | |||
+ | In order to use XML based smart tags with OpenOffice.org a smart tag component was written which implements the Recognizer and Action Library interfaces as described in the sections above. This component parses XML files which comply with the MOSTL schema. The behavior of the recognize and the invokeAction methods is determined by the given XML description. The XML files currently have to reside in a subfolder called "smarttags" in the "share" folder of your OOo installation. For each XML file in this directory OOo Writer creates an instance of the MOSTL Smart Tag component. | ||
+ | |||
+ | The source code of the MOSTL Smart Tag component can be found here: [[Media:mostl.tar.gz]] | ||
+ | |||
+ | The MOSTL component depends on the [http://xmlsoft.org/ libxml] library and can be compiled with [http://download.openoffice.org/index.html OpenOffice.org SDK]. | ||
+ | |||
+ | =See also= | ||
+ | |||
+ | *[[Constructing_Components|Great tutorial about constucting UNO components]] | ||
+ | *[http://blogs.sun.com/GullFOSS/entry/successful_community_project_smart_tags Blog entry about smart tag project] |
Revision as of 09:11, 3 September 2007
Contents
Introduction
Smart Tags were introduced in Microsoft Office XP and allow to recognize words that have a special meaning to the user and furthermore allow to execute certain actions for a recognized word. The OpenOffice.org smart tag project has been initiated by Jakob Lechner/Fabalabs Software GmbH. OpenOffice.org 2.2 included a first draft of the new smart tag API, for OpenOffice.org 2.3 this API has been enhanced significantly. In order to use this functionality, 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 installation of OpenOffice.org. The necessary interfaces for smart tag libraries currently have the status "unpublished" because will most likely be published in the next version of OpenOffice.org.
Basic functionality of Smart Tags
Basically smart tags UNO components consist of two parts:
- A recognizer component
- An action component
If a recognizer component is installed in OpenOffice.org its recognize() method will be invoked by OpenOffice.org Writer for every paragraph found in the opened document. The recognize method then decides if any of the words has some specific meaning. Recognized words will be underlined violet in OpenOffice.org Writer. Ctrl-click on a recognized smart tag opens the smart tag menu. 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 smart tag 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.
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).
Next sections explain the interfaces of recognizer and action components in detail.
The Recognizer Interface
For a look at the recognizer interface definition go to this page.
string getName() | |
---|---|
Description | obtains a name that describes this recognizer component. |
Arguments | [in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the name. |
Return Value | the name of the recognizer component. |
string getDescription() | |
---|---|
Description | obtains a detailed description of this recognizer component. |
Arguments | [in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the description. |
Return Value | the description of the recognizer component. |
long getSmartTagCount() | |
---|---|
Description | The number of smart tag types supported by this recognizer component. |
Arguments | None. |
Return Value | The number of smart tag types supported by this recognizer component. |
string getSmartTagName() | |
---|---|
Description | obtains the name of one specific smart tag type supported by this recognizer component. |
Arguments | [in] long nSmartTagIndex: Index of the wanted smart tag type. |
Return Value | the unique name of the smart tag type. Smart tag type names are always in the format of namespaceURI#tagname. |
string getSmartTagDownloadURL() | |
---|---|
Description | obtains the URL that can be used to download new or updated recognizers. |
Arguments | [in] long nSmartTagIndex: Index of the wanted smart tag type. |
Return Value | the download URL. |
void recognize() | |
---|---|
Description | recognizes smart tags. |
Arguments | [in] string aText: The text that should be scanned by the recognizer. |
[in] long nStart: Denotes the start position of the region to scan. | |
[in] long nLength: Denotes the length of the text to scan. | |
[in] SmartTagRecognizerMode eDataType: This value indicates the type of the passed text. | |
[in] com::sun::star::lang::Locale aLocale: Is used to indicate the language of the passed text. | |
[in] com::sun::star::text::XTextMarkup xTextMarkup: This object is used to submit any recognized smart tags to the calling application. | |
[in] string aApplicationName: A string containing the name of the calling application. | |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
[in] com::sun::star::i18n::XBreakIterator xTokenizer: This can be used to tokenize the string to recognize. | |
Return Value | None. |
boolean hasPropertyPage() | |
---|---|
Description | indicates whether there is a property page for a smart tag type. |
Arguments | [in] long nSmartTagIndex: Index of the wanted smart tag type. |
[in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the property page. | |
Return Value | None. |
void displayPropertyPage() | |
---|---|
Description | launches the property page for a smart tag type. |
Arguments | [in] long nSmartTagIndex: Index of the wanted smart tag type. |
[in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the property page. | |
Return Value | None. |
The Action Library Interface
For a look at the action library interface definition go to this page.
string getName() | |
---|---|
Description | obtains a name that describes this action component. |
Arguments | [in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the name. |
Return Value | the name of the action component. |
string getDescription() | |
---|---|
Description | obtains a detailed description of this action component. |
Arguments | [in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the description. |
Return Value | the description of the action component. |
long getSmartTagCount() | |
---|---|
Description | The number of smart tag types supported by this action component. |
Arguments | None. |
Return Value | The number of smart tag types supported by this action component. |
string getSmartTagName() | |
---|---|
Description | obtains the name of one specific smart tag type supported by this action component. |
Arguments | [in] long nSmartTagIndex: Index of the wanted smart tag type. |
Return Value | the unique name of the smart tag type. Smart tag type names are always in the format of namespaceURI#tagname. |
string getSmartTagCaption() | |
---|---|
Description | obtains the caption of the smart tag type for using in user interfaces. |
Arguments | [in] long nSmartTagIndex: Index of the wanted smart tag type. |
in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the caption. | |
Return Value | the caption associated with the smart tag type. |
long getActionCount() | |
---|---|
Description | obtains the number of actions provided for a specifiy smart tag type. |
Arguments | [in] string aSmartTagName: Name of the wanted smart tag type. This is one of the names obtained by getSmartTagName() |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
Return Value | the number of actions available for the given smart tag type. |
long getActionID() | |
---|---|
Description | obtains a unique integer identifier for an action. |
Arguments | [in] string aSmartTagName: Name of the wanted smart tag type. This is one of the names obtained by getSmartTagName() |
[in] long nActionIndex: The index of the action for the given smart tag type. | |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
Return Value | the unique integer identifier for the requested action. |
string getActionCaptionFromID() | |
---|---|
Description | obtains a caption for a specified action for use in user interfaces. |
Arguments | [in] long nActionID: The identifier of the requested action. |
[in] string aApplicationName: A string containing the name of the calling application. | |
[in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the caption. | |
[in] com::sun::star::container::XStringKeyMap xProperties: Contains additional smart tag properties collected by the smart tag recognizer. | |
[in] string aText: The calling application can pass the text of the smart tag to the action component. | |
[in] string aXML: A string that is a XML representation of the smart tag. | |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
[in] com::sun::star::text::XTextRange xTarget: A text range representing the smart tag in the document. | |
Return Value | the caption of the requested action. |
string getActionNameFromID() | |
---|---|
Description | obtains a language independant name of an action. |
Arguments | [in] long nActionID: The identifier of the requested action. |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
Return Value | the language independant name of the specified action. |
void invokeAction() | |
---|---|
Description | invokes an action. |
Arguments | [in] long nActionID: The identifier of the requested action. |
[in] string aApplicationName: A string containing the name of the calling application. | |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
[in] com::sun::star::text::XTextRange xTarget: A text range representing the smart tag in the document. | |
[in] com::sun::star::container::XStringKeyMap xProperties: Contains additional smart tag properties collected by the smart tag recognizer. | |
[in] string aText: The calling application can pass the text of the smart tag to the action component. | |
[in] string aXML: A string that is a XML representation of the smart tag. | |
[in] ::com::sun::star::lang::Locale aLocale: Is used for localization of the caption. | |
Return Value | None. |
boolean isCaptionDynamic() | |
---|---|
Description | determines whether a caption is dynamic. |
Arguments | [in] long nActionID: The identifier of the requested action. |
[in] string aApplicationName: A string containing the name of the calling application. | |
[in] ::com::sun::star::lang::Locale aLocale: Is used for localization. | |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
Return Value | a boolean indicating whether the caption is dynamic. |
boolean isShowSmartTagIndicator() | |
---|---|
Description | determines whether the smart tag indicator should be visible. |
Arguments | [in] long nActionID: The identifier of the requested action. |
[in] string aApplicationName: A string containing the name of the calling application. | |
[in] ::com::sun::star::lang::Locale aLocale: Is used for localization. | |
[in] com::sun::star::frame::XController xController: The current controller of the document. | |
Return Value | a boolean indicating whether the smart tag indicator should be visible. |
Example implementations
Document Properties Smart Tag
Recognizer
As described above the recognizer matches document property keywords like title, author, description etc. The matching of scanned words of the current document is done by the Recognize() method as you can see below. This recognizer component contains just one smart tag type. Thus the getSmartTagCount() method returns 1. The name of this recognizer ("Document Properties Recognizer") is returned by the method getSmartTagName().
[java]
Action Library
Implementing an action library is quite similar to implementing the recognizer. Of course you have to support the action service instead of the recongizer service. Since this component just provides actions for one smart tag type the getSmartTagCount() method returns 1. And for this single smart tag the component just provides one action, as you can see in the invokeAction() method. This action retrieves the document properties value and inserts it into the document.
[cpp]
XML based Smart Tags
In some cases you just want to match a list of words or regular expressions and open some URL associated with these words. For such simple smart tag components Microsoft Office provides the possiblity to define a recognizer or an action library with a XML schema. These simple smart tag descriptions are called "Microsoft Office Smart Tag Lists" (MOSTL). Below you can find an example XML description which defines some OOo related terms and some actions involving OOo websites. The XML description is pretty self-explanatory. As mentioned it is also possible to specify regular expressions in order to recognize certain word patterns. If you want to see how regular expressions are defined have a look at this site.
[xml]
<FL:smarttaglist xmlns:FL="http://schemas.microsoft.com/office/smarttags/2003/mostl">
<FL:name>OOo Smart Tags</FL:name>
<FL:lcid>1033</FL:lcid>
<FL:description>OOo Smart Tags</FL:description>
<FL:smarttag type="urn:schemas-openoffice-org:smarttags#ooo">
<FL:caption>OOo Smart Tags</FL:caption> <FL:terms> <FL:termlist>OpenOffice.org, Writer, OOo, UNO</FL:termlist> </FL:terms>
<FL:actions> <FL:action id="ooo1"> <FL:caption>OpenOffice.org Homepage</FL:caption> <FL:url>http://www.openoffice.org</FL:url> </FL:action> <FL:action id="ooo2"> <FL:caption>Download OpenOffice.org</FL:caption> <FL:url>http://download.openoffice.org/index.html</FL:url> </FL:action>
<FL:action id="ooo3">
<FL:caption>Search in OOo Wiki</FL:caption> <FL:url>http://wiki.services.openoffice.org/wiki/Special:Search?search={TEXT}&fulltext=Search</FL:url> </FL:action> </FL:actions>
</FL:smarttag> </FL:smarttaglist>
In order to use XML based smart tags with OpenOffice.org a smart tag component was written which implements the Recognizer and Action Library interfaces as described in the sections above. This component parses XML files which comply with the MOSTL schema. The behavior of the recognize and the invokeAction methods is determined by the given XML description. The XML files currently have to reside in a subfolder called "smarttags" in the "share" folder of your OOo installation. For each XML file in this directory OOo Writer creates an instance of the MOSTL Smart Tag component.
The source code of the MOSTL Smart Tag component can be found here: Media:mostl.tar.gz
The MOSTL component depends on the libxml library and can be compiled with OpenOffice.org SDK.