final StaticQueryContext sqc = runtimeConfig.getStaticQueryContext();
final Configuration config = sqc.getConfiguration();
try {
final XQueryExpression exp = runtimeConfig.getXQueryExpressionPool().getCompiledExpression(xqExpression);
final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
// define external parameters
for (int i = 0; i < externalParamDefs.length; i++) {
XQueryExternalParamDef externalParamDef = externalParamDefs[i];
String externalParamName = BaseTemplater.execute( externalParamDef.getName(), scraper.getScriptEngine() );
String externalParamType = BaseTemplater.execute( externalParamDefs[i].getType(), scraper.getScriptEngine() );
if (externalParamType == null) {
externalParamType = DEFAULT_PARAM_TYPE;
}
// check if param type is one of allowed
if ( !ALLOWED_PARAM_TYPES.contains(externalParamType) ) {
throw new ScraperXQueryException("Type " + externalParamType + " is not allowed. Use one of " + ALLOWED_PARAM_TYPES.toString());
}
if ( externalParamType.endsWith("*") ) {
BodyProcessor bodyProcessor = new BodyProcessor(externalParamDef);
bodyProcessor.setProperty("Name", externalParamName);
bodyProcessor.setProperty("Type", externalParamType);
ListVariable listVar = (ListVariable) bodyProcessor.run(scraper, context);
debug(externalParamDef, scraper, listVar);
Iterator it = listVar.toList().iterator();
List paramList = new ArrayList();
while (it.hasNext()) {
Variable currVar = (Variable) it.next();
paramList.add( castSimpleValue(externalParamType, currVar, sqc) );
}
dynamicContext.setParameter(externalParamName, paramList);
} else {
KeyValuePair props[] = {new KeyValuePair("Name", externalParamName), new KeyValuePair("Type", externalParamType)};
Variable var = getBodyTextContent(externalParamDef, scraper, context, true, props);
debug(externalParamDef, scraper, var);
Object value = castSimpleValue(externalParamType, var, sqc);
dynamicContext.setParameter(externalParamName, value);
}
}
return XmlUtil.createListOfXmlNodes(exp, dynamicContext);
} catch (XPathException e) {