Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
linux - ubuntu 14.04
Description
Im trying to convert odt to html. In doing the conversion Im trying to obtain the charset encoding of the odt document so that I can set the appropriate value on the html end. However I always get a 'null' value when trying to read the charset.
OdfTextDocument odfDoc = OdfTextDocument.loadDocument(is)
System.out.println(odfDoc.getContentDom.getXmlEncoding)
For the test document attached I am expecting to get UTF-8 but always see 'null'. Happens on other docs as well,
Is there a better way to obtain the charset encoding of an odt document?
Diagnosis: No XML declaration fields of the DOM document are currently set because the file is parsed with a SAX parser, and SAX does not reveal the XML declaration to SAX handlers (org.xml.sax).
Approach: Parse the beginning bytes with a StAX parser (javax.xml.stream), which is included in Java 6 and later.
Attached are odfdom patches for
Details
xmlVersion, xmlEncoding, and xmlstandalone.
(The XML declaration is parsed during initialization and not later because after the DOM is created, bytes are generated from the DOM, not the original file. For low overhead, the same internal-document byte array is used for both the StAX parser and SAX parser input streams. The StAX parser is closed immediately after the XML declaration fields are extracted and it does not read the rest of the stream.)
patch -p 1 -i 400-partN-xxx.patch
(note: OdfFileDom.java currently has a mix of '\n' and '\r\n' line terminators.)