使用java.util.Base64.Decoder

时间:2018-03-20 16:03:48

标签: xslt saxon

我正在尝试将输入String解码为我的XSLT中的base64。

我已经定义了2个名称空间:

xmlns:base64Decoder="java:java.util.Base64.Decoder"
xmlns:base64="java:java.util.Base64"

这是我的简单尝试:

        <xsl:variable name="base64Value" select="'aGVsbG8='"/>
        <xsl:variable name="deco" select="base64:getDecoder()"/>
        <xsl:value-of select="base64Decoder:decode($deco, $base64Value)"/>

执行没有编译并向我显示消息:

找不到名为{java:java.util.Base64.Decoder} decode()的匹配2参数函数

我知道还有另外一种方法,但我特别感兴趣的是知道为什么这个方法不起作用。

提前致谢。

为解析方法调用添加Oxygen诊断信息(请参阅跟踪:“几乎无法加载类java.util.Base64.Decoder:java.util.Base64.Decoder”):

Looking for function {java:java.util.Base64}getDecoder
Trying net.sf.saxon.functions.SystemFunctionLibrary
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Trying com.saxonica.functions.extfn.ExtraFunctionLibrary
Trying net.sf.saxon.functions.ConstructorFunctionLibrary
Trying net.sf.saxon.query.XQueryFunctionLibrary
Trying net.sf.saxon.functions.IntegratedFunctionLibrary
Trying com.saxonica.config.JavaExtensionLibrary
Looking for method getDecoder in namespace java:java.util.Base64
Number of actual arguments = 0
Loading java.util.Base64
Looking in Java class class java.util.Base64
Trying method getMimeDecoder: name does not match
Trying method getDecoder: name matches
Method is static
Method has 0 arguments; expecting 0
Found a candidate method:
    public static java.util.Base64$Decoder java.util.Base64.getDecoder()
Trying method getEncoder: name does not match
Trying method getMimeEncoder: name does not match
Trying method getMimeEncoder: name does not match
Trying method getUrlDecoder: name does not match
Trying method getUrlEncoder: name does not match
Trying method wait: name does not match
Trying method wait: name does not match
Trying method wait: name does not match
Trying method equals: name does not match
Trying method toString: name does not match
Trying method hashCode: name does not match
Trying method getClass: name does not match
Trying method notify: name does not match
Trying method notifyAll: name does not match
Looking for function {java:java.util.Base64.Decoder}decode
Trying net.sf.saxon.functions.SystemFunctionLibrary
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Trying com.saxonica.functions.extfn.ExtraFunctionLibrary
Trying net.sf.saxon.functions.ConstructorFunctionLibrary
Trying net.sf.saxon.query.XQueryFunctionLibrary
Trying net.sf.saxon.functions.IntegratedFunctionLibrary
Trying com.saxonica.config.JavaExtensionLibrary
Looking for method decode in namespace java:java.util.Base64.Decoder
Number of actual arguments = 2
Loading java.util.Base64.Decoder
The class java.util.Base64.Decoder could not be loaded: java.util.Base64.Decoder
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Function {java:java.util.Base64.Decoder}decode not found!
Loading java.util.Base64.Decoder
The class java.util.Base64.Decoder could not be loaded: java.util.Base64.Decoder

1 个答案:

答案 0 :(得分:1)

如果您使用Java内部类名,则会找到该类:

xmlns:base64Decoder="java:java.util.Base64$Decoder"

不幸的是,你又遇到了另一个问题:

Static error in xsl:value-of/@select on line 16 column 71 of test.xsl:
  XPST0017: There is more than one method matching the function call base64Decoder:decode,
  and there is insufficient type information to determine which one should be used

您可以通过将呼叫编写为:

来解决此问题
<xsl:value-of select="base64Decoder:decode($deco, $base64Value treat as xs:string)"/>

然后代码成功运行并打印输出

104 101 108 108 111