Open drmacro opened 3 years ago
Updated non-POI dependencies to latest versions and all tests pass. Merged that change to develop branch. Updating to POI 5 leads to some errors around changes in packages and whatnot. Not pursuing this upgrade at this time due to time constraints.
The following is a (likely incomplete) initial patch to switch to support Apache POI 5.0.0, tests run fine after this is applied.
Note: I had to comment out one line to make it compile: style.setCustomStyle(STOnOffImpl.X_1);
, not sure what the replacement is in the new classes.
diff --git a/pom.xml b/pom.xml
index ce14237..33f4a22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,17 +57,17 @@ arbitrary XML, JSON, etc.</description>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
- <version>4.1.2</version>
+ <version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
- <version>4.1.2</version>
+ <version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
- <version>3.1.0</version>
+ <version>4.0.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
@@ -85,11 +85,11 @@ arbitrary XML, JSON, etc.</description>
<artifactId>Saxon-HE</artifactId>
<version>10.3</version>
</dependency>
- <!-- https://mvnrepository.com/artifact/org.apache.poi/ooxml-schemas -->
+ <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-full -->
<dependency>
<groupId>org.apache.poi</groupId>
- <artifactId>ooxml-schemas</artifactId>
- <version>1.4</version>
+ <artifactId>poi-ooxml-full</artifactId>
+ <version>5.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
diff --git a/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java b/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java
index 9e1601b..7f6cb0f 100644
--- a/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java
+++ b/src/main/java/org/wordinator/xml2docx/generator/DocxGenerator.java
@@ -52,44 +52,10 @@ import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlCursor.TokenType;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTMarkupRange;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageNumber;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageSz;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSimpleField;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STChapterSep;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STPageOrientation;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STSectionMark;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.STOnOffImpl;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.impl.STOnOff1Impl;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.wordinator.xml2docx.xwpf.model.XWPFHeaderFooterPolicy;
/**
@@ -710,7 +676,7 @@ public class DocxGenerator {
localSectPr = doc.getDocument().getBody().getSectPr();
}
CTOnOff titlePg = (localSectPr.isSetTitlePg() ? localSectPr.getTitlePg() : localSectPr.addNewTitlePg());
- titlePg.setVal(STOnOff.TRUE);
+ titlePg.setVal(STOnOff1.ON);
}
if (type == HeaderFooterType.DEFAULT) {
haveOddHeader = true;
@@ -745,7 +711,7 @@ public class DocxGenerator {
localSectPr = doc.getDocument().getBody().getSectPr();
}
CTOnOff titlePg = (localSectPr.isSetTitlePg() ? localSectPr.getTitlePg() : localSectPr.addNewTitlePg());
- titlePg.setVal(STOnOff.TRUE);
+ titlePg.setVal(STOnOff1.ON);
}
if (isDocument) {
// Document-level footer
@@ -1148,9 +1114,7 @@ public class DocxGenerator {
boolean value = Boolean.parseBoolean(attValue);
run.setItalic(value);
} else if ("outline".equals(attName)) {
- CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(STOnOff.Enum.forString(attValue));
- run.getCTR().getRPr().setOutline(onOff);
+ run.getCTR().getRPr().addNewOutline().setVal(STOnOff1.Enum.forString(attValue));
} else if ("position".equals(attName)) {
int val = Integer.parseInt(attValue);
run.setTextPosition(val);
@@ -2381,7 +2345,7 @@ public class DocxGenerator {
doc.getStyles().addStyle(new XWPFStyle(style));
style = CTStyle.Factory.newInstance();
- style.setCustomStyle(STOnOffImpl.X_1);
+ //style.setCustomStyle(STOnOff1.X_1);
style.setStyleId("FootnoteTextChar");
style.setType(STStyleType.CHARACTER);
style.addNewName().setVal("Footnote Text Char");
diff --git a/src/main/java/org/wordinator/xml2docx/xwpf/model/XWPFHeaderFooterPolicy.java b/src/main/java/org/wordinator/xml2docx/xwpf/model/XWPFHeaderFooterPolicy.java
index a63b103..1f20427 100644
--- a/src/main/java/org/wordinator/xml2docx/xwpf/model/XWPFHeaderFooterPolicy.java
+++ b/src/main/java/org/wordinator/xml2docx/xwpf/model/XWPFHeaderFooterPolicy.java
@@ -26,6 +26,7 @@ import org.apache.poi.xwpf.usermodel.XWPFHeaderFooter;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
@@ -51,7 +52,6 @@ import com.microsoft.schemas.vml.CTShape;
import com.microsoft.schemas.vml.CTShapetype;
import com.microsoft.schemas.vml.CTTextPath;
import com.microsoft.schemas.vml.STExt;
-import com.microsoft.schemas.vml.STTrueFalse;
/**
* A .docx file can have no headers/footers, the same header/footer
diff --git a/src/test/java/org/wordinator/xml2docx/TestUseCatalogs.java b/src/test/java/org/wordinator/xml2docx/TestUseCatalogs.java
index 0bf169a..0158d83 100644
--- a/src/test/java/org/wordinator/xml2docx/TestUseCatalogs.java
+++ b/src/test/java/org/wordinator/xml2docx/TestUseCatalogs.java
@@ -66,11 +66,7 @@ public class TestUseCatalogs extends TestCase {
assertNotNull("No catalog option value", catalog);
assertEquals(catalogFile.getAbsolutePath(), catalog.trim());
- try {
MakeDocx.handleCommandLine(options, args, log);
- } catch (Throwable e) {
- fail("Got exception from handleCommandLine(): " + e.getMessage());
- }
}
Thanks--any chance you can put this on a branch and make a pull request?
I am not sure this is all that is needed, it just made the unit tests green, but at least one line is commented out for now.
I don't know much about this application and don't use it regularly, I just tried to see how far upgrading would go before stumbling into issues so we know if we need to include some more fixes in the upcoming Apache POI 5.0.1.
So I can't spend more time here for now, sorry.
No worries. I'll see what I can do with the patch as you provided it here.
My main problem with 5.0 was actually making Wordinator run under Java 11--I don't really understand how the new Java packaging stuff affects things but I was getting runtime class-not-found issues that I understand to be a problem with how Java includes or doesn't include various packages.
Feel free to post issues here, I can at least try to take a quick look and state if it is something related to changes in POI.
I have succeeded in making Wordinator run under Java 9+ (release 1.1.2) by not using the all-dependencies jar.
With that I've started trying to make the code work with POI 5.
I got it to compile by commenting out a few places where I couldn't quickly find the replacement type, including the one mentioned above.
With that change the code compiles and all the tests pass (which means the things I commented out are not tested for, not that they are not important).
POI 5.0.0 release 20 Jan 2021. Should update to it.