public CustomTag(String qName, String prefix, String localName, String uri, Attributes attrs, Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent, TagFileInfo tagFileInfo) { super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent); this.uri = uri; this.prefix = prefix; this.tagFileInfo = tagFileInfo; this.tagInfo = tagFileInfo.getTagInfo(); this.customNestingLevel = makeCustomNestingLevel(); this.childInfo = new ChildInfo(); this.implementsIterationTag = false; this.implementsBodyTag = false; this.implementsTryCatchFinally = false; this.implementsSimpleTag = true; this.implementsJspIdConsumer = false; this.implementsDynamicAttributes = tagInfo.hasDynamicAttributes(); }
public void visit(Node.CustomTag n) throws JasperException { TagFileInfo tagFileInfo = n.getTagFileInfo(); if (tagFileInfo != null) { String tagFilePath = tagFileInfo.getPath(); if (tagFilePath.startsWith("/META-INF/")) { // For tags in JARs, add the TLD and the tag as a dependency String[] location = compiler.getCompilationContext().getTldLocation( tagFileInfo.getTagInfo().getTagLibrary().getURI()); // Add TLD pageInfo.addDependant("jar:" + location[0] + "!/" + location[1]); // Add Tag pageInfo.addDependant("jar:" + location[0] + "!" + tagFilePath); } else { pageInfo.addDependant(tagFilePath); } Class c = loadTagFile(compiler, tagFilePath, n.getTagInfo(), pageInfo); n.setTagHandlerClass(c); } visitBody(n); }
public CustomTag(String jspVersion, String qName, String prefix, String localName, String uri, Attributes attrs, Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent, TagFileInfo tagFileInfo) { super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent); this.jspVersion = Double.valueOf(jspVersion).doubleValue(); this.uri = uri; this.prefix = prefix; this.tagFileInfo = tagFileInfo; this.tagInfo = tagFileInfo.getTagInfo(); this.customNestingLevel = makeCustomNestingLevel(); this.childInfo = new ChildInfo(); this.implementsIterationTag = false; this.implementsBodyTag = false; this.implementsTryCatchFinally = false; this.implementsSimpleTag = true; this.implementsDynamicAttributes = tagInfo.hasDynamicAttributes(); }
@Override public void visit(Node.CustomTag n) throws JasperException { TagFileInfo tagFileInfo = n.getTagFileInfo(); if (tagFileInfo != null) { String tagFilePath = tagFileInfo.getPath(); if (tagFilePath.startsWith("/META-INF/")) { // For tags in JARs, add the TLD and the tag as a dependency TldLocation location = compiler.getCompilationContext().getTldLocation( tagFileInfo.getTagInfo().getTagLibrary().getURI()); JarResource jarResource = location.getJarResource(); if (jarResource != null) { try { // Add TLD pageInfo.addDependant(jarResource.getEntry(location.getName()).toString(), Long.valueOf(jarResource.getJarFile().getEntry(location.getName()).getTime())); // Add Tag pageInfo.addDependant(jarResource.getEntry(tagFilePath.substring(1)).toString(), Long.valueOf(jarResource.getJarFile().getEntry(tagFilePath.substring(1)).getTime())); } catch (IOException ioe) { throw new JasperException(ioe); } } else { pageInfo.addDependant(tagFilePath, compiler.getCompilationContext().getLastModified( tagFilePath)); } } else { pageInfo.addDependant(tagFilePath, compiler.getCompilationContext().getLastModified( tagFilePath)); } Class<?> c = loadTagFile(compiler, tagFilePath, n.getTagInfo(), pageInfo); n.setTagHandlerClass(c); } visitBody(n); }
@Test public void testBug54240() throws Exception { Tomcat tomcat = getTomcatInstance(); File appDir = new File("test/webapp-3.0"); Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); tomcat.start(); ServletContext context = ctx.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()); }
/** * Get the TagFileInfo for a given tag name, looking through all the * tag files in this tag library. * * @param shortname The short name (no prefix) of the tag * @return the TagFileInfo for the specified Tag file, or null * if no Tag file is found * @since JSP 2.0 */ public TagFileInfo getTagFile(String shortname) { TagFileInfo tagFiles[] = getTagFiles(); if (tagFiles == null || tagFiles.length == 0) { return null; } for (int i=0; i < tagFiles.length; i++) { if (tagFiles[i].getName().equals(shortname)) { return tagFiles[i]; } } return null; }
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; }
private TagFileInfo createTagFileInfo(TreeNode elem, JarResource jarResource) throws JasperException { String name = null; String path = null; Iterator<TreeNode> list = elem.findChildren(); while (list.hasNext()) { TreeNode child = 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 // See https://bz.apache.org/bugzilla/show_bug.cgi?id=46471 // This needs to be removed once all the broken code that depends on // it has been removed ctxt.setTagFileJarResource(path, jarResource); } else if (!path.startsWith("/WEB-INF/tags")) { err.jspError("jsp.error.tagfile.illegalPath", path); } TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, jarResource, this); return new TagFileInfo(name, path, tagInfo); }
@Override public void visit(Node.CustomTag n) throws JasperException { TagFileInfo tagFileInfo = n.getTagFileInfo(); if (tagFileInfo != null) { String tagFilePath = tagFileInfo.getPath(); if (tagFilePath.startsWith("/META-INF/")) { // For tags in JARs, add the TLD and the tag as a dependency TldLocation location = compiler.getCompilationContext() .getTldLocation(tagFileInfo.getTagInfo().getTagLibrary().getURI()); JarResource jarResource = location.getJarResource(); if (jarResource != null) { try { // Add TLD pageInfo.addDependant(jarResource.getEntry(location.getName()).toString(), Long.valueOf(jarResource.getJarFile().getEntry(location.getName()).getTime())); // Add Tag pageInfo.addDependant(jarResource.getEntry(tagFilePath.substring(1)).toString(), Long .valueOf(jarResource.getJarFile().getEntry(tagFilePath.substring(1)).getTime())); } catch (IOException ioe) { throw new JasperException(ioe); } } else { pageInfo.addDependant(tagFilePath, compiler.getCompilationContext().getLastModified(tagFilePath)); } } else { pageInfo.addDependant(tagFilePath, compiler.getCompilationContext().getLastModified(tagFilePath)); } Class<?> c = loadTagFile(compiler, tagFilePath, n.getTagInfo(), pageInfo); n.setTagHandlerClass(c); } visitBody(n); }
public CustomTag(String jspVersion, String qName, String prefix, String localName, String uri, Attributes attrs, Mark start, Node parent, TagFileInfo tagFileInfo) { this(jspVersion, qName, prefix, localName, uri, attrs, null, null, start, parent, tagFileInfo); }
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; }
private void parseTaglibDirective(Node parent) throws JasperException { Attributes attrs = parseAttributes(); String uri = attrs.getValue("uri"); String prefix = attrs.getValue("prefix"); if (prefix != null) { Mark prevMark = pageInfo.getNonCustomTagPrefix(prefix); if (prevMark != null) { err.jspError(reader.mark(), "jsp.error.prefix.use_before_dcl", prefix, prevMark.getFile(), "" + prevMark.getLineNumber()); } if (uri != null) { String uriPrev = pageInfo.getURI(prefix); if (uriPrev != null && !uriPrev.equals(uri)) { err.jspError(reader.mark(), "jsp.error.prefix.refined", prefix, uri, uriPrev); } if (pageInfo.getTaglib(uri) == null) { TagLibraryInfoImpl impl = null; if (ctxt.getOptions().isCaching()) { impl = (TagLibraryInfoImpl) ctxt.getOptions() .getCache().get(uri); } if (impl == null) { TldLocation location = ctxt.getTldLocation(uri); impl = new TagLibraryInfoImpl(ctxt, parserController, pageInfo, prefix, uri, location, err, reader.mark()); if (ctxt.getOptions().isCaching()) { ctxt.getOptions().getCache().put(uri, impl); } } else { // Current compilation context needs location of cached // tag files for (TagFileInfo info : impl.getTagFiles()) { ctxt.setTagFileJarResource(info.getPath(), ctxt.getTagFileJarResource()); } } pageInfo.addTaglib(uri, impl); } pageInfo.addPrefixMapping(prefix, uri); } else { String tagdir = attrs.getValue("tagdir"); if (tagdir != null) { String urnTagdir = URN_JSPTAGDIR + tagdir; if (pageInfo.getTaglib(urnTagdir) == null) { pageInfo.addTaglib(urnTagdir, new ImplicitTagLibraryInfo(ctxt, parserController, pageInfo, prefix, tagdir, err)); } pageInfo.addPrefixMapping(prefix, urnTagdir); } } } new Node.TaglibDirective(attrs, start, parent); }
public CustomTag(String qName, String prefix, String localName, String uri, Attributes attrs, Mark start, Node parent, TagFileInfo tagFileInfo) { this(qName, prefix, localName, uri, attrs, null, null, start, parent, tagFileInfo); }
public TagFileInfo getTagFileInfo() { return tagFileInfo; }
private TagFileInfo createTagFileInfo(TreeNode elem, JarResource jarResource) throws JasperException { String name = null; String path = null; Iterator<TreeNode> list = elem.findChildren(); while (list.hasNext()) { TreeNode child = 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 // See https://bz.apache.org/bugzilla/show_bug.cgi?id=46471 // This needs to be removed once all the broken code that depends on // it has been removed ctxt.setTagFileJarResource(path, jarResource); } else if (!path.startsWith("/WEB-INF/tags")) { err.jspError("jsp.error.tagfile.illegalPath", path); } TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives( parserController, name, path, jarResource, this); return new TagFileInfo(name, path, tagInfo); }
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 SAXException( Localizer.getMessage("jsp.error.xml.bad_tag", localName, uri)); } Class tagHandlerClass = null; if (tagInfo != null) { String handlerClassName = tagInfo.getTagClassName(); try { tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName); } catch (Exception e) { throw new SAXException( Localizer.getMessage("jsp.error.loadclass.taghandler", handlerClassName, qName), 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; }
private void parseTaglibDirective(Node parent) throws JasperException { Attributes attrs = parseAttributes(); String uri = attrs.getValue("uri"); String prefix = attrs.getValue("prefix"); if (prefix != null) { Mark prevMark = pageInfo.getNonCustomTagPrefix(prefix); if (prevMark != null) { err.jspError(reader.mark(), "jsp.error.prefix.use_before_dcl", prefix, prevMark.getFile(), "" + prevMark.getLineNumber()); } if (uri != null) { String uriPrev = pageInfo.getURI(prefix); if (uriPrev != null && !uriPrev.equals(uri)) { err.jspError(reader.mark(), "jsp.error.prefix.refined", prefix, uri, uriPrev); } if (pageInfo.getTaglib(uri) == null) { TagLibraryInfoImpl impl = null; if (ctxt.getOptions().isCaching()) { impl = (TagLibraryInfoImpl) ctxt.getOptions() .getCache().get(uri); } if (impl == null) { String[] location = ctxt.getTldLocation(uri); impl = new TagLibraryInfoImpl(ctxt, parserController, pageInfo, prefix, uri, location, err); if (ctxt.getOptions().isCaching()) { ctxt.getOptions().getCache().put(uri, impl); } } else { // Current compilation context needs location of cached // tag files for (TagFileInfo info : impl.getTagFiles()) { ctxt.setTagFileJarUrl(info.getPath(), ctxt.getTagFileJarUrl()); } } pageInfo.addTaglib(uri, impl); } pageInfo.addPrefixMapping(prefix, uri); } else { String tagdir = attrs.getValue("tagdir"); if (tagdir != null) { String urnTagdir = URN_JSPTAGDIR + tagdir; if (pageInfo.getTaglib(urnTagdir) == null) { pageInfo.addTaglib(urnTagdir, new ImplicitTagLibraryInfo(ctxt, parserController, pageInfo, prefix, tagdir, err)); } pageInfo.addPrefixMapping(prefix, urnTagdir); } } } new Node.TaglibDirective(attrs, start, parent); }
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 { log.warn(Localizer.getMessage( "jsp.warning.unknown.element.in.tagfile", tname)); } } if (path.startsWith("/META-INF/tags")) { // Tag file packaged in JAR // See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471 // This needs to be removed once all the broken code that depends on // it has been removed 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, jarFileUrl, this); return new TagFileInfo(name, path, tagInfo); }