public Record executeRead(XMLFileInteractionSpec spec, File file) throws Exception {
// Parse file and return document, or xpath/xquery result from dom.
if (!file.exists()) {
return null;
}
EISDOMRecord fileRecord = connection.getXMLFileTransaction().retrieveDOMRecord(file);
// Check for and process XPath or XQuery
if (spec.getXPath() != null) {
// Either a value/string or list of element records is returned
Object result = fileRecord.getValues(buildField(spec));
EISDOMRecord output = new EISDOMRecord();
if (result instanceof List) {
List results = (List)result;
output.setDOM(output.createNewDocument("results"));
if (results != null) {
for (int index = 0; index < results.size(); index++) {
output.add(new DatabaseField("result"), results.get(index));
}
}
} else {
output.setDOM(output.createNewDocument("results"));
output.add(new DatabaseField("result"), result);
}
return output;
} else {
return fileRecord;
}