Preventing content insertion

Oxygen general issues.
neon096
Posts: 45
Joined: Wed May 23, 2012 11:20 am

Preventing content insertion

Post by neon096 »

I'm trying to restrict a user from entering more than 2000 characters for a given element. Whereby the content the user is trying to insert is ignored. I'm currently looking at the AuthoringListenerAdapter beforeContentInsert method and I can count the text content but I'm struggling to prevent the component from adding the text.

The other way I've thought of is to change and use the contentInserted method and then manually code for the removing of the inserted text. Which could get quite messy if there are nested nodes.

Can you please advise what the best approach will be?
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Preventing content insertion

Post by Radu »

Hi Neil,

We have an API method like:

AuthorDocumentController.setDocumentFilter(AuthorDocumentFilter)

and in the filter you can overwrite the method:

AuthorDocumentFilter.insertText(AuthorDocumentFilterBypass, int, String)

You can check which AuthorNode contains the offset:

AuthorDocumentController.getNodeAtOffset(int)

and then if that node is a certain node you can look at its start and end offsets to see how much content it has inside.

If it has too much content you can stop delegating to the "AuthorDocumentFilterBypass" the event.

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