use of jakarta.servlet.jsp.tagext.TagVariableInfo in project tomcat by apache.
the class Generator method declareTemporaryScriptingVars.
private void declareTemporaryScriptingVars(Node.Nodes page) throws JasperException {
class ScriptingVarVisitor extends Node.Visitor {
private final Vector<String> vars;
ScriptingVarVisitor() {
vars = new Vector<>();
}
@Override
public void visit(Node.CustomTag n) throws JasperException {
if (n.getCustomNestingLevel() > 0) {
TagVariableInfo[] tagVarInfos = n.getTagVariableInfos();
VariableInfo[] varInfos = n.getVariableInfos();
if (varInfos.length > 0) {
for (VariableInfo varInfo : varInfos) {
String varName = varInfo.getVarName();
String tmpVarName = "_jspx_" + varName + "_" + n.getCustomNestingLevel();
if (!vars.contains(tmpVarName)) {
vars.add(tmpVarName);
out.printin(varInfo.getClassName());
out.print(" ");
out.print(tmpVarName);
out.print(" = ");
out.print(null);
out.println(";");
}
}
} else {
for (TagVariableInfo tagVarInfo : tagVarInfos) {
String varName = tagVarInfo.getNameGiven();
if (varName == null) {
varName = n.getTagData().getAttributeString(tagVarInfo.getNameFromAttribute());
} else if (tagVarInfo.getNameFromAttribute() != null) {
// alias
continue;
}
String tmpVarName = "_jspx_" + varName + "_" + n.getCustomNestingLevel();
if (!vars.contains(tmpVarName)) {
vars.add(tmpVarName);
out.printin(tagVarInfo.getClassName());
out.print(" ");
out.print(tmpVarName);
out.print(" = ");
out.print(null);
out.println(";");
}
}
}
}
visitBody(n);
}
}
page.visit(new ScriptingVarVisitor());
}
use of jakarta.servlet.jsp.tagext.TagVariableInfo in project tomcat by apache.
the class TestTldParser method testTld.
@Test
public void testTld() throws Exception {
TaglibXml xml = parse("test/tld/test.tld");
Assert.assertEquals("1.0", xml.getTlibVersion());
Assert.assertEquals("2.1", xml.getJspVersion());
Assert.assertEquals("test", xml.getShortName());
Assert.assertEquals("http://tomcat.apache.org/TldTests", xml.getUri());
Assert.assertEquals(1, xml.getFunctions().size());
ValidatorXml validator = xml.getValidator();
Assert.assertEquals("com.example.Validator", validator.getValidatorClass());
Assert.assertEquals(1, validator.getInitParams().size());
Assert.assertEquals("value", validator.getInitParams().get("name"));
Assert.assertEquals(1, xml.getTags().size());
TagXml tag = xml.getTags().get(0);
Assert.assertEquals("org.apache.jasper.compiler.TestValidator$Echo", tag.getTagClass());
Assert.assertEquals("empty", tag.getBodyContent());
Assert.assertTrue(tag.hasDynamicAttributes());
Assert.assertEquals(1, tag.getVariables().size());
TagVariableInfo variableInfo = tag.getVariables().get(0);
Assert.assertEquals("var", variableInfo.getNameGiven());
Assert.assertEquals("java.lang.Object", variableInfo.getClassName());
Assert.assertTrue(variableInfo.getDeclare());
Assert.assertEquals(VariableInfo.AT_END, variableInfo.getScope());
Assert.assertEquals(4, tag.getAttributes().size());
TagAttributeInfo attributeInfo = tag.getAttributes().get(0);
Assert.assertEquals("Echo Tag", tag.getInfo());
Assert.assertEquals("Echo", tag.getDisplayName());
Assert.assertEquals("small", tag.getSmallIcon());
Assert.assertEquals("large", tag.getLargeIcon());
Assert.assertEquals("echo", attributeInfo.getName());
Assert.assertTrue(attributeInfo.isRequired());
Assert.assertTrue(attributeInfo.canBeRequestTime());
attributeInfo = tag.getAttributes().get(1);
Assert.assertEquals("fragment", attributeInfo.getName());
Assert.assertTrue(attributeInfo.isFragment());
Assert.assertTrue(attributeInfo.canBeRequestTime());
Assert.assertEquals("jakarta.servlet.jsp.tagext.JspFragment", attributeInfo.getTypeName());
attributeInfo = tag.getAttributes().get(2);
Assert.assertEquals("deferredValue", attributeInfo.getName());
Assert.assertEquals("jakarta.el.ValueExpression", attributeInfo.getTypeName());
Assert.assertEquals("java.util.Date", attributeInfo.getExpectedTypeName());
attributeInfo = tag.getAttributes().get(3);
Assert.assertEquals("deferredMethod", attributeInfo.getName());
Assert.assertEquals("jakarta.el.MethodExpression", attributeInfo.getTypeName());
Assert.assertEquals("java.util.Date getDate()", attributeInfo.getMethodSignature());
Assert.assertEquals(1, xml.getTagFiles().size());
TagFileXml tagFile = xml.getTagFiles().get(0);
Assert.assertEquals("Echo", tag.getDisplayName());
Assert.assertEquals("small", tag.getSmallIcon());
Assert.assertEquals("large", tag.getLargeIcon());
Assert.assertEquals("Echo2", tagFile.getName());
Assert.assertEquals("/echo.tag", tagFile.getPath());
Assert.assertEquals(1, xml.getFunctions().size());
FunctionInfo fn = xml.getFunctions().get(0);
Assert.assertEquals("trim", fn.getName());
Assert.assertEquals("org.apache.el.TesterFunctions", fn.getFunctionClass());
Assert.assertEquals("java.lang.String trim(java.lang.String)", fn.getFunctionSignature());
}
use of jakarta.servlet.jsp.tagext.TagVariableInfo in project tomcat by apache.
the class Generator method generateSetJspContext.
/*
* Generate setter for JspContext so we can create a wrapper and store both
* the original and the wrapper. We need the wrapper to mask the page
* context from the tag file and simulate a fresh page context. We need the
* original to do things like sync AT_BEGIN and AT_END scripting variables.
*/
private void generateSetJspContext(TagInfo tagInfo) {
boolean nestedSeen = false;
boolean atBeginSeen = false;
boolean atEndSeen = false;
// Determine if there are any aliases
boolean aliasSeen = false;
TagVariableInfo[] tagVars = tagInfo.getTagVariableInfos();
for (TagVariableInfo var : tagVars) {
// will ensure that an alias is configured.
if (var.getNameFromAttribute() != null) {
aliasSeen = true;
break;
}
}
if (aliasSeen) {
out.printil("public void setJspContext(jakarta.servlet.jsp.JspContext ctx, java.util.Map aliasMap) {");
} else {
out.printil("public void setJspContext(jakarta.servlet.jsp.JspContext ctx) {");
}
out.pushIndent();
out.printil("super.setJspContext(ctx);");
out.printil("java.util.ArrayList _jspx_nested = null;");
out.printil("java.util.ArrayList _jspx_at_begin = null;");
out.printil("java.util.ArrayList _jspx_at_end = null;");
for (TagVariableInfo tagVar : tagVars) {
switch(tagVar.getScope()) {
case VariableInfo.NESTED:
if (!nestedSeen) {
out.printil("_jspx_nested = new java.util.ArrayList();");
nestedSeen = true;
}
out.printin("_jspx_nested.add(");
break;
case VariableInfo.AT_BEGIN:
if (!atBeginSeen) {
out.printil("_jspx_at_begin = new java.util.ArrayList();");
atBeginSeen = true;
}
out.printin("_jspx_at_begin.add(");
break;
case VariableInfo.AT_END:
if (!atEndSeen) {
out.printil("_jspx_at_end = new java.util.ArrayList();");
atEndSeen = true;
}
out.printin("_jspx_at_end.add(");
break;
}
// switch
out.print(quote(tagVar.getNameGiven()));
out.println(");");
}
if (aliasSeen) {
out.printil("this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(this, ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, aliasMap);");
} else {
out.printil("this.jspContext = new org.apache.jasper.runtime.JspContextWrapper(this, ctx, _jspx_nested, _jspx_at_begin, _jspx_at_end, null);");
}
out.popIndent();
out.printil("}");
out.println();
out.printil("public jakarta.servlet.jsp.JspContext getJspContext() {");
out.pushIndent();
out.printil("return this.jspContext;");
out.popIndent();
out.printil("}");
}
use of jakarta.servlet.jsp.tagext.TagVariableInfo in project tomcat by apache.
the class TagLibraryInfoImpl method createTagInfo.
private TagInfo createTagInfo(TagXml tagXml) throws JasperException {
String teiClassName = tagXml.getTeiClass();
TagExtraInfo tei = null;
if (teiClassName != null && !teiClassName.isEmpty()) {
try {
Class<?> teiClass = ctxt.getClassLoader().loadClass(teiClassName);
tei = (TagExtraInfo) teiClass.getConstructor().newInstance();
} catch (Exception e) {
err.jspError(e, "jsp.error.teiclass.instantiation", teiClassName);
}
}
List<TagAttributeInfo> attributeInfos = tagXml.getAttributes();
List<TagVariableInfo> variableInfos = tagXml.getVariables();
return new TagInfo(tagXml.getName(), tagXml.getTagClass(), tagXml.getBodyContent(), tagXml.getInfo(), this, tei, attributeInfos.toArray(new TagAttributeInfo[0]), tagXml.getDisplayName(), tagXml.getSmallIcon(), tagXml.getLargeIcon(), variableInfos.toArray(new TagVariableInfo[0]), tagXml.hasDynamicAttributes());
}
Aggregations