String renderDeclaration;
Renderer renderer;
Context context = Context.getCurrentThreadContext();
Configuration conf = Configuration.getConfiguration();
final SnippetInvoker invoker = conf.getSnippetInvoker();
String refId;
Element renderTarget;
for (Element element : snippetList) {
if (!conf.isSkipSnippetExecution()) {
// for a faked snippet node which is created by template
// analyzing process, the render target element should be its
// child.
if (element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE).equals(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE_FAKE)) {
renderTarget = element.children().first();
// the hosting element of this faked snippet has been removed by outer a snippet
if (renderTarget == null) {
element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_FINISHED);
continue;
}
} else {
renderTarget = element;
}
context.setCurrentRenderingElement(renderTarget);
renderDeclaration = element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_RENDER);
refId = element.attr(ExtNodeConstants.ATTR_SNIPPET_REF);
try {
if (element.hasAttr(ExtNodeConstants.SNIPPET_NODE_ATTR_PARALLEL)) {
ConcurrentRenderHelper crHelper = ConcurrentRenderHelper.getInstance(context, doc);
final Context newContext = context.clone();
final String declaration = renderDeclaration;
crHelper.submitWithContext(newContext, declaration, refId, new Callable<Renderer>() {
@Override
public Renderer call() throws Exception {
return invoker.invoke(declaration);
}
});
element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_WAITING);
} else {
renderer = invoker.invoke(renderDeclaration);
applySnippetResultToElement(doc, refId, element, renderTarget, renderer);
}
} catch (SnippetNotResovlableException | SnippetInvokeException e) {
throw e;
} catch (Exception e) {