use of lucee.transformer.bytecode.Page in project Lucee by lucee.
the class Sprite method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
String id = "sprite_" + IDGenerator.intId();
try {
Page page = ASMUtil.getAncestorPage(tag);
SourceCode sc = page.getSourceCode();
String key = sc.id();
key = HashUtil.create64BitHashAsString(Thread.currentThread().getId() + ":" + key);
Expression src = tag.getAttribute("src").getValue();
// get data from previous sprites
Previous previous = sprites.get(key);
if (previous != null) {
previous.tag.removeAttribute("_ids");
previous.tag.removeAttribute("_srcs");
previous.tag = tag;
} else {
sprites.put(key, previous = new Previous(tag));
}
previous.ids.add(id);
if (previous.src == null)
previous.src = src;
else {
previous.src = tag.getFactory().opString(previous.src, tag.getFactory().createLitString(","));
previous.src = tag.getFactory().opString(previous.src, src);
}
tag.addAttribute(new Attribute(false, "_id", tag.getFactory().createLitString(id), "string"));
tag.addAttribute(new Attribute(false, "_ids", tag.getFactory().createLitString(lucee.runtime.type.util.ListUtil.listToList(previous.ids, ",")), "string"));
tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string"));
} catch (Throwable e) {
// TODO handle Excpetion much more precise
ExceptionUtil.rethrowIfNecessary(e);
throw new PageRuntimeException(Caster.toPageException(e));
}
}
Aggregations