是否可以在 Android 上从 Xalan 调用 Java 扩展函数?
Posted
技术标签:
【中文标题】是否可以在 Android 上从 Xalan 调用 Java 扩展函数?【英文标题】:Is it possible to call a Java extension function from Xalan on Android? 【发布时间】:2012-05-21 16:50:37 【问题描述】:docx4j 使用 Xalan 将 docx 转换为 html,并且严重依赖 Xalan Java 扩展来完成这项工作。
但 Xalan 扩展不适用于我在 android 上(使用 4.0.3)。 LogCat 说:
05-14 15:38:02.840: I/dalvikvm(7249): DexOpt: illegal method access (call Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class; from Lorg/apache/xalan/extensions/ExtensionHandlerJavaPackage;)
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.extensions.ExtensionHandler.getClassForName, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve static method 21489: Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class;
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x71 at 0x0096
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.transformer.TransformerImpl.getDebug, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve virtual method 23717: Lorg/apache/xalan/transformer/TransformerImpl;.getDebug ()Z
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x74 at 0x0133
05-14 15:38:02.840: I/dalvikvm(7249): DexOpt: illegal method access (call Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class; from Lorg/apache/xalan/extensions/ExtensionHandlerJavaPackage;)
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.extensions.ExtensionHandler.getClassForName, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve static method 21489: Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class;
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x71 at 0x0189
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.transformer.TransformerImpl.getDebug, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve virtual method 23717: Lorg/apache/xalan/transformer/TransformerImpl;.getDebug ()Z
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x74 at 0x028e
05-14 15:38:02.840: I/dalvikvm(7249): DexOpt: illegal method access (call Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class; from Lorg/apache/xalan/extensions/ExtensionHandlerJavaPackage;)
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.extensions.ExtensionHandler.getClassForName, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.isElementAvailable
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve static method 21489: Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class;
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x71 at 0x0022
05-14 15:38:02.840: I/dalvikvm(7249): DexOpt: illegal method access (call Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class; from Lorg/apache/xalan/extensions/ExtensionHandlerJavaPackage;)
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.extensions.ExtensionHandler.getClassForName, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.isFunctionAvailable
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve static method 21489: Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class;
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x71 at 0x0021
05-14 15:38:02.840: I/dalvikvm(7249): DexOpt: illegal method access (call Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class; from Lorg/apache/xalan/extensions/ExtensionHandlerJavaPackage;)
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.extensions.ExtensionHandler.getClassForName, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.processElement
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve static method 21489: Lorg/apache/xalan/extensions/ExtensionHandler;.getClassForName (Ljava/lang/String;)Ljava/lang/Class;
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x71 at 0x004c
05-14 15:38:02.840: I/dalvikvm(7249): Could not find method org.apache.xalan.transformer.TransformerImpl.getDebug, referenced from method org.apache.xalan.extensions.ExtensionHandlerJavaPackage.processElement
05-14 15:38:02.840: W/dalvikvm(7249): VFY: unable to resolve virtual method 23717: Lorg/apache/xalan/transformer/TransformerImpl;.getDebug ()Z
05-14 15:38:02.840: D/dalvikvm(7249): VFY: replacing opcode 0x74 at 0x0091
05-14 15:38:02.860: D/AndroidRuntime(7249): Shutting down VM
05-14 15:38:02.860: W/dalvikvm(7249): threadid=1: thread exiting with uncaught exception (group=0x40a531f8)
05-14 15:38:02.860: E/AndroidRuntime(7249): FATAL EXCEPTION: main
05-14 15:38:02.860: E/AndroidRuntime(7249): java.lang.IllegalAccessError: tried to access method org.apache.xalan.extensions.ExtensionHandler.getClassForName:(Ljava/lang/String;Ljava/util/Vector;Ljava/lang/Object;Lorg/apache/xalan/extensions/ExpressionContext;)Ljava/lang/Object; from class org.apache.xalan.extensions.ExtensionHandlerJavaPackage
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:315)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:440)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:222)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:417)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:208)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xpath.XPath.execute(XPath.java:337)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:274)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:245)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:370)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:175)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2223)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2096)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1228)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:614)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1145)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1123)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.docx4j.XmlUtils.transform(XmlUtils.java:841)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.docx4j.XmlUtils.transform(XmlUtils.java:734)
05-14 15:38:02.860: E/AndroidRuntime(7249): at org.docx4j.convert.out.html.HtmlExporterNG2.html(HtmlExporterNG2.java:269)
05-14 15:38:02.860: E/AndroidRuntime(7249): at com.example.HelloAndroid.HelloAndroid.onCreate(HelloAndroid.java:58)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.Activity.performCreate(Activity.java:4465)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.os.Looper.loop(Looper.java:137)
05-14 15:38:02.860: E/AndroidRuntime(7249): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-14 15:38:02.860: E/AndroidRuntime(7249): at java.lang.reflect.Method.invokeNative(Native Method)
05-14 15:38:02.860: E/AndroidRuntime(7249): at java.lang.reflect.Method.invoke(Method.java:511)
05-14 15:38:02.860: E/AndroidRuntime(7249): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-14 15:38:02.860: E/AndroidRuntime(7249): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-14 15:38:02.860: E/AndroidRuntime(7249): at dalvik.system.NativeStart.main(Native Method)
对问题到底是什么以及解决方法有什么想法吗?
【问题讨论】:
你是如何声明和使用你的扩展函数的? 使用 xmlns:java="xml.apache.org/xalan/java",类似于xmlns:java="http://xml.apache.org/xalan/java"
。在我发布此评论后,我可以看到 http://
正在从您的原始评论中隐藏...您可能正在与 SecurityManager 或其他东西作斗争。 耸耸肩
目前,我避免在 Android 上使用 XSLT(我现在在 Java 代码中进行节点树遍历)。我想如果有其他事情让我想使用 Xalan Java 扩展,我会回到这个。
【参考方案1】:
Android 包含自己的一些 Apache XML 库副本。如果您想在自己的应用中包含自己的版本,最好的办法是使用instructions here 重新打包它。
【讨论】:
我已经重新打包了各种东西(例如 javax.xml.bind),但没有迹象表明这是这里的问题,是吗?以上是关于是否可以在 Android 上从 Xalan 调用 Java 扩展函数?的主要内容,如果未能解决你的问题,请参考以下文章
Android:从 Java 代码调用 Python 脚本(通过 SL4A)
如何在设备上从 github 测试构建的 android 应用程序?
以前可以在 Android 上从 PersistentDataPath 保存和加载,现在无法