use of gov.sandia.n2a.db.Schema in project n2a by frothga.
the class SafeTextTransferHandler method importData.
public boolean importData(TransferSupport support) {
try {
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
if (data.startsWith("N2A.schema")) {
if (safeTypes == null)
return false;
Schema schema = new Schema();
MNode nodes = new MVolatile();
BufferedReader br = new BufferedReader(new StringReader(data));
schema.read(br);
if (schema.type.startsWith("Clip"))
schema.type = schema.type.substring(4);
if (!safeTypes.contains(schema.type)) {
br.close();
return false;
}
nodes.read(br);
br.close();
// Process into a suitable string
for (MNode n : nodes) {
String key = n.key();
String value = n.get();
if (key.startsWith("@"))
data = value + key;
else if (value.isEmpty())
data = key;
else
data = key + "=" + value;
// Only process the first node
break;
}
}
JTextComponent comp = (JTextComponent) support.getComponent();
InputContext ic = comp.getInputContext();
if (ic != null)
ic.endComposition();
comp.replaceSelection(data);
return true;
} catch (UnsupportedFlavorException | IOException e) {
}
return false;
}
Aggregations