-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
7
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Our application supports complex HTML pasting, such as content pasted from Microsoft Word. We use java.awt.datatransfer.Transferable#getTransferData() passing in a DataFlavor from the available clipboard data flavor list that has mime type "text/html".
In previous releases of Java, this returned the entire HTML clipboard contents. In Java 7, this is only returning content between the <!--StartFragment--> and <!--EndFragment--> comment tags.
This is a serious regression as it means we can no longer import correct HTML from complete documents copied to the clipboard.
REGRESSION. Last worked in version 6u26
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a basic document in Microsoft Word (I used 2010 in my testing, but as far back as 2003 should exhibit this behaviour as well).
2. Select all content in the document, copy
3. Load the HTMLPaste application
4. Paste (ctrl+v should work)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The console output should contain a full HTML document with a large amount of MS Word styles
ACTUAL -
Only the content between the <!--StartFragment--> and <!--EndFragment--> comment tags is printed to the console
ERROR MESSAGES/STACK TRACES THAT OCCUR :
None, it is a regression
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;
public final class HTMLPaste extends JFrame {
public HTMLPaste() throws HeadlessException {
setTitle("Paste test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JEditorPane field = createEditor();
add(new JScrollPane(field));
setSize(300, 400);
}
private JEditorPane createEditor() {
final JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
editorPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
editorPane.setTransferHandler(overrideTransferHandler(editorPane));
return editorPane;
}
private TransferHandler overrideTransferHandler(final JEditorPane editorPane) {
return new TransferHandler() {
final TransferHandler delegate = editorPane.getTransferHandler();
@Override
public boolean importData(final TransferSupport support) {
try {
readData(support);
//do the normal import process
return delegate.importData(support);
} catch (Error e) {
e.printStackTrace();
throw e;
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
};
}
private void readData(final TransferHandler.TransferSupport support) throws UnsupportedFlavorException, IOException {
final DataFlavor[] flavors = support.getDataFlavors();
System.out.println(Arrays.toString(flavors));
for (final DataFlavor flavor : flavors) {
if (flavor.getRepresentationClass() == String.class && flavor.getMimeType().startsWith("text/html")) {
System.out.println("found html");
outputData(support, flavor);
break;
}
if (flavor.getRepresentationClass() == String.class && flavor.getMimeType().startsWith("text/plain")) {
System.out.println("found text");
outputData(support, flavor);
break;
}
}
}
private void outputData(TransferHandler.TransferSupport support, DataFlavor flavor) throws UnsupportedFlavorException, IOException {
Object out = support.getTransferable().getTransferData(flavor);
System.out.println("out = " + out);
}
public static void main(String[] args) {
new HTMLPaste().setVisible(true);
}
}
---------- END SOURCE ----------
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Our application supports complex HTML pasting, such as content pasted from Microsoft Word. We use java.awt.datatransfer.Transferable#getTransferData() passing in a DataFlavor from the available clipboard data flavor list that has mime type "text/html".
In previous releases of Java, this returned the entire HTML clipboard contents. In Java 7, this is only returning content between the <!--StartFragment--> and <!--EndFragment--> comment tags.
This is a serious regression as it means we can no longer import correct HTML from complete documents copied to the clipboard.
REGRESSION. Last worked in version 6u26
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a basic document in Microsoft Word (I used 2010 in my testing, but as far back as 2003 should exhibit this behaviour as well).
2. Select all content in the document, copy
3. Load the HTMLPaste application
4. Paste (ctrl+v should work)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The console output should contain a full HTML document with a large amount of MS Word styles
ACTUAL -
Only the content between the <!--StartFragment--> and <!--EndFragment--> comment tags is printed to the console
ERROR MESSAGES/STACK TRACES THAT OCCUR :
None, it is a regression
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;
public final class HTMLPaste extends JFrame {
public HTMLPaste() throws HeadlessException {
setTitle("Paste test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JEditorPane field = createEditor();
add(new JScrollPane(field));
setSize(300, 400);
}
private JEditorPane createEditor() {
final JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
editorPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
editorPane.setTransferHandler(overrideTransferHandler(editorPane));
return editorPane;
}
private TransferHandler overrideTransferHandler(final JEditorPane editorPane) {
return new TransferHandler() {
final TransferHandler delegate = editorPane.getTransferHandler();
@Override
public boolean importData(final TransferSupport support) {
try {
readData(support);
//do the normal import process
return delegate.importData(support);
} catch (Error e) {
e.printStackTrace();
throw e;
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
};
}
private void readData(final TransferHandler.TransferSupport support) throws UnsupportedFlavorException, IOException {
final DataFlavor[] flavors = support.getDataFlavors();
System.out.println(Arrays.toString(flavors));
for (final DataFlavor flavor : flavors) {
if (flavor.getRepresentationClass() == String.class && flavor.getMimeType().startsWith("text/html")) {
System.out.println("found html");
outputData(support, flavor);
break;
}
if (flavor.getRepresentationClass() == String.class && flavor.getMimeType().startsWith("text/plain")) {
System.out.println("found text");
outputData(support, flavor);
break;
}
}
}
private void outputData(TransferHandler.TransferSupport support, DataFlavor flavor) throws UnsupportedFlavorException, IOException {
Object out = support.getTransferable().getTransferData(flavor);
System.out.println("out = " + out);
}
public static void main(String[] args) {
new HTMLPaste().setVisible(true);
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-7075105 WIN: Provide a way to format HTML on drop
- Resolved
- relates to
-
JDK-6513578 WIN32 HTML Clipboard support enhancement
- Closed