String name = _tag.getId();
String className = _tagInfo.getTagClassName();
String tagHackVar = "_jsp_endTagHack" + _gen.uniqueId();
Class cl = _tagClass;
AnalyzedTag analyzedTag = _tag.getAnalyzedTag();
boolean isIterator = (IterationTag.class.isAssignableFrom(cl)
|| BodyTag.class.isAssignableFrom(cl));
boolean isBodyTag = BodyTag.class.isAssignableFrom(cl);
boolean isCatch = TryCatchFinally.class.isAssignableFrom(cl);
boolean isEmpty = isEmpty();
boolean usesTagBody = (isBodyTag && ! isEmpty
&& analyzedTag.getStartReturnsBuffered());
boolean hasEndTag = analyzedTag.getDoEnd();
if ("empty".equalsIgnoreCase(getBodyContent())) {
if (! isEmpty)
throw error(L.l("<{0}> expects an empty body", getTagName()));
}
if (usesTagBody && hasEndTag)
out.println("com.caucho.jsp.BodyContentImpl " + tagHackVar + " = null;");
else
tagHackVar = "out";
if (! isDeclared()) {
out.println(name + " = _jsp_state.get" + name + "(pageContext, _jsp_parent_tag);");
}
if (JspIdConsumer.class.isAssignableFrom(_tag.getTagClass())) {
out.println(name + ".setJspId(\"jsp" + _gen.generateJspId() + "\");");
/*
String shortName = className;
int p = shortName.lastIndexOf('.');
if (p >= 0)
shortName = shortName.substring(p + 1);
out.println(name + ".setJspId(\"" + shortName + "-" + _gen.generateJspId() + "\");");
*/
}
fillAttributes(out, name);
printVarDeclare(out, VariableInfo.AT_BEGIN);
String oldTag = "_jsp_writer" + _gen.uniqueId();
if (analyzedTag.getDoCatch())
out.println("javax.servlet.jsp.JspWriter " + oldTag + " = out;");
if (analyzedTag.getDoCatch() || analyzedTag.getDoFinally()) {
out.println("try {");
out.pushDepth();
}
boolean hasStartTag = analyzedTag.getDoStart();
int startCount = ((analyzedTag.getStartReturnsSkip() ? 1 : 0)
+ (analyzedTag.getStartReturnsInclude() ? 1 : 0)
+ (analyzedTag.getStartReturnsBuffered() ? 1 : 0));
int thisId = _gen.uniqueId();
if (! hasStartTag) {
}
else if (startCount == 1) {
out.println(name + ".doStartTag();");
}
else {
out.println("int _jspEval" + thisId + " = " + name + ".doStartTag();");
}
printVarAssign(out, VariableInfo.AT_BEGIN);
if (analyzedTag.getStartReturnsSkip()
&& ! analyzedTag.getStartReturnsInclude()
&& ! analyzedTag.getStartReturnsBuffered()) {
// jsp/18cp
generateChildrenEmpty();
}
else if (isEmpty) {
// jsp/18kc
/*
if (isBodyTag)
out.println(" " + name + ".setBodyContent((javax.servlet.jsp.tagext.BodyContent) null);");
*/
}
else {
if (startCount > 1 && analyzedTag.getStartReturnsSkip()) {
out.println("if (_jspEval" + thisId + " != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {");
out.pushDepth();
}
else if ((hasVarDeclaration(VariableInfo.NESTED)
|| childHasScriptlet())
&& ! (analyzedTag.getDoCatch()
|| analyzedTag.getDoFinally()
|| (analyzedTag.getDoAfter()
&& analyzedTag.getAfterReturnsAgain()))) {
out.println("{");
out.pushDepth();
}
if (usesTagBody) {
if (analyzedTag.getStartReturnsBuffered()
&& analyzedTag.getStartReturnsInclude()) {
out.println("if (_jspEval" + thisId + " == javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_BUFFERED) {");
out.pushDepth();
}
out.println("out = pageContext.pushBody();");
if (hasEndTag) {
out.println(tagHackVar + " = (com.caucho.jsp.BodyContentImpl) out;");
out.println(name + ".setBodyContent(" + tagHackVar + ");");
}
else
out.println(name + ".setBodyContent((javax.servlet.jsp.tagext.BodyContent) " + tagHackVar + ");");
if (analyzedTag.getDoInit())
out.println(name + ".doInitBody();");
if (analyzedTag.getStartReturnsBuffered()
&& analyzedTag.getStartReturnsInclude()) {
out.popDepth();
out.println("}");
// jsp/18kf - req by JSP TCK
/*
if (_tag.getBodyContent()) {
out.println("else");
out.println(" " + name + ".setBodyContent((javax.servlet.jsp.tagext.BodyContent) null);");
}
*/
}
}
else if (isBodyTag && _tag.getBodyContent())
out.println(name + ".setBodyContent((javax.servlet.jsp.tagext.BodyContent) null);");
if (analyzedTag.getDoAfter() && analyzedTag.getAfterReturnsAgain()) {
out.println("do {");
out.pushDepth();
}
out.setLocation(getFilename(), getStartLine());
if (_children != null)
printVarDeclaration(out, VariableInfo.NESTED);
out.setLocation(getFilename(), getStartLine());
generateChildren(out);
out.setLocation(getFilename(), getEndLine());
if (analyzedTag.getDoAfter() && analyzedTag.getAfterReturnsAgain()) {
out.popDepth();
out.println("} while (" + name + ".doAfterBody() == javax.servlet.jsp.tagext.IterationTag.EVAL_BODY_AGAIN);");
}
else if (analyzedTag.getDoAfter()) {
out.println(name + ".doAfterBody();");
}
if (usesTagBody) {
if (analyzedTag.getStartReturnsBuffered()
&& analyzedTag.getStartReturnsInclude()) {
out.println("if (_jspEval" + thisId + " == javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_BUFFERED)");
if (hasEndTag)
out.println(" out = pageContext.popBody();");
else
out.println(" out = pageContext.popAndReleaseBody();");
}
else if (analyzedTag.getStartReturnsBuffered()) {
if (hasEndTag)
out.println("out = pageContext.popBody();");
else
out.println("out = pageContext.popAndReleaseBody();");
}
}
if (startCount > 1 && analyzedTag.getStartReturnsSkip()) {
out.popDepth();
out.println("}");
}
else if (isEmpty) {
}
else if ((hasVarDeclaration(VariableInfo.NESTED)
|| childHasScriptlet())
&& ! (analyzedTag.getDoCatch()
|| analyzedTag.getDoFinally()
|| (analyzedTag.getDoAfter()
&& analyzedTag.getAfterReturnsAgain()))) {
out.popDepth();
out.println("}");
}
}
out.setLocation(getFilename(), getEndLine());
int endCount = ((analyzedTag.getEndReturnsSkip() ? 1 : 0)
+ (analyzedTag.getEndReturnsEval() ? 1 : 0));
String endVar = "_jsp_end_" + _gen.uniqueId();
if (! hasEndTag) {
}
else if (endCount > 1)
out.println("int " + endVar + " = " + name + ".doEndTag();");
else
out.println(name + ".doEndTag();");
if (! hasEndTag || ! usesTagBody) {
}
else if (hasStartTag
&& (analyzedTag.getStartReturnsSkip()
|| analyzedTag.getStartReturnsInclude())) {
out.println("if (" + tagHackVar + " != null) {");
out.println(" pageContext.releaseBody(" + tagHackVar + ");");
out.println(" " + tagHackVar + " = null;");
out.println("}");
}
else {
out.println("pageContext.releaseBody(" + tagHackVar + ");");
}
if (analyzedTag.getEndReturnsSkip()) {
if (hasEndTag && endCount > 1)
out.println("if (" + endVar + " == javax.servlet.jsp.tagext.Tag.SKIP_PAGE)");
else
out.println("if (true)");
if (_gen.isTag() || isInFragment())
out.println(" throw new SkipPageException();");
else
out.println(" return;");
}
if (analyzedTag.getDoCatch()) {
String t = "_jsp_exn_" + _gen.uniqueId();
out.popDepth();
out.println("} catch (Throwable " + t + ") {");
out.println(" pageContext.setWriter(" + oldTag + ");");
out.println(" out = " + oldTag + ";");
out.println(" " + name + ".doCatch(" + t + ");");
out.pushDepth();
}
if (analyzedTag.getDoFinally()) {
out.popDepth();
out.println("} finally {");
out.println(" " + name + ".doFinally();");
out.pushDepth();
}
if (analyzedTag.getDoCatch() || analyzedTag.getDoFinally()) {
out.popDepth();
out.println("}");
}
printVarDeclaration(out, VariableInfo.AT_END);