如何获取 com.sun.javadoc.Taglet 中 {@docroot} 的值?
我正在编写一个自定义 taglet,用于将 mathML 文件包含在 javadoc html 文件中。我想将所有 *.mml 文件存储在同一个文件夹中,可能在该
{@docroot}/doc-files
文件夹中。我的问题是:我如何知道 Taglet 对象中的 @docRoot 字符串的值(更具体地说,在 toString(com.sun.javadoc.Tag tag)
方法中? 非常感谢!
I'm writing a custom taglet for inclusion of a mathML file in a javadoc html file. I would like to store all my *.mml files in the same folder, possibly in the
{@docroot}/doc-files
folder. My question is : how can I know the value of the @docRoot string within a Taglet object (more specifically, within the toString(com.sun.javadoc.Tag tag)
method ?
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还需要在 javadoc 中显示 MathML。我在这里写了一篇关于如何解决它的博客文章: http://chadretz.wordpress.com/2010/12/19/mathml-inside-javadoc-using-mathjax-and-a-custom-taglet/
更具体地说,您的但问题是,如果你查看我发布在那里的 Taglet 源代码(默认情况下折叠),你可以看到我在哪里获取 Tag.holder() 的顶级 ClassDoc 来获取我所在的目录深度,以便我可以向上遍历。如果您需要相对 HTML 根目录,这会有所帮助。如果您需要在 Taglet 运行时知道 MML 的位置,我建议您将它们放在类路径中并作为资源访问它们。
I also needed to display MathML in my javadoc. I wrote a blog post about how I solved it here: http://chadretz.wordpress.com/2010/12/19/mathml-inside-javadoc-using-mathjax-and-a-custom-taglet/
More specifically to your problem though, if you look at the Taglet source code I posted there (collapsed by default), you can see where I get the top level ClassDoc of the Tag.holder() to obtain the directory depth I am at so I can traverse up. This helps if you need the relative HTML root. If you need to know the location of your MML's while the Taglet is running, I suggest you put them on the classpath and access them as resources.
从 @ChadRetz 的博客,我创建了一个实用程序类,其中包含一个可以执行您想要的操作的函数:给定一个
com.sun.javadoc.Tag
,它返回从其封闭文件(包含该标记的文件)到 JavaDoc 根目录的相对 url ——这相当于{@docRoot}
。该类名为 < code>ComSunJavaDocUtil,函数名称为
getRelativeUrlToDocRoot
。taglet 的
toString()
函数示例:该实用程序类是 Codelet 的一部分。安装说明位于此处。如果您要使用的只是这个实用程序类,那么您的类路径中所需的唯一 jar 就是
codelet
和xbnjava
...当然,还有com.sun.javadoc
。Starting with the
getPackageDoc
function from @ChadRetz's blog, I've created a utility class that contains a function that does what you wish: Given acom.sun.javadoc.Tag
, it returns the relative url from its enclosing file (the file containing that tag), to the JavaDoc root directory--this is the equivalent of{@docRoot}
.The class is called
ComSunJavaDocUtil
, and the function name isgetRelativeUrlToDocRoot
.An example taglet's
toString()
function:This utility class is part of Codelet. Installation instructions are here. If this utility class is all you're going to use, then the only jars you need on your classpath are
codelet
andxbnjava
...and, of course,com.sun.javadoc
.