Charset mixed up in Dnd / File List / URI

M

mtp

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
 
S

Soren Kuula

mtp said:
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
 
O

Oliver Wong

mtp said:
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?

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
 
M

mtp

Soren said:
try

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

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());
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.

true, but i can't drop it ...
 
M

mtp

Oliver said:
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
^^^^^^
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top