use of jakarta.servlet.jsp.tagext.TagInfo in project tomcat by apache.
the class ImplicitTagLibraryInfo method getTagFile.
/**
* Checks to see if the given tag name maps to a tag file path,
* and if so, parses the corresponding tag file.
*
* @return The TagFileInfo corresponding to the given tag name, or null if
* the given tag name is not implemented as a tag file
*/
@Override
public TagFileInfo getTagFile(String shortName) {
TagFileInfo tagFile = super.getTagFile(shortName);
if (tagFile == null) {
String path = tagFileMap.get(shortName);
if (path == null) {
return null;
}
TagInfo tagInfo = null;
try {
tagInfo = TagFileProcessor.parseTagFileDirectives(pc, shortName, path, null, this);
} catch (JasperException je) {
throw new RuntimeException(je.toString(), je);
}
tagFile = new TagFileInfo(shortName, path, tagInfo);
vec.addElement(tagFile);
this.tagFiles = new TagFileInfo[vec.size()];
vec.copyInto(this.tagFiles);
}
return tagFile;
}
use of jakarta.servlet.jsp.tagext.TagInfo in project tomcat by apache.
the class JspDocumentParser method parseCustomAction.
/*
* Checks if the XML element with the given tag name is a custom action,
* and returns the corresponding Node object.
*/
private Node parseCustomAction(String qName, String localName, String uri, Attributes nonTaglibAttrs, Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent) throws SAXException {
// Check if this is a user-defined (custom) tag
TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
if (tagLibInfo == null) {
return null;
}
TagInfo tagInfo = tagLibInfo.getTag(localName);
TagFileInfo tagFileInfo = tagLibInfo.getTagFile(localName);
if (tagInfo == null && tagFileInfo == null) {
throw new SAXParseException(Localizer.getMessage("jsp.error.xml.bad_tag", localName, uri), locator);
}
Class<?> tagHandlerClass = null;
if (tagInfo != null) {
String handlerClassName = tagInfo.getTagClassName();
try {
tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
} catch (Exception e) {
throw new SAXParseException(Localizer.getMessage("jsp.error.loadclass.taghandler", handlerClassName, qName), locator, e);
}
}
String prefix = getPrefix(qName);
Node.CustomTag ret = null;
if (tagInfo != null) {
ret = new Node.CustomTag(qName, prefix, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent, tagInfo, tagHandlerClass);
} else {
ret = new Node.CustomTag(qName, prefix, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent, tagFileInfo);
}
return ret;
}
use of jakarta.servlet.jsp.tagext.TagInfo in project tomcat by apache.
the class TagLibraryInfoImpl method toString.
@Override
public String toString() {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
print("tlibversion", tlibversion, out);
print("jspversion", jspversion, out);
print("shortname", shortname, out);
print("urn", urn, out);
print("info", info, out);
print("uri", uri, out);
print("tagLibraryValidator", "" + tagLibraryValidator, out);
for (TagInfo tag : tags) {
out.println(tag.toString());
}
for (TagFileInfo tagFile : tagFiles) {
out.println(tagFile.toString());
}
for (FunctionInfo function : functions) {
out.println(function.toString());
}
return sw.toString();
}
use of jakarta.servlet.jsp.tagext.TagInfo in project tomcat by apache.
the class Parser method getAttributeBodyType.
/**
* Determine the body type of <jsp:attribute> from the enclosing node
*/
private String getAttributeBodyType(Node n, String name) {
if (n instanceof Node.CustomTag) {
TagInfo tagInfo = ((Node.CustomTag) n).getTagInfo();
TagAttributeInfo[] tldAttrs = tagInfo.getAttributes();
for (TagAttributeInfo tldAttr : tldAttrs) {
if (name.equals(tldAttr.getName())) {
if (tldAttr.isFragment()) {
return TagInfo.BODY_CONTENT_SCRIPTLESS;
}
if (tldAttr.canBeRequestTime()) {
return TagInfo.BODY_CONTENT_JSP;
}
}
}
if (tagInfo.hasDynamicAttributes()) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.IncludeAction) {
if ("page".equals(name)) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.ForwardAction) {
if ("page".equals(name)) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.SetProperty) {
if ("value".equals(name)) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.UseBean) {
if ("beanName".equals(name)) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.PlugIn) {
if ("width".equals(name) || "height".equals(name)) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.ParamAction) {
if ("value".equals(name)) {
return TagInfo.BODY_CONTENT_JSP;
}
} else if (n instanceof Node.JspElement) {
return TagInfo.BODY_CONTENT_JSP;
}
return JAVAX_BODY_CONTENT_TEMPLATE_TEXT;
}
use of jakarta.servlet.jsp.tagext.TagInfo in project tomcat by apache.
the class Parser method parseCustomTag.
/*
* # '<' CustomAction CustomActionBody
*
* CustomAction ::= TagPrefix ':' CustomActionName
*
* TagPrefix ::= Name
*
* CustomActionName ::= Name
*
* CustomActionBody ::= ( Attributes CustomActionEnd ) | <TRANSLATION_ERROR>
*
* Attributes ::= ( S Attribute )* S?
*
* CustomActionEnd ::= CustomActionTagDependent | CustomActionJSPContent |
* CustomActionScriptlessContent
*
* CustomActionTagDependent ::= TagDependentOptionalBody
*
* CustomActionJSPContent ::= OptionalBody
*
* CustomActionScriptlessContent ::= ScriptlessOptionalBody
*/
// tagFileInfo can't be null after initial test
@SuppressWarnings("null")
private boolean parseCustomTag(Node parent) throws JasperException {
if (reader.peekChar() != '<') {
return false;
}
// Parse 'CustomAction' production (tag prefix and custom action name)
// skip '<'
reader.nextChar();
String tagName = reader.parseToken(false);
int i = tagName.indexOf(':');
if (i == -1) {
reader.reset(start);
return false;
}
String prefix = tagName.substring(0, i);
String shortTagName = tagName.substring(i + 1);
// Check if this is a user-defined tag.
String uri = pageInfo.getURI(prefix);
if (uri == null) {
if (pageInfo.isErrorOnUndeclaredNamespace()) {
err.jspError(start, "jsp.error.undeclared_namespace", prefix);
} else {
reader.reset(start);
// Remember the prefix for later error checking
pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
return false;
}
}
TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
TagInfo tagInfo = tagLibInfo.getTag(shortTagName);
TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName);
if (tagInfo == null && tagFileInfo == null) {
err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
}
Class<?> tagHandlerClass = null;
if (tagInfo != null) {
// Must be a classic tag, load it here.
// tag files will be loaded later, in TagFileProcessor
String handlerClassName = tagInfo.getTagClassName();
try {
tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
} catch (Exception e) {
err.jspError(start, "jsp.error.loadclass.taghandler", handlerClassName, tagName);
}
}
// Parse 'CustomActionBody' production:
// At this point we are committed - if anything fails, we produce
// a translation error.
// Parse 'Attributes' production:
Attributes attrs = parseAttributes();
reader.skipSpaces();
// Parse 'CustomActionEnd' production:
if (reader.matches("/>")) {
if (tagInfo != null) {
@SuppressWarnings("unused") Node unused = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
} else {
@SuppressWarnings("unused") Node unused = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
}
return true;
}
// Now we parse one of 'CustomActionTagDependent',
// 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.
// depending on body-content in TLD.
// Looking for a body, it still can be empty; but if there is a
// a tag body, its syntax would be dependent on the type of
// body content declared in the TLD.
String bc;
if (tagInfo != null) {
bc = tagInfo.getBodyContent();
} else {
bc = tagFileInfo.getTagInfo().getBodyContent();
}
Node tagNode = null;
if (tagInfo != null) {
tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
} else {
tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
}
parseOptionalBody(tagNode, tagName, bc);
return true;
}
Aggregations