Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Encoding option ignored in class XMLProcessor(UTF-8 encoding option ignored in saveToString method of class XMLProcessor)
Encoding option ignored in class XMLProcessor [message #1202752] Fri, 22 November 2013 09:50 Go to next message
Arastoo Barji is currently offline Arastoo BarjiFriend
Messages: 2
Registered: November 2013
Junior Member
Hello,

when using method saveToString(Resource, Map) of class XMLProcessor, encoding option can either be set by passing option XMLResource.OPTION_ENCODING with value "UTF-8" or by calling method setEncoding("UTF-8") on the passed XmlResource object. We did both but somehow saveToString(...) method ignores this option.
We implemented a workaround by calling method save(ByteArrayOutputStream, Resource, Map) of class XMLProcessor where we pass an own ByteArrayOutputStream object where encoding is set to UTF-8 and write the content of the outputstream into a String afterwards.
This workaround works, but does someone know why the first approach doesn't work correctly? We think this might be a bug of EMF package but maybe we just call the method in a wrong way.

Thanks,

Arastoo
Re: Encoding option ignored in class XMLProcessor [message #1203273 is a reply to message #1202752] Fri, 22 November 2013 15:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Arastoo,

Oh, you mean this last line

return os.toString();

should really use the encoding you've specified to decode the bytes.
That looks like a bug.

In any case, it would be better to use a StringWriter and avoid any
String -> byte[] -> String encoding. You could do that direct by
calling org.eclipse.emf.ecore.xmi.util.XMLProcessor.save(Writer,
Resource, Map<?, ?>) with a StringWriter.


On 22/11/2013 3:06 PM, Arastoo Barji wrote:
> Hello,
>
> when using method saveToString(Resource, Map) of class XMLProcessor,
> encoding option can either be set by passing option
> XMLResource.OPTION_ENCODING with value "UTF-8" or by calling method
> setEncoding("UTF-8") on the passed XmlResource object. We did both but
> somehow saveToString(...) method ignores this option.
> We implemented a workaround by calling method
> save(ByteArrayOutputStream, Resource, Map) of class XMLProcessor where
> we pass an own ByteArrayOutputStream object where encoding is set to
> UTF-8 and write the content of the outputstream into a String
> afterwards. This workaround works, but does someone know why the first
> approach doesn't work correctly? We think this might be a bug of EMF
> package but maybe we just call the method in a wrong way.
>
> Thanks,
>
> Arastoo


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Encoding option ignored in class XMLProcessor [message #1203312 is a reply to message #1203273] Fri, 22 November 2013 15:44 Go to previous message
Arastoo Barji is currently offline Arastoo BarjiFriend
Messages: 2
Registered: November 2013
Junior Member
Hello Ed,

Yes, exactly! The toString() method of the OutputStream object which needs an encoding argument should be called.

Also, thanks for the hint to use StringWriter instead of an OutputStream. I will change our code to use the right method now.


Previous Topic:[Xcore] Maven plugin for generating classes?
Next Topic:Modifying EMF model
Goto Forum:
  


Current Time: Fri Apr 26 00:03:52 GMT 2024

Powered by FUDForum. Page generated in 0.03567 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top