格式化 HTML 作为 MX4J HTTP 页面方法调用的输出

发布于 2024-08-24 05:21:59 字数 467 浏览 5 评论 0原文

我有大量数据,想要以某种格式显示数据。
该方法基本上如下所示:


    @ManagedOperation(description = "return html")
@ManagedOperationParameters({@ManagedOperationParameter(name = "someVal", description = "text")})
public String returnAsHtml(String someVal)
{
return "some formatted xml";
}

看起来 XSLTProcessor 可以配置为使用 XSLT 模板。然而,我在互联网上找不到任何在 MX4J 上下文中使用 XSLT 进行 html 转换的示例。谁能提供一个示例 XSLT 模板吗?

I have a huge set of data and want to display the data with some formatting.
This is what the method basically looks like:


    @ManagedOperation(description = "return html")
@ManagedOperationParameters({@ManagedOperationParameter(name = "someVal", description = "text")})
public String returnAsHtml(String someVal)
{
return "some formatted xml";
}

Looks like XSLTProcessor can be configured to use a XSLT template. However I could not find any examples on the internet using XSLT for html transformation in the context of MX4J. Could any one provide a sample XSLT template?

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

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

发布评论

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

评论(2

瘫痪情歌 2024-08-31 05:21:59

如果有人回到这个问题,我会想到两件事:

1) MX4J 有几个 HttpCommandProcessorAdaptor 的默认实现。这些操作是从路径映射的。对于 JMX 操作(Spring 术语中的 ManagedOperation),MX4J 使用 /invoke?operation=returnAsHtml 之类的 URL,

这将被传递到 InvokeOperationCommandProcessor 以创建一个 XML 文档,其结果只是属性中返回的任何内容的 toString()称为‘回归’。它还在名为“returnclass”的属性中传回返回类型。如果您只需将 &template=identity 添加到调用 URL,您就可以看到所有这些。

我提到这一切是因为一种选择是实现您自己的“invoke.xsl”。 MX4J 中的只是调用 renderobject 模板:

你瞧,您在 mbean_attributes.xsl 中找到了这一点,其中的注释准确地显示了您需要执行的操作:

   <xsl:template name="renderobject">
  <xsl:param name="objectclass"/>
  <xsl:param name="objectvalue"/>
  <xsl:choose>
     <xsl:when test="$objectclass='javax.management.ObjectName'">
        <xsl:variable name="name_encoded">
           <xsl:call-template name="uri-encode">
              <xsl:with-param name="uri">
                 <xsl:value-of select="$objectvalue"/>
              </xsl:with-param>
           </xsl:call-template>
        </xsl:variable>
        <a href="/mbean?objectname={$name_encoded}">
           <xsl:value-of select="$objectvalue"/>
        </a>
     </xsl:when>
     <xsl:otherwise>
        <!-- Use the following line when the result of an invocation
        returns e.g. HTML or XML data
        <xsl:value-of select="$objectvalue" disable-output-escaping="true" />
        -->
        <xsl:value-of select="$objectvalue"/>
     </xsl:otherwise>
  </xsl:choose>

将“disable-output-escaping”设置为 true 即可解决问题

2) 另一种选择是编写自己的 HttpCommandProcessorAdaptor,并将其设置在 HttpAdapter 上。这可以替换“调用”处理器,或者您可以拥有一个全新的处理器。

希望有帮助

In case anyone comes back to this question, two things come to mind:

1) MX4J has several default implementations of HttpCommandProcessorAdaptor. These operations are mapped from the path. For JMX operations (aka ManagedOperation in Spring parlance), MX4J uses URLs like /invoke?operation=returnAsHtml

This will be passed to the InvokeOperationCommandProcessor to create an XML document with the result being just the toString() of whatever you returned, in an attribute called 'return'. It also passes back the return type in an attribute called 'returnclass'. You can see all this if you just add &template=identity to the invoke URL.

I mention all this because one option is to implement your own 'invoke.xsl'. The one in MX4J just calls the renderobject template:

Lo and behold, you find this in mbean_attributes.xsl, with a comment showing you exactly what you need to do:

   <xsl:template name="renderobject">
  <xsl:param name="objectclass"/>
  <xsl:param name="objectvalue"/>
  <xsl:choose>
     <xsl:when test="$objectclass='javax.management.ObjectName'">
        <xsl:variable name="name_encoded">
           <xsl:call-template name="uri-encode">
              <xsl:with-param name="uri">
                 <xsl:value-of select="$objectvalue"/>
              </xsl:with-param>
           </xsl:call-template>
        </xsl:variable>
        <a href="/mbean?objectname={$name_encoded}">
           <xsl:value-of select="$objectvalue"/>
        </a>
     </xsl:when>
     <xsl:otherwise>
        <!-- Use the following line when the result of an invocation
        returns e.g. HTML or XML data
        <xsl:value-of select="$objectvalue" disable-output-escaping="true" />
        -->
        <xsl:value-of select="$objectvalue"/>
     </xsl:otherwise>
  </xsl:choose>

Setting 'disable-output-escaping' to true will do the trick

2) Another option is to write your own HttpCommandProcessorAdaptor, and set it on the HttpAdapter. This could either replace the 'invoke' processor, or you could have an entirely new one.

Hope that helps

如梦亦如幻 2024-08-31 05:21:59

我想到的一种方法是在 XSL 模板中使用 java 脚本来提取和解析字符串。确保测试浏览器(IE 与非 IE)并使用正确的解析器。

One way I figured out is to use java script in the XSL template to extract and parse the string. Make sure you test for the browser (IE vs Non IE) and use proper parser.

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