Skip to main content



      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 04:50 Go to next message
Eclipse UserFriend
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 10:19 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Encoding option ignored in class XMLProcessor [message #1203312 is a reply to message #1203273] Fri, 22 November 2013 10:44 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 00:30:50 EDT 2025

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

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

Back to the top