Page 1 of 1

Triger reformatting

Posted: Mon Dec 03, 2018 8:47 pm
by honyk
When document is opened in Author mode, until it is modified no XML formatting takes place. Can I somehow force this via code and reformat several files in bulk?

I am able to open files via my plugin class implementing AuthorOperation:

As I couldn't find any formatting trigger, I am trying inserting and removing XML fragment to zero position. But this approach fails (Premature end of file).

Code: Select all

Reader reader = new InputStreamReader(new FileInputStream(processedFile), "UTF-8");
authorAccess.getEditorAccess().reloadContent(reader);
// inserting and removing content
authorAccess.getDocumentController().insertXMLFragment("<?pi?>", 0); --> Error: Premature end of file.
authorAccess.getDocumentController().delete(0, 6);
Any idea?

Re: Triger reformatting

Posted: Tue Dec 04, 2018 8:54 am
by Radu
Hi,

If you want to make bulk format and indent changes, in the Oxygen Project view you can right click on a folder linked there and then choose "Format and Indent Files".
In addition, the Oxygen Preferences->"Editor / Edit Modes / Author" page has a "Format and indent->The entire document" radio button which should always format and indent the entire document when the contents are saved.
About what you are trying to do right now, you should try to insert the processing instruction at offset "1", we consider offset "0" to be the "document" node (which contains all comments, PIs and the root element) and you cannot insert anything before the "document" node.

Regards,
Radu