use of javax.servlet.jsp.tagext.TagFileInfo in project sling by apache.
the class TagLibraryInfoImpl method parseTLD.
/*
* @param ctxt The JSP compilation context @param uri The TLD's uri @param
* in The TLD's input stream @param jarFileUrl The JAR file containing the
* TLD, or null if the tag library is not packaged in a JAR
*/
private void parseTLD(JspCompilationContext ctxt, String uri, InputStream in, URL jarFileUrl) throws JasperException {
Vector tagVector = new Vector();
Vector tagFileVector = new Vector();
Hashtable functionTable = new Hashtable();
// Create an iterator over the child elements of our <taglib> element
ParserUtils pu = new ParserUtils();
TreeNode tld = pu.parseXMLDocument(uri, in);
// Check to see if the <taglib> root element contains a 'version'
// attribute, which was added in JSP 2.0 to replace the <jsp-version>
// subelement
this.jspversion = tld.findAttribute("version");
// Process each child element of our <taglib> element
Iterator list = tld.findChildren();
while (list.hasNext()) {
TreeNode element = (TreeNode) list.next();
String tname = element.getName();
if (// JSP 1.1
"tlibversion".equals(tname) || "tlib-version".equals(tname)) {
// JSP 1.2
this.tlibversion = element.getBody();
} else if ("jspversion".equals(tname) || "jsp-version".equals(tname)) {
this.jspversion = element.getBody();
} else if ("shortname".equals(tname) || "short-name".equals(tname))
this.shortname = element.getBody();
else if ("uri".equals(tname))
this.urn = element.getBody();
else if ("info".equals(tname) || "description".equals(tname))
this.info = element.getBody();
else if ("validator".equals(tname))
this.tagLibraryValidator = createValidator(element);
else if ("tag".equals(tname))
tagVector.addElement(createTagInfo(element, jspversion));
else if ("tag-file".equals(tname)) {
TagFileInfo tagFileInfo = createTagFileInfo(element, uri, jarFileUrl);
tagFileVector.addElement(tagFileInfo);
} else if ("function".equals(tname)) {
// JSP2.0
FunctionInfo funcInfo = createFunctionInfo(element);
String funcName = funcInfo.getName();
if (functionTable.containsKey(funcName)) {
err.jspError("jsp.error.tld.fn.duplicate.name", funcName, uri);
}
functionTable.put(funcName, funcInfo);
} else if (// Ignored elements
"display-name".equals(tname) || "small-icon".equals(tname) || "large-icon".equals(tname) || "listener".equals(tname)) {
;
} else if ("taglib-extension".equals(tname)) {
// Recognized but ignored
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.taglib", tname));
}
}
}
if (tlibversion == null) {
err.jspError("jsp.error.tld.mandatory.element.missing", "tlib-version");
}
if (jspversion == null) {
err.jspError("jsp.error.tld.mandatory.element.missing", "jsp-version");
}
this.tags = new TagInfo[tagVector.size()];
tagVector.copyInto(this.tags);
this.tagFiles = new TagFileInfo[tagFileVector.size()];
tagFileVector.copyInto(this.tagFiles);
this.functions = new FunctionInfo[functionTable.size()];
int i = 0;
Enumeration enumeration = functionTable.elements();
while (enumeration.hasMoreElements()) {
this.functions[i++] = (FunctionInfo) enumeration.nextElement();
}
}
use of javax.servlet.jsp.tagext.TagFileInfo in project tomcat by apache.
the class TestTagPluginManager method testBug54240.
@Test
public void testBug54240() throws Exception {
Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);
ServletContext context = ((Context) tomcat.getHost().findChildren()[0]).getServletContext();
TagPluginManager manager = new TagPluginManager(context);
Node.Nodes nodes = new Node.Nodes();
Node.CustomTag c = new Node.CustomTag("test:ATag", "test", "ATag", "http://tomcat.apache.org/jasper", null, null, null, null, null, new TagFileInfo("ATag", "http://tomcat.apache.org/jasper", tagInfo));
c.setTagHandlerClass(TesterTag.class);
nodes.add(c);
manager.apply(nodes, null, null);
Node n = nodes.getNode(0);
Assert.assertNotNull(n);
Assert.assertTrue(n instanceof Node.CustomTag);
Node.CustomTag t = (Node.CustomTag) n;
Assert.assertNotNull(t.getAtSTag());
Node.Nodes sTag = c.getAtSTag();
Node scriptlet = sTag.getNode(0);
Assert.assertNotNull(scriptlet);
Assert.assertTrue(scriptlet instanceof Node.Scriptlet);
Node.Scriptlet s = (Node.Scriptlet) scriptlet;
Assert.assertEquals("//Just a comment", s.getText());
}
use of javax.servlet.jsp.tagext.TagFileInfo in project tomcat by apache.
the class TagLibraryInfoImpl method createTagFileInfo.
private TagFileInfo createTagFileInfo(TagFileXml tagFileXml, Jar jar) throws JasperException {
String name = tagFileXml.getName();
String path = tagFileXml.getPath();
if (path == null) {
// path is required
err.jspError("jsp.error.tagfile.missingPath");
} else if (!path.startsWith("/META-INF/tags") && !path.startsWith("/WEB-INF/tags")) {
err.jspError("jsp.error.tagfile.illegalPath", path);
}
TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, jar, this);
return new TagFileInfo(name, path, tagInfo);
}
use of javax.servlet.jsp.tagext.TagFileInfo in project sling by apache.
the class TagLibraryInfoImpl method createTagFileInfo.
/*
* Parses the tag file directives of the given TagFile and turns them into a
* TagInfo.
*
* @param elem The <tag-file> element in the TLD @param uri The location of
* the TLD, in case the tag file is specified relative to it @param jarFile
* The JAR file, in case the tag file is packaged in a JAR
*
* @return TagInfo correspoding to tag file directives
*/
private TagFileInfo createTagFileInfo(TreeNode elem, String uri, URL jarFileUrl) throws JasperException {
String name = null;
String path = null;
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode child = (TreeNode) list.next();
String tname = child.getName();
if ("name".equals(tname)) {
name = child.getBody();
} else if ("path".equals(tname)) {
path = child.getBody();
} else if ("example".equals(tname)) {
// Ignore <example> element: Bugzilla 33538
} else if ("tag-extension".equals(tname)) {
// Ignore <tag-extension> element: Bugzilla 33538
} else if ("icon".equals(tname) || "display-name".equals(tname) || "description".equals(tname)) {
// Ignore these elements: Bugzilla 38015
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tagfile", tname));
}
}
}
if (path.startsWith("/META-INF/tags")) {
// Tag file packaged in JAR
ctxt.setTagFileJarUrl(path, jarFileUrl);
} else if (!path.startsWith("/WEB-INF/tags")) {
err.jspError("jsp.error.tagfile.illegalPath", path);
}
TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, this);
return new TagFileInfo(name, path, tagInfo);
}
use of javax.servlet.jsp.tagext.TagFileInfo in project sling 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
*/
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) {
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) {
new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
} else {
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