Sandbox.enterSafeZone(secureCode);
RythmEvents.ENTER_INVOKE_TEMPLATE.trigger(this, (TemplateBase) caller);
try {
// try tag registry first
ITemplate t = _tags.get(name);
if (null == t) {
t = _templates.get(name);
}
if (null == t) {
// is calling self
if (S.isEqual(name, caller.__getName())) t = caller;
}
if (null == t) {
// try imported path
TemplateClass tc = caller.__getTemplateClass(true);
if (null != tc.importPaths) {
for (String s : tc.importPaths) {
String name0 = s + "." + name;
t = _tags.get(name0);
if (null == t) t = _templates.get(name0);
if (null != t) break;
}
}
// try relative path
if (null == t) {
String callerName = tc.getTagName();
int pos = -1;
if (null != callerName) pos = callerName.lastIndexOf(".");
if (-1 != pos) {
String name0 = callerName.substring(0, pos) + "." + name;
t = _tags.get(name0);
if (null == t) t = _templates.get(name0);
}
}
// try load the tag from resource
if (null == t) {
tc = resourceManager().tryLoadTemplate(name, tc);
if (null != tc) t = _templates.get(tc.getTagName());
if (null == t) {
if (ignoreNonExistsTag) {
if (logger.isDebugEnabled()) {
logger.debug("cannot find tag: " + name);
}
_nonExistsTags.add(name);
if (isDevMode() && nonExistsTemplatesChecker == null) {
nonExistsTemplatesChecker = new NonExistsTemplatesChecker();
}
return;
} else {
throw new NullPointerException("cannot find tag: " + name);
}
}
t = t.__cloneMe(this, caller);
}
}
if (!(t instanceof JavaTagBase)) {
// try refresh the tag loaded from template file under tag root
// note Java source tags are not reloaded here
String cn = t.getClass().getName();
TemplateClass tc0 = classes().getByClassName(cn);
if (null == tc0) {
System.out.println(t.getClass());
System.out.println(name);
System.out.println(cn);
System.out.println(caller.getClass());
}
t = tc0.asTemplate(caller, this);
} else {
t = t.__cloneMe(this, caller);
}
if (null != params) {
if (t instanceof JavaTagBase) {
((JavaTagBase) t).__setRenderArgs0(params);
} else {
for (int i = 0; i < params.size(); ++i) {
ITag.__Parameter param = params.get(i);
if (null != param.name) t.__setRenderArg(param.name, param.value);
else t.__setRenderArg(i, param.value);
}
}
}
if (null == body && null != params) {
body = (ITag.__Body) params.getByName("__body");
if (null == body) {
body = (ITag.__Body) params.getByName("_body");
}
}
if (null != body) {
t.__setRenderArg("__body", body);
t.__setRenderArg("_body", body); // for compatibility
}
RythmEvents.ON_TAG_INVOCATION.trigger(this, F.T2((TemplateBase) caller, t));
try {
if (null != context) {
t.__setBodyContext(context);
}
t.__setSecureCode(secureCode).__call(line);
} finally {
RythmEvents.TAG_INVOKED.trigger(this, F.T2((TemplateBase) caller, t));
}
} finally {
RythmEvents.EXIT_INVOKE_TEMPLATE.trigger(this, (TemplateBase) caller);