是否可以使用 SiteMesh 提取 SCRIPT 标签?

发布于 2024-08-14 11:42:56 字数 332 浏览 12 评论 0原文

我有自定义 JSP 标记,可以生成一些 HTML 内容,以及一些由该 HTML 代码调用的 javascript 函数。在当前的实现中,SCRIPT 标记是在 HTML 代码上方创建的。

为了避免修改现有的代码库,我想使用 SiteMesh 或其他一些装饰器工具在页面的 HEAD 部分中提取这些脚本。

我知道 SiteMesh 可以从 元素中提取内容,但我想知道是否也可以使用其他标签(例如 SCRIPT)。

SiteMesh 可以做到这一点吗?或者知道有什么工具可以让我做到这一点吗?

谢谢你!

I have custom JSP tags that generate some HTML content, along with some javascript functions that get called by this HTML code. In the current implementation, the SCRIPT tags are created just above the HTML code.

To avoid modifying the existing code base, I want to pull up these scripts inside the HEAD section of the page using SiteMesh or some other decorator tool.

I know SiteMesh can extract content from <content tag="..."> elements, but I was wondering if it was possible also with other tags, such as SCRIPT.

Is this possible with SiteMesh, or know of any tools that could allow me to do that?

Thank you!

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

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

发布评论

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

评论(1

东风软 2024-08-21 11:42:56

SiteMesh 的 HTMLPageParser 是可扩展的,因此您可以通过扩展 HTMLPageParser 和 将 SiteMesh 配置为使用您的类而不是 HTMLPageParser,如下所示:

import com.opensymphony.module.sitemesh.parser.HTMLPageParser;

public CustomPageParser extends HTMLPageParser {

    protected void addUserDefinedRules(State html, PageBuilder page) {
        super.addUserDefinedRules(html, page);

        html.addRule(new ScriptExtractingRule(page));
    }

}

我想您的 ScriptExtractingRule 将按照标准 SiteMesh ContentBlockExtractingRule,将内容存储在页面上下文中,以便您的装饰器可以访问这些块,就像它们是 <内容> 块。

SiteMesh's HTMLPageParser is extensible, so you can add your own custom rule to extract <script> elements by extending HTMLPageParser and configuring SiteMesh to use your class instead of HTMLPageParser, something like this:

import com.opensymphony.module.sitemesh.parser.HTMLPageParser;

public CustomPageParser extends HTMLPageParser {

    protected void addUserDefinedRules(State html, PageBuilder page) {
        super.addUserDefinedRules(html, page);

        html.addRule(new ScriptExtractingRule(page));
    }

}

I imagine your ScriptExtractingRule would be modeled after the standard SiteMesh ContentBlockExtractingRule, storing the content in the page context so your decorator can access the blocks as if they were <content> blocks.

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