accessing text in Text Mode

Post here questions and problems related to oXygen frameworks/document types.
daniel7
Posts: 10
Joined: Tue May 27, 2014 10:00 am

accessing text in Text Mode

Post by daniel7 »

Hi,

is there a recommended way to get the text content of a document in Text mode, similar to what TextContentIterator does in Author mode?

I see I could just parse the XML myself, but I'm trying to write a grammar checker for text mode, so I'd need to re-parse the whole XML on almost every key press (to underline mistakes as they are typed) and I'm afraid that becomes too slow.

I'm using Oxygen Author 16.0 but I can update to 16.1 if needed.

Regards
Daniel
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: accessing text in Text Mode

Post by Radu »

Dear Daniel,

I will assume you are writing the customization for the standalone editor and not for the Oxygen Eclipse plugin.
So you are probably using the ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage API to access the text page.
Unfortunately for the text page we do not have a fixed hierarchy of nodes and the API can mostly return the Swing JTextArea WSTextEditorPage.getTextComponent() and the Swing document WSTextEditorPage.getDocument().
So you would need to have your own small parser.

But sending to a grammar checker the entire text content of the document every time a key is pressed is a bad idea in terms of performance, either when working in the Text or the Author editing modes.
Here are some possible solutions:

1) Instead of automatic grammar checking have a custom manual grammar checking toolbar button which checks the entire document when pressed.

2) The auto spell checker functionality in Oxygen works by spell checking only the content in the visible area each time the user presses a key. As you have access to the JTextArea, you can gain access to its JScrollPane and obtain the visible rectangle, then try to parse and send to the checker only the text content which is visible in the visible rectangle.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
daniel7
Posts: 10
Joined: Tue May 27, 2014 10:00 am

Re: accessing text in Text Mode

Post by daniel7 »

Thanks for your fast reply. I actually have a timer so that the check doesn't start when the key is pressed but after a timeout of (currently) 500ms. I'll see if that works good enough.
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: accessing text in Text Mode

Post by Radu »

Hi,

One more thing, for spell checking instead of using the text content iterator in the Author mode API you could have used:

AuthorDocumentController.getFilteredContent(int, int, AuthorNodesFilter)

It's Javadoc says something like:
* Retrieves the content between the given start and end offset, excluding the
* content of the invisible nodes (that have display none style property), the
* content deleted with track changes, the sentinels of inline elements and the
* content of filtered nodes
That filtered content has a method AuthorFilteredContent.getOriginalOffset(int) which maps an offset in the checked content to an actual offset in the Author document.
We created this API specifically for spell/grammar checking.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply