home | projects | develop | info | Clipboard and text/html Dataflavor in Windows |
Problems transfering 'text/html' from Java to native applications |
develop java-snippets clipboard & html zip: only ascii graphic: bezier tools |
IntroductionTry to copy some text as html into the windows clipboard with jdk1.3/1.4 (others not tested).
Some other applications don't accept this as valid data. Known as:
If you put data into the clipboard with a Windows html clipboard formatHtml as a clipboard format is registered in Windows with the identifier 'HTML Format'. The data-format is text, something like this: Version:1.0 StartHTML:0000000000 EndHTML:0000000000 StartFragment:0000000000 EndFragment:0000000000 <!--StartFragment--> ... <!-- EndFragment-- >
Links Clipboard inspecting toolI have written a small native (win) application to inspect the clipboard in a nearly raw way. Get it Bugs in other applicationsA little test helps to find out what is wrong with some destination applications. They can't handle StartHTML & EndHTML set to -1. If you set them to real values all works fine. Oddly enough Eudora doesn't understand its own Html Format. Bug in Java
If you use a Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:0000000111 EndFragment:0000000417 <!--StartFragment--> Version:0.9 StartHTML:-1 EndHTML:-1 StartFragment:0000000111 EndFragment:0000000286 <!--StartFragment--> Version:0.9 StartHTML:00000000108 EndHTML:00000000168 StartFragment:00000000108 EndFragment:00000000168 <!--StartFragment--><b>Example text</b><!--EndFragment-->
Reason: If you look at the code below you can
see that first Java - Workaround
First, use only For the interaction with other programs, i don't know a clean one. Since some of the important methods in WClipboard are private, you have to get access with reflection, and become really dependant from the underlying implementation, see below.
It probably works to exchange the class HTMLSupport with bootclasspath
(see 'java.exe -X'), you only want this for your own computer. Or try to use
your own classloader to inject a new class. SystemFlavorMap - mapping of native/DataFlavorI tried to overwrite the default mapping of native/DataFlavor by playing around with: SystemFlavorMap.getDefaultFlavorMap() SystemFlavorMap.setNativesForFlavor(...) SystemFlavorMap.addUnencodedNativeForFlavor(...)
but this doesn't help. public byte[] translateTransferable( Transferable transferable, DataFlavor dataflavor, long nativeFormat) throws IOException{ byte data[] = super.translateTransferable( transferable, dataflavor, nativeFormat); if(nativeFormat == CF_HTML) data = HTMLSupport.convertToHTMLFormat(data); return data; }
They always compare to the native format, so it is always translated in the standard way.
Even if one uses a different DataFlavor, e.g. 'text/myOwn' which i may map to the
native 'Html Format'. Using a different
native Format is possible, but then other applications doesn't know about this.
Workaround to interact with buggy software
Access the native clipboard, windows only, write only.
Needs work to become fool-proof, you may look into WClipboard.
Since this class hacks a private method, it may be harmful if
the underlying implementation is changed.
To get access to the native windows clipboard: PEBClip.java |
© July 2003 Peter Büttner