public void evaluate(Tag tag,TagLibTag tagLibTag,FunctionLib[] flibs) throws EvaluatorException {
TagLoop loop=(TagLoop) tag;
// attribute maxrows and endrow not allowd at the same time
if(tag.containsAttribute("maxrows") && tag.containsAttribute("endrow"))
throw new EvaluatorException("Wrong Context, you cannot use attribute maxrows and endrow at the same time.");
// file loop
if(tag.containsAttribute("file")) {
if(!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute file you must also use attribute index and/or item");
loop.setType(TagLoop.TYPE_FILE);
return;
}
// list loop
if(tag.containsAttribute("list")){
if(!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute list,you must define attribute index and/or item");
loop.setType(TagLoop.TYPE_LIST);
return;
}
// array loop
if(tag.containsAttribute("array")){
if(!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute array, you must define attribute index and/or item");
loop.setType(TagLoop.TYPE_ARRAY);
return;
}
// collection loop
if(tag.containsAttribute("collection")) {
if(!tag.containsAttribute("index") && !tag.containsAttribute("item"))
throw new EvaluatorException("Wrong Context, when you use attribute collection,you must define attribute index and/or item");
loop.setType(TagLoop.TYPE_COLLECTION);
return;
}
// index loop
if(tag.containsAttribute("index")) {
if(!tag.containsAttribute("from") || !tag.containsAttribute("to"))
throw new EvaluatorException("Wrong Context, when you use attribute index you must also use attribute from and to or list or file");
loop.setType(TagLoop.TYPE_INDEX);
return;
}
// condition loop
if(tag.containsAttribute("condition")){
if(tag.isScriptBase())
throw new EvaluatorException("tag loop-condition is not supported within cfscript, use instead a while statement.");
TagLib tagLib=tagLibTag.getTagLib();
ExprTransformer transformer;
String text=ASMUtil.getAttributeString(tag, "condition");
try {
ConfigImpl config=(ConfigImpl) ThreadLocalPageContext.getConfig();
transformer = tagLib.getExprTransfomer();
Expression expr=transformer.transform(ASMUtil.getAncestorPage(tag),null,flibs,config.getCoreTagLib().getScriptTags(),new CFMLString(text,"UTF-8"),TransfomerSettings.toSetting(ThreadLocalPageContext.getConfig(),null));
tag.addAttribute(new Attribute(false,"condition",CastBoolean.toExprBoolean(expr),"boolean"));
}
catch (Exception e) {
throw new EvaluatorException(e.getMessage());
}
loop.setType(TagLoop.TYPE_CONDITION);
return;
}
// query loop