if(testFileRelDir != null) {
if(fromUri) {
File testDataFile = new File(xqtsDir, testFileRelDir);
String dest = testDataFile.toURI().toString();
QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, varNameStr);
Variable var = new Variable.GlobalVariable(varName, null);
var.setResult(new XString(dest));
xqmod.putVariable(varName, var);
} else {
DTMDocument testDataDoc = _docCache.get(testDataId);
if(testDataDoc == null) {
File testDataFile = new File(xqtsDir, testFileRelDir);
// load test data
DocumentTableModel dtm = new DocumentTableModel(false);
dtm.loadDocument(new FileInputStream(testDataFile));
testDataDoc = dtm.documentNode();
_docCache.put(testDataId, testDataDoc);
}
// import namespace decl
Map<String, String> nsmap = testDataDoc.documentTable().getDeclaredNamespaces();
NamespaceBinder nsResolver = statEnv.getStaticalyKnownNamespaces();
nsResolver.declarePrefixs(nsmap);
// reserve variable
QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, varNameStr);
Variable var = new Variable.GlobalVariable(varName, null);
var.setResult(testDataDoc);
xqmod.putVariable(varName, var);
}
} else {
NodeList list = (NodeList) xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='collection'][@ID='"
+ testDataId + "']/*[local-name()='input-document']/text()", catalog, XPathConstants.NODESET);
final int listlen = list.getLength();
if(listlen > 0) {
final NodeSequence<DTMDocument> ret = new NodeSequence<DTMDocument>(new DynamicContext(statEnv));
for(int i = 0; i < listlen; i++) {
String name = list.item(i).getTextContent();
DTMDocument testDataDoc = _docCache.get(name);
if(testDataDoc == null) {
File testDataFile = new File(xqtsDir, name + ".xml");
DocumentTableModel dtm = new DocumentTableModel(false);
dtm.loadDocument(new FileInputStream(testDataFile));
testDataDoc = dtm.documentNode();
_docCache.put(testDataId, testDataDoc);
}
// import namespace decl
Map<String, String> nsmap = testDataDoc.documentTable().getDeclaredNamespaces();
NamespaceBinder nsResolver = statEnv.getStaticalyKnownNamespaces();
nsResolver.declarePrefixs(nsmap);
ret.addItem(testDataDoc);
}
// reserve variable
QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, varNameStr);
Variable var = new Variable.GlobalVariable(varName, null);
var.setResult(ret);
xqmod.putVariable(varName, var);
}
}
}
}