DOCX2JATS
DOCX2JATS copied to clipboard
Null pointer exception for figures
The program stops conversion and throws a null pointer exception when using a Harvard references.
Full trace:
BUILD SUCCESSFUL Total time: 4 seconds
reference list has been found
Exception in thread "main" java.lang.NullPointerException at doc.transformation.xml.transformerFigures.transformerFiguresImpl(transformerFigures.java:75) at doc.transformation.xml.docIngestion.ingestionAndTransform(docIngestion.java:122) at doc.transformation.xml.docIngestion.main(docIngestion.java:52)
After testing with another file turns out that the issue is not related to the references.
This could be because of many reasons. Can you show a problematic DOCX file?
It is a part of the code that responsible for figure comments. Do you know Java? You can simply put this part of code into the try-cache block: https://github.com/Vitaliy-1/DOCX2JATS/blob/master/src/doc/transformation/xml/transformerFigures.java#L72-L78
If it helps, do the commit. Tell me if this is problematic for you.
Keep in mind that I'm not planning to continue this project as for next several months will be writing a new parser on PHP that can be integrated to OJS. This current parser relies on a side project (TEIC Stylesheets) and on that transformation stage much data are lost. As I see from now, it is better to write all from the scratch.
Here a link to the article that is causing the issue: article.docx
Good to see that a integrated solution is on its way, but I need a stopgap for now.
For the java bit, Looks like any easy modification I can for the figure comments, but couldn't manage to build a new jar file using javac as I got a build exception:
./docIngestion.java:34: error: package org.apache.tools.ant does not exist import org.apache.tools.ant.BuildException;
Which build settings did you use?
This is apache ant library. It should be include into the project.
Ok, I will look at the file
Any specific instructions on how to build it using ant?
@Vitaliy-1 So I have been trying to run an ant build but I couldn't find the build.xml file in the directory. Should I make one myself, if so what dependencies should I use?
Don't recommend to do anything in the build.xml
managing those dependencies there was a headache for me, as I don't know ant build well :)
Basically, if you using eclipse, it recommends you what libraries you are missing: ant-launcher.jar, ant.jar, and saxon9he.jar. Did you include all 3 in your classpath?
https://github.com/Vitaliy-1/DOCX2JATS/blob/master/stylesheets/docx/build-from.xml Ideally. this project should be converted to maven project and point all dependencies there...
@Vitaliy-1 I placed them in eclipse and did get the missing warnings for ant-launcher.jar, ant.jar, and saxon9he.jar. From where do I include them?
They are all available through maven. For example: https://mvnrepository.com/artifact/net.sf.saxon/saxon9he/9.4.0.4
The also can be download manually. if you are not familiar with maven. Saxon, for example, is available here: https://sourceforge.net/projects/saxon/files/
@Vitaliy-1
It is asking for a pattern and a pattern name, what should I put in here?
Not sure. And what you are trying to do?
The main method is inside docIngestion class. If you want to run it from IDE (to check the code before making a jar file) you can specify your input and output file paths here: https://github.com/Vitaliy-1/DOCX2JATS/blob/master/src/doc/transformation/xml/docIngestion.java#L46 and here: https://github.com/Vitaliy-1/DOCX2JATS/blob/master/src/doc/transformation/xml/docIngestion.java#L50
@Vitaliy-1 I'm trying to build the project to get the jar file to run the program not run it from the IDE.
I've only done this before in Eclipse: https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm
@Vitaliy-1 Managed to get the jar, but there seems to be an issue with class path/definitions as it throws this when I try to run it:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.privateGetMethodRecursive(Unknown Source) at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.validateMainClass(Unknown Source) at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.BuildException at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 7 more
Java can't find ant library here. OK, I will rebuild the project as a Maven to ease the work with dependencies at the end of next week.