Seraching for words with the Author API

Post here questions and problems related to oXygen frameworks/document types.
ms-badw
Posts: 2
Joined: Wed Oct 01, 2014 6:36 pm

Seraching for words with the Author API

Post by ms-badw »

Hi,

I currently work with the Oxygen SDK to provide additional functionality to the Oxygen Author mode. The goal is to create a number of Author operations, that enable users unfamiliar with XML to add tags to a TEI document without having to write actual markup.

I would like to provide the users with an operation, that allows them to highlight a certain part of the text, for exampe the name of a person or a place, and then automatically surround all matching occurences of the selected text in the document with the necessary tags.

Unfortunately there doesn't seem to be any method in the Author API in Java, that is able to search the text of a document for a String or Regular Expression an return the offset of it's occurences.

Am I missing something? Or is there another (indirect) way to achieve the functionality I need?

Regards,

Maximilian
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Seraching for words with the Author API

Post by alex_jitianu »

Hello,

There is no such API method to search for a text, but you can implement one yourself with the help of the API. I'm talking about using a TextContentIterator to iterate through all the text intervals. For each interval you can get the text and search for the token or apply a regular expression. I suggest iterating through the entire document and collecting the intervals that need to be surrounded. Afterwards, you can iterate through these intervals backwards and call AuthorDocumentController.surroundInFragment(String, int, int) for each interval.

Right now, in the text page, you can do a Find All action and afterwards you can choose to surround the matches in an element.

Best regards,
Alex
Post Reply