如何在sitebricks中实现对jsp的注释支持? [英] How is annotations support in jsp implemented in sitebricks?

查看:82
本文介绍了如何在sitebricks中实现对jsp的注释支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 SiteBricks用户指南中的示例:

<html>
<body>
    @ShowIf(true)     <----- I'm impressed with this line
    <p>${message} from Sitebricks!</p>
</body>
</html>

我很好奇它是如何实现的? (我的意思是站点砖创建者如何以及在哪个切入点设法将jsp转换为servlet?)

I'm curious how is it implemented? (I mean how and at which entry point sitebricks creators managed to enhance transforming jsp to servlet?)

感谢任何想法!

推荐答案

没有过滤器执行此操作.我们有自己的模板逻辑,使用的是递归下降解析器.

There is no filter doing this. We have our own templating logic that uses what is known as a recursive descent parser.

完成这种注释解析实际上不是一个简单的问题.我们首先要做的是使用Jsoup将整个HTML像DOM一样树化. Jsoup负责将HTML规范化为类似XML的结构(尽管不完全一样).

It's actually a non-trivial problem to accomplish this kind of annotation parsing. What we do first is to slurp the entire HTML as a DOM-like tree using Jsoup. Jsoup takes care of normalizing the HTML into an XML-like structure (not exactly, though).

然后,我们降下这棵树,并构建一个并行的"Renderers"树作为Java对象.每个渲染器都有能力执行特定的操作,例如吐出HTML,显示值是否为真等.鉴于渲染器树与HTML树匹配,如果ShowIf返回false,我们也将其下面的整个分支都删除.

We then descend this tree and build a parallel tree of "Renderers" as Java objects. Each renderer has the ability to do something specific, i.e. spit out HTML, Show If the value is true etc. Given that the renderer tree matches the HTML tree, if ShowIf returns false, we elide the entire branch below it too.

在页面嵌入等方面还有一些更复杂的事情,但这是要点.感谢您的客气话!

There are some more complex things going on under the hood for page-embedding and so on, but this is the gist of it. Thanks for the kind words!

Sitebricks&的创作者Dhanji Guice Servlet.

Dhanji, creator, Sitebricks & Guice Servlet.

这篇关于如何在sitebricks中实现对jsp的注释支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆