src/windows/classes/sun/awt/windows/WDataTransferer.java
Print this page
*** 184,219 ****
public byte[] translateTransferable(Transferable contents,
DataFlavor flavor,
long format) throws IOException
{
! byte[] bytes = super.translateTransferable(contents, flavor, format);
!
if (format == CF_HTML) {
! bytes = HTMLCodec.convertToHTMLFormat(bytes);
}
return bytes;
}
! protected Object translateBytesOrStream(InputStream str, byte[] bytes,
DataFlavor flavor, long format,
Transferable localeTransferable)
! throws IOException
! {
if (format == CF_HTML && flavor.isFlavorTextType()) {
! if (str == null) {
! str = new ByteArrayInputStream(bytes);
! bytes = null;
! }
- str = new HTMLCodec(str, EHTMLReadMode.HTML_READ_ALL);
}
if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
- if (null != str ) {
- str.close();
- }
if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
String st = new String(bytes, 0, bytes.length, "UTF-16LE");
String[] filenames = st.split("\0");
--- 184,243 ----
public byte[] translateTransferable(Transferable contents,
DataFlavor flavor,
long format) throws IOException
{
! byte[] bytes = null;
if (format == CF_HTML) {
! if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
! // if a user provides data represented by
! // DataFlavor.selectionHtmlFlavor format, we use this
! // type to store the data in the native clipboard
! bytes = super.translateTransferable(contents,
! DataFlavor.selectionHtmlFlavor,
! format);
! } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
! // if we cannot get data represented by the
! // DataFlavor.selectionHtmlFlavor format
! // but the DataFlavor.allHtmlFlavor format is avialable
! // we belive that the user knows how to represent
! // the data and how to mark up selection in a
! // system specific manner. Therefor, we use this data
! bytes = super.translateTransferable(contents,
! DataFlavor.allHtmlFlavor,
! format);
! } else {
! // handle other html flavor types, including custom and
! // fragment ones
! bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format));
! }
! } else {
! // we handle non-html types basing on their
! // flavors
! bytes = super.translateTransferable(contents, flavor, format);
}
return bytes;
}
! // The stream is closed as a closable object
! public Object translateStream(InputStream str,
DataFlavor flavor, long format,
Transferable localeTransferable)
! throws IOException {
if (format == CF_HTML && flavor.isFlavorTextType()) {
! str = new HTMLCodec(str,
! EHTMLReadMode.getEHTMLReadMode(flavor));
}
+ return super.translateStream(str, flavor, format,
+ localeTransferable);
+ }
+
+ public Object translateBytes(byte[] bytes, DataFlavor flavor, long format,
+ Transferable localeTransferable) throws IOException {
if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
throw new IOException("data translation failed");
}
String st = new String(bytes, 0, bytes.length, "UTF-16LE");
String[] filenames = st.split("\0");
*** 233,262 ****
}
if (format == CFSTR_INETURL &&
URL.class.equals(flavor.getRepresentationClass()))
{
- if (bytes == null) {
- bytes = inputStreamToByteArray(str);
- str = null;
- }
String charset = getDefaultTextCharset();
! if (localeTransferable != null && localeTransferable.
! isDataFlavorSupported(javaTextEncodingFlavor))
{
try {
charset = new String((byte[])localeTransferable.
! getTransferData(javaTextEncodingFlavor),
! "UTF-8");
} catch (UnsupportedFlavorException cannotHappen) {
}
}
return new URL(new String(bytes, charset));
}
! return super.translateBytesOrStream(str, bytes, flavor, format,
localeTransferable);
}
public boolean isLocaleDependentTextFormat(long format) {
return format == CF_TEXT || format == CFSTR_INETURL;
}
--- 257,281 ----
}
if (format == CFSTR_INETURL &&
URL.class.equals(flavor.getRepresentationClass()))
{
String charset = getDefaultTextCharset();
! if (localeTransferable != null && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor))
{
try {
charset = new String((byte[])localeTransferable.
! getTransferData(javaTextEncodingFlavor), "UTF-8");
} catch (UnsupportedFlavorException cannotHappen) {
}
}
return new URL(new String(bytes, charset));
}
! return super.translateBytes(bytes , flavor, format,
localeTransferable);
+
}
public boolean isLocaleDependentTextFormat(long format) {
return format == CF_TEXT || format == CFSTR_INETURL;
}
*** 412,437 ****
/**
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
*/
! protected Image platformImageBytesOrStreamToImage(InputStream str,
! byte[] bytes,
! long format)
throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
} else if (format == CF_JFIF) {
mimeType = "image/jpeg";
}
if (mimeType != null) {
! return standardImageBytesOrStreamToImage(str, bytes, mimeType);
! }
!
! if (bytes == null) {
! bytes = inputStreamToByteArray(str);
}
int[] imageData = platformImageBytesToImageData(bytes, format);
if (imageData == null) {
throw new IOException("data translation failed");
--- 431,450 ----
/**
* Translates either a byte array or an input stream which contain
* platform-specific image data in the given format into an Image.
*/
! protected Image platformImageBytesToImage(byte[] bytes, long format)
throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
} else if (format == CF_JFIF) {
mimeType = "image/jpeg";
}
if (mimeType != null) {
! return standardImageBytesToImage(bytes, mimeType);
}
int[] imageData = platformImageBytesToImageData(bytes, format);
if (imageData == null) {
throw new IOException("data translation failed");
*** 485,495 ****
}
enum EHTMLReadMode {
HTML_READ_ALL,
HTML_READ_FRAGMENT,
! HTML_READ_SELECTION
}
/**
* on decode: This stream takes an InputStream which provides data in CF_HTML format,
* strips off the description and context to extract the original HTML data.
--- 498,523 ----
}
enum EHTMLReadMode {
HTML_READ_ALL,
HTML_READ_FRAGMENT,
! HTML_READ_SELECTION;
!
! public static EHTMLReadMode getEHTMLReadMode (DataFlavor df) {
!
! EHTMLReadMode mode = HTML_READ_SELECTION;
!
! String parameter = df.getParameter("document");
!
! if ("all".equals(parameter)) {
! mode = HTML_READ_ALL;
! } else if ("fragment".equals(parameter)) {
! mode = HTML_READ_FRAGMENT;
! }
!
! return mode;
! }
}
/**
* on decode: This stream takes an InputStream which provides data in CF_HTML format,
* strips off the description and context to extract the original HTML data.
*** 574,585 ****
if( -1 == stUpContext.indexOf("<BODY") ) {
htmlPrefix = htmlPrefix +"<BODY>";
htmlSuffix = "</BODY>" + htmlSuffix;
};
};
- htmlPrefix = htmlPrefix + START_FRAGMENT_CMT;
- htmlSuffix = END_FRAGMENT_CMT + htmlSuffix;
}
String stBaseUrl = DEF_SOURCE_URL;
int nStartHTML =
VERSION.length() + VERSION_NUM.length() + EOLN.length()
--- 602,611 ----