类似于ZPT(属性语言)的Java模板库

发布于 2024-12-13 17:11:33 字数 347 浏览 1 评论 0原文

我最近一直在 python 中使用 ZPT ,我喜欢模板语言。我一直在寻找与 Java 类似的东西,但找不到我喜欢的东西。最接近的是 FreeMarker

FreeMarker 和我研究过的其他 Java 模板引擎的问题是它们的 JSP 样式语法允许不符合规范的 XML。我只是想知道是否有一个类似于 Zope 页面模板的 Java 模板引擎,这样它就是一种需要有效 xml 的“属性”语言。

I've been using ZPT in python recently and I love the templating language. I was looking for something similar for Java but couldn't really find anything I liked as well. The closest thing is FreeMarker.

The problem with FreeMarker and the other Java template engines I looked at was their JSP style syntax that allows for non-conforming XML. I was just wondering if there was a Java template engine that is similar to Zope Page Templates such that it's an "attribute" language that requires valid xml.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

红颜悴 2024-12-20 17:11:33

我认为您正在寻找相当多的模板引擎:

支持有效 html 的其他方法有:

I think think there quite some of the template engines your looking for:

Other approaches supporting valid html are:

半城柳色半声笛 2024-12-20 17:11:33

FreeMarker 对 AWT 有着严重的依赖。它使得它无法与 Google App Engine 等工具一起使用。

我更喜欢使用 StringTemplate 来满足我所有的 Java 模板需求。它是唯一一个基于Java的模板系统,将逻辑与模板严格分离。

StringTemplate 是一个 Java 模板引擎(带有 C#、Python、
Ruby 和 Scala)用于生成源代码、网页、电子邮件或任何
其他格式的文本输出。 StringTemplate特别擅长
多目标代码生成器、多个站点皮肤,以及
国际化/本地化

其显着特点是严格执行
与其他引擎不同,模型视图分离
。严格的分离使得
网站和代码生成器更加灵活和可维护;它也
提供了针对恶意模板作者的出色防御。

由于您正在生成 XML

另一个乍一看并不明显的解决方案是使用 JAXB。我们这里有一个项目需要生成 XML,我们为输出文件定义了非常明确的 XSD 文件,构建对象并编组它们非常简单且轻松。

FreeMarker has a nasty dependency on AWT. It makes it impossible to use with things like Google App Engine.

I prefer to use StringTemplate for all my Java templating needs. It is the only Java based template system that strictly separates the logic from the template.

StringTemplate is a java template engine (with ports for C#, Python,
Ruby, and Scala) for generating source code, web pages, emails, or any
other formatted text output. StringTemplate is particularly good at
multi-targeted code generators, multiple site skins, and
internationalization/localization

Its distinguishing characteristic is that it strictly enforces
model-view separation unlike other engines
. Strict separation makes
websites and code generators more flexible and maintainable; it also
provides an excellent defense against malicious template authors.

Since you are generating XML

Another solution that isn't obvious at first sight is using JAXB. We have a project here that requires us to generate XML, we have very well defined XSD files for the output files, building the objects and marshalling them is super easy and very painless.

狼亦尘 2024-12-20 17:11:33

您会发现与 Chameleon 最相似的 Java 模板引擎是 Thymeleaf

The java template engine you will find to be most similar to Chameleon is Thymeleaf.

何其悲哀 2024-12-20 17:11:33

Distal 用于基于客户端的模板。

There is Distal for client based templating.

还如梦归 2024-12-20 17:11:33

据我所知,目前有两个 Java 实现的:

There are currently two implementations for Java that I know of:

于我来说 2024-12-20 17:11:33

还有 Apache Velocity。尽管它不要求您的模板是有效的 XML。考虑到这个问题,这可能会破坏你的交易。不过,您可能可以通过对核心类的扩展来强制执行该规则。

There is also Apache Velocity. Although it doesn't require that your templates be valid XML. That may be a deal breaker for you given the question. You could likely enforce that rule with extensions to the core classes though.

予囚 2024-12-20 17:11:33

GXP 怎么样?

还有 LSPxtempore

What about GXP?

There's also LSP and xtempore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文