src/share/classes/java/awt/datatransfer/DataFlavor.java
Print this page
@@ -168,10 +168,22 @@
} catch (Exception e) {
return null;
}
}
+ /*
+ * private initializer
+ */
+ static private DataFlavor initHtmlDataFlavor(String htmlFlavorType) {
+ try {
+ return new DataFlavor ("text/html; class=java.lang.String;document=" +
+ htmlFlavorType + ";charset=Unicode");
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
/**
* The <code>DataFlavor</code> representing a Java Unicode String class,
* where:
* <pre>
* representationClass = java.lang.String
@@ -252,10 +264,50 @@
* transferred.
*/
public static final String javaRemoteObjectMimeType = "application/x-java-remote-object";
/**
+ * Represents a piece of an HTML markup. The markup consists of the part
+ * selected on the source side. Therefore some tags in the markup may be
+ * unpaired. If the flavor is used to represent the data in
+ * a {@link Transferable} instance, no additional changes will be made.
+ * This DataFlavor instance represents the same HTML markup as DataFlavor
+ * instances which content MIME type does not contain document parameter
+ * and representation class is the String class.
+ * <pre>
+ * representationClass = String
+ * mimeType = "text/html"
+ * </pre>
+ */
+ public static DataFlavor selectionHtmlFlavor = initHtmlDataFlavor("selection");
+
+ /**
+ * Represents a piece of an HTML markup. If possible, the markup received
+ * from a native system is supplemented with pair tags to be
+ * a well-formed HTML markup. If the flavor is used to represent the data in
+ * a {@link Transferable} instance, no additional changes will be made.
+ * <pre>
+ * representationClass = String
+ * mimeType = "text/html"
+ * </pre>
+ */
+ public static DataFlavor fragmentHtmlFlavor = initHtmlDataFlavor("fragment");
+
+ /**
+ * Represents a piece of an HTML markup. If possible, the markup
+ * received from a native system is supplemented with additional
+ * tags to make up a well-formed HTML document. If the flavor is used to
+ * represent the data in a {@link Transferable} instance,
+ * no additional changes will be made.
+ * <pre>
+ * representationClass = String
+ * mimeType = "text/html"
+ * </pre>
+ */
+ public static DataFlavor allHtmlFlavor = initHtmlDataFlavor("all");
+
+ /**
* Constructs a new <code>DataFlavor</code>. This constructor is
* provided only for the purpose of supporting the
* <code>Externalizable</code> interface. It is not
* intended for public (client) use.
*
@@ -955,12 +1007,12 @@
} else {
if (!mimeType.match(that.mimeType)) {
return false;
}
- if ("text".equals(getPrimaryType()) &&
- DataTransferer.doesSubtypeSupportCharset(this) &&
+ if ("text".equals(getPrimaryType())) {
+ if (DataTransferer.doesSubtypeSupportCharset(this) &&
representationClass != null &&
!(isRepresentationClassReader() ||
String.class.equals(representationClass) ||
isRepresentationClassCharBuffer() ||
DataTransferer.charArrayClass.equals(representationClass)))
@@ -977,10 +1029,21 @@
if (!thisCharset.equals(thatCharset)) {
return false;
}
}
}
+
+ if ("html".equals(getSubType()) &&
+ this.getParameter("document") != null )
+ {
+ if (!this.getParameter("document").
+ equals(that.getParameter("document")))
+ {
+ return false;
+ }
+ }
+ }
}
return true;
}