Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Byte Order Mark ( BOM ) and Editor
Byte Order Mark ( BOM ) and Editor [message #496597] Tue, 10 November 2009 16:31 Go to next message
Andreas Winkler is currently offline Andreas Winkler
Messages: 14
Registered: July 2009
Junior Member
Hi!

I am working on an editor and have to edit files which could have a byte order mark at the beginning of the file. But I don't want the user to see the BOM and also the BOM must not be lost when the file is saved.

Could you give please give me a hint where to look and/or what to do?

Thanks in advance
Andreas
Re: Byte Order Mark ( BOM ) and Editor [message #496724 is a reply to message #496597] Wed, 11 November 2009 07:26 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
Andreas Winkler wrote:
> Hi!
>
> I am working on an editor and have to edit files which could have a
> byte order mark at the beginning of the file. But I don't want the
> user to see the BOM and also the BOM must not be lost when the file is
> saved.
>
> Could you give please give me a hint where to look and/or what to do?
Simply use file buffers (see IFileBuffer) - they handle this
automatically for you.

Dani
>
> Thanks in advance
> Andreas
Re: Byte Order Mark ( BOM ) and Editor [message #496910 is a reply to message #496724] Wed, 11 November 2009 17:15 Go to previous messageGo to next message
Andreas Winkler is currently offline Andreas Winkler
Messages: 14
Registered: July 2009
Junior Member
Hi

I extended AbstractDecoratedTextEditor with my editor and I thought it already uses FileBuffers?!

Maybe I have to set the FileBuffers somewhere to accept byte order mark?

Regards
Andreas
Re: Byte Order Mark ( BOM ) and Editor [message #496993 is a reply to message #496910] Thu, 12 November 2009 07:02 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
Andreas Winkler wrote:
> Hi
>
> I extended AbstractDecoratedTextEditor with my editor and I thought it
> already uses FileBuffers?!
Yes, it does. But of course the file has to have an encoding/charset
which has a BOM.

Dani
>
> Maybe I have to set the FileBuffers somewhere to accept byte order mark?
>
> Regards
> Andreas
Re: Byte Order Mark ( BOM ) and Editor [message #497015 is a reply to message #496993] Thu, 12 November 2009 09:27 Go to previous messageGo to next message
Andreas Winkler is currently offline Andreas Winkler
Messages: 14
Registered: July 2009
Junior Member
But I thought the BOM indicates the charset/encoding?
That's why I am little confused, we use it to ensure that if another charset is used the editor recognises it and shows the correct text.

Do I have to tell the editor the file could have a UTF-8 encoding or UTF-16, or should FileBuffer already recognise this automatically and therefor doesn't show the BOM. If I have to tell the editor(FileBuffer) which encoding is "allowed" where do I have to put it? Is it a extension point?

Re: Byte Order Mark ( BOM ) and Editor [message #497022 is a reply to message #497015] Thu, 12 November 2009 09:48 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
Andreas Winkler wrote:
> But I thought the BOM indicates the charset/encoding?
> That's why I am little confused, we use it to ensure that if another
> charset is used the editor recognises it and shows the correct text.
>
> Do I have to tell the editor the file could have a UTF-8 encoding or
> UTF-16, or should FileBuffer already recognise this automatically and
> therefor doesn't show the BOM. If I have to tell the
> editor(FileBuffer) which encoding is "allowed" where do I have to put
> it? Is it a extension point?
>
>
File buffers detect and preserve BOMs in existing files but when
creating files we don't add BOMs (see
https://bugs.eclipse.org/bugs/show_bug.cgi?id=78455).

Dani
Re: Byte Order Mark ( BOM ) and Editor [message #497036 is a reply to message #497022] Thu, 12 November 2009 10:51 Go to previous messageGo to next message
Andreas Winkler is currently offline Andreas Winkler
Messages: 14
Registered: July 2009
Junior Member
So far so good, but how do I tell my editor to not show the BOM?
Re: Byte Order Mark ( BOM ) and Editor [message #497040 is a reply to message #497036] Thu, 12 November 2009 11:05 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
Andreas Winkler wrote:
> So far so good, but how do I tell my editor to not show the BOM?
>
If it really uses file buffers underneath then the BOM is stripped and
should not appear in the editor.
org.eclipse.core.filebuffers.ITextFileBuffer.getDocument() should return
the file contents without the BOM.

Dani
Re: Byte Order Mark ( BOM ) and Editor [message #497049 is a reply to message #497040] Thu, 12 November 2009 11:33 Go to previous messageGo to next message
Andreas Winkler is currently offline Andreas Winkler
Messages: 14
Registered: July 2009
Junior Member
Thank you for your patience!

I don't get it then, I use IDE.openEditorOnFileStore( page, fileStore ); to send a file to my editor.
My Editor extends AbstractDecoratedTextEditor which should already use FileBuffers, at least that's what I thought.
In my editor i commented everything out so it doesn't do anything at the moment. But still I can see the BOM. That's why I am a little bit confused.
Have you any idea where I could look?

Thanks in advance
Andreas
Re: Byte Order Mark ( BOM ) and Editor [message #497057 is a reply to message #497049] Thu, 12 November 2009 11:52 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
Andreas Winkler wrote:
> Thank you for your patience!
>
> I don't get it then, I use IDE.openEditorOnFileStore( page, fileStore
> ); to send a file to my editor.
OK, so you are not opening a workspace resource but an external file.
You might run into https://bugs.eclipse.org/bugs/show_bug.cgi?id=160614
then.

Dani
> My Editor extends AbstractDecoratedTextEditor which should already use
> FileBuffers, at least that's what I thought.
> In my editor i commented everything out so it doesn't do anything at
> the moment. But still I can see the BOM. That's why I am a little bit
> confused.
> Have you any idea where I could look?
>
> Thanks in advance
> Andreas
Re: Byte Order Mark ( BOM ) and Editor [message #497077 is a reply to message #497057] Thu, 12 November 2009 13:21 Go to previous message
Andreas Winkler is currently offline Andreas Winkler
Messages: 14
Registered: July 2009
Junior Member
Thank you for your help!

I found a solution even if I don't know if this is the best way Wink
I used the extension point org.eclipse.core.contenttype.contentTypes and made org.eclipse.core.runtime.text as base-type for my extensions. This seems to do the job.

Regards
Andreas


Previous Topic:Databinding Confusion
Next Topic:Binding a set of radio buttons to an int property
Goto Forum:
  


Current Time: Sun Oct 26 00:32:11 GMT 2014

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

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