使用 java.util.Base64.Decoder 解码 base64
Decoding base64 with java.util.Base64.Decoder
我正在尝试在我的 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()[=15= 的匹配双参数函数]
我知道还有另一种方法,但我特别想知道为什么这个方法不起作用。
提前致谢。
添加 Oxygen 诊断信息以解决方法调用(参见跟踪:"The class java.util.Base64.Decoder could not be loaded: 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
如果您使用 Java 内部 class 名称,则会找到 class:
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
我正在尝试在我的 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()[=15= 的匹配双参数函数]
我知道还有另一种方法,但我特别想知道为什么这个方法不起作用。
提前致谢。
添加 Oxygen 诊断信息以解决方法调用(参见跟踪:"The class java.util.Base64.Decoder could not be loaded: 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
如果您使用 Java 内部 class 名称,则会找到 class:
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