applySnippetResultToElement(doc, refId, element, renderTarget, renderer);
}
} catch (SnippetNotResovlableException | SnippetInvokeException e) {
throw e;
} catch (Exception e) {
SnippetInvokeException se = new SnippetInvokeException("Error occured when executing rendering on [" +
renderDeclaration + "]", e);
throw se;
}
context.setCurrentRenderingElement(null);
} else {// if skip snippet
element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS, ExtNodeConstants.SNIPPET_NODE_ATTR_STATUS_FINISHED);
}
}
// load embed nodes which blocking parents has finished
List<Element> embedNodeList = doc.select(ExtNodeConstants.EMBED_NODE_TAG_SELECTOR);
int embedNodeListCount = embedNodeList.size();
Iterator<Element> embedNodeIterator = embedNodeList.iterator();
Element embed;
Element embedContent;
while (embedNodeIterator.hasNext()) {
embed = embedNodeIterator.next();
if (isBlockedByParentSnippet(doc, embed)) {
embedNodeListCount--;
continue;
}
embedContent = TemplateUtil.getEmbedNodeContent(embed);
TemplateUtil.mergeBlock(doc, embedContent);
embed.before(embedContent);
embed.remove();
}
if ((readySnippetCount + embedNodeListCount) > 0) {
TemplateUtil.regulateElement(doc);
applySnippets(doc);
} else {
ConcurrentRenderHelper crHelper = ConcurrentRenderHelper.getInstance(context, doc);
String delcaration = null;
if (crHelper.hasUnCompletedTask()) {
delcaration = null;
try {
FutureRendererHolder holder = crHelper.take();
delcaration = holder.getRenderDeclaration();
String ref = holder.getSnippetRefId();
String reSelector = SelectorUtil.attr(ExtNodeConstants.SNIPPET_NODE_TAG_SELECTOR, ExtNodeConstants.ATTR_SNIPPET_REF,
ref);
Element element = doc.select(reSelector).get(0);// must have
Element target;
if (element.attr(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE).equals(ExtNodeConstants.SNIPPET_NODE_ATTR_TYPE_FAKE)) {
target = element.children().first();
} else {
target = element;
}
applySnippetResultToElement(doc, ref, element, target, holder.getRenderer());
applySnippets(doc);
} catch (InterruptedException | ExecutionException e) {
throw new SnippetInvokeException("Concurrent snippet invocation failed" +
(delcaration == null ? "" : " on [" + delcaration + "]"), e);
}
}
}
}