use of sun.awt.datatransfer.DataTransferer in project jdk8u_jdk by JetBrains.
the class DataFlavor method getTextPlainUnicodeFlavor.
/**
* Returns a <code>DataFlavor</code> representing plain text with Unicode
* encoding, where:
* <pre>
* representationClass = java.io.InputStream
* mimeType = "text/plain;
* charset=<platform default Unicode encoding>"
* </pre>
* Sun's implementation for Microsoft Windows uses the encoding <code>utf-16le</code>.
* Sun's implementation for Solaris and Linux uses the encoding
* <code>iso-10646-ucs-2</code>.
*
* @return a <code>DataFlavor</code> representing plain text
* with Unicode encoding
* @since 1.3
*/
public static final DataFlavor getTextPlainUnicodeFlavor() {
String encoding = null;
DataTransferer transferer = DataTransferer.getInstance();
if (transferer != null) {
encoding = transferer.getDefaultUnicodeEncoding();
}
return new DataFlavor("text/plain;charset=" + encoding + ";class=java.io.InputStream", "Plain Text");
}
use of sun.awt.datatransfer.DataTransferer in project jdk8u_jdk by JetBrains.
the class SystemFlavorMap method parseAndStoreReader.
/**
* Copied code from java.util.Properties. Parsing the data ourselves is the
* only way to handle duplicate keys and values.
*/
private void parseAndStoreReader(BufferedReader in) throws IOException {
while (true) {
// Get next line
String line = in.readLine();
if (line == null) {
return;
}
if (line.length() > 0) {
// Continue lines that end in slashes if they are not comments
char firstChar = line.charAt(0);
if (firstChar != '#' && firstChar != '!') {
while (continueLine(line)) {
String nextLine = in.readLine();
if (nextLine == null) {
nextLine = "";
}
String loppedLine = line.substring(0, line.length() - 1);
// Advance beyond whitespace on new line
int startIndex = 0;
for (; startIndex < nextLine.length(); startIndex++) {
if (whiteSpaceChars.indexOf(nextLine.charAt(startIndex)) == -1) {
break;
}
}
nextLine = nextLine.substring(startIndex, nextLine.length());
line = loppedLine + nextLine;
}
// Find start of key
int len = line.length();
int keyStart = 0;
for (; keyStart < len; keyStart++) {
if (whiteSpaceChars.indexOf(line.charAt(keyStart)) == -1) {
break;
}
}
// Blank lines are ignored
if (keyStart == len) {
continue;
}
// Find separation between key and value
int separatorIndex = keyStart;
for (; separatorIndex < len; separatorIndex++) {
char currentChar = line.charAt(separatorIndex);
if (currentChar == '\\') {
separatorIndex++;
} else if (keyValueSeparators.indexOf(currentChar) != -1) {
break;
}
}
// Skip over whitespace after key if any
int valueIndex = separatorIndex;
for (; valueIndex < len; valueIndex++) {
if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1) {
break;
}
}
// Skip over one non whitespace key value separators if any
if (valueIndex < len) {
if (strictKeyValueSeparators.indexOf(line.charAt(valueIndex)) != -1) {
valueIndex++;
}
}
// Skip over white space after other separators if any
while (valueIndex < len) {
if (whiteSpaceChars.indexOf(line.charAt(valueIndex)) == -1) {
break;
}
valueIndex++;
}
String key = line.substring(keyStart, separatorIndex);
String value = (separatorIndex < len) ? line.substring(valueIndex, len) : "";
// Convert then store key and value
key = loadConvert(key);
value = loadConvert(value);
try {
MimeType mime = new MimeType(value);
if ("text".equals(mime.getPrimaryType())) {
String charset = mime.getParameter("charset");
if (DataTransferer.doesSubtypeSupportCharset(mime.getSubType(), charset)) {
// We need to store the charset and eoln
// parameters, if any, so that the
// DataTransferer will have this information
// for conversion into the native format.
DataTransferer transferer = DataTransferer.getInstance();
if (transferer != null) {
transferer.registerTextFlavorProperties(key, charset, mime.getParameter("eoln"), mime.getParameter("terminators"));
}
}
// But don't store any of these parameters in the
// DataFlavor itself for any text natives (even
// non-charset ones). The SystemFlavorMap will
// synthesize the appropriate mappings later.
mime.removeParameter("charset");
mime.removeParameter("class");
mime.removeParameter("eoln");
mime.removeParameter("terminators");
value = mime.toString();
}
} catch (MimeTypeParseException e) {
e.printStackTrace();
continue;
}
DataFlavor flavor;
try {
flavor = new DataFlavor(value);
} catch (Exception e) {
try {
flavor = new DataFlavor(value, null);
} catch (Exception ee) {
ee.printStackTrace();
continue;
}
}
final LinkedHashSet<DataFlavor> dfs = new LinkedHashSet<>();
dfs.add(flavor);
if ("text".equals(flavor.getPrimaryType())) {
dfs.addAll(convertMimeTypeToDataFlavors(value));
store(flavor.mimeType.getBaseType(), key, getTextTypeToNative());
}
for (DataFlavor df : dfs) {
store(df, key, getFlavorToNative());
store(key, df, getNativeToFlavor());
}
}
}
}
}
use of sun.awt.datatransfer.DataTransferer in project jdk8u_jdk by JetBrains.
the class SystemFlavorMap method nativeToFlavorLookup.
/**
* Semantically equivalent to 'nativeToFlavor.get(nat)'. This method
* handles the case where 'nat' is not found in 'nativeToFlavor'. In that
* case, a new DataFlavor is synthesized, stored, and returned, if and
* only if the specified native is encoded as a Java MIME type.
*/
private LinkedHashSet<DataFlavor> nativeToFlavorLookup(String nat) {
LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(nat);
if (nat != null && !disabledMappingGenerationKeys.contains(nat)) {
DataTransferer transferer = DataTransferer.getInstance();
if (transferer != null) {
LinkedHashSet<DataFlavor> platformFlavors = transferer.getPlatformMappingsForNative(nat);
if (!platformFlavors.isEmpty()) {
if (flavors != null) {
// Prepending the platform-specific mappings ensures
// that the flavors added with
// addFlavorForUnencodedNative() are at the end of
// list.
platformFlavors.addAll(flavors);
}
flavors = platformFlavors;
}
}
}
if (flavors == null && isJavaMIMEType(nat)) {
String decoded = decodeJavaMIMEType(nat);
DataFlavor flavor = null;
try {
flavor = new DataFlavor(decoded);
} catch (Exception e) {
System.err.println("Exception \"" + e.getClass().getName() + ": " + e.getMessage() + "\"while constructing DataFlavor for: " + decoded);
}
if (flavor != null) {
flavors = new LinkedHashSet<>(1);
getNativeToFlavor().put(nat, flavors);
flavors.add(flavor);
flavorsForNativeCache.remove(nat);
LinkedHashSet<String> natives = getFlavorToNative().get(flavor);
if (natives == null) {
natives = new LinkedHashSet<>(1);
getFlavorToNative().put(flavor, natives);
}
natives.add(nat);
nativesForFlavorCache.remove(flavor);
}
}
return (flavors != null) ? flavors : new LinkedHashSet<>(0);
}
use of sun.awt.datatransfer.DataTransferer in project jdk8u_jdk by JetBrains.
the class SystemFlavorMap method flavorToNativeLookup.
/**
* Semantically equivalent to 'flavorToNative.get(flav)'. This method
* handles the case where 'flav' is not found in 'flavorToNative' depending
* on the value of passes 'synthesize' parameter. If 'synthesize' is
* SYNTHESIZE_IF_NOT_FOUND a native is synthesized, stored, and returned by
* encoding the DataFlavor's MIME type. Otherwise an empty List is returned
* and 'flavorToNative' remains unaffected.
*/
private LinkedHashSet<String> flavorToNativeLookup(final DataFlavor flav, final boolean synthesize) {
LinkedHashSet<String> natives = getFlavorToNative().get(flav);
if (flav != null && !disabledMappingGenerationKeys.contains(flav)) {
DataTransferer transferer = DataTransferer.getInstance();
if (transferer != null) {
LinkedHashSet<String> platformNatives = transferer.getPlatformMappingsForFlavor(flav);
if (!platformNatives.isEmpty()) {
if (natives != null) {
// Prepend the platform-specific mappings to ensure
// that the natives added with
// addUnencodedNativeForFlavor() are at the end of
// list.
platformNatives.addAll(natives);
}
natives = platformNatives;
}
}
}
if (natives == null) {
if (synthesize) {
String encoded = encodeDataFlavor(flav);
natives = new LinkedHashSet<>(1);
getFlavorToNative().put(flav, natives);
natives.add(encoded);
LinkedHashSet<DataFlavor> flavors = getNativeToFlavor().get(encoded);
if (flavors == null) {
flavors = new LinkedHashSet<>(1);
getNativeToFlavor().put(encoded, flavors);
}
flavors.add(flav);
nativesForFlavorCache.remove(flav);
flavorsForNativeCache.remove(encoded);
} else {
natives = new LinkedHashSet<>(0);
}
}
return new LinkedHashSet<>(natives);
}
Aggregations