Issue 83004

Summary: cannot paste HTML data from any java application via clipboard
Product: Writer Reporter: dmpl <dpolivaev>
Component: editingAssignee: AOO issues mailing list <issues>
Status: RESOLVED FIXED QA Contact:
Severity: Trivial    
Priority: P3 CC: damjan, issues, megadix
Version: OOo 2.3   
Target Milestone: 4.2.0   
Hardware: PC   
OS: Windows, all   
Issue Type: DEFECT Latest Confirmation in: 4.1.3
Developer Difficulty: ---
Attachments:
Description Flags
java program to reproduce none

Description dmpl 2007-10-26 14:18:41 UTC
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the code below to fill the clipboard.
Try to paste in OpenOffice 2.3 Writer (or older version). Notice the error
message "Requested clipboard format is not available".

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The formatted text should be inserted.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.*;
import java.io.IOException;

public class HtmlStreamCopy {
    public static void main(String[] args) throws ClassNotFoundException {
        String htmlText = "The quick <font color='#78650d'>brown</font>
<b>mouse</b> jumped over the lazy <b>cat</b>.";
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable htmlTransferable = new
HtmlStreamCopy.HtmlInputStreamTransferable(htmlText);
        clipboard.setContents(htmlTransferable, null);
    }

    private static class HtmlInputStreamTransferable implements Transferable {
        private final DataFlavor _htmlDataFlavor;
        private final String _htmlText;

        public HtmlInputStreamTransferable(String htmlText) throws
ClassNotFoundException {
            _htmlText = htmlText;
            _htmlDataFlavor = new DataFlavor("text/html; class=java.lang.String");
        }

        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[]{_htmlDataFlavor};
        }

        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return "text/html".equals(flavor.getMimeType());

        }

        public Object getTransferData(DataFlavor flavor) throws
UnsupportedFlavorException, IOException
        {
        	return _htmlText;
        }
    }
}
---------- END SOURCE ----------

DISCUSSION:

The reason copy & paste of text/html from Java to e.g. OpenOffice Writer doesn't
work (tested with different JDK 1.4.2, 1.5 and 1.6 and Windows 2000, similar
problem was reported also for Windows XP as issue 51267) seems to be that Java
sets the StartHTML and EndHTML properties of the Windows HTML clipboard format
to -1.  

See http://www.peterbuettner.de/develop/javasnippets/clipHtml/index.html

If I use the Clipview app on that page and manually modify the StartHTML and
EndHTML properties of the text/html copied from Java, I am able to paste it into
OpenOffice Writer.
Comment 1 michael.ruess 2007-10-26 14:48:58 UTC
Reassigned to ES.
Comment 2 eric.savary 2008-05-29 13:21:25 UTC
@sg: please have a look
Comment 3 steffen.grund 2008-05-29 15:17:04 UTC
Created attachment 54059 [details]
java program to reproduce
Comment 4 steffen.grund 2008-05-29 15:20:19 UTC
call java -jar HtmlStreamCopy.jar, wait until "DONE." appears, then try to paste
from clipboard to OpenOffice.org.
Checked on Solaris, woks fine there.
Comment 5 steffen.grund 2008-05-29 15:21:23 UTC
sg -> os: as discussed, one for you.
Comment 6 Oliver Specht 2008-05-29 16:09:05 UTC
The ...StartHTML:-1 EndHTML:-1... is (not) handled in
sfx2/source/bastyp/mieclip.cxx in MSE40HTMLClipFormatObj::IsValid( SvStream&
rStream ). -1 is casted to some illegal ULONG value.

Comment 7 Rob Weir 2013-07-30 02:42:39 UTC
Reset assignee on issues not touched by assignee in more than 1000 days.
Comment 8 SVN Robot 2016-10-20 15:47:12 UTC
"damjan" committed SVN revision 1765837 into trunk:
#i83004# cannot paste HTML data from any Java application via clipboard
Comment 9 damjan 2016-10-20 15:49:02 UTC
Java worked around this issue by proving StartHTML and EndHTML values of >= 0, so you could paste from Java for a while now, but I still implemented support for < 0 for other applications that still don't. Excel supports < 0, and so does Mozilla since 2011 (https://hg.mozilla.org/mozilla-central/rev/16c9cfa0cf84), so we really should too. Resolving fixed.
Comment 10 damjan 2016-10-20 15:49:56 UTC
.
Comment 11 damjan 2016-10-20 15:52:33 UTC
*** Issue 51267 has been marked as a duplicate of this issue. ***