Page 1 of 1

How to retreive the xml file encoding ?

Posted: Wed Sep 04, 2013 10:17 am
by sebastienlavandier
Hi,

I want to know if a getter exist in the Oxygen Author API for find the xml file encoding ?
Something like: authorAccess.getDocumentController().getDoctype();

Thanks for your help.

Sébastien

Re: How to retreive the xml file encoding ?

Posted: Wed Sep 04, 2013 11:19 am
by Radu
Hi Sébastien,

We do not have such an API. Could you elaborate on the use case? Maybe we could add such API in the future.

If you use our "editorComponentProvider.getWSEditorAccess().save()" API the document will be saved with the proper encoding detected when it was opened.
But indeed if you create a reader over the document and then construct a file output stream on it you would need to know the proper encoding for saving the document.

One workaround would be to create the reader over the document's content and look in it for the XML
declaration:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
If it contains an encoding, it can be used for save. But it's more complicated because the encoding specified in the XML declaration is a IANA encoding and it needs to be converted to a Java encoding to be used when creating an OutputStreamWriter over the file output stream. The code we use to detect the proper encoding on save is quite large.
If there is no XML declaration or if it does not contain an encoding you fall-back to UTF-8.

Regards,
Radu

Re: How to retreive the xml file encoding ?

Posted: Wed Sep 04, 2013 11:44 am
by sebastienlavandier
Hi Radu,

Ok, it's my conclusion too.

Thanks for your help again.
Sébastien.

Re: How to retreive the xml file encoding ?

Posted: Wed Sep 04, 2013 11:54 am
by Radu
Hi Sébastien,

I will also add an issue on our list so that in the future besides the API WSEditor.createContentReader() we could also add some API like WSEditor.createContentInputStream().

Regards,
Radu

Re: How to retreive the xml file encoding ?

Posted: Mon Jan 27, 2014 2:00 pm
by Radu
Hi Sébastien,

Oxygen 15.2 and the corresponding Author Component Project were released about a week ago.
In it we added the API:

ro.sync.exml.workspace.api.editor.WSEditorBase.createContentInputStream()

which should create an input stream with the proper encoding over the edited XML contents.

Regards,
Radu