Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Charset mixed up in Dnd / File List / URI

Thread view: 
mtp - 21 Aug 2006 14:57 GMT
Hello,

i work on linux/gnome (jdk1.4.2_10 to compile, jdk 1.5.0_07 to run), and
when i drag and drop a file whose name is ("données.xls") on my java
application i accept the Drop with DataFlavor:

java.awt.datatransfer.DataFlavor[mimetype=application/x-java-serialized-object;representationclass=java.lang.String]

the drop data is "file:///home/user/.../donn%E9es.xls\r\n"

I drop the "\r\n", and i try to decode the %xx :

URI uri = new URI(filename);
String decodedPath = uri.getPath();

but the decoded path is: "/home/user/.../donn�es.xls"

So i guess it's a Charset problem but what can i do to solve it?

In short:
- "ls" and gnome explorer shows "données.xls"
- the drop data is "donn%E9es.xls"
- the decoded path is "donn�es.xls"

Does anyone know how to solve this?

TIA
Soren Kuula - 21 Aug 2006 16:43 GMT
> Hello,

> the drop data is "file:///home/user/.../donn%E9es.xls\r\n"
>
> I drop the "\r\n", and i try to decode the %xx :
>
> URI uri = new URI(filename);
> String decodedPath = uri.getPath();

try

String decodedPath = URLDecoder.decode(filename, "ISO-8859-1");

instead. My guess at ISO-8859 is inzzzztinct (from seeing the %E9).
> but the decoded path is: "/home/user/.../donn�es.xls"
>
> So i guess it's a Charset problem but what can i do to solve

Unless there is a way to query the Java drag and drop stuff about the
encoding used, my suggesting is to kick that penguin out of your
computer. Drag and drop has always been a pain in Linux, and character
encoding issues are not taken too seriously there either.

Søren
mtp - 22 Aug 2006 09:50 GMT
>> Hello,
>
[quoted text clipped - 10 lines]
>
> instead. My guess at ISO-8859 is inzzzztinct (from seeing the %E9).

you were right. My only idea about where the encoding come from is the
file.encoding system property:

String fileEncodingCharsetName = System.getProperty("file.encoding");
String decodedUrl = URLDecoder.decode(s, fileEncodingCharsetName);
URL url = new URL(decodedUrl);
File f = new File(url.getPath());

>> but the decoded path is: "/home/user/.../donn�es.xls"
>>
[quoted text clipped - 4 lines]
> computer. Drag and drop has always been a pain in Linux, and character
> encoding issues are not taken too seriously there either.

true, but i can't drop it ...
Oliver Wong - 21 Aug 2006 16:50 GMT
> Hello,
>
[quoted text clipped - 21 lines]
>
> Does anyone know how to solve this?

   In your "incorrect" decoded path, what's the unicode value of the
incorrect character? E9 is indeed the correct unicode value for the
"lowercase latin e with acute accent":
http://www.eki.ee/letter/chardata.cgi?ucode=00E9

   - Oliver
mtp - 22 Aug 2006 10:18 GMT
>    In your "incorrect" decoded path, what's the unicode value of the
> incorrect character? E9 is indeed the correct unicode value for the
> "lowercase latin e with acute accent":
> http://www.eki.ee/letter/chardata.cgi?ucode=00E9

it's also true for ISO-8859-1 and ISO-8859-15:

found in charsets:  8859-1 (E9); 8859-10 (E9); 8859-13 (E9); 8859-14
(E9); 8859-15 (E9); ...

but the page explains it:
UTF-8 (c3, a9) é
       ^^^^^^

which i checked :

bsh % print(URLDecoder.decode("donn%E9es", "UTF-8"));
donn�es

bsh % print(URLDecoder.decode("donn%E9es", "ISO-8859-1"));
données

bsh % print(URLEncoder.encode("données", "UTF-8"));
donn%C3%A9es
    ^^^^^^


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.