* @since 1.4
*/
public synchronized List<DataFlavor> getFlavorsForNative(String nat) {
// Check cache, even for null nat
SoftReference ref = (SoftReference)getFlavorsForNativeCache.get(nat);
if (ref != null) {
ArrayList retval = (ArrayList)ref.get();
if (retval != null) {
return (List)retval.clone();
}
}
LinkedList retval = new LinkedList();
if (nat == null) {
List natives = getNativesForFlavor(null);
HashSet dups = new HashSet(natives.size());
for (Iterator natives_iter = natives.iterator();
natives_iter.hasNext(); )
{
List flavors =
getFlavorsForNative((String)natives_iter.next());
for (Iterator flavors_iter = flavors.iterator();
flavors_iter.hasNext(); )
{
Object flavor = flavors_iter.next();
if (dups.add(flavor)) {
retval.add(flavor);
}
}
}
} else {
List flavors = nativeToFlavorLookup(nat);
if (disabledMappingGenerationKeys.contains(nat)) {
return flavors;
}
HashSet dups = new HashSet(flavors.size());
List flavorsAndbaseTypes = nativeToFlavorLookup(nat);
for (Iterator flavorsAndbaseTypes_iter =
flavorsAndbaseTypes.iterator();
flavorsAndbaseTypes_iter.hasNext(); )
{
Object value = flavorsAndbaseTypes_iter.next();
if (value instanceof String) {
String baseType = (String)value;
String subType = null;
try {
MimeType mimeType = new MimeType(baseType);
subType = mimeType.getSubType();
} catch (MimeTypeParseException mtpe) {
// Cannot happen, since we checked all mappings
// on load from flavormap.properties.
assert(false);
}
if (DataTransferer.doesSubtypeSupportCharset(subType,
null)) {
if (TEXT_PLAIN_BASE_TYPE.equals(baseType) &&
dups.add(DataFlavor.stringFlavor))
{
retval.add(DataFlavor.stringFlavor);
}
for (int i = 0; i < UNICODE_TEXT_CLASSES.length; i++) {
DataFlavor toAdd = null;
try {
toAdd = new DataFlavor
(baseType + ";charset=Unicode;class=" +
UNICODE_TEXT_CLASSES[i]);
} catch (ClassNotFoundException cannotHappen) {
}
if (dups.add(toAdd)) {
retval.add(toAdd);
}
}
for (Iterator charset_iter =
DataTransferer.standardEncodings();
charset_iter.hasNext(); )
{
String charset = (String)charset_iter.next();
for (int i = 0; i < ENCODED_TEXT_CLASSES.length;
i++)
{
DataFlavor toAdd = null;
try {
toAdd = new DataFlavor
(baseType + ";charset=" + charset +
";class=" + ENCODED_TEXT_CLASSES[i]);
} catch (ClassNotFoundException cannotHappen) {
}
// Check for equality to plainTextFlavor so
// that we can ensure that the exact charset of
// plainTextFlavor, not the canonical charset
// or another equivalent charset with a
// different name, is used.
if (toAdd.equals(DataFlavor.plainTextFlavor)) {
toAdd = DataFlavor.plainTextFlavor;
}
if (dups.add(toAdd)) {
retval.add(toAdd);
}
}
}
if (TEXT_PLAIN_BASE_TYPE.equals(baseType) &&
dups.add(DataFlavor.plainTextFlavor))
{
retval.add(DataFlavor.plainTextFlavor);
}
} else {
// Non-charset text natives should be treated as
// opaque, 8-bit data in any of its various
// representations.
for (int i = 0; i < ENCODED_TEXT_CLASSES.length; i++) {
DataFlavor toAdd = null;
try {
toAdd = new DataFlavor(baseType +
";class=" + ENCODED_TEXT_CLASSES[i]);
} catch (ClassNotFoundException cannotHappen) {
}
if (dups.add(toAdd)) {
retval.add(toAdd);
}
}
}
} else {
DataFlavor flavor = (DataFlavor)value;
if (dups.add(flavor)) {
retval.add(flavor);
}
}
}
}
ArrayList arrayList = new ArrayList(retval);
getFlavorsForNativeCache.put(nat, new SoftReference(arrayList));
return (List)arrayList.clone();
}