From 44802f16b9a86dd227f77913ed3253f882e4a005 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Thu, 7 Jul 2022 14:16:53 +0200 Subject: [PATCH] allow to create fx 1 files with command line again --- History.md | 1 + .../org/mustangproject/commandline/Main.java | 21 +++++++++-------- .../org/mustangproject/ZUGFeRD/Profiles.java | 6 ++++- .../ZUGFeRD/ZUGFeRDExporterFromA1.java | 4 ++++ .../ZUGFeRD/ZUGFeRDExporterFromA3.java | 23 +++++++++++++++++++ 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/History.md b/History.md index e857c5d8..4aef1910 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,4 @@ +- allow to create fx 1 files with command line again - is maven build profile to gen xslt, mvn clean package -P generateXSLTFromSchematron - OXPullprovider to no longer generate invsalid XML if a duedate is set diff --git a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java index c30e1638..048dff03 100755 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java @@ -635,6 +635,9 @@ public class Main { } EStandard standard=EStandard.facturx; + if (format.equals("zf")) { + standard=EStandard.zugferd; + } if (format.equals("da")) { standard=EStandard.despatchadvice; @@ -644,8 +647,6 @@ public class Main { if (format.equals("ox")) { standard=EStandard.orderx; } - - if (zfProfile.equals("b")) { zfConformanceLevelProfile = Profiles.getByName(standard, "BASIC", zfIntVersion); } else if (zfProfile.equals("c")) { @@ -657,19 +658,19 @@ public class Main { } } else if (((format.equals("zf")) && (zfIntVersion == 2)) || (format.equals("fx"))) { if (zfProfile.equals("m")) { - zfConformanceLevelProfile = Profiles.getByName("MINIMUM", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "MINIMUM", zfIntVersion); } else if (zfProfile.equals("w")) { - zfConformanceLevelProfile = Profiles.getByName("BASICWL", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "BASICWL", zfIntVersion); } else if (zfProfile.equals("b")) { - zfConformanceLevelProfile = Profiles.getByName("BASIC", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "BASIC", zfIntVersion); } else if (zfProfile.equals("c")) { - zfConformanceLevelProfile = Profiles.getByName("CIUS", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "CIUS", zfIntVersion); } else if (zfProfile.equals("e")) { - zfConformanceLevelProfile = Profiles.getByName("EN16931", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "EN16931", zfIntVersion); } else if (zfProfile.equals("t")) { - zfConformanceLevelProfile = Profiles.getByName("EXTENDED", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "EXTENDED", zfIntVersion); } else if (zfProfile.equals("x")) { - zfConformanceLevelProfile = Profiles.getByName("XRECHNUNG", zfIntVersion); + zfConformanceLevelProfile = Profiles.getByName(standard, "XRECHNUNG", zfIntVersion); } else { throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile)); } @@ -698,7 +699,7 @@ public class Main { } else { ze = new ZUGFeRDExporterFromA1().setProducer("Mustang-cli") - .setZUGFeRDVersion(zfIntVersion) + .setZUGFeRDVersion(standard, zfIntVersion) .setCreator(System.getProperty("user.name")).setProfile(zfConformanceLevelProfile); if (ignoreInputErrors) { ((ZUGFeRDExporterFromA1)ze).ignorePDFAErrors(); diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/Profiles.java b/library/src/main/java/org/mustangproject/ZUGFeRD/Profiles.java index b5b9ae88..5a39f67f 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/Profiles.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/Profiles.java @@ -71,7 +71,11 @@ public class Profiles { } return result; } else { - return getByName(name, version); + int generation = version; + if ((standard==EStandard.facturx) && (version==1)) { + generation = 2; + } + return getByName(name, generation); } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1.java index 951e568b..752d88bb 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1.java @@ -22,6 +22,7 @@ package org.mustangproject.ZUGFeRD; import org.apache.pdfbox.preflight.PreflightDocument; import org.apache.pdfbox.preflight.exception.ValidationException; import org.apache.pdfbox.preflight.parser.PreflightParser; +import org.mustangproject.EStandard; import javax.activation.DataSource; import java.io.IOException; @@ -106,6 +107,9 @@ public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 implements IZUG public ZUGFeRDExporterFromA1 setProducer(String producer){ return (ZUGFeRDExporterFromA1) super.setProducer(producer); } + public ZUGFeRDExporterFromA1 setZUGFeRDVersion(EStandard est, int version){ + return (ZUGFeRDExporterFromA1) super.setZUGFeRDVersion(est, version); + } public ZUGFeRDExporterFromA1 setZUGFeRDVersion(int version){ return (ZUGFeRDExporterFromA1) super.setZUGFeRDVersion(version); } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java index 82bb5f3b..ba76a9d9 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java @@ -44,6 +44,7 @@ import org.apache.xmpbox.type.BadFieldValueException; import org.apache.xmpbox.xml.DomXmpParser; import org.apache.xmpbox.xml.XmpParsingException; import org.apache.xmpbox.xml.XmpSerializer; +import org.mustangproject.EStandard; import org.mustangproject.FileAttachment; import javax.activation.DataSource; @@ -851,6 +852,28 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte } } + public ZUGFeRDExporterFromA3 setZUGFeRDVersion(EStandard est, int version) { + this.ZFVersion = version; + if ((version<1) || (version>2)) { + throw new IllegalArgumentException("Version not supported"); + } + int generation=version; + if ((est==EStandard.facturx)&&(version==1)) { + generation=2; + } + if (generation == 1) { + ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider(); + disableFacturX(); + setXMLProvider(z1p); + } else if (generation == 2) { + ZUGFeRD2PullProvider z2p = new ZUGFeRD2PullProvider(); + setXMLProvider(z2p); + } + + + return this; + } + @Override public ZUGFeRDExporterFromA3 setZUGFeRDVersion(int version) { this.ZFVersion = version;