+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/library/src/test/resources/migration/input/ZUGFeRD1_COMFORT_Einfach.xml b/library/src/test/resources/migration/input/ZUGFeRD1_COMFORT_Einfach.xml
index 08991a06..db6672dd 100644
--- a/library/src/test/resources/migration/input/ZUGFeRD1_COMFORT_Einfach.xml
+++ b/library/src/test/resources/migration/input/ZUGFeRD1_COMFORT_Einfach.xml
@@ -1,216 +1,216 @@
-
-
-
-
- true
-
- urn:ferd:CrossIndustryDocument:invoice:1p0:comfort
-
-
-
- 471102
- RECHNUNG
- 380
- 20130305
-
- Rechnung gemäß Bestellung vom 01.03.2013.
-
-
- Lieferant GmbH
-Lieferantenstraße 20
-80333 München
-Deutschland
-Geschäftsführer: Hans Muster
-Handelsregisternummer: H A 123
-
-REG
-
-
-
-
-
- 4000001123452
- Lieferant GmbH
-
- 80333
- Lieferantenstraße 20
- München
- DE
-
-
- 201/113/40209
-
-
- DE123456789
-
-
-
- GE2020211
- 4000001987658
- Kunden AG Mitte
-
- Hans Muster
-
-
- 69876
- Kundenstraße 15
- Frankfurt
- DE
-
-
-
-
-
- 20130305
-
-
-
- 2013-471102
- EUR
-
- 31
- Überweisung
-
- DE08700901001234567890
-
-
- GENODEF1M04
-
-
-
- 19.25
- VAT
- 275.00
- S
- 7.00
-
-
- 37.62
- VAT
- 198.00
- S
- 19.00
-
-
- Zahlbar innerhalb 30 Tagen netto bis 04.04.2013, 3% Skonto innerhalb 10 Tagen bis 15.03.2013
- 20130404
-
-
- 473.00
- 0.00
- 0.00
- 473.00
- 56.87
- 529.87
- 0.00
- 529.87
-
-
-
-
- 1
-
-
-
- 9.9000
-
-
- 9.9000
-
-
-
- 20.0000
-
-
-
- VAT
- S
- 19.00
-
-
- 198.00
-
-
-
- 4012345001235
- TB100A4
- Trennblätter A4
-
-
-
-
- 2
-
-
-
- 5.5000
-
-
- 5.5000
-
-
-
- 50.0000
-
-
-
- VAT
- S
- 7.00
-
-
- 275.00
-
-
-
- 4000050986428
- ARNR2
- Joghurt Banane
-
-
-
+
+
+
+
+ true
+
+ urn:ferd:CrossIndustryDocument:invoice:1p0:comfort
+
+
+
+ 471102
+ RECHNUNG
+ 380
+ 20130305
+
+ Rechnung gemäß Bestellung vom 01.03.2013.
+
+
+ Lieferant GmbH
+Lieferantenstraße 20
+80333 München
+Deutschland
+Geschäftsführer: Hans Muster
+Handelsregisternummer: H A 123
+
+REG
+
+
+
+
+
+ 4000001123452
+ Lieferant GmbH
+
+ 80333
+ Lieferantenstraße 20
+ München
+ DE
+
+
+ 201/113/40209
+
+
+ DE123456789
+
+
+
+ GE2020211
+ 4000001987658
+ Kunden AG Mitte
+
+ Hans Muster
+
+
+ 69876
+ Kundenstraße 15
+ Frankfurt
+ DE
+
+
+
+
+
+ 20130305
+
+
+
+ 2013-471102
+ EUR
+
+ 31
+ Überweisung
+
+ DE08700901001234567890
+
+
+ GENODEF1M04
+
+
+
+ 19.25
+ VAT
+ 275.00
+ S
+ 7.00
+
+
+ 37.62
+ VAT
+ 198.00
+ S
+ 19.00
+
+
+ Zahlbar innerhalb 30 Tagen netto bis 04.04.2013, 3% Skonto innerhalb 10 Tagen bis 15.03.2013
+ 20130404
+
+
+ 473.00
+ 0.00
+ 0.00
+ 473.00
+ 56.87
+ 529.87
+ 0.00
+ 529.87
+
+
+
+
+ 1
+
+
+
+ 9.9000
+
+
+ 9.9000
+
+
+
+ 20.0000
+
+
+
+ VAT
+ S
+ 19.00
+
+
+ 198.00
+
+
+
+ 4012345001235
+ TB100A4
+ Trennblätter A4
+
+
+
+
+ 2
+
+
+
+ 5.5000
+
+
+ 5.5000
+
+
+
+ 50.0000
+
+
+
+ VAT
+ S
+ 7.00
+
+
+ 275.00
+
+
+
+ 4000050986428
+ ARNR2
+ Joghurt Banane
+
+
+
\ No newline at end of file
diff --git a/library/src/test/resources/migration/input/ZUGFeRD1_EXTENDED_Warenrechnung.xml b/library/src/test/resources/migration/input/ZUGFeRD1_EXTENDED_Warenrechnung.xml
index 2f3c87bf..0f26d3ea 100644
--- a/library/src/test/resources/migration/input/ZUGFeRD1_EXTENDED_Warenrechnung.xml
+++ b/library/src/test/resources/migration/input/ZUGFeRD1_EXTENDED_Warenrechnung.xml
@@ -1,520 +1,520 @@
-
-
-
-
-
- true
-
- urn:ferd:CrossIndustryDocument:invoice:1p0:extended
-
-
-
- R87654321012345
- WARENRECHNUNG
- 380
-
- 20130806
-
-
- ST3
- Es bestehen Rabatt- oder Bonusvereinbarungen.
- AAK
-
-
- EEV
- Der Verkäufer bleibt Eigentümer der Waren bis zu vollständigen Erfüllung der Kaufpreisforderung.
- AAJ
-
-
- MUSTERLIEFERANT GMBH
-BAHNHOFSTRASSE 99
-99199 MUSTERHAUSEN
-Geschäftsführung:
-Max Mustermann
-USt-IdNr: DE123456789
-Telefon: +49 932 431 0
-www.musterlieferant.de
-HRB Nr. 372876
-Amtsgericht Musterstadt
-GLN 4304171000002
-WEEE-Reg-Nr.: DE87654321
- REG
-
-
- Leergutwert: 46,50
-
-
-
-
-
- 549910
- 4333741000005
- MUSTERLIEFERANT GMBH
-
-
- +49 932 431 500
-
-
- max.mustermann@musterlieferant.de
-
-
-
- 99199
- BAHNHOFSTRASSE 99
- MUSTERHAUSEN
- DE
-
-
- DE123456789
-
-
-
- 009420
- 4304171000002
- MUSTER-KUNDE GMBH
-
- 40235
- KUNDENWEG 88
- DUESSELDORF
- DE
-
-
-
- 2013-08-01T00:00:00
- B123456789
-
-
- 2013-08-02T00:00:00
- VN
- A456123
-
-
-
-
- 4304171088093
- MUSTER-MARKT
-
- 8211
-
-
- 31157
- HAUPTSTRASSE 44
- SARSTEDT
- DE
-
-
-
-
- 20130805
-
-
-
- 2013-08-05T00:00:00
- L87654321012345
-
-
-
- EUR
-
- 009420
- 4304171000002
- MUSTER-KUNDE GMBH
-
- 40235
- KUNDENWEG 88
- DUESSELDORF
- DE
-
-
-
- 61.07
- VAT
- 321.40
- 326.50
- -5.10
- S
- 19.00
-
-
- 8.93
- VAT
- 127.59
- 130.70
- -3.11
- S
- 7.00
-
-
- false
- 2.00
- 280.00
- 5.60
- Rechnungsrabatt 1
-
- VAT
- S
- 19.00
-
-
-
- false
- 2.00
- 130.70
- 2.61
- Rechnungsrabatt 1
-
- VAT
- S
- 7.00
-
-
-
- false
- 280.00
- 2.50
- Rechnungsrabatt 2
-
- VAT
- S
- 19.00
-
-
-
- false
- 130.70
- 0.50
- Rechnungsrabatt 2
-
- VAT
- S
- 7.00
-
-
-
- Transportkosten
- 3.00
-
- VAT
- S
- 19.00
-
-
-
- Bei Zahlung innerhalb 14 Tagen gewähren wir 2,0% Skonto.
-
- 14
- 2.00
-
-
-
- 457.20
- 3.00
- 11.21
- 448.99
- 70.00
- 518.99
- 0.00
- 518.99
-
-
-
-
-
- Wichtige Information: Bei Bestellungen bis zum 19.12. ist die Auslieferung bis spätestens 23.12. garantiert.
-
-
-
-
-
-
-
-
- 1.0000
-
-
- 1.0000
-
-
-
- 100.0000
- 4.0000
-
-
-
- VAT
- S
- 19.00
-
-
- 100.00
-
-
-
- 4123456000014
- ZS997
- Zitronensäure 100ml
-
- PACKAGING_TYPE
- Verpackungsart
- BO
-
-
-
-
-
-
-
- 1.5000
-
- false
- 2.00
- 1.5000
- 0.0300
- Artikelrabatt 1
-
-
- false
- 1
- 0.0200
- Artikelrabatt 2
-
-
-
- 1.4500
-
-
-
- 50.0000
- 1.0000
-
-
-
- VAT
- S
- 7.00
-
-
- 72.50
-
-
-
- 4123456000021
- GZ250
- Gelierzucker Extra 250g
-
-
-
-
-
-
- 0.0000
-
-
- 0.0000
-
-
-
- 10.0000
- 1.0000
-
-
-
- VAT
- S
- 7.00
-
-
- 0.00
-
-
-
- 4123456000021
- GZ250
- Gelierzucker Extra 250g
- Artikel wie vereinbart ohne Berechnung
-
-
-
-
-
- Öko-Kontroll-Nr.: DE-BW-006-987654321054
- AAY
-
-
-
-
- 12.0000
-
-
- 12.0000
-
-
-
- 15.0000
- 20.0000
-
-
-
- VAT
- S
- 19.00
-
-
- 180.00
-
-
-
- 4100130013294
- 2031
- K4321
- Bierbrau Pils 20/0500
- EAN-VKE: 4100130913297
-
- PACKAGING_MATERIAL
- Verpackung
- Kiste
-
-
-
-
-
-
-
- 3.1000
-
-
- 3.1000
-
-
-
- 15.0000
- 1.0000
-
-
-
- VAT
- S
- 19.00
-
-
- 46.50
-
-
-
- 2001015001325
- 1805
- K4322
- Leergutpfand 20 x 0,5l
-
- PACKAGING_MATERIAL
- Verpackung
- unverpackt
-
-
-
-
-
-
-
- 30.0000
-
- false
- 3.00
- 30.0000
- 0.9000
- Artikelrabatt 1
-
-
-
- 29.1000
-
-
-
- 2.0000
- 1.0000
-
-
-
- VAT
- S
- 7.00
-
-
- 58.20
-
-
-
- 4123456000038
- MP107
- Mischpalette Joghurt Karton 3 x 20
-
- PACKAGING_MATERIAL
- Verpackung
- Karton
-
-
- 4123456001035
- JOG103
- Erdbeer 20 x 150g Becher
- 20.0000
-
-
- 4123456002032
- JOG203
- Banane 20 x 150g Becher
- 20.0000
-
-
- 4123456003039
- JOG303
- Schoko 20 x 150g Becher
- 20.0000
-
-
-
-
-
+
+
+
+
+
+ true
+
+ urn:ferd:CrossIndustryDocument:invoice:1p0:extended
+
+
+
+ R87654321012345
+ WARENRECHNUNG
+ 380
+
+ 20130806
+
+
+ ST3
+ Es bestehen Rabatt- oder Bonusvereinbarungen.
+ AAK
+
+
+ EEV
+ Der Verkäufer bleibt Eigentümer der Waren bis zu vollständigen Erfüllung der Kaufpreisforderung.
+ AAJ
+
+
+ MUSTERLIEFERANT GMBH
+BAHNHOFSTRASSE 99
+99199 MUSTERHAUSEN
+Geschäftsführung:
+Max Mustermann
+USt-IdNr: DE123456789
+Telefon: +49 932 431 0
+www.musterlieferant.de
+HRB Nr. 372876
+Amtsgericht Musterstadt
+GLN 4304171000002
+WEEE-Reg-Nr.: DE87654321
+ REG
+
+
+ Leergutwert: 46,50
+
+
+
+
+
+ 549910
+ 4333741000005
+ MUSTERLIEFERANT GMBH
+
+
+ +49 932 431 500
+
+
+ max.mustermann@musterlieferant.de
+
+
+
+ 99199
+ BAHNHOFSTRASSE 99
+ MUSTERHAUSEN
+ DE
+
+
+ DE123456789
+
+
+
+ 009420
+ 4304171000002
+ MUSTER-KUNDE GMBH
+
+ 40235
+ KUNDENWEG 88
+ DUESSELDORF
+ DE
+
+
+
+ 2013-08-01T00:00:00
+ B123456789
+
+
+ 2013-08-02T00:00:00
+ VN
+ A456123
+
+
+
+
+ 4304171088093
+ MUSTER-MARKT
+
+ 8211
+
+
+ 31157
+ HAUPTSTRASSE 44
+ SARSTEDT
+ DE
+
+
+
+
+ 20130805
+
+
+
+ 2013-08-05T00:00:00
+ L87654321012345
+
+
+
+ EUR
+
+ 009420
+ 4304171000002
+ MUSTER-KUNDE GMBH
+
+ 40235
+ KUNDENWEG 88
+ DUESSELDORF
+ DE
+
+
+
+ 61.07
+ VAT
+ 321.40
+ 326.50
+ -5.10
+ S
+ 19.00
+
+
+ 8.93
+ VAT
+ 127.59
+ 130.70
+ -3.11
+ S
+ 7.00
+
+
+ false
+ 2.00
+ 280.00
+ 5.60
+ Rechnungsrabatt 1
+
+ VAT
+ S
+ 19.00
+
+
+
+ false
+ 2.00
+ 130.70
+ 2.61
+ Rechnungsrabatt 1
+
+ VAT
+ S
+ 7.00
+
+
+
+ false
+ 280.00
+ 2.50
+ Rechnungsrabatt 2
+
+ VAT
+ S
+ 19.00
+
+
+
+ false
+ 130.70
+ 0.50
+ Rechnungsrabatt 2
+
+ VAT
+ S
+ 7.00
+
+
+
+ Transportkosten
+ 3.00
+
+ VAT
+ S
+ 19.00
+
+
+
+ Bei Zahlung innerhalb 14 Tagen gewähren wir 2,0% Skonto.
+
+ 14
+ 2.00
+
+
+
+ 457.20
+ 3.00
+ 11.21
+ 448.99
+ 70.00
+ 518.99
+ 0.00
+ 518.99
+
+
+
+
+
+ Wichtige Information: Bei Bestellungen bis zum 19.12. ist die Auslieferung bis spätestens 23.12. garantiert.
+
+
+
+
+
+
+
+
+ 1.0000
+
+
+ 1.0000
+
+
+
+ 100.0000
+ 4.0000
+
+
+
+ VAT
+ S
+ 19.00
+
+
+ 100.00
+
+
+
+ 4123456000014
+ ZS997
+ Zitronensäure 100ml
+
+ PACKAGING_TYPE
+ Verpackungsart
+ BO
+
+
+
+
+
+
+
+ 1.5000
+
+ false
+ 2.00
+ 1.5000
+ 0.0300
+ Artikelrabatt 1
+
+
+ false
+ 1
+ 0.0200
+ Artikelrabatt 2
+
+
+
+ 1.4500
+
+
+
+ 50.0000
+ 1.0000
+
+
+
+ VAT
+ S
+ 7.00
+
+
+ 72.50
+
+
+
+ 4123456000021
+ GZ250
+ Gelierzucker Extra 250g
+
+
+
+
+
+
+ 0.0000
+
+
+ 0.0000
+
+
+
+ 10.0000
+ 1.0000
+
+
+
+ VAT
+ S
+ 7.00
+
+
+ 0.00
+
+
+
+ 4123456000021
+ GZ250
+ Gelierzucker Extra 250g
+ Artikel wie vereinbart ohne Berechnung
+
+
+
+
+
+ Öko-Kontroll-Nr.: DE-BW-006-987654321054
+ AAY
+
+
+
+
+ 12.0000
+
+
+ 12.0000
+
+
+
+ 15.0000
+ 20.0000
+
+
+
+ VAT
+ S
+ 19.00
+
+
+ 180.00
+
+
+
+ 4100130013294
+ 2031
+ K4321
+ Bierbrau Pils 20/0500
+ EAN-VKE: 4100130913297
+
+ PACKAGING_MATERIAL
+ Verpackung
+ Kiste
+
+
+
+
+
+
+
+ 3.1000
+
+
+ 3.1000
+
+
+
+ 15.0000
+ 1.0000
+
+
+
+ VAT
+ S
+ 19.00
+
+
+ 46.50
+
+
+
+ 2001015001325
+ 1805
+ K4322
+ Leergutpfand 20 x 0,5l
+
+ PACKAGING_MATERIAL
+ Verpackung
+ unverpackt
+
+
+
+
+
+
+
+ 30.0000
+
+ false
+ 3.00
+ 30.0000
+ 0.9000
+ Artikelrabatt 1
+
+
+
+ 29.1000
+
+
+
+ 2.0000
+ 1.0000
+
+
+
+ VAT
+ S
+ 7.00
+
+
+ 58.20
+
+
+
+ 4123456000038
+ MP107
+ Mischpalette Joghurt Karton 3 x 20
+
+ PACKAGING_MATERIAL
+ Verpackung
+ Karton
+
+
+ 4123456001035
+ JOG103
+ Erdbeer 20 x 150g Becher
+ 20.0000
+
+
+ 4123456002032
+ JOG203
+ Banane 20 x 150g Becher
+ 20.0000
+
+
+ 4123456003039
+ JOG303
+ Schoko 20 x 150g Becher
+ 20.0000
+
+
+
+
+
diff --git a/src/main/java-templates/org/mustangproject/ZUGFeRD/Version.java b/src/main/java-templates/org/mustangproject/ZUGFeRD/Version.java
deleted file mode 100644
index f669dfe4..00000000
--- a/src/main/java-templates/org/mustangproject/ZUGFeRD/Version.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public final class Version {
- public static final String VERSION = "${project.version}";
-}
diff --git a/src/main/java/org/mustangproject/XMLTools.java b/src/main/java/org/mustangproject/XMLTools.java
deleted file mode 100644
index 4c2877b3..00000000
--- a/src/main/java/org/mustangproject/XMLTools.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.mustangproject;
-
-public class XMLTools {
- public static String encodeXML(CharSequence s) {
- StringBuilder sb = new StringBuilder();
- int len = s.length();
- for (int i=0;i= 0xd800 && c <= 0xdbff && i + 1 < len) {
- c = ((c-0xd7c0)<<10) | (s.charAt(++i)&0x3ff); // UTF16 decode
- }
- if (c < 0x80) { // ASCII range: test most common case first
- if (c < 0x20 && (c != '\t' && c != '\r' && c != '\n')) {
- // Illegal XML character, even encoded. Skip or substitute
- sb.append("�"); // Unicode replacement character
- } else {
- switch(c) {
- case '&': sb.append("&"); break;
- case '>': sb.append(">"); break;
- case '<': sb.append("<"); break;
- // Uncomment next two if encoding for an XML attribute
-// case '\'' sb.append("'"); break;
-// case '\"' sb.append("""); break;
- // Uncomment next three if you prefer, but not required
-// case '\n' sb.append("
"); break;
-// case '\r' sb.append("
"); break;
-// case '\t' sb.append(" "); break;
-
- default: sb.append((char)c);
- }
- }
- } else if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) {
- // Illegal XML character, even encoded. Skip or substitute
- sb.append("�"); // Unicode replacement character
- } else {
- sb.append("");
- sb.append(Integer.toHexString(c));
- sb.append(';');
- }
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/CustomXMLProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/CustomXMLProvider.java
deleted file mode 100644
index 0b03bd69..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/CustomXMLProvider.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public class CustomXMLProvider implements IXMLProvider, IProfileProvider {
-
- protected byte[] zugferdData;
-
- @Override
- public byte[] getXML() {
- return zugferdData;
- }
-
- public void setXML(byte[] newData) {
- String zf = new String(newData);
- if (!zf.contains("CrossIndustry")) {
- throw new RuntimeException("ZUGFeRD XML does not contain (
- * Lieferant GmbH Lieferantenstraße 20 80333 München Deutschland Geschäftsführer: Hans Muster Handelsregisternummer: H A 123
- *
- * @return null or full sender institution name, details, manager and tax registration
- */
- default String getOwnOrganisationFullPlaintextInfo() {
- return null;
- }
-
-
- /**
- * when the invoice is to be paid
- *
- * @return when the invoice is to be paid
- */
- default Date getDueDate() {
- return null;
- }
-
-
- /**
- * who processed the order
- *
- * @return the contact person at the supplier side
- */
- default IZUGFeRDExportableContact getOwnContact() {
- return null;
- }
-
-
- IZUGFeRDAllowanceCharge[] getZFAllowances();
-
-
- IZUGFeRDAllowanceCharge[] getZFCharges();
-
-
- IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges();
-
-
- IZUGFeRDExportableItem[] getZFItems();
-
-
- /**
- * the recipient
- *
- * @return the recipient of the invoice
- */
- IZUGFeRDExportableContact getRecipient();
-
-
- /**
- * the creditors payment informations
- * @deprecated use getTradeSettlement
- * @return an array of IZUGFeRDTradeSettlementPayment
- */
- @Deprecated
- default IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() {
- return null;
- }
- /**
- * the payment information for any payment means
- *
- * @return an array of IZUGFeRDTradeSettlement
- */
- default IZUGFeRDTradeSettlement[] getTradeSettlement() {
- return null;
- }
-
-
- /**
- * Tax ID (not VAT ID) of the sender
- *
- * @return Tax ID (not VAT ID) of the sender
- */
- default String getOwnTaxID() {
- return null;
- }
-
-
- /**
- * VAT ID (Umsatzsteueridentifikationsnummer) of the sender
- *
- * @return VAT ID (Umsatzsteueridentifikationsnummer) of the sender
- */
- default String getOwnVATID() {
- return null;
- }
-
-
- /**
- * supplier identification assigned by the costumer
- *
- * @return the sender's identification
- */
- default String getOwnForeignOrganisationID() {
- return null;
- }
-
-
- /**
- * own name
- *
- * @return the sender's organisation name
- */
- default String getOwnOrganisationName() {
- return null;
- }
-
-
- /**
- * own street address
- *
- * @return sender street address
- */
- default String getOwnStreet() {
- return null;
- }
-
-
- /**
- * own street postal code
- *
- * @return sender postal code
- */
- default String getOwnZIP() {
- return null;
- }
-
-
- /**
- * own city
- *
- * @return the invoice sender's city
- */
- default String getOwnLocation() {
- return null;
- }
-
-
- /**
- * own two digit country code
- *
- * @return the invoice senders two character country iso code
- */
- default String getOwnCountry() {
- return null;
- }
-
-
- /**
- * get delivery date
- *
- * @return the day the goods have been delivered
- */
- Date getDeliveryDate();
-
- /**
- * get delivery date in more specific form. If this and getDeliveryDate() are
- * specified, this value will be taken
- *
- * @return instance holding date and format
- */
- default IZUGFeRDDate getZFDeliveryDate() {
- return null;
- }
-
-
- /**
- * get main invoice currency used on the invoice
- *
- * @return three character currency of this invoice
- */
- default String getCurrency() {
- return null;
- }
-
-
- /**
- * get payment term descriptional text e.g. Bis zum 22.10.2015 ohne Abzug
- *
- * @return get payment terms
- */
- default String getPaymentTermDescription() {
- return null;
- }
-
- /**
- * get payment terms. if set, getPaymentTermDescription() and getDueDate() are
- * ignored
- *
- * @return
- */
- default IZUGFeRDPaymentTerms getPaymentTerms() {
- return null;
- }
-
-
- /**
- * get reference document number typically used for Invoice Corrections Will be added as IncludedNote in comfort profile
- *
- * @return the ID of the document this document refers to
- */
- default String getReferenceNumber() {
- return null;
- }
-
-
- /**
- * consignee identification (identification of the organisation the goods are shipped to [assigned by the costumer])
- *
- * @return the sender's identification
- */
- default String getShipToOrganisationID() {
- return null;
- }
-
-
- /**
- * consignee name (name of the organisation the goods are shipped to)
- *
- * @return the consignee's organisation name
- */
- default String getShipToOrganisationName() {
- return null;
- }
-
-
- /**
- * consignee street address (street of the organisation the goods are shipped to)
- *
- * @return consignee street address
- */
- default String getShipToStreet() {
- return null;
- }
-
-
- /**
- * consignee street postal code (postal code of the organisation the goods are shipped to)
- *
- * @return consignee postal code
- */
- default String getShipToZIP() {
- return null;
- }
-
-
- /**
- * consignee city (city of the organisation the goods are shipped to)
- *
- * @return the consignee's city
- */
- default String getShipToLocation() {
- return null;
- }
-
-
- /**
- * consignee two digit country code (country code of the organisation the goods are shipped to)
- *
- * @return the consignee's two character country iso code
- */
- default String getShipToCountry() {
- return null;
- }
-
-
- /**
- * get the ID of the BuyerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement
- *
- * @return the ID of the document
- */
- default String getBuyerOrderReferencedDocumentID() {
- return null;
- }
-
-
- /**
- * get the issue timestamp of the BuyerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement
- *
- * @return the IssueDateTime in format CCYY-MM-DDTHH:MM:SS
- */
- default String getBuyerOrderReferencedDocumentIssueDateTime() {
- return null;
- }
-
-
- /**
- * get the TotalPrepaidAmount located in SpecifiedTradeSettlementMonetarySummation (v1) or SpecifiedTradeSettlementHeaderMonetarySummation (v2)
- *
- * @return the total sum (incl. VAT) of prepayments, i.e. the difference between GrandTotalAmount and DuePayableAmount
- */
- default BigDecimal getTotalPrepaidAmount() {
- return BigDecimal.ZERO;
- }
-
-
- /***
- * delivery address, i.e. ram:ShipToTradeParty (only supported for zf2)
- * @return
- */
-
- default IZUGFeRDExportableContact getDeliveryAddress() {
- return null;
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDPaymentDiscountTerms.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDPaymentDiscountTerms.java
deleted file mode 100644
index ebb6bee0..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDPaymentDiscountTerms.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.mustangproject.ZUGFeRD;
-
-import java.math.BigDecimal;
-
-public interface IZUGFeRDPaymentDiscountTerms {
-
- BigDecimal getCalculationPercentage();
-
- IZUGFeRDDate getBaseDate();
-
- int getBasePeriodMeasure();
-
- String getBasePeriodUnitCode();
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDPaymentTerms.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDPaymentTerms.java
deleted file mode 100644
index f49215bc..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDPaymentTerms.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.mustangproject.ZUGFeRD;
-
-public interface IZUGFeRDPaymentTerms {
-
- String getDescription();
-
- IZUGFeRDDate getDueDate();
-
- IZUGFeRDPaymentDiscountTerms getDiscountTerms();
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlement.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlement.java
deleted file mode 100644
index 7e92b204..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlement.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2019 by ak on 12.04.19.
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public interface IZUGFeRDTradeSettlement {
-
- /***
- *
- * @return zf2 xml for applicableHeaderTradeSettlement
- */
- String getSettlementXML();
-
-
- /***
- *
- * @return zf2 xml for applicableHeaderTradePayment
- */
- default String getPaymentXML() {
- return null;
- }
-
-
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementDebit.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementDebit.java
deleted file mode 100644
index 457c2a3d..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementDebit.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2019 by ak on 12.04.19.
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import org.mustangproject.XMLTools;
-
-public interface IZUGFeRDTradeSettlementDebit extends IZUGFeRDTradeSettlement {
-
-
-
- default String getSettlementXML() {
-
-
-
- String xml = " \n" //$NON-NLS-1$
- + " 59\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " "+XMLTools.encodeXML(getIBAN())+"\n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
-
- xml = xml + " \n"; //$NON-NLS-1$
- return xml;
- }
-
- default String getPaymentXML() {
- return ""+XMLTools.encodeXML(getMandate())+"";
- }
-
-
- /***
- * @return IBAN of the debtor (optional)
- */
- String getIBAN();
-
-
- /***
- * @return sepa direct debit mandate reference
- */
- String getMandate();
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java
deleted file mode 100644
index f4ecaf4d..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2019 by ak on 12.04.19.
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import java.text.SimpleDateFormat;
-
-import org.mustangproject.XMLTools;
-
-public interface IZUGFeRDTradeSettlementPayment extends IZUGFeRDTradeSettlement {
-
- /**
- * get payment information text. e.g. Bank transfer
- *
- * @return payment information text
- */
- default String getOwnPaymentInfoText() {
- return null;
- }
-
- /**
- * BIC of the sender
- *
- * @return the BIC code of the recipient sender's bank
- */
- default String getOwnBIC() {
- return null;
- }
-
-
- /**
- * BLZ of the sender
- *
- * @return the BLZ code of the recipient sender's bank
- */
- default String getOwnBLZ() {
- return null;
- }
-
-
- /**
- * Bank name of the sender
- *
- * @return the name of the sender's bank
- */
- default String getOwnBankName() {
- return null;
- }
-
-
- /**
- * IBAN of the sender
- *
- * @return the IBAN of the invoice sender's bank account
- */
- default String getOwnIBAN() {
- return null;
- }
-
-
- /**
- * IBAN of the sender
- *
- * @return the Account Number of the invoice sender's bank account
- */
- default String getOwnKto() {
- return null;
- }
-
- default String getSettlementXML() {
- String xml = " \n" //$NON-NLS-1$
- + " 42\n" //$NON-NLS-1$
- + " Überweisung\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(getOwnIBAN()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
- if (getOwnKto()!=null) {
- xml+= " " + XMLTools.encodeXML(getOwnKto()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
-
- }
- xml+= " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(getOwnBIC()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // + " "+trans.getOwnBankName()+"\n" //$NON-NLS-1$
- // //$NON-NLS-2$
- + " \n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
- return xml;
- }
-
-
- /* I'd love to implement getPaymentXML() and put there because this is where it belongs
- * unfortunately, the due date is part of the transaction which is not accessible here :-(
- */
-
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/PDFAConformanceLevel.java b/src/main/java/org/mustangproject/ZUGFeRD/PDFAConformanceLevel.java
deleted file mode 100644
index 47cfaeb6..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/PDFAConformanceLevel.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public enum PDFAConformanceLevel {
- ACCESSIBLE("A"), BASIC("B"), UNICODE("U");
-
- private final String letter;
-
- PDFAConformanceLevel(String letter) {
- this.letter = letter;
- }
-
- public String getLetter() {
- return letter;
- }
-
- public static PDFAConformanceLevel findByLetter(String letter) {
- for (PDFAConformanceLevel candidate : values()) {
- if (candidate.letter.equals(letter)) {
- return candidate;
- }
- }
- throw new IllegalArgumentException("PDF conformance level <" + letter + "> is unknown.");
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java b/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java
deleted file mode 100644
index 3ba0acc1..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import java.math.BigDecimal;
-
-/**
- * Mustangproject's ZUGFeRD implementation
- * ZUGFeRD exporter helper class
- * Licensed under the APLv2
- *
- * @author jstaerk
- * @version 1.2.0
- * dated 2015-10-29
- */
-public class VATAmount {
-
- public VATAmount(BigDecimal basis, BigDecimal calculated, String categoryCode) {
- super();
- this.basis = basis;
- this.calculated = calculated;
- this.categoryCode = categoryCode;
- }
-
- BigDecimal basis, calculated;
-
- String categoryCode;
-
- public BigDecimal getBasis() {
- return basis;
- }
-
- public void setBasis(BigDecimal basis) {
- this.basis = basis;
- }
-
- public BigDecimal getCalculated() {
- return calculated;
- }
-
- public void setCalculated(BigDecimal calculated) {
- this.calculated = calculated;
- }
-
- /**
- *
- * @deprecated Use {@link #getCategoryCode() instead}
- * @return String with category code
- */
- @Deprecated
- public String getDocumentCode() {
- return categoryCode;
- }
-
- /**
- * @param documentCode as String
- * @deprecated Use {@link #setCategoryCode(String)} instead
- */
- @Deprecated
- public void setDocumentCode(String documentCode) {
- this.categoryCode = documentCode;
- }
-
- public String getCategoryCode() {
- return categoryCode;
- }
-
- public void setCategoryCode(String categoryCode) {
- this.categoryCode = categoryCode;
- }
-
- public VATAmount add(VATAmount v) {
- return new VATAmount(basis.add(v.getBasis()), calculated.add(v.getCalculated()), this.categoryCode);
- }
-
- public VATAmount subtract(VATAmount v) {
- return new VATAmount(basis.subtract(v.getBasis()), calculated.subtract(v.getCalculated()), this.categoryCode);
- }
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaPDFAExtensions.java b/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaPDFAExtensions.java
deleted file mode 100644
index 3e0dca57..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaPDFAExtensions.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-/**
- * Mustangproject's ZUGFeRD implementation
- * ZUGFeRD exporter helper class
- * Licensed under the APLv2
- * @date 2014-05-10
- * @version 1.2.0
- * @author jstaerk
- * */
-
-import org.apache.xmpbox.XMPMetadata;
-import org.apache.xmpbox.XmpConstants;
-import org.apache.xmpbox.schema.PDFAExtensionSchema;
-import org.apache.xmpbox.type.*;
-
-/**
- * Additionally to adding a RDF namespace with a indication which file
- * attachment if Zugferd, this namespace has to be described in a PDFA Extension
- * Schema. I know there is a PDFAExtensionSchema in the context of PDFBox'
- * XMPBOX but I have been using PDFBox' JempBOX so far because I could not find
- * out how to write XMPBOX XMPMetadata to a PDF file. So this is my version of
- * PDFAExtensionSchema for PDFBox' jempbox XMPMetadata
- *
- * @author jstaerk
- */
-
-@StructuredType(preferedPrefix = "pdfaExtension", namespace = "http://www.aiim.org/pdfa/ns/extension/")
-public class XMPSchemaPDFAExtensions extends PDFAExtensionSchema {
-
- public final String xmlns_pdfaSchema = "http://www.aiim.org/pdfa/ns/schema#";
- public final String prefix_pdfaSchema = "pdfaSchema";
- public final String xmlns_pdfaProperty = "http://www.aiim.org/pdfa/ns/property#";
- public final String prefix_pdfaProperty = "pdfaProperty";
- public String namespace = null;
- public String prefix = null;
-
- protected ZUGFeRDExporter exporter;
-
-
- protected void setZUGFeRDVersion(int ver) {
- namespace = exporter.getNamespaceForVersion(ver);
- prefix = exporter.getPrefixForVersion(ver);
- }
-
-
- private DefinedStructuredType addProperty(ArrayProperty parent, String name, String type, String category,
- String description) {
- XMPMetadata metadata = getMetadata();
-
- DefinedStructuredType li = new DefinedStructuredType(metadata, getNamespace(), getPrefix(),
- XmpConstants.LIST_NAME);
- li.setAttribute(new Attribute(getNamespace(), XmpConstants.PARSE_TYPE, XmpConstants.RESOURCE_NAME));
-
- ChoiceType pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.NAME,
- name);
- li.addProperty(pdfa2);
-
- pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.VALUETYPE, type);
- li.addProperty(pdfa2);
-
- pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.CATEGORY, category);
- li.addProperty(pdfa2);
-
- pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.DESCRIPTION,
- description);
- li.addProperty(pdfa2);
-
- parent.addProperty(li);
-
- return li;
- }
-
- public XMPSchemaPDFAExtensions(ZUGFeRDExporter ze, XMPMetadata metadata, int ZFVersion) {
- super(metadata);
- exporter=ze;
- setZUGFeRDVersion(ZFVersion);
- attachExtensions(metadata, true);
- }
-
- public XMPSchemaPDFAExtensions(ZUGFeRDExporter ze, XMPMetadata metadata, int ZFVersion, boolean withZF) {
- super(metadata);
- exporter=ze;
- setZUGFeRDVersion(ZFVersion);
- attachExtensions(metadata, withZF);
- }
-
- public void attachExtensions(XMPMetadata metadata, boolean withZF) {
-
- addNamespace(xmlns_pdfaSchema, prefix_pdfaSchema);
- addNamespace(xmlns_pdfaProperty, prefix_pdfaProperty);
-
- ArrayProperty newBag = createArrayProperty(SCHEMAS, Cardinality.Bag);
- DefinedStructuredType li = new DefinedStructuredType(metadata, getNamespace(), getPrefix(),
- XmpConstants.LIST_NAME);
- li.setAttribute(new Attribute(getNamespace(), XmpConstants.PARSE_TYPE, XmpConstants.RESOURCE_NAME));
- newBag.addProperty(li);
- addProperty(newBag);
- if (withZF) {
- TextType pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.SCHEMA,
- "ZUGFeRD PDFA Extension Schema");
- li.addProperty(pdfa1);
-
- pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.NAMESPACE_URI,
- namespace);
- li.addProperty(pdfa1);
-
- pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.PREFIX, prefix);
- li.addProperty(pdfa1);
-
- ArrayProperty newSeq = new ArrayProperty(metadata, xmlns_pdfaSchema, prefix_pdfaSchema,
- PDFASchemaType.PROPERTY, Cardinality.Seq);
- li.addProperty(newSeq);
-
- addProperty(newSeq, "DocumentFileName", "Text", "external", "name of the embedded XML invoice file");
- addProperty(newSeq, "DocumentType", "Text", "external", "INVOICE");
- addProperty(newSeq, "Version", "Text", "external", "The actual version of the ZUGFeRD XML schema");
- addProperty(newSeq, "ConformanceLevel", "Text", "external",
- "The selected ZUGFeRD profile completeness");
- }
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java b/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java
deleted file mode 100644
index 04d19c21..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/XMPSchemaZugferd.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-/**
- * Mustangproject's ZUGFeRD implementation
- * ZUGFeRD exporter helper class
- * Licensed under the APLv2
- * @date 2014-05-10
- * @version 1.2.0s
- * @author jstaerk
- * */
-
-import org.apache.xmpbox.XMPMetadata;
-import org.apache.xmpbox.schema.XMPSchema;
-
-public class XMPSchemaZugferd extends XMPSchema {
-
- /***
- * This is what needs to be added to the RDF metadata - basically the name of the embedded Zugferd file
- * @param metadata the xmp to be added to
- * @param zfVersion which ZF version to use (2 for FX)
- * @param isFacturX whether to export as Factur-X
- * @param conformanceLevel e.g. conformanceLevel.EN16931
- * @param URN the xml URI for the XMP
- * @param prefix the xml namespace prefix for the XMP, zf for ZUGFeRD, fx for Factur-X
- * @param filename the filename of the invoice
- */
- public XMPSchemaZugferd(XMPMetadata metadata, int zfVersion, boolean isFacturX, ZUGFeRDConformanceLevel conformanceLevel, String URN, String prefix, String filename) {
- super(metadata, URN, prefix, "ZUGFeRD Schema");
-
- setAboutAsSimple("");
-
- String conformanceLevelValue = conformanceLevel.name();
- if (conformanceLevelValue.equals("BASICWL")) {
- conformanceLevelValue = "BASIC WL";
- } else if (conformanceLevelValue.equals("EN16931")) {
- conformanceLevelValue = "EN 16931";
- }
- setTextPropertyValue("ConformanceLevel", conformanceLevelValue);
- setTextPropertyValue("DocumentType", "INVOICE");
- setTextPropertyValue("DocumentFileName", filename);
- String version="1.0";
- if ((zfVersion==2)&&(!isFacturX)) {
- version="2p0";
- }
- setTextPropertyValue("Version", version);
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD1PullProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD1PullProvider.java
deleted file mode 100644
index f8278a32..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD1PullProvider.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
-import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants;
-import org.mustangproject.ZUGFeRD.model.ZFNamespacePrefixMapper;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import java.io.ByteArrayOutputStream;
-
-public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
-
-
- protected byte[] zugferdData;
- private Marshaller marshaller;
-
- private boolean isTest;
- private ZUGFeRDConformanceLevel level;
-
-
- public void setProfile(ZUGFeRDConformanceLevel level) {
- this.level = level;
- }
-
- public String getProfile() {
- switch (level) {
- case BASIC: return DocumentContextParameterTypeConstants.BASIC;
- case COMFORT: return DocumentContextParameterTypeConstants.COMFORT;
- default: return DocumentContextParameterTypeConstants.EXTENDED;
- }
- }
-
-
- /**
- * enables the flag to indicate a test invoice in the XML structure
- */
- public void setTest() {
- isTest = true;
- }
-
- public ZUGFeRD1PullProvider() {
- // TODO Auto-generated constructor stub
- try {
- marshaller = JAXBContext.newInstance("org.mustangproject.ZUGFeRD.model").createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new ZFNamespacePrefixMapper());
- } catch (JAXBException e) {
- throw new ZUGFeRDExportException("Could not initialize JAXB", e);
- }
-
- }
-
- private String createZugferdXMLForTransaction(IZUGFeRDExportableTransaction trans) {
-
- JAXBElement jaxElement =
- new ZUGFeRDTransactionModelConverter(trans).withTest(isTest).withProfile(getProfile()).convertToModel();
-
- try {
- return marshalJaxToXMLString(jaxElement);
- } catch (JAXBException e) {
- throw new ZUGFeRDExportException("Could not marshal ZUGFeRD transaction to XML", e);
- }
- }
-
- private String marshalJaxToXMLString(Object jaxElement) throws JAXBException {
- ByteArrayOutputStream outputXml = new ByteArrayOutputStream();
- marshaller.marshal(jaxElement, outputXml);
- return outputXml.toString();
- }
-
-
- @Override
- public byte[] getXML() {
- return zugferdData;
- }
-
-
- @Override
- public void generateXML(IZUGFeRDExportableTransaction trans) {
- // create a dummy file stream, this would probably normally be a
- // FileInputStream
-
- byte[] zugferdRaw = createZugferdXMLForTransaction(trans).getBytes(); //$NON-NLS-1$
-
- if ((zugferdRaw[0] == (byte) 0xEF)
- && (zugferdRaw[1] == (byte) 0xBB)
- && (zugferdRaw[2] == (byte) 0xBF)) {
- // I don't like BOMs, lets remove it
- zugferdData = new byte[zugferdRaw.length - 3];
- System.arraycopy(zugferdRaw, 3, zugferdData, 0,
- zugferdRaw.length - 3);
- } else {
- zugferdData = zugferdRaw;
- }
- }
-
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java
deleted file mode 100644
index ebfb6135..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java
+++ /dev/null
@@ -1,624 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.DocumentHelper;
-import org.dom4j.io.OutputFormat;
-import org.dom4j.io.XMLWriter;
-import org.mustangproject.XMLTools;
-import org.mustangproject.toecount.Toecount;
-
-public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
-
- private class LineCalc {
- private BigDecimal totalGross;
- private BigDecimal priceGross;
- private BigDecimal itemTotalNetAmount;
- private BigDecimal itemTotalVATAmount;
-
- public LineCalc(IZUGFeRDExportableItem currentItem) {
- BigDecimal multiplicator = currentItem.getProduct().getVATPercent().divide(new BigDecimal(100))
- .add(new BigDecimal(1));
- priceGross = currentItem.getPrice().multiply(multiplicator);
- totalGross = currentItem.getPrice().multiply(multiplicator).multiply(currentItem.getQuantity());
- itemTotalNetAmount = currentItem.getQuantity().multiply(currentItem.getPrice()).setScale(2,
- BigDecimal.ROUND_HALF_UP);
- itemTotalVATAmount = totalGross.subtract(itemTotalNetAmount);
- }
-
- public BigDecimal getItemTotalNetAmount() {
- return itemTotalNetAmount;
- }
-
- public BigDecimal getItemTotalVATAmount() {
- return itemTotalVATAmount;
- }
-
- public BigDecimal getItemTotalGrossAmount() {
- return itemTotalVATAmount;
- }
-
- public BigDecimal getPriceGross() {
- return priceGross;
- }
-
- }
-
- //// MAIN CLASS
-
- protected byte[] zugferdData;
- private IZUGFeRDExportableTransaction trans;
- private ZUGFeRDConformanceLevel level;
- private String paymentTermsDescription;
-
- @Override
- public void setProfile(ZUGFeRDConformanceLevel level) {
- this.level = level;
- }
-
- /**
- * enables the flag to indicate a test invoice in the XML structure
- */
- @Override
- public void setTest() {
- }
-
- public static String nDigitFormat(BigDecimal value, int scale) {
- /*
- * I needed 123,45, locale independent.I tried
- * NumberFormat.getCurrencyInstance().format( 12345.6789 ); but that is locale
- * specific.I also tried DecimalFormat df = new DecimalFormat( "0,00" );
- * df.setDecimalSeparatorAlwaysShown(true); df.setGroupingUsed(false);
- * DecimalFormatSymbols symbols = new DecimalFormatSymbols();
- * symbols.setDecimalSeparator(','); symbols.setGroupingSeparator(' ');
- * df.setDecimalFormatSymbols(symbols);
- *
- * but that would not switch off grouping. Although I liked very much the
- * (incomplete) "BNF diagram" in
- * http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html in the
- * end I decided to calculate myself and take eur+sparator+cents
- *
- */
- return value.setScale(scale, RoundingMode.HALF_UP).toPlainString();
-
- }
-
- private String vatFormat(BigDecimal value) {
- return ZUGFeRD2PullProvider.nDigitFormat(value, 2);
- }
-
- private String currencyFormat(BigDecimal value) {
- return ZUGFeRD2PullProvider.nDigitFormat(value, 2);
- }
-
- private String priceFormat(BigDecimal value) {
- return ZUGFeRD2PullProvider.nDigitFormat(value, 4);
- }
-
- private String quantityFormat(BigDecimal value) {
- return ZUGFeRD2PullProvider.nDigitFormat(value, 4);
- }
-
- @Override
- public byte[] getXML() {
-
- byte[] res = zugferdData;
-
- StringWriter sw = new StringWriter();
- Document document = null;
- try {
- document = DocumentHelper.parseText(new String(zugferdData));
- } catch (DocumentException e1) {
- Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e1);
- }
- try {
- OutputFormat format = OutputFormat.createPrettyPrint();
- XMLWriter writer = new XMLWriter(sw, format);
- writer.write(document);
- res = sw.toString().getBytes("UTF-8");
-
- } catch (IOException e) {
- Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
- }
-
- return res;
-
- }
-
- private BigDecimal getTotalPrepaid() {
- if (trans.getTotalPrepaidAmount() == null) {
- return new BigDecimal(0);
- } else {
- return trans.getTotalPrepaidAmount();
- }
- }
-
- private BigDecimal getTotalGross() {
-
- BigDecimal res = getTotal();
- HashMap VATPercentAmountMap = getVATPercentAmountMap();
- for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
- VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
- res = res.add(amount.getCalculated());
- }
- return res;
- }
-
- private BigDecimal getTotal() {
- BigDecimal res = new BigDecimal(0);
- for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
- LineCalc lc = new LineCalc(currentItem);
- res = res.add(lc.getItemTotalNetAmount());
- }
- return res;
- }
-
- /**
- * which taxes have been used with which amounts in this transaction, empty for
- * no taxes, or e.g. 19=>190 and 7=>14 if 1000 Eur were applicable to 19% VAT
- * (=>190 EUR VAT) and 200 EUR were applicable to 7% (=>14 EUR VAT) 190 Eur
- *
- * @return which taxes have been used with which amounts in this invoice
- */
- private HashMap getVATPercentAmountMap() {
- HashMap hm = new HashMap<>();
-
- for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
- BigDecimal percent = currentItem.getProduct().getVATPercent();
- LineCalc lc = new LineCalc(currentItem);
- VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(),
- trans.getDocumentCode());
- VATAmount current = hm.get(percent);
- if (current == null) {
- hm.put(percent, itemVATAmount);
- } else {
- hm.put(percent, current.add(itemVATAmount));
- }
- }
- return hm;
- }
-
- @Override
- public String getProfile() {
-// return "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_1.2";
- return "urn:cen.eu:en16931:2017";
- }
-
- protected String getContactAsXML(IZUGFeRDExportableContact contact) {
- String xml = " " + XMLTools.encodeXML(contact.getName()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // + " \n"
- // + " xxx\n"
- // + " \n"
- + " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(contact.getZIP()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(contact.getStreet()) //$NON-NLS-1$
- + "\n"; //$NON-NLS-1$
- if (trans.getRecipient().getAdditionalAddress() != null) {
- xml += " " + XMLTools.encodeXML(contact.getAdditionalAddress()) //$NON-NLS-1$
- + "\n"; //$NON-NLS-1$
- }
- xml += " " + XMLTools.encodeXML(contact.getLocation()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(contact.getCountry()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
- if (contact.getVATID() != null) {
- xml += " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(contact.getVATID()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
- }
- return xml;
-
- }
-
- @Override
- public void generateXML(IZUGFeRDExportableTransaction trans) {
- this.trans = trans;
-
- boolean hasDueDate=false;
- String taxCategoryCode="";
- SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$
- SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd"); //$NON-NLS-1$
- String exemptionReason="";
-
- if (paymentTermsDescription==null) {
- paymentTermsDescription= "Zahlbar ohne Abzug bis " + germanDateFormat.format(trans.getDueDate());
-
- }
- if (trans.getPaymentTermDescription()!=null) {
- paymentTermsDescription=trans.getPaymentTermDescription();
- }
-
- String senderReg = "";
- if (trans.getOwnOrganisationFullPlaintextInfo() != null) {
- senderReg = "" + "\n" + " \n"
- + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + " \n"
- + "REG\n" + "\n";
-
- }
-
- String xml = "\n" //$NON-NLS-1$
-
- + "\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- // + "
- // "+testBooleanStr+"\n"
- // //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + getProfile() + "\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(trans.getNumber()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // + " RECHNUNG\n" //$NON-NLS-1$
- + " 380\n" //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + zugferdDateFormat.format(trans.getIssueDate()) + "\n" // date //$NON-NLS-1$
- // format
- // was
- // 20130605
- + senderReg
- // + " \n"
- // + " \n"
- // + "Rechnung gemäß Bestellung Nr. 2013-471331 vom 01.03.2013.\n"
- // + "\n"
- // + " \n"
- // + " \n"
- // + " \n"
- // + " \n"
- // + "Es bestehen Rabatt- und Bonusvereinbarungen.\n"
- // + " \n"
- // + " AAK\n"
- // + " \n"
- + " \n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
- int lineID = 0;
- for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
- lineID++;
- taxCategoryCode=currentItem.getProduct().getTaxCategoryCode();
- if (currentItem.getProduct().isIntraCommunitySupply()) {
- exemptionReason="Intra-community supply";
- }
-
- LineCalc lc = new LineCalc(currentItem);
- xml = xml + " \n" + //$NON-NLS-1$
- " \n" //$NON-NLS-1$
- + " " + lineID + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- // + " 4012345001235\n"
- // + " KR3M\n"
- // + " 55T01\n"
- + " " + XMLTools.encodeXML(currentItem.getProduct().getName()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- + " " + XMLTools.encodeXML(currentItem.getProduct().getDescription()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
-
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + priceFormat(lc.getPriceGross()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$ //currencyID=\"EUR\"
- + " 1.0000\n" //$NON-NLS-1$
- // + " \n"
- // + " false\n"
- // + " 0.6667\n"
- // + " Rabatt\n"
- // + " \n"
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + priceFormat(currentItem.getPrice()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$ // currencyID=\"EUR\"
- + " 1.0000\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
-
- + " \n" //$NON-NLS-1$
- + " " //$NON-NLS-1$ //$NON-NLS-2$
- + quantityFormat(currentItem.getQuantity()) + "\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " VAT\n" //$NON-NLS-1$
- + exemptionReason
- + " "+currentItem.getProduct().getTaxCategoryCode()+"\n" //$NON-NLS-1$
-
- + " " //$NON-NLS-1$
- + vatFormat(currentItem.getProduct().getVATPercent()) + "\n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + currencyFormat(lc.getItemTotalNetAmount()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$ // currencyID=\"EUR\"
- + " \n"; //$NON-NLS-1$
- if (currentItem.getAdditionalReferencedDocumentID()!=null) {
- xml=xml + " "+currentItem.getAdditionalReferencedDocumentID()+"130\n"; //$NON-NLS-1$
-
- }
- xml=xml + " \n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
-
- }
-
- xml = xml + " \n"; //$NON-NLS-1$
- if (trans.getReferenceNumber() != null) {
- xml = xml + " " + XMLTools.encodeXML(trans.getReferenceNumber()) + "\n";
-
- }
- xml = xml + " \n" //$NON-NLS-1$
- // + " 4000001123452\n"
- + " " + XMLTools.encodeXML(trans.getOwnOrganisationName()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
-
- if ((trans.getOwnVATID()!=null)&&(trans.getOwnOrganisationName()!=null)) {
-
- xml = xml + " \n" + " "
- + XMLTools.encodeXML(trans.getOwnVATID()) + "\n" + " "
- + XMLTools.encodeXML(trans.getOwnOrganisationName()) + "\n"
- + " ";
- }
-
- if (trans.getOwnContact() != null) {
- xml = xml + "\n" + " " + XMLTools.encodeXML(trans.getOwnContact().getName())
- + "\n";
- if (trans.getOwnContact().getPhone() != null) {
-
- xml = xml + " \n" + " "
- + XMLTools.encodeXML(trans.getOwnContact().getPhone()) + "\n"
- + " \n";
- }
- if (trans.getOwnContact().getEMail() != null) {
-
- xml = xml + " \n" + " "
- + XMLTools.encodeXML(trans.getOwnContact().getEMail()) + "\n"
- + " \n";
- }
- xml = xml + " ";
-
- }
-
- xml = xml + " \n" + " "
- + XMLTools.encodeXML(trans.getOwnZIP()) + "\n" + " "
- + XMLTools.encodeXML(trans.getOwnStreet()) + "\n" + " " + XMLTools.encodeXML(trans.getOwnLocation())
- + "\n" + " " + XMLTools.encodeXML(trans.getOwnCountry())
- + "\n" + " \n"
- + " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(trans.getOwnTaxID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " " + XMLTools.encodeXML(trans.getOwnVATID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- + " \n" //$NON-NLS-1$
- + " \n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
- // + " GE2020211\n"
- // + " 4000001987658\n"
-
- xml+=getContactAsXML(trans.getRecipient());
- xml += " \n" //$NON-NLS-1$
- // + " \n"
- // + " 20130301\n"
- // + " 2013-471331\n"
- // + " \n"
- + " \n" //$NON-NLS-1$
- + " \n" ;
- if (this.trans.getDeliveryAddress()!=null) {
- xml += ""+
- getContactAsXML(this.trans.getDeliveryAddress())+
- "";
- }
-
- xml+= " \n"
- + " ";
-
- if (trans.getZFDeliveryDate() != null) {
- ZUGFeRDDateFormat dateFormat = trans.getZFDeliveryDate().getFormat();
- Date date = trans.getZFDeliveryDate().getDate();
- xml += ""
- + dateFormat.getFormatter().format(date) + "";
- } else if (trans.getDeliveryDate() != null) {
- xml += "" + zugferdDateFormat.format(trans.getDeliveryDate())
- + "";
- } else {
- throw new IllegalStateException("No delivery date provided");
- }
- xml += "\n";
- xml += " \n"
- /*
- * + " \n" +
- * " 20130603\n" +
- * " 2013-51112\n" +
- * " \n"
- */
- + " \n" + " \n" //$NON-NLS-2$
- + " " + XMLTools.encodeXML(trans.getNumber()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- + " " + trans.getCurrency() + "\n"; //$NON-NLS-1$
-
- if (trans.getTradeSettlementPayment()!=null) {
- for (IZUGFeRDTradeSettlementPayment payment : trans.getTradeSettlementPayment()) {
- if(payment!=null) {
- hasDueDate=true;
- xml+=payment.getSettlementXML();
- }
- }
- }
- if (trans.getTradeSettlement()!=null) {
- for (IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) {
- if(payment!=null) {
- if (payment instanceof IZUGFeRDTradeSettlementPayment) {
- hasDueDate=true;
- }
- xml+=payment.getSettlementXML();
- }
- }
- }
-
- HashMap VATPercentAmountMap = getVATPercentAmountMap();
- for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
- VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
- if (amount != null) {
- xml += " \n" //$NON-NLS-1$
- + " " + currencyFormat(amount.getCalculated()) //$NON-NLS-1$
- + "\n" //$NON-NLS-1$ //currencyID=\"EUR\"
- + " VAT\n" //$NON-NLS-1$
- + exemptionReason
- + " " + currencyFormat(amount.getBasis()) + "\n" // currencyID=\"EUR\"
- + " "+taxCategoryCode+"\n" //$NON-NLS-1$
- + " " + vatFormat(currentTaxPercent) //$NON-NLS-1$
- + "\n" + " \n"; //$NON-NLS-2$
-
- }
- }
-
- if (trans.getPaymentTerms() == null) {
- xml = xml + " \n" //$NON-NLS-1$
- + " " + paymentTermsDescription + "\n";
-
- if (trans.getTradeSettlement() != null) {
- for (IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) {
- if (payment != null) {
- xml += payment.getPaymentXML();
- }
- }
- }
-
- if (hasDueDate) {
- xml = xml + " " // $NON-NLS-2$
- + zugferdDateFormat.format(trans.getDueDate())
- + "\n";// 20130704 //$NON-NLS-1$
-
- }
- xml = xml + " \n"; //$NON-NLS-1$
- } else {
- xml = xml + buildPaymentTermsXml();
- }
-
- xml = xml + " \n" //$NON-NLS-1$
- + " " + currencyFormat(getTotal()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // currencyID=\"EUR\"
- + " 0.00\n" //$NON-NLS-1$ currencyID=\"EUR\"
- + " 0.00\n" //$NON-NLS-1$ //
- // currencyID=\"EUR\"
- // + " 5.80\n"
- // + " 14.73\n"
- + " " + currencyFormat(getTotal()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // //
- // currencyID=\"EUR\"
- + " " //$NON-NLS-1$
- + currencyFormat(getTotalGross().subtract(getTotal())) + "\n" //$NON-NLS-1$
- + " " + currencyFormat(getTotalGross()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // //
- // currencyID=\"EUR\"
- + " " + currencyFormat(getTotalPrepaid()) + "\n"
- + " " + currencyFormat(getTotalGross().subtract(getTotalPrepaid())) + "\n" //$NON-NLS-1$ //$NON-NLS-2$
- // //
- // currencyID=\"EUR\"
- + " \n" //$NON-NLS-1$
- + " \n"; //$NON-NLS-1$
- // + " \n"
- // + " \n"
- // + " \n"
- // + " Wir erlauben uns Ihnen folgende Positionen aus der Lieferung Nr.
- // 2013-51112 in Rechnung zu stellen:\n"
- // + " \n"
- // + " \n"
- // + " \n";
-
- xml = xml + " \n" //$NON-NLS-1$
- + ""; //$NON-NLS-1$
-
- byte[] zugferdRaw;
- try {
- zugferdRaw = xml.getBytes("UTF-8");
-
- if ((zugferdRaw[0] == (byte) 0xEF) && (zugferdRaw[1] == (byte) 0xBB) && (zugferdRaw[2] == (byte) 0xBF)) {
- // I don't like BOMs, lets remove it
- zugferdData = new byte[zugferdRaw.length - 3];
- System.arraycopy(zugferdRaw, 3, zugferdData, 0, zugferdRaw.length - 3);
- } else {
- zugferdData = zugferdRaw;
- }
- } catch (UnsupportedEncodingException e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
- } // $NON-NLS-1$
- }
-
- private String buildPaymentTermsXml() {
- String paymentTermsXml = "";
-
- IZUGFeRDPaymentTerms paymentTerms = trans.getPaymentTerms();
- IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
- IZUGFeRDDate dueDate = paymentTerms.getDueDate();
- if (dueDate != null && discountTerms != null && discountTerms.getBaseDate() != null) {
- throw new IllegalStateException(
- "if paymentTerms.dueDate is specified, paymentTerms.discountTerms.baseDate has not to be specified");
- }
- paymentTermsXml += "" + paymentTerms.getDescription() + "";
- if (dueDate != null) {
- paymentTermsXml += "";
- paymentTermsXml += ""
- + dueDate.getFormat().getFormatter().format(dueDate.getDate()) + "";
- paymentTermsXml += "";
- }
-
- if (discountTerms != null) {
- paymentTermsXml += "";
- String currency = trans.getCurrency();
- String basisAmount = currencyFormat(getTotalGross());
- paymentTermsXml += "" + basisAmount + "";
- paymentTermsXml += "" + discountTerms.getCalculationPercentage().toString()
- + "";
-
- if (discountTerms.getBaseDate() != null) {
- Date baseDate = discountTerms.getBaseDate().getDate();
- ZUGFeRDDateFormat baseDateFormat = discountTerms.getBaseDate().getFormat();
- paymentTermsXml += "";
- paymentTermsXml += "" + baseDateFormat.getFormatter().format(baseDate) + "";
- paymentTermsXml += "";
-
- paymentTermsXml += ""
- + discountTerms.getBasePeriodMeasure() + "";
- }
-
- paymentTermsXml += "";
- }
-
- paymentTermsXml += "";
- return paymentTermsXml;
- }
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDConformanceLevel.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDConformanceLevel.java
deleted file mode 100644
index d59b2f40..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDConformanceLevel.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public enum ZUGFeRDConformanceLevel {
- BASIC, COMFORT, EXTENDED, EN16931/*=Comfort*/, MINIMUM, BASICWL /*basic without lines, less than basic*/, CIUS
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDDateFormat.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDDateFormat.java
deleted file mode 100644
index 3457fe18..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDDateFormat.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.mustangproject.ZUGFeRD;
-
-import java.text.SimpleDateFormat;
-
-import org.mustangproject.ZUGFeRD.model.DateTimeTypeConstants;
-
-public enum ZUGFeRDDateFormat {
-
- MONTH_OF_YEAR(DateTimeTypeConstants.MONTH, new SimpleDateFormat("yyyyMM")),
- WEEK_OF_YEAR(DateTimeTypeConstants.WEEK, new SimpleDateFormat("yyyyww")),
- DATE(DateTimeTypeConstants.DATE, new SimpleDateFormat("yyyyMMdd"));
-
- private String dateTimeType;
- private SimpleDateFormat formatter;
-
- private ZUGFeRDDateFormat(String dateTimeType, SimpleDateFormat formatter) {
- this.dateTimeType = dateTimeType;
- this.formatter = formatter;
- }
-
- public String getDateTimeType() {
- return dateTimeType;
- }
-
- public SimpleDateFormat getFormatter() {
- return formatter;
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExportException.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExportException.java
deleted file mode 100644
index c318fccd..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExportException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public class ZUGFeRDExportException extends RuntimeException {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public ZUGFeRDExportException() {
- }
-
- public ZUGFeRDExportException(String message) {
- super(message);
- }
-
- public ZUGFeRDExportException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ZUGFeRDExportException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java
deleted file mode 100644
index 87db4324..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java
+++ /dev/null
@@ -1,746 +0,0 @@
-
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-/*
- * Mustangproject's ZUGFeRD implementation ZUGFeRD exporter Licensed under the
- * APLv2
- *
- * @date 2014-07-12
- * @version 1.2.0
- * @author jstaerk
- *
- */
-
-import org.apache.pdfbox.cos.COSArray;
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.cos.COSObject;
-import org.apache.pdfbox.pdmodel.*;
-import org.apache.pdfbox.pdmodel.common.PDMetadata;
-import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
-import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
-import org.apache.xmpbox.XMPMetadata;
-import org.apache.xmpbox.schema.AdobePDFSchema;
-import org.apache.xmpbox.schema.DublinCoreSchema;
-import org.apache.xmpbox.schema.PDFAIdentificationSchema;
-import org.apache.xmpbox.schema.XMPBasicSchema;
-import org.apache.xmpbox.type.BadFieldValueException;
-import org.apache.xmpbox.xml.XmpSerializer;
-
-import javax.xml.transform.TransformerException;
-import java.io.*;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
-
-public class ZUGFeRDExporter implements Closeable {
-
- public static final int DefaultZUGFeRDVersion = 1;
-
- private boolean isFacturX = false;
-
- /**
- * To use the ZUGFeRD exporter, implement IZUGFeRDExportableTransaction in
- * yourTransaction (which will require you to implement Product, Item and
- * Contact) then call doc = PDDocument.load(PDFfilename); // automatically add
- * Zugferd to all outgoing invoices ZUGFeRDExporter ze = new ZUGFeRDExporter();
- * ze.PDFmakeA3compliant(doc, "Your application name",
- * System.getProperty("user.name"), true); ze.PDFattachZugferdFile(doc,
- * yourTransaction);
- *
- * doc.save(PDFfilename);
- *
- * @author jstaerk
- * @deprecated Use the factory methods {@link #createFromPDFA3(String)},
- * {@link #createFromPDFA3(InputStream)} or the
- * {@link ZUGFeRDExporterFromA1Factory} instead
- */
- // // MAIN CLASS
- @Deprecated
- private PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
-
- // BASIC, COMFORT etc - may be set from outside.
- @Deprecated
- private ZUGFeRDConformanceLevel profile = ZUGFeRDConformanceLevel.EN16931;
-
- /**
- * Data (XML invoice) to be added to the ZUGFeRD PDF. It may be externally set,
- * in which case passing a IZUGFeRDExportableTransaction is not necessary. By
- * default it is null meaning the caller needs to pass a
- * IZUGFeRDExportableTransaction for the XML to be populated.
- */
- IXMLProvider xmlProvider;
- protected PDMetadata metadata = null;
- protected PDFAIdentificationSchema pdfaid = null;
- protected XMPMetadata xmp = null;
- /**
- * Producer attribute for PDF
- */
- protected String producer = "mustangproject";
- /**
- * Author/Creator attribute for PDF
- */
- protected String creator = "mustangproject";
- /**
- * CreatorTool
- */
- protected String creatorTool = "mustangproject";
-
- @Deprecated
- private boolean ignoreA1Errors;
- protected boolean ensurePDFisUpgraded = true;
- private PDDocument doc;
- int ZFVersion;
-
- private HashMap additionalFiles = new HashMap();
-
-
- private boolean disableAutoClose;
-
- private boolean fileAttached = false;
- protected boolean attachZUGFeRDHeaders = true;
-
- private boolean documentPrepared = false;
-
- public ZUGFeRDExporter() {
- init();
- }
-
- public ZUGFeRDExporter(PDDocument doc2) {
- doc = doc2;
- init();
- }
-
- /**
- * Adds additional file attachments into the ZF
- * @param filename the name of the attachment
- * @param filecontent the bytearray with the file contents
- */
- public void addAdditionalFile(String filename, byte[] filecontent) {
- additionalFiles.put(filename, filecontent);
-
- }
-
- /***
- * internal helper function: get namespace for given zugferd or factur-x version
- * @param ver the ZUGFeRD version
- * @return the URN of the namespace
- */
- public String getNamespaceForVersion(int ver) {
- if (isFacturX) {
- return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";
- } else if (ver == 1) {
- return "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#";
- } else if (ver == 2) {
- return "urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#";
-
- } else {
- throw new IllegalArgumentException("Version not supported");
- }
- }
-
- /***
- * internal helper: returns the namespace prefix for the given zf/fx version number
- * @param ver the zf/fx version
- * @return the namespace prefix as string, without colon
- */
- public String getPrefixForVersion(int ver) {
- if (isFacturX) {
- return "fx";
- } else {
- return "zf";
- }
- }
-
- /***
- * internal helper: return the name of the file attachment for the given zf/fx version
- * @param ver the zf/fx version
- * @return the filename of the file to be embedded
- */
- public String getFilenameForVersion(int ver) {
- if (isFacturX) {
- return "factur-x.xml";
- } else {
- if (ver==1) {
- return "ZUGFeRD-invoice.xml";
- } else {
- return "zugferd-invoice.xml";
- }
- }
- }
-
- @Deprecated
- public void setZUGFeRDVersion(int ver) {
- if (ver == 1) {
- ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider();
- this.xmlProvider = z1p;
- } else if (ver == 2) {
- ZUGFeRD2PullProvider z2p = new ZUGFeRD2PullProvider();
- this.xmlProvider = z2p;
- } else {
- throw new IllegalArgumentException("Version not supported");
- }
- ZFVersion = ver;
- }
-
- public IXMLProvider getProvider() {
- return xmlProvider;
- }
-
- private void init() {
- setZUGFeRDVersion(DefaultZUGFeRDVersion);
- }
-
- public void setFacturX() {
- setZUGFeRDVersion(2);
- isFacturX = true;
- }
-
- /**
- * All files are PDF/A-3, setConformance refers to the level conformance.
- *
- * PDF/A-3 has three conformance levels, called "A", "U" and "B".
- *
- * PDF/A-3-B where B means only visually preservable, U -standard for Mustang-
- * means visually and unicode preservable and A means full compliance, i.e.
- * visually, unicode and structurally preservable and tagged PDF, i.e. useful
- * metainformation for blind people.
- *
- * Feel free to pass "A" as new level if you know what you are doing :-)
- * @param newLevel "A", "U" or "B"
- *
- * @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
- */
- @Deprecated
- public void setConformanceLevel(PDFAConformanceLevel newLevel) {
- if (newLevel == null) {
- throw new NullPointerException("pdf conformance level");
- }
- conformanceLevel = newLevel;
- }
-
- /**
- * All files are PDF/A-3, setConformance refers to the level conformance.
- *
- * PDF/A-3 has three conformance levels, called "A", "U" and "B".
- *
- * PDF/A-3-B where B means only visually preservable, U -standard for Mustang-
- * means visually and unicode preservable and A means full compliance, i.e.
- * visually, unicode and structurally preservable and tagged PDF, i.e. useful
- * metainformation for blind people.
- *
- * Feel free to pass "A" as new level if you know what you are doing :-)
- *
- * @param newLevel "A", "U" or "B"
- * @deprecated Use
- * {@link #setConformanceLevel(org.mustangproject.ZUGFeRD.PDFAConformanceLevel)}
- * instead
- */
- @Deprecated
- public void setConformanceLevel(String newLevel) {
- conformanceLevel = PDFAConformanceLevel.findByLetter(newLevel);
- }
-
- /**
- * enables the flag to indicate a test invoice in the XML structure
- */
- public void setTest() {
- xmlProvider.setTest();
- }
-
- /**
- * @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
- */
- @Deprecated
- public void ignoreA1Errors() {
- ignoreA1Errors = true;
- }
-
- /***
- * load from a pdf which is already A/3
- * @param filename the PDF
- * @throws IOException if anything is wrong with filename
- * @deprecated Use the factory method {@link #createFromPDFA3(String)} instead
- */
- @Deprecated
- public void loadPDFA3(String filename) throws IOException {
- doc = PDDocument.load(new File(filename));
- }
-
- /***
- * factory create a ZUGFeRD exporter for a PDF/A-3 pdf file
- * @param filename of the pdf
- * @return the created ZUGFeRDExporter
- * @throws IOException if something is wrong with filename
- */
- public static ZUGFeRDExporter createFromPDFA3(String filename) throws IOException {
- return new ZUGFeRDExporter(PDDocument.load(new File(filename)));
- }
-
- /**
- * load from a pdf which is already A/3 from filestream
- * @param file InputStream to load pdf from
- * @deprecated Use the factory method {@link #createFromPDFA3(InputStream)} instead
- * @throws IOException in case anything is wrong with file
- *
- */
- @Deprecated
- public void loadPDFA3(InputStream file) throws IOException {
- doc = PDDocument.load(file);
- }
-
- /***
- * factory create a ZUGFeRD exporter for a PDF/A-3 inputstream
- * @param pdfSource the InputStream of the pdf
- * @return the created ZUGFeRDExporter
- * @throws IOException (should not happen)
- */
- public static ZUGFeRDExporter createFromPDFA3(InputStream pdfSource) throws IOException {
- return new ZUGFeRDExporter(PDDocument.load(pdfSource));
- }
-
- /**
- * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
- * metadata level, this will not e.g. convert graphics to JPG-2000)
- * @param filename the pdf
- * @param producer the name of the xmp producer (app)
- * @param creator the name of the xmp creator (user)
- * @param attachZugferdHeaders whether to attach XMP ZUGFeRD headers
- * @return the created PDFbox PDDocumentCatalog
- * @throws IOException if anything is wrong with file
- * @throws TransformerException in case of xml (XMP) parsing issues
- * @deprecated use the {@link ZUGFeRDExporterFromA1Factory} instead
- */
- @Deprecated
- public PDDocumentCatalog PDFmakeA3compliant(String filename, String producer, String creator,
- boolean attachZugferdHeaders) throws IOException, TransformerException {
-
- doc = createPDFA1Factory().setProducer(producer).setCreator(creator).load(filename).doc;
-
- return doc.getDocumentCatalog();
- }
-
- /***
- *
- * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
- * metadata level, this will not e.g. convert graphics to JPG-2000)
-
- * @param file the InputStream of the pdf
- * @param producer the name of the xmp producer (app)
- * @param creator the name of the xmp creator (user)
- * @param attachZugferdHeaders whether to attach XMP ZUGFeRD headers
- * @return the created PDFbox PDDocumentCatalog
- * @throws IOException if anything is wrong with file
- * @throws TransformerException in case of xml (XMP) parsing issues
- * @deprecated use the {@link ZUGFeRDExporterFromA1Factory} instead
- */
- @Deprecated
- public PDDocumentCatalog PDFmakeA3compliant(InputStream file, String producer, String creator,
- boolean attachZugferdHeaders) throws IOException, TransformerException {
-
- doc = createPDFA1Factory().setProducer(producer).setCreator(creator).load(file).doc;
-
- return doc.getDocumentCatalog();
- }
-
-
- private IExporterFactory createPDFA1Factory() {
- ZUGFeRDExporterFromA1Factory factory = new ZUGFeRDExporterFromA1Factory();
- if (ignoreA1Errors) {
- factory.ignorePDFAErrors();
- }
- return factory.setZUGFeRDConformanceLevel(profile).setConformanceLevel(conformanceLevel);
- }
-
- @Override
- public void close() throws IOException {
- if (doc != null) {
- doc.close();
- }
- }
-
- /**
- * Embeds the Zugferd XML structure in a file named ZUGFeRD-invoice.xml.
- *
- * @param trans a IZUGFeRDExportableTransaction that provides the data-model to
- * populate the XML. This parameter may be null, if so the XML data
- * should hav ebeen set via
- * setZUGFeRDXMLData(byte[] zugferdData)
- * @throws IOException if anything is wrong with already loaded PDF
- */
- public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException {
- prepareDocument();
- ((IProfileProvider) xmlProvider).setProfile(profile);
- xmlProvider.generateXML(trans);
- String filename = getFilenameForVersion(ZFVersion);
- PDFAttachGenericFile(doc, filename, "Alternative",
- "Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
- "text/xml", xmlProvider.getXML());
- for (String filenameAdditional : additionalFiles.keySet()) {
- PDFAttachGenericFile(doc, filenameAdditional, "Supplement", "ZUGFeRD extension/additional data", "text/xml", additionalFiles.get(filenameAdditional));
- }
- }
-
- /***
- * Perform the final export to a now ZUGFeRD-enriched PDF file
- * @param ZUGFeRDfilename the pdf file name
- * @throws IOException if anything is wrong in the target location
- */
- public void export(String ZUGFeRDfilename) throws IOException {
- if (!documentPrepared) {
- prepareDocument();
- }
- if ((!fileAttached) && (attachZUGFeRDHeaders)) {
- throw new IOException(
- "File must be attached (usually with PDFattachZugferdFile) before perfoming this operation");
- }
- doc.save(ZUGFeRDfilename);
- if (!disableAutoClose) {
- close();
- }
- }
-
-
- /***
- * Perform the final export to a now ZUGFeRD-enriched PDF file as OutputStream
- * @param output the OutputStream
- * @throws IOException if anything is wrong in the OutputStream
- */
- public void export(OutputStream output) throws IOException {
- if (!documentPrepared) {
- prepareDocument();
- }
- if ((!fileAttached) && (attachZUGFeRDHeaders)) {
- throw new IOException(
- "File must be attached (usually with PDFattachZugferdFile) before perfoming this operation");
- }
- doc.save(output);
- if (!disableAutoClose) {
- close();
- }
- }
-
- /**
- * Embeds an external file (generic - any type allowed) in the PDF.
- *
- * @param doc PDDocument to attach the file to.
- * @param filename name of the file that will become attachment name in the PDF
- * @param relationship how the file relates to the content, e.g. "Alternative"
- * @param description Human-readable description of the file content
- * @param subType type of the data e.g. could be "text/xml" - mime like
- * @param data the binary data of the file/attachment
- * @throws java.io.IOException if anything is wrong with filename
- */
- public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description,
- String subType, byte[] data) throws IOException {
- fileAttached = true;
-
- PDComplexFileSpecification fs = new PDComplexFileSpecification();
- fs.setFile(filename);
-
- COSDictionary dict = fs.getCOSObject();
- dict.setName("AFRelationship", relationship);
- dict.setString("UF", filename);
- dict.setString("Desc", description);
-
- ByteArrayInputStream fakeFile = new ByteArrayInputStream(data);
- PDEmbeddedFile ef = new PDEmbeddedFile(doc, fakeFile);
-// ef.addCompression();
- ef.setSubtype(subType);
- ef.setSize(data.length);
- ef.setCreationDate(new GregorianCalendar());
-
- ef.setModDate(GregorianCalendar.getInstance());
-
- fs.setEmbeddedFile(ef);
-
- // In addition make sure the embedded file is set under /UF
- dict = fs.getCOSObject();
- COSDictionary efDict = (COSDictionary) dict.getDictionaryObject(COSName.EF);
- COSBase lowerLevelFile = efDict.getItem(COSName.F);
- efDict.setItem(COSName.UF, lowerLevelFile);
-
- // now add the entry to the embedded file tree and set in the document.
- PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
- PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles();
- if (efTree == null) {
- efTree = new PDEmbeddedFilesNameTreeNode();
- }
-
- Map namesMap = new HashMap<>();
-
- Map oldNamesMap = efTree.getNames();
- if (oldNamesMap != null) {
- for (String key : oldNamesMap.keySet()) {
- namesMap.put(key, oldNamesMap.get(key));
- }
- }
- namesMap.put(filename, fs);
- efTree.setNames(namesMap);
-
- names.setEmbeddedFiles(efTree);
- doc.getDocumentCatalog().setNames(names);
-
- // AF entry (Array) in catalog with the FileSpec
- COSBase AFEntry = (COSBase)doc.getDocumentCatalog().getCOSObject().getItem("AF");
- if ((AFEntry == null))
- {
- COSArray cosArray = new COSArray();
- cosArray.add(fs);
- doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray);
- } else if (AFEntry instanceof COSArray)
- {
- COSArray cosArray = (COSArray)AFEntry;
- cosArray.add(fs);
- doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray);
- } else if ((AFEntry instanceof COSObject) &&
- ((COSObject)AFEntry).getObject() instanceof COSArray)
- {
- COSArray cosArray = (COSArray)((COSObject)AFEntry).getObject();
- cosArray.add(fs);
- } else
- {
- throw new IOException("Unexpected object type for PDFDocument/Catalog/COSDictionary/Item(AF)");
- }
- }
-
- /**
- * Sets the ZUGFeRD XML data to be attached as a single byte array. This is
- * useful for use-cases where the XML has already been produced by some external
- * API or component.
- *
- * @param zugferdData XML data to be set as a byte array (XML file in raw form).
- * @throws IOException (should not happen)
- */
- public void setZUGFeRDXMLData(byte[] zugferdData) throws IOException {
- CustomXMLProvider cus = new CustomXMLProvider();
- cus.setXML(zugferdData);
- this.xmlProvider = cus;
- PDFattachZugferdFile(null);
-
- }
-
- /**
- * Sets the ZUGFeRD profile.
- *
- * @param zUGFeRDConformanceLevel the new conformance level
- * @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
- */
- @Deprecated
- public void setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel zUGFeRDConformanceLevel) {
- if (zUGFeRDConformanceLevel == null) {
- throw new NullPointerException("ZUGFeRD conformance level");
- }
- this.profile = zUGFeRDConformanceLevel;
- }
-
- /**
- * Sets the ZUGFeRD profile.
- *
- * @param zUGFeRDConformanceLevel the new conformance level
- * @deprecated Use {@link #setConformanceLevel(PDFAConformanceLevel)} instead
- */
- @Deprecated
- public void setZUGFeRDConformanceLevel(String zUGFeRDConformanceLevel) {
- this.profile = ZUGFeRDConformanceLevel.valueOf(zUGFeRDConformanceLevel);
- }
-
- /**
- * *
- * Returns the PDFBox PDF Document
- *
- * @return PDDocument the PDFBox PDF
- */
- public PDDocument getDoc() {
- return doc;
- }
-
- /**
- * This will add both the RDF-indication which embedded file is Zugferd and the
- * neccessary PDF/A schema extension description to be able to add this
- * information to RDF
- *
- * @param metadata the PDFbox XMPMetadata object
- */
- protected void addXMP(XMPMetadata metadata) {
-
- if (attachZUGFeRDHeaders) {
- XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, ZFVersion, isFacturX, profile,
- getNamespaceForVersion(ZFVersion), getPrefixForVersion(ZFVersion),
- getFilenameForVersion(ZFVersion));
-
- metadata.addSchema(zf);
- }
-
- XMPSchemaPDFAExtensions pdfaex = new XMPSchemaPDFAExtensions(this, metadata, ZFVersion, attachZUGFeRDHeaders);
- pdfaex.setZUGFeRDVersion(ZFVersion);
- metadata.addSchema(pdfaex);
- }
-
- protected byte[] serializeXmpMetadata(XMPMetadata xmpMetadata) throws TransformerException {
- XmpSerializer serializer = new XmpSerializer();
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
- String prefix = "";
- String suffix = "";
-
- try {
- buffer.write(prefix.getBytes("UTF-8")); // see https://github.com/ZUGFeRD/mustangproject/issues/44
- serializer.serialize(xmpMetadata, buffer, false);
- buffer.write(suffix.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e)
- {
- throw new TransformerException(e);
- } catch (IOException e)
- {
- throw new TransformerException(e);
- }
- return buffer.toByteArray();
- }
-
- protected void prepareDocument() throws IOException {
- String fullProducer = producer + " (via mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + ")";
-
- PDDocumentCatalog cat = doc.getDocumentCatalog();
- metadata = new PDMetadata(doc);
- cat.setMetadata(metadata);
-
- xmp = XMPMetadata.createXMPMetadata();
-
- pdfaid = new PDFAIdentificationSchema(xmp);
-
- xmp.addSchema(pdfaid);
-
- DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
-
- dc.addCreator(creator);
-
- XMPBasicSchema xsb = xmp.createAndAddXMPBasicSchema();
-
- xsb.setCreatorTool(creatorTool);
- xsb.setCreateDate(GregorianCalendar.getInstance());
- // PDDocumentInformation pdi=doc.getDocumentInformation();
- PDDocumentInformation pdi = new PDDocumentInformation();
- pdi.setProducer(fullProducer);
- pdi.setAuthor(creator);
- doc.setDocumentInformation(pdi);
-
- AdobePDFSchema pdf = xmp.createAndAddAdobePDFSchema();
- pdf.setProducer(fullProducer);
- if (ensurePDFisUpgraded) {
- try {
- pdfaid.setConformance(conformanceLevel.getLetter());// $NON-NLS-1$ //$NON-NLS-1$
- } catch (BadFieldValueException ex) {
- // This should be impossible, because it would occur only if an illegal
- // conformance level is supplied,
- // however the enum enforces that the conformance level is valid.
- throw new Error(ex);
- }
-
- pdfaid.setPart(3);
- }
- addXMP(xmp); /*
- * this is the only line where we do something Zugferd-specific, i.e. add PDF
- * metadata specifically for Zugferd, not generically for a embedded file
- */
-
-
- try {
- metadata.importXMPMetadata(serializeXmpMetadata(xmp));
-
- } catch (TransformerException e) {
- throw new ZUGFeRDExportException("Could not export XmpMetadata", e);
- }
- documentPrepared = true;
- }
-
- /**
- * @return if pdf file will be automatically closed after adding ZF
- */
- public boolean isAutoCloseDisabled() {
- return disableAutoClose;
- }
-
- /**
- * @param disableAutoClose prevent PDF file from being closed after adding ZF
- */
- public void disableAutoClose(boolean disableAutoClose) {
- this.disableAutoClose = disableAutoClose;
- }
-
- /**
- * the human author (use factory method instead)
- *
- * @param creator the (human) name who created the PDF
- */
- @Deprecated
- public void setCreator(String creator) {
- this.creator = creator;
- }
-
- /**
- * the CreatorTool attribute for the PDF
- *
- * @param creatorTool the application which created the PDF
- */
- protected void setCreatorTool(String creatorTool) {
- this.creatorTool = creatorTool;
- }
-
- /**
- * the authoring software (use factory method instead)
- *
- * @param producer the authoring software
- */
- @Deprecated
- public void setProducer(String producer) {
- this.producer = producer;
- }
-
- /**
- * @param ensurePDFisUpgraded if not set the PDF/A won't be relabelled A/3, e.g. if it already is one
- */
- public void setPDFA3(boolean ensurePDFisUpgraded) {
- this.ensurePDFisUpgraded = ensurePDFisUpgraded;
- }
-
- /**
- * @param attachZUGFeRDHeaders if false the ZUGFeRD XMP metadata won't be added, e.g. if it's not the first file
- */
- public void setAttachZUGFeRDHeaders(boolean attachZUGFeRDHeaders) {
- this.attachZUGFeRDHeaders = attachZUGFeRDHeaders;
- }
-
- /**
- * encapsulate the deprecated setters
- * @param zfVersion 1 or 2
- * @param zugferdConformanceLevel BASIC, COMFORT, EN16931, etc.
- * @param creator PDF creator
- * @param producer PDF producer
- */
- public void configure(int zfVersion, ZUGFeRDConformanceLevel zugferdConformanceLevel, String creator, String producer) {
- setZUGFeRDVersion(zfVersion);
- setZUGFeRDConformanceLevel(zugferdConformanceLevel);
- setCreator(creator);
- setProducer(producer);
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1Factory.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1Factory.java
deleted file mode 100644
index 7e61b8c3..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA1Factory.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-
-public class ZUGFeRDExporterFromA1Factory extends ZUGFeRDExporterFromA3Factory implements IExporterFactory {
- public ZUGFeRDExporterFromA1Factory() {
- ensurePDFisUpgraded = true;
-
- }
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3Factory.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3Factory.java
deleted file mode 100644
index 483f174f..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3Factory.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import org.apache.pdfbox.io.IOUtils;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.preflight.PreflightDocument;
-import org.apache.pdfbox.preflight.exception.ValidationException;
-import org.apache.pdfbox.preflight.parser.PreflightParser;
-import org.apache.pdfbox.preflight.utils.ByteArrayDataSource;
-
-import javax.activation.DataSource;
-import javax.activation.FileDataSource;
-import java.io.*;
-import java.util.HashMap;
-
-public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
- protected boolean ignorePDFAErrors = false;
- protected ZUGFeRDConformanceLevel zugferdConformanceLevel = ZUGFeRDConformanceLevel.EXTENDED;
- protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
- /**
- * Producer (attribute for PDF
- */
- protected String producer = "mustangproject";
- /**
- * Human creator (attribute for PDF)
- */
- protected String creator = "mustangproject";
- /**
- * Creator tool (attribute for PDF)
- */
- protected String creatorTool = null;
-
- private HashMap additionalXMLs = new HashMap();
-
-
- protected int ZFVersion = ZUGFeRDExporter.DefaultZUGFeRDVersion;
- protected boolean ensurePDFisUpgraded = false;
- private boolean attachZUGFeRDHeaders = true;
-
- /**
- * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
- * metadata level, this will not e.g. convert graphics to JPG-2000)
- *
- * @param pdfFilename filename of an PDF/A1 compliant document
- */
- public ZUGFeRDExporter load(String pdfFilename) throws IOException {
-
- ensurePDFIsValidPDFA(new FileDataSource(pdfFilename));
- try (FileInputStream pdf = new FileInputStream(pdfFilename)) {
- return load(readAllBytes(pdf));
- }
- }
-
-
- /**
- * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
- * metadata level, this will not e.g. convert graphics to JPG-2000)
- *
- * @param pdfBinary binary of a PDF/A1 compliant document
- */
- public ZUGFeRDExporter load(byte[] pdfBinary) throws IOException {
- ensurePDFIsValidPDFA(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary)));
- PDDocument doc = PDDocument.load(pdfBinary);
- ZUGFeRDExporter zugFeRDExporter = new ZUGFeRDExporter(doc);
- zugFeRDExporter.configure(ZFVersion, zugferdConformanceLevel, creator, producer);
- zugFeRDExporter.setAttachZUGFeRDHeaders(attachZUGFeRDHeaders);
- zugFeRDExporter.setPDFA3(ensurePDFisUpgraded);
-
- return zugFeRDExporter;
- }
-
- public ZUGFeRDExporterFromA3Factory() {
-
- ensurePDFisUpgraded = false;
- }
-
- /**
- * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
- * metadata level, this will not e.g. convert graphics to JPG-2000)
- *
- * @param pdfSource source to read a PDF/A1 compliant document from
- */
- public ZUGFeRDExporter load(InputStream pdfSource) throws IOException {
- return load(readAllBytes(pdfSource));
- }
-
- private void ensurePDFIsValidPDFA(final DataSource dataSource) throws IOException {
- if (!ignorePDFAErrors && !isValidA1(dataSource)) {
- throw new IOException("File is not a valid PDF/A input file");
- }
- }
-
- private static byte[] readAllBytes(InputStream in) throws IOException {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- IOUtils.copy(in, buffer);
- return buffer.toByteArray();
- }
-
- private static boolean isValidA1(DataSource dataSource) throws IOException {
- return getPDFAParserValidationResult(new PreflightParser(dataSource));
- }
-
- /**
- * Sets the ZUGFeRD conformance level (override).
- *
- * @param zugferdConformanceLevel the new conformance level
- */
- public IExporterFactory setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel zugferdConformanceLevel) {
- this.zugferdConformanceLevel = zugferdConformanceLevel;
- return this;
- }
-
- private static boolean getPDFAParserValidationResult(PreflightParser parser) throws IOException {
- /*
- * Parse the PDF file with PreflightParser that inherits from the
- * NonSequentialParser. Some additional controls are present to check a set of
- * PDF/A requirements. (Stream length consistency, EOL after some Keyword...)
- */
- parser.parse();// might add a Format.PDF_A1A as parameter and iterate through A1 and A3
-
- try (PreflightDocument document = parser.getPreflightDocument()) {
- /*
- * Once the syntax validation is done, the parser can provide a
- * PreflightDocument (that inherits from PDDocument) This document process the
- * end of PDF/A validation.
- */
-
- document.validate();
-
- // Get validation result
- return document.getResult().isValid();
- } catch (ValidationException e) {
- /*
- * the parse method can throw a SyntaxValidationException if the PDF file can't
- * be parsed. In this case, the exception contains an instance of
- * ValidationResult
- */
- return false;
- }
- }
-
- /**
- * All files are PDF/A-3, setConformance refers to the level conformance.
- *
- * PDF/A-3 has three coformance levels, called "A", "U" and "B".
- *
- * PDF/A-3-B where B means only visually preservable, U -standard for Mustang-
- * means visually and unicode preservable and A means full compliance, i.e.
- * visually, unicode and structurally preservable and tagged PDF, i.e. useful
- * metainformation for blind people.
- *
- * Feel free to pass "A" as new level if you know what you are doing :-)
- */
- public IExporterFactory setConformanceLevel(PDFAConformanceLevel newLevel) {
- conformanceLevel = newLevel;
- return this;
- }
-
- public IExporterFactory ignorePDFAErrors() {
- this.ignorePDFAErrors = true;
- return this;
- }
-
-
- public IExporterFactory setCreator(String creator) {
- this.creator = creator;
- return this;
- }
-
- public IExporterFactory setCreatorTool(String creatorTool) {
- this.creatorTool = creatorTool;
- return this;
- }
-
- public IExporterFactory setProducer(String producer) {
- this.producer = producer;
- return this;
- }
-
- public IExporterFactory setAttachZUGFeRDHeaders(boolean attachHeaders) {
- this.attachZUGFeRDHeaders = attachHeaders;
- return this;
- }
-
-
- @Override
- public IExporterFactory setZUGFeRDVersion(int version) {
- this.ZFVersion = version;
- return this;
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java
deleted file mode 100644
index 2179cfe7..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java
+++ /dev/null
@@ -1,452 +0,0 @@
-/**
- * ********************************************************************** Copyright 2018 Jochen Staerk Use is subject to license terms. Licensed under the
- * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
- * and limitations under the License.
- */
-package org.mustangproject.ZUGFeRD;
-/**
- * Mustangproject's ZUGFeRD implementation ZUGFeRD importer Licensed under the APLv2
- *
- * @date 2014-07-07
- * @version 1.1.0
- * @author jstaerk
- */
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Scanner;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
-import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
-import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
-import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
-import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-public class ZUGFeRDImporter {
-
- /**
- * if metadata has been found
- */
- private boolean containsMeta = false;
- /**
- * map filenames of additional XML files to their contents
- */
- private HashMap additionalXMLs = new HashMap<>();
- /**
- * Raw XML form of the extracted data - may be directly obtained.
- */
- private byte[] rawXML = null;
- /**
- * XMP metadata
- */
- private String xmpString = null; // XMP metadata
- /**
- * parsed Document
- */
- private Document document;
-
-
- public ZUGFeRDImporter(String pdfFilename) {
- try (InputStream bis = Files.newInputStream(Paths.get(pdfFilename), StandardOpenOption.READ)) {
- extractLowLevel(bis);
- } catch (IOException e) {
- Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
- throw new ZUGFeRDExportException(e);
- }
- }
-
-
- public ZUGFeRDImporter(InputStream pdfStream) {
- try {
- extractLowLevel(pdfStream);
- } catch (IOException e) {
- Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
- throw new ZUGFeRDExportException(e);
- }
- }
-
-
- /**
- * Extracts a ZUGFeRD invoice from a PDF document represented by an input stream. Errors are reported via exception handling.
- *
- * @param pdfStream a inputstream of a pdf file
- */
- private void extractLowLevel(InputStream pdfStream) throws IOException {
- try (PDDocument doc = PDDocument.load(pdfStream)) {
- // PDDocumentInformation info = doc.getDocumentInformation();
- PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
- //start
-
- if (doc.getDocumentCatalog() == null || doc.getDocumentCatalog().getMetadata() == null) {
- Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.INFO, "no-xmlpart");
- return;
- }
-
- InputStream XMP = doc.getDocumentCatalog().getMetadata().exportXMPMetadata();
- xmpString = convertStreamToString(XMP);
-
- PDEmbeddedFilesNameTreeNode etn = names.getEmbeddedFiles();
- if (etn == null) {
- return;
- }
-
- Map efMap = etn.getNames();
- // String filePath = "/tmp/";
-
- if (efMap != null) {
- extractFiles(efMap); // see
- // https://memorynotfound.com/apache-pdfbox-extract-embedded-file-pdf-document/
- } else {
-
- List> kids = etn.getKids();
- for (PDNameTreeNode node : kids) {
- Map namesL = node.getNames();
- extractFiles(namesL);
- }
- }
- }
- }
-
-
- private void extractFiles(Map names) throws IOException {
- for (String alias : names.keySet()) {
-
- PDComplexFileSpecification fileSpec = names.get(alias);
- String filename = fileSpec.getFilename();
- /**
- * filenames for invoice data (ZUGFeRD v1 and v2, Factur-X)
- */
- if ((filename.equals("ZUGFeRD-invoice.xml") || (filename.equals("zugferd-invoice.xml")) || filename.equals("factur-x.xml"))) { //$NON-NLS-1$
- containsMeta = true;
-
- PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
- // String embeddedFilename = filePath + filename;
- // File file = new File(filePath + filename);
- // System.out.println("Writing " + embeddedFilename);
- // ByteArrayOutputStream fileBytes=new
- // ByteArrayOutputStream();
- // FileOutputStream fos = new FileOutputStream(file);
-
- setRawXML(embeddedFile.toByteArray());
-
- // fos.write(embeddedFile.getByteArray());
- // fos.close();
- }
- if (filename.startsWith("additional_data")) {
- PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
- additionalXMLs.put(filename, embeddedFile.toByteArray());
- }
- }
- }
-
-
- private Document getDocument() {
- return document;
- }
-
-
- private void setDocument() throws ParserConfigurationException, IOException, SAXException {
- DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance();
- xmlFact.setNamespaceAware(false);
- DocumentBuilder builder = xmlFact.newDocumentBuilder();
- ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
- is.skip(guessBOMSize(is));
- document = builder.parse(is);
- }
-
-
- public void setRawXML(byte[] rawXML) throws IOException {
- this.rawXML = rawXML;
- try {
- setDocument();
- } catch (ParserConfigurationException | SAXException e) {
- Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
- throw new ZUGFeRDExportException(e);
- }
- }
-
-
- /**
- * Skips over a BOM at the beginning of the given ByteArrayInputStream, if one exists.
- *
- * @param is the ByteArrayInputStream used
- * @throws IOException if can not be read from is
- * @see Autodetection of Character Encodings
- */
- private int guessBOMSize(ByteArrayInputStream is) throws IOException {
- byte[] pad = new byte[4];
- is.read(pad);
- is.reset();
- int test2 = ((pad[0] & 0xFF) << 8) | (pad[1] & 0xFF);
- int test3 = ((test2 & 0xFFFF) << 8) | (pad[2] & 0xFF);
- int test4 = ((test3 & 0xFFFFFF) << 8) | (pad[3] & 0xFF);
- //
- if (test4 == 0x0000FEFF || test4 == 0xFFFE0000 || test4 == 0x0000FFFE || test4 == 0xFEFF0000) {
- // UCS-4: BOM takes 4 bytes
- return 4;
- } else if (test3 == 0xEFBBFF) {
- // UTF-8: BOM takes 3 bytes
- return 3;
- } else if (test2 == 0xFEFF || test2 == 0xFFFE) {
- // UTF-16: BOM takes 2 bytes
- return 2;
- }
- return 0;
- }
-
-
- private String extractString(String xpathStr) {
- if (!containsMeta) {
- throw new ZUGFeRDExportException("No suitable data/ZUGFeRD file could be found.");
- }
- String result;
- try {
- Document document = getDocument();
- XPathFactory xpathFact = XPathFactory.newInstance();
- XPath xpath = xpathFact.newXPath();
- result = xpath.evaluate(xpathStr, document);
- } catch (XPathExpressionException e) {
- Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
- throw new ZUGFeRDExportException(e);
- }
- return result;
- }
-
-
- /**
- * @return the reference (purpose) the sender specified for this invoice
- */
- public String getForeignReference() {
- String result = extractString("//ApplicableHeaderTradeSettlement/PaymentReference");
- if (result == null || result.isEmpty()) {
- result = extractString("//ApplicableSupplyChainTradeSettlement/PaymentReference");
- }
- return result;
- }
-
-
- /**
- * @return the document code
- */
- public String getDocumentCode() {
- return extractString("//HeaderExchangedDocument/TypeCode");
- }
-
-
- /**
- * @return the referred document
- */
- public String getReference() {
- return extractString("//ApplicableHeaderTradeAgreement/BuyerReference");
- }
-
-
- /**
- * @return the sender's bank's BLZ code
- * @deprecated use BIC and IBAN instead of BLZ and KTO
- */
- @Deprecated
- public String getBLZ() {
- return extractString("//PayeeSpecifiedCreditorFinancialInstitution/GermanBankleitzahlID");
- }
-
-
- /**
- * @return the sender's account number
- * @deprecated use BIC and IBAN instead of BLZ and KTO
- */
- @Deprecated
- public String getKTO() {
- return extractString("//PayeePartyCreditorFinancialAccount/ProprietaryID");
- }
-
-
- /**
- * @return the sender's bank's BIC code
- */
- public String getBIC() {
- return extractString("//PayeeSpecifiedCreditorFinancialInstitution/BICID");
- }
-
-
- /**
- * @return the sender's bank name
- */
- public String getBankName() {
- return extractString("//PayeeSpecifiedCreditorFinancialInstitution/Name");
- }
-
-
- /**
- * @return the sender's account IBAN code
- */
- public String getIBAN() {
- return extractString("//PayeePartyCreditorFinancialAccount/IBANID");
- }
-
-
- public String getHolder() {
- return extractString("//SellerTradeParty/Name");
- }
-
-
- /**
- * @return the total payable amount
- */
- public String getAmount() {
- String result = extractString("//SpecifiedTradeSettlementHeaderMonetarySummation/DuePayableAmount");
- if (result == null || result.isEmpty()) {
- result = extractString("//SpecifiedTradeSettlementMonetarySummation/GrandTotalAmount");
- }
- return result;
- }
-
-
- /**
- * @return when the payment is due
- */
- public String getDueDate() {
- return extractString("//SpecifiedTradePaymentTerms/DueDateDateTime/DateTimeString");
- }
-
-
- public HashMap getAdditionalData() {
- return additionalXMLs;
- }
-
-
- /**
- * get xmp metadata of the PDF, null if not available
- *
- * @return string
- */
- public String getXMP() {
- return xmpString;
- }
-
-
- /**
- * @return if export found parseable ZUGFeRD data
- */
- public boolean containsMeta() {
- return containsMeta;
- }
-
-
- /**
- * @param meta raw XML to be set
- * @throws IOException if raw can not be set
- */
- public void setMeta(String meta) throws IOException {
- setRawXML(meta.getBytes());
- }
-
-
- /**
- * @return raw XML of the invoice
- */
- public String getMeta() {
- if (rawXML == null) {
- return null;
- }
-
- return new String(rawXML);
- }
-
-
- public int getVersion() throws Exception {
- if (!containsMeta) {
- throw new Exception("Not yet parsed");
- }
- if (getUTF8().contains(" 0) && ((meta.contains("SpecifiedExchangedDocumentContext") //$NON-NLS-1$
- /* ZF1 */ || meta.contains("ExchangedDocumentContext") /* ZF2 */));
- }
-
-
- static String convertStreamToString(java.io.InputStream is) {
- // source https://stackoverflow.com/questions/309424/how-do-i-read-convert-an-inputstream-into-a-string-in-java referring to
- // https://community.oracle.com/blogs/pat/2004/10/23/stupid-scanner-tricks
- Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
- return s.hasNext() ? s.next() : "";
- }
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporterException.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporterException.java
deleted file mode 100644
index a1ea969f..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporterException.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2019 ak on 09.04.19.
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-public class ZUGFeRDImporterException extends RuntimeException {
-
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java
deleted file mode 100644
index 83d67468..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDMigrator.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import javax.xml.transform.*;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import java.io.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class ZUGFeRDMigrator {
-
- static final ClassLoader CLASS_LOADER = ZUGFeRDMigrator.class.getClassLoader();
- private static final String RESOURCE_PATH = ""; //$NON-NLS-1$
- private static final Logger LOG = Logger.getLogger(ZUGFeRDMigrator.class.getName());
- // private static File createTempFileResult(final Transformer transformer, final StreamSource toTransform,
-// final String suffix) throws TransformerException, IOException {
-// File result = File.createTempFile("ZUV_", suffix); //$NON-NLS-1$
-// result.deleteOnExit();
-//
-// try (FileOutputStream fos = new FileOutputStream(result)) {
-// transformer.transform(toTransform, new StreamResult(fos));
-// }
-// return result;
-// }
- private TransformerFactory mFactory = null;
- private Templates mXsltTemplate = null;
-
- public ZUGFeRDMigrator() {
- mFactory = new net.sf.saxon.TransformerFactoryImpl();
- //fact = TransformerFactory.newInstance();
- mFactory.setURIResolver(new ClasspathResourceURIResolver());
- try {
- mXsltTemplate = mFactory.newTemplates(new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "COMFORTtoEN16931.xsl")));
- } catch (TransformerConfigurationException ex) {
- LOG.log(Level.SEVERE, null, ex);
- }
- }
-
- public String migrateFromV1ToV2(String xmlFilename) throws FileNotFoundException, TransformerException, UnsupportedEncodingException {
- /**
- * *
- * http://www.unece.org/fileadmin/DAM/cefact/xml/XML-Naming-And-Design-Rules-V2_1.pdf
- * http://www.ferd-net.de/upload/Dokumente/FACTUR-X_ZUGFeRD_2p0_Teil1_Profil_EN16931_1p03.pdf
- * http://countwordsfree.com/xmlviewer
- */
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- applySchematronXsl(new FileInputStream(xmlFilename), baos);
-
- String res = null;
- res = baos.toString("UTF-8");
-
- //migrate the profiles
-
- res=res.replace("urn:ferd:CrossIndustryDocument:invoice:1p0:basic", "urn:cen.eu:en16931:2017#compliant#urn:zugferd.de:2p0:basic");
- res=res.replace("urn:ferd:CrossIndustryDocument:invoice:1p0:comfort", "urn:cen.eu:en16931:2017");
- res=res.replace("urn:ferd:CrossIndustryDocument:invoice:1p0:extended", "urn:cen.eu:en16931:2017#conformant#urn:zugferd.de:2p0:extended");
-
- //somehow the XML parser seems to insert erreneous XML namespaces, depending on which one it is, saxon seems to be cleaner.
- //nevertheless, remove them manually
- res=res.replace("", "");
- res=res.replace("", "");
-
-
- return res;
- }
-
- public void applySchematronXsl(final InputStream xmlFile,
- final OutputStream EN16931Outstream) throws TransformerException {
- Transformer transformer = mXsltTemplate.newTransformer();
- transformer.transform(new StreamSource(xmlFile), new StreamResult(EN16931Outstream));
- }
-
- private static class ClasspathResourceURIResolver implements URIResolver {
- ClasspathResourceURIResolver() {
- // Do nothing, just prevents synthetic access warning.
- }
-
- @Override
- public Source resolve(String href, String base) throws TransformerException {
- return new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + href));
- }
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java
deleted file mode 100644
index b89f17de..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java
+++ /dev/null
@@ -1,1263 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.xml.bind.JAXBElement;
-
-import org.mustangproject.ZUGFeRD.model.AmountType;
-import org.mustangproject.ZUGFeRD.model.CodeType;
-import org.mustangproject.ZUGFeRD.model.CountryIDType;
-import org.mustangproject.ZUGFeRD.model.CreditorFinancialAccountType;
-import org.mustangproject.ZUGFeRD.model.CreditorFinancialInstitutionType;
-import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
-import org.mustangproject.ZUGFeRD.model.DateTimeType;
-import org.mustangproject.ZUGFeRD.model.DateTimeTypeConstants;
-import org.mustangproject.ZUGFeRD.model.DocumentCodeType;
-import org.mustangproject.ZUGFeRD.model.DocumentContextParameterType;
-import org.mustangproject.ZUGFeRD.model.DocumentLineDocumentType;
-import org.mustangproject.ZUGFeRD.model.ExchangedDocumentContextType;
-import org.mustangproject.ZUGFeRD.model.ExchangedDocumentType;
-import org.mustangproject.ZUGFeRD.model.IDType;
-import org.mustangproject.ZUGFeRD.model.IndicatorType;
-import org.mustangproject.ZUGFeRD.model.LogisticsServiceChargeType;
-import org.mustangproject.ZUGFeRD.model.MeasureType;
-import org.mustangproject.ZUGFeRD.model.NoteType;
-import org.mustangproject.ZUGFeRD.model.NoteTypeConstants;
-import org.mustangproject.ZUGFeRD.model.ObjectFactory;
-import org.mustangproject.ZUGFeRD.model.PaymentMeansCodeType;
-import org.mustangproject.ZUGFeRD.model.PaymentMeansCodeTypeConstants;
-import org.mustangproject.ZUGFeRD.model.PercentType;
-import org.mustangproject.ZUGFeRD.model.QuantityType;
-import org.mustangproject.ZUGFeRD.model.ReferencedDocumentType;
-import org.mustangproject.ZUGFeRD.model.SupplyChainEventType;
-import org.mustangproject.ZUGFeRD.model.SupplyChainTradeAgreementType;
-import org.mustangproject.ZUGFeRD.model.SupplyChainTradeDeliveryType;
-import org.mustangproject.ZUGFeRD.model.SupplyChainTradeLineItemType;
-import org.mustangproject.ZUGFeRD.model.SupplyChainTradeSettlementType;
-import org.mustangproject.ZUGFeRD.model.SupplyChainTradeTransactionType;
-import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeType;
-import org.mustangproject.ZUGFeRD.model.TaxRegistrationType;
-import org.mustangproject.ZUGFeRD.model.TaxRegistrationTypeConstants;
-import org.mustangproject.ZUGFeRD.model.TaxTypeCodeType;
-import org.mustangproject.ZUGFeRD.model.TaxTypeCodeTypeConstants;
-import org.mustangproject.ZUGFeRD.model.TextType;
-import org.mustangproject.ZUGFeRD.model.TradeAddressType;
-import org.mustangproject.ZUGFeRD.model.TradeAllowanceChargeType;
-import org.mustangproject.ZUGFeRD.model.TradePartyType;
-import org.mustangproject.ZUGFeRD.model.TradePaymentDiscountTermsType;
-import org.mustangproject.ZUGFeRD.model.TradePaymentTermsType;
-import org.mustangproject.ZUGFeRD.model.TradePriceType;
-import org.mustangproject.ZUGFeRD.model.TradeProductType;
-import org.mustangproject.ZUGFeRD.model.TradeSettlementMonetarySummationType;
-import org.mustangproject.ZUGFeRD.model.TradeSettlementPaymentMeansType;
-import org.mustangproject.ZUGFeRD.model.TradeTaxType;
-
-class ZUGFeRDTransactionModelConverter {
- private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd");
- private static final ObjectFactory xmlFactory = new ObjectFactory();
-
- private final IZUGFeRDExportableTransaction trans;
- private final Totals totals;
- private boolean isTest;
- private String currency = "EUR";
- private String profile;
-
-
- ZUGFeRDTransactionModelConverter(IZUGFeRDExportableTransaction trans) {
- this.trans = trans;
- totals = new Totals();
- currency = trans.getCurrency() != null ? trans.getCurrency() : currency;
- }
-
-
- JAXBElement convertToModel() {
- CrossIndustryDocumentType invoice = xmlFactory
- .createCrossIndustryDocumentType();
-
- invoice.setSpecifiedExchangedDocumentContext(getDocumentContext());
- invoice.setHeaderExchangedDocument(getDocument());
- invoice.setSpecifiedSupplyChainTradeTransaction(getTradeTransaction());
-
- return xmlFactory
- .createCrossIndustryDocument(invoice);
- }
-
-
- private ExchangedDocumentContextType getDocumentContext() {
-
- ExchangedDocumentContextType context = xmlFactory
- .createExchangedDocumentContextType();
- DocumentContextParameterType contextParameter = xmlFactory
- .createDocumentContextParameterType();
- IDType idType = xmlFactory.createIDType();
- idType.setValue(profile);
- contextParameter.setID(idType);
- context.getGuidelineSpecifiedDocumentContextParameter().add(
- contextParameter);
-
- IndicatorType testIndicator = xmlFactory.createIndicatorType();
- testIndicator.setIndicator(isTest);
- context.setTestIndicator(testIndicator);
-
- return context;
- }
-
-
- private ExchangedDocumentType getDocument() {
-
- ExchangedDocumentType document = xmlFactory
- .createExchangedDocumentType();
-
- IDType id = xmlFactory.createIDType();
- id.setValue(trans.getNumber());
- document.setID(id);
-
- DateTimeType issueDateTime = xmlFactory.createDateTimeType();
- DateTimeType.DateTimeString issueDateTimeString = xmlFactory
- .createDateTimeTypeDateTimeString();
- issueDateTimeString.setFormat(DateTimeTypeConstants.DATE);
- issueDateTimeString.setValue(zugferdDateFormat.format(trans
- .getIssueDate()));
- issueDateTime.setDateTimeString(issueDateTimeString);
- document.setIssueDateTime(issueDateTime);
-
- DocumentCodeType documentCodeType = xmlFactory.createDocumentCodeType();
- documentCodeType.setValue(trans.getDocumentCode());
- document.setTypeCode(documentCodeType);
-
- TextType name = xmlFactory.createTextType();
- name.setValue(trans.getDocumentName());
- document.getName().add(name);
-
- if (trans.getOwnOrganisationFullPlaintextInfo() != null) {
- NoteType regularInfo = xmlFactory.createNoteType();
- CodeType regularInfoSubjectCode = xmlFactory.createCodeType();
- regularInfoSubjectCode.setValue(NoteTypeConstants.REGULARINFO);
- regularInfo.setSubjectCode(regularInfoSubjectCode);
- TextType regularInfoContent = xmlFactory.createTextType();
- regularInfoContent.setValue(trans
- .getOwnOrganisationFullPlaintextInfo());
- regularInfo.getContent().add(regularInfoContent);
- document.getIncludedNote().add(regularInfo);
- }
-
- if (trans.getReferenceNumber() != null && !"".equals(trans.getReferenceNumber())) {
- NoteType referenceInfo = xmlFactory.createNoteType();
- TextType referenceInfoContent = xmlFactory.createTextType();
- referenceInfoContent.setValue(trans.getReferenceNumber());
- referenceInfo.getContent().add(referenceInfoContent);
- document.getIncludedNote().add(referenceInfo);
- }
-
- return document;
- }
-
-
- private SupplyChainTradeTransactionType getTradeTransaction() {
-
- SupplyChainTradeTransactionType transaction = xmlFactory
- .createSupplyChainTradeTransactionType();
- transaction.getApplicableSupplyChainTradeAgreement().add(
- getTradeAgreement());
- transaction.setApplicableSupplyChainTradeDelivery(getTradeDelivery());
- transaction.setApplicableSupplyChainTradeSettlement(getTradeSettlement());
- transaction.getIncludedSupplyChainTradeLineItem().addAll(
- getLineItems());
-
- return transaction;
- }
-
-
- private SupplyChainTradeAgreementType getTradeAgreement() {
-
- SupplyChainTradeAgreementType tradeAgreement = xmlFactory
- .createSupplyChainTradeAgreementType();
-
- tradeAgreement.setBuyerTradeParty(getBuyer());
- tradeAgreement.setSellerTradeParty(getSeller());
-
- if (trans.getBuyerOrderReferencedDocumentID() != null) {
- ReferencedDocumentType refdoc = xmlFactory.createReferencedDocumentType();
- IDType id = xmlFactory.createIDType();
- id.setValue(trans.getBuyerOrderReferencedDocumentID());
- refdoc.getID().add(id);
-
- if (trans.getBuyerOrderReferencedDocumentIssueDateTime() != null) {
- refdoc.setIssueDateTime(trans.getBuyerOrderReferencedDocumentIssueDateTime());
- }
-
- tradeAgreement.getBuyerOrderReferencedDocument().add(refdoc);
- }
-
- return tradeAgreement;
- }
-
-
- private TradePartyType getBuyer() {
-
- TradePartyType buyerTradeParty = xmlFactory.createTradePartyType();
-
- if (trans.getRecipient().getID() != null) {
- IDType buyerID = xmlFactory.createIDType();
- buyerID.setValue(trans.getRecipient().getID());
- buyerTradeParty.getID().add(buyerID);
- }
- if (trans.getRecipient().getGlobalID() != null) {
- IDType globalID = xmlFactory.createIDType();
- globalID.setValue(trans.getRecipient().getGlobalID());
- globalID.setSchemeID(trans.getRecipient().getGlobalIDScheme());
- buyerTradeParty.getGlobalID().add(globalID);
- }
-
- TextType buyerName = xmlFactory.createTextType();
- buyerName.setValue(trans.getRecipient().getName());
- buyerTradeParty.setName(buyerName);
-
- TradeAddressType buyerAddressType = xmlFactory.createTradeAddressType();
- TextType buyerCityName = xmlFactory.createTextType();
- buyerCityName.setValue(trans.getRecipient().getLocation());
- buyerAddressType.setCityName(buyerCityName);
-
- CountryIDType buyerCountryId = xmlFactory.createCountryIDType();
- buyerCountryId.setValue(trans.getRecipient().getCountry());
- buyerAddressType.setCountryID(buyerCountryId);
-
- TextType buyerAddress = xmlFactory.createTextType();
- buyerAddress.setValue(trans.getRecipient().getStreet());
- buyerAddressType.setLineOne(buyerAddress);
-
- if (trans.getRecipient().getAdditionalAddress() != null) {
- TextType buyerAdditionalAddress = xmlFactory.createTextType();
- buyerAdditionalAddress.setValue(trans.getRecipient().getAdditionalAddress());
- buyerAddressType.setLineTwo(buyerAdditionalAddress);
- }
-
- CodeType buyerPostcode = xmlFactory.createCodeType();
- buyerPostcode.setValue(trans.getRecipient().getZIP());
- buyerAddressType.getPostcodeCode().add(buyerPostcode);
-
- buyerTradeParty.setPostalTradeAddress(buyerAddressType);
-
- // Ust-ID
- TaxRegistrationType buyerTaxRegistration = xmlFactory
- .createTaxRegistrationType();
- IDType buyerUstId = xmlFactory.createIDType();
- buyerUstId.setValue(trans.getRecipient().getVATID());
- buyerUstId.setSchemeID(TaxRegistrationTypeConstants.USTID);
- buyerTaxRegistration.setID(buyerUstId);
- buyerTradeParty.getSpecifiedTaxRegistration().add(buyerTaxRegistration);
-
- return buyerTradeParty;
- }
-
-
- private TradePartyType getSeller() {
-
- TradePartyType sellerTradeParty = xmlFactory.createTradePartyType();
-
- if (trans.getOwnForeignOrganisationID() != null) {
- IDType sellerID = xmlFactory.createIDType();
- sellerID.setValue(trans.getOwnForeignOrganisationID());
- sellerTradeParty.getID().add(sellerID);
- }
-
- TextType sellerName = xmlFactory.createTextType();
- sellerName.setValue(trans.getOwnOrganisationName());
- sellerTradeParty.setName(sellerName);
-
- TradeAddressType sellerAddressType = xmlFactory
- .createTradeAddressType();
- TextType sellerCityName = xmlFactory.createTextType();
- sellerCityName.setValue(trans.getOwnLocation());
- sellerAddressType.setCityName(sellerCityName);
-
- CountryIDType sellerCountryId = xmlFactory.createCountryIDType();
- sellerCountryId.setValue(trans.getOwnCountry());
- sellerAddressType.setCountryID(sellerCountryId);
-
- TextType sellerAddress = xmlFactory.createTextType();
- sellerAddress.setValue(trans.getOwnStreet());
- sellerAddressType.setLineOne(sellerAddress);
-
- CodeType sellerPostcode = xmlFactory.createCodeType();
- sellerPostcode.setValue(trans.getOwnZIP());
- sellerAddressType.getPostcodeCode().add(sellerPostcode);
-
- sellerTradeParty.setPostalTradeAddress(sellerAddressType);
-
- // Steuernummer
- TaxRegistrationType sellerTaxRegistration = xmlFactory
- .createTaxRegistrationType();
- IDType sellerTaxId = xmlFactory.createIDType();
- sellerTaxId.setValue(trans.getOwnTaxID());
- sellerTaxId.setSchemeID(TaxRegistrationTypeConstants.TAXID);
- sellerTaxRegistration.setID(sellerTaxId);
- sellerTradeParty.getSpecifiedTaxRegistration().add(
- sellerTaxRegistration);
-
- // Ust-ID
- sellerTaxRegistration = xmlFactory.createTaxRegistrationType();
- IDType sellerUstId = xmlFactory.createIDType();
- sellerUstId.setValue(trans.getOwnVATID());
- sellerUstId.setSchemeID(TaxRegistrationTypeConstants.USTID);
- sellerTaxRegistration.setID(sellerUstId);
- sellerTradeParty.getSpecifiedTaxRegistration().add(
- sellerTaxRegistration);
-
- return sellerTradeParty;
- }
-
-
- /**
- * If the ship-to party (e.g. in the case of international transactions) or, in the case of virtual goods, the recipient has to be shown separately on an
- * invoice, then this is done by adding the ShipToTradeParty
- */
- private TradePartyType getShipToParty() {
- if (trans.getShipToOrganisationName() == null) {
- return null;
- }
-
- TradePartyType shipToParty = xmlFactory.createTradePartyType();
-
- if (trans.getShipToOrganisationID() != null) {
- IDType sellerID = xmlFactory.createIDType();
- sellerID.setValue(trans.getShipToOrganisationID());
- shipToParty.getID().add(sellerID);
- }
-
- TextType shipToName = xmlFactory.createTextType();
- shipToName.setValue(trans.getShipToOrganisationName());
- shipToParty.setName(shipToName);
-
- if (trans.getShipToLocation() != null) {
- TradeAddressType shipToAddressType = xmlFactory
- .createTradeAddressType();
- TextType shipToCityName = xmlFactory.createTextType();
- shipToCityName.setValue(trans.getShipToLocation());
- shipToAddressType.setCityName(shipToCityName);
-
- CountryIDType shipToCountryId = xmlFactory.createCountryIDType();
- shipToCountryId.setValue(trans.getShipToCountry());
- shipToAddressType.setCountryID(shipToCountryId);
-
- TextType shipToAddress = xmlFactory.createTextType();
- shipToAddress.setValue(trans.getShipToStreet());
- shipToAddressType.setLineOne(shipToAddress);
-
- CodeType shipToPostcode = xmlFactory.createCodeType();
- shipToPostcode.setValue(trans.getShipToZIP());
- shipToAddressType.getPostcodeCode().add(shipToPostcode);
-
- shipToParty.setPostalTradeAddress(shipToAddressType);
- }
-
- return shipToParty;
- }
-
-
- private SupplyChainTradeDeliveryType getTradeDelivery() {
-
- SupplyChainTradeDeliveryType tradeDelivery = xmlFactory
- .createSupplyChainTradeDeliveryType();
-
- if (getShipToParty() != null) {
- tradeDelivery.setShipToTradeParty(getShipToParty());
- }
-
- SupplyChainEventType deliveryEvent = xmlFactory
- .createSupplyChainEventType();
- DateTimeType deliveryDate = xmlFactory.createDateTimeType();
- DateTimeType.DateTimeString deliveryDateString = xmlFactory
- .createDateTimeTypeDateTimeString();
- IZUGFeRDDate zfDeliveryDate = trans.getZFDeliveryDate();
- if (zfDeliveryDate != null) {
- ZUGFeRDDateFormat deliveryDateFormat = zfDeliveryDate.getFormat();
- deliveryDateString.setFormat(deliveryDateFormat.getDateTimeType());
- deliveryDateString.setValue(
- deliveryDateFormat.getFormatter().format(zfDeliveryDate.getDate()));
- } else if (trans.getDeliveryDate() != null) {
- deliveryDateString.setFormat(DateTimeTypeConstants.DATE);
- deliveryDateString.setValue(zugferdDateFormat.format(trans.getDeliveryDate()));
- } else {
- throw new IllegalStateException("No delivery date provided");
- }
- deliveryDate.setDateTimeString(deliveryDateString);
- deliveryEvent.getOccurrenceDateTime().add(deliveryDate);
- tradeDelivery.getActualDeliverySupplyChainEvent().add(deliveryEvent);
-
- return tradeDelivery;
- }
-
-
- private SupplyChainTradeSettlementType getTradeSettlement() {
- SupplyChainTradeSettlementType tradeSettlement = xmlFactory
- .createSupplyChainTradeSettlementType();
-
- TextType paymentReference = xmlFactory.createTextType();
- paymentReference.setValue(trans.getNumber());
- tradeSettlement.getPaymentReference().add(paymentReference);
-
- CodeType currencyCode = xmlFactory.createCodeType();
- currencyCode.setValue(currency);
- tradeSettlement.setInvoiceCurrencyCode(currencyCode);
-
- tradeSettlement.getSpecifiedTradeSettlementPaymentMeans().addAll(
- getPaymentData());
- tradeSettlement.getApplicableTradeTax().addAll(getTradeTax());
- tradeSettlement.getSpecifiedTradePaymentTerms().addAll(
- getPaymentTerms());
- if (trans.getZFAllowances() != null) {
- tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll(
- getHeaderAllowances());
- }
- if (trans.getZFLogisticsServiceCharges() != null) {
- tradeSettlement.getSpecifiedLogisticsServiceCharge().addAll(
- getHeaderLogisticsServiceCharges());
- }
- if (trans.getZFCharges() != null) {
- tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll(
- getHeaderCharges());
- }
-
- tradeSettlement.setSpecifiedTradeSettlementMonetarySummation(getMonetarySummation());
-
- return tradeSettlement;
- }
-
-
- private List getPaymentData() {
- List result = new ArrayList<>();
- for (IZUGFeRDTradeSettlementPayment settlementPayment : trans.getTradeSettlementPayment()) {
- TradeSettlementPaymentMeansType paymentData = xmlFactory
- .createTradeSettlementPaymentMeansType();
- PaymentMeansCodeType paymentDataType = xmlFactory
- .createPaymentMeansCodeType();
- paymentDataType.setValue(PaymentMeansCodeTypeConstants.BANKACCOUNT);
- paymentData.setTypeCode(paymentDataType);
-
- TextType paymentInfo = xmlFactory.createTextType();
- String paymentInfoText = settlementPayment.getOwnPaymentInfoText();
- if (paymentInfoText == null) {
- paymentInfoText = "";
- }
- paymentInfo.setValue(paymentInfoText);
- paymentData.getInformation().add(paymentInfo);
-
- CreditorFinancialAccountType bankAccount = xmlFactory
- .createCreditorFinancialAccountType();
- IDType iban = xmlFactory.createIDType();
- iban.setValue(settlementPayment.getOwnIBAN());
- bankAccount.setIBANID(iban);
- IDType kto = xmlFactory.createIDType();
- kto.setValue(settlementPayment.getOwnKto());
- bankAccount.setProprietaryID(kto);
- paymentData.setPayeePartyCreditorFinancialAccount(bankAccount);
-
- CreditorFinancialInstitutionType bankData = xmlFactory
- .createCreditorFinancialInstitutionType();
- IDType bicId = xmlFactory.createIDType();
- bicId.setValue(settlementPayment.getOwnBIC());
- bankData.setBICID(bicId);
- TextType bankName = xmlFactory.createTextType();
- bankName.setValue(settlementPayment.getOwnBankName());
- bankData.setName(bankName);
- IDType blz = xmlFactory.createIDType();
- blz.setValue(settlementPayment.getOwnBLZ());
- bankData.setGermanBankleitzahlID(blz);
-
- paymentData.setPayeeSpecifiedCreditorFinancialInstitution(bankData);
- result.add(paymentData);
- }
- return result;
- }
-
-
- private Collection getTradeTax() {
- List tradeTaxTypes = new ArrayList<>();
-
- HashMap VATPercentAmountMap = this.getVATPercentAmountMap();
- for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
-
- TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
- TaxTypeCodeType taxTypeCode = xmlFactory.createTaxTypeCodeType();
- taxTypeCode.setValue(TaxTypeCodeTypeConstants.SALESTAX);
- tradeTax.setTypeCode(taxTypeCode);
-
- TaxCategoryCodeType taxCategoryCode = xmlFactory.createTaxCategoryCodeType();
- VATAmount vatAmount = VATPercentAmountMap.get(currentTaxPercent);
- taxCategoryCode.setValue(vatAmount.getCategoryCode());
- tradeTax.setCategoryCode(taxCategoryCode);
-
- VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
-
- PercentType taxPercent = xmlFactory.createPercentType();
- taxPercent.setValue(vatFormat(currentTaxPercent));
- tradeTax.setApplicablePercent(taxPercent);
-
- AmountType calculatedTaxAmount = xmlFactory.createAmountType();
- calculatedTaxAmount.setCurrencyID(currency);
- calculatedTaxAmount.setValue(currencyFormat(amount.getCalculated()));
- tradeTax.getCalculatedAmount().add(calculatedTaxAmount);
-
- AmountType basisTaxAmount = xmlFactory.createAmountType();
- basisTaxAmount.setCurrencyID(currency);
- basisTaxAmount.setValue(currencyFormat(amount.getBasis()));
- tradeTax.getBasisAmount().add(basisTaxAmount);
-
- tradeTaxTypes.add(tradeTax);
- }
-
- return tradeTaxTypes;
- }
-
-
- private Collection getHeaderAllowances() {
- List headerAllowances = new ArrayList<>();
-
- for (IZUGFeRDAllowanceCharge iAllowance : trans.getZFAllowances()) {
-
- TradeAllowanceChargeType allowance = xmlFactory.createTradeAllowanceChargeType();
- IndicatorType chargeIndicator = xmlFactory.createIndicatorType();
- chargeIndicator.setIndicator(false);
- allowance.setChargeIndicator(chargeIndicator);
-
- AmountType actualAmount = xmlFactory.createAmountType();
- actualAmount.setCurrencyID(currency);
- actualAmount.setValue(currencyFormat(iAllowance.getTotalAmount()));
- allowance.getActualAmount().add(actualAmount);
-
- TextType reason = xmlFactory.createTextType();
- reason.setValue(iAllowance.getReason());
- allowance.setReason(reason);
-
- TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
- PercentType vatPercent = xmlFactory.createPercentType();
- vatPercent.setValue(currencyFormat(iAllowance.getTaxPercent()));
- tradeTax.setApplicablePercent(vatPercent);
-
- /*
- * Only in extended AmountType basisAmount =
- * xmlFactory.createAmountType();
- * basisAmount.setCurrencyID(trans.getInvoiceCurrency());
- * basisAmount.setValue(amount.getBasis());
- * allowance.setBasisAmount(basisAmount);
- */
- TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
- taxType.setValue(iAllowance.getCategoryCode());
- tradeTax.setCategoryCode(taxType);
-
- TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
- taxCode.setValue(TaxTypeCodeTypeConstants.SALESTAX);
- tradeTax.setTypeCode(taxCode);
-
- allowance.getCategoryTradeTax().add(tradeTax);
- headerAllowances.add(allowance);
- }
-
- return headerAllowances;
- }
-
-
- private Collection getHeaderCharges() {
- List headerCharges = new ArrayList<>();
-
- for (IZUGFeRDAllowanceCharge iCharge : trans.getZFCharges()) {
-
- TradeAllowanceChargeType charge = xmlFactory.createTradeAllowanceChargeType();
- IndicatorType chargeIndicator = xmlFactory.createIndicatorType();
- chargeIndicator.setIndicator(true);
- charge.setChargeIndicator(chargeIndicator);
-
- AmountType actualAmount = xmlFactory.createAmountType();
- actualAmount.setCurrencyID(currency);
- actualAmount.setValue(currencyFormat(iCharge.getTotalAmount()));
- charge.getActualAmount().add(actualAmount);
-
- TextType reason = xmlFactory.createTextType();
- reason.setValue(iCharge.getReason());
- charge.setReason(reason);
-
- TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
- PercentType vatPercent = xmlFactory.createPercentType();
- vatPercent.setValue(currencyFormat(iCharge.getTaxPercent()));
- tradeTax.setApplicablePercent(vatPercent);
-
- /*
- * Only in extended AmountType basisAmount =
- * xmlFactory.createAmountType();
- * basisAmount.setCurrencyID(trans.getInvoiceCurrency());
- * basisAmount.setValue(amount.getBasis());
- * allowance.setBasisAmount(basisAmount);
- */
- TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
- taxType.setValue(iCharge.getCategoryCode());
- tradeTax.setCategoryCode(taxType);
-
- TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
- taxCode.setValue(TaxTypeCodeTypeConstants.SALESTAX);
- tradeTax.setTypeCode(taxCode);
-
- charge.getCategoryTradeTax().add(tradeTax);
- headerCharges.add(charge);
-
- }
-
- return headerCharges;
- }
-
-
- private Collection getHeaderLogisticsServiceCharges() {
- List headerServiceCharge = new ArrayList<>();
-
- for (IZUGFeRDAllowanceCharge iServiceCharge : trans.getZFLogisticsServiceCharges()) {
-
- LogisticsServiceChargeType serviceCharge = xmlFactory.createLogisticsServiceChargeType();
-
- AmountType actualAmount = xmlFactory.createAmountType();
- actualAmount.setCurrencyID(currency);
- actualAmount.setValue(currencyFormat(iServiceCharge.getTotalAmount()));
- serviceCharge.getAppliedAmount().add(actualAmount);
-
- TextType reason = xmlFactory.createTextType();
- reason.setValue(iServiceCharge.getReason());
- serviceCharge.getDescription().add(reason);
-
- TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
-
- PercentType vatPercent = xmlFactory.createPercentType();
- vatPercent.setValue(currencyFormat(iServiceCharge.getTaxPercent()));
- tradeTax.setApplicablePercent(vatPercent);
-
- /*
- * Only in extended AmountType basisAmount =
- * xmlFactory.createAmountType();
- * basisAmount.setCurrencyID(trans.getInvoiceCurrency());
- * basisAmount.setValue(amount.getBasis());
- * allowance.setBasisAmount(basisAmount);
- */
- TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
- taxType.setValue(iServiceCharge.getCategoryCode());
- tradeTax.setCategoryCode(taxType);
-
- TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
- taxCode.setValue(TaxTypeCodeTypeConstants.SALESTAX);
- tradeTax.setTypeCode(taxCode);
-
- serviceCharge.getAppliedTradeTax().add(tradeTax);
- headerServiceCharge.add(serviceCharge);
-
- }
-
- return headerServiceCharge;
- }
-
-
- private Collection getPaymentTerms() {
- if (trans.getPaymentTerms() != null) {
- return handlePaymentTermsObject(trans.getPaymentTerms());
- }
- List paymentTerms = new ArrayList<>();
-
- TradePaymentTermsType paymentTerm = xmlFactory
- .createTradePaymentTermsType();
- DateTimeType dueDate = xmlFactory.createDateTimeType();
- DateTimeType.DateTimeString dueDateString = xmlFactory
- .createDateTimeTypeDateTimeString();
- dueDateString.setFormat(DateTimeTypeConstants.DATE);
- dueDateString.setValue(zugferdDateFormat.format(trans.getDueDate()));
- dueDate.setDateTimeString(dueDateString);
- paymentTerm.setDueDateDateTime(dueDate);
-
- TextType paymentTermDescr = xmlFactory.createTextType();
-
- String paymentTermDescription = trans.getPaymentTermDescription();
- if (paymentTermDescription == null) {
- paymentTermDescription = "";
- }
- paymentTermDescr.setValue(paymentTermDescription);
- paymentTerm.getDescription().add(paymentTermDescr);
-
- paymentTerms.add(paymentTerm);
-
- return paymentTerms;
- }
-
- private Collection handlePaymentTermsObject(IZUGFeRDPaymentTerms paymentTerms) {
- List xmlPaymentTerms = new ArrayList<>();
-
- TradePaymentTermsType paymentTerm = xmlFactory.createTradePaymentTermsType();
-
- TextType paymentTermDescr = xmlFactory.createTextType();
-
- String paymentTermDescription = paymentTerms.getDescription();
- if (paymentTermDescription == null) {
- paymentTermDescription = "";
- }
- paymentTermDescr.setValue(paymentTermDescription);
- paymentTerm.getDescription().add(paymentTermDescr);
-
- IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
- if (paymentTerms.getDueDate() != null && discountTerms != null && discountTerms.getBaseDate() != null) {
- throw new IllegalStateException(
- "if paymentTerms.dueDate is specified, paymentTerms.discountTerms.baseDate has not to be specified");
- }
-
- if (paymentTerms.getDueDate() != null) {
- DateTimeType dueDate = xmlFactory.createDateTimeType();
- DateTimeType.DateTimeString dueDateString = xmlFactory.createDateTimeTypeDateTimeString();
- dueDateString.setFormat(paymentTerms.getDueDate().getFormat().getDateTimeType());
- dueDateString.setValue(
- paymentTerms.getDueDate().getFormat().getFormatter().format(paymentTerms.getDueDate().getDate()));
- dueDate.setDateTimeString(dueDateString);
- paymentTerm.setDueDateDateTime(dueDate);
- }
-
- if (discountTerms != null) {
- TradePaymentDiscountTermsType tradePaymentDiscountTerms = xmlFactory.createTradePaymentDiscountTermsType();
-
- PercentType calculationPercent = xmlFactory.createPercentType();
- calculationPercent.setValue(discountTerms.getCalculationPercentage());
- tradePaymentDiscountTerms.setCalculationPercent(calculationPercent);
-
- AmountType basisAmount = xmlFactory.createAmountType();
- basisAmount.setCurrencyID(currency);
- basisAmount.setValue(currencyFormat(totals.totalGrossAmount));
- tradePaymentDiscountTerms.getBasisAmount().add(basisAmount);
-
- if (discountTerms.getBaseDate() != null) {
- DateTimeType baseDate = xmlFactory.createDateTimeType();
- DateTimeType.DateTimeString baseDateString = xmlFactory.createDateTimeTypeDateTimeString();
- baseDateString.setFormat(discountTerms.getBaseDate().getFormat().getDateTimeType());
- baseDateString.setValue(discountTerms.getBaseDate().getFormat().getFormatter()
- .format(discountTerms.getBaseDate().getDate()));
- baseDate.setDateTimeString(baseDateString);
- tradePaymentDiscountTerms.setBasisDateTime(baseDate);
-
- MeasureType basisPeriodMeasure = xmlFactory.createMeasureType();
- basisPeriodMeasure.setUnitCode(discountTerms.getBasePeriodUnitCode());
- basisPeriodMeasure.setValue(new BigDecimal(discountTerms.getBasePeriodMeasure()));
- tradePaymentDiscountTerms.setBasisPeriodMeasure(basisPeriodMeasure);
- }
- paymentTerm.getApplicableTradePaymentDiscountTerms().add(tradePaymentDiscountTerms);
- }
- xmlPaymentTerms.add(paymentTerm);
-
- return xmlPaymentTerms;
- }
-
-
- private TradeSettlementMonetarySummationType getMonetarySummation() {
- TradeSettlementMonetarySummationType monetarySummation = xmlFactory
- .createTradeSettlementMonetarySummationType();
-
- // AllowanceTotalAmount = sum of all allowances
- AmountType allowanceTotalAmount = xmlFactory.createAmountType();
- allowanceTotalAmount.setCurrencyID(currency);
- if (trans.getZFAllowances() != null) {
- BigDecimal totalHeaderAllowance = BigDecimal.ZERO;
- for (IZUGFeRDAllowanceCharge headerAllowance : trans
- .getZFAllowances()) {
- totalHeaderAllowance = headerAllowance.getTotalAmount().add(
- totalHeaderAllowance);
- }
- allowanceTotalAmount.setValue(currencyFormat(totalHeaderAllowance));
- } else {
- allowanceTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
- }
- monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount);
-
- // ChargeTotalAmount = sum of all Logistic service charges + normal
- // charges
- BigDecimal totalCharge = BigDecimal.ZERO;
- AmountType totalChargeAmount = xmlFactory.createAmountType();
- totalChargeAmount.setCurrencyID(currency);
- if (trans.getZFLogisticsServiceCharges() != null) {
- for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans
- .getZFLogisticsServiceCharges()) {
- totalCharge = logisticsServiceCharge.getTotalAmount().add(
- totalCharge);
- }
- }
- if (trans.getZFCharges() != null) {
- for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()) {
- totalCharge = charge.getTotalAmount().add(totalCharge);
- }
- }
-
- totalChargeAmount.setValue(currencyFormat(totalCharge));
-
- monetarySummation.getChargeTotalAmount().add(totalChargeAmount);
-
- /*
- * AmountType chargeTotalAmount = xmlFactory.createAmountType();
- * chargeTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
- * chargeTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
- * monetarySummation.getChargeTotalAmount().add(chargeTotalAmount);
- */
-
- AmountType lineTotalAmount = xmlFactory.createAmountType();
- lineTotalAmount.setCurrencyID(currency);
- lineTotalAmount.setValue(currencyFormat(totals.getLineTotal()));
- monetarySummation.getLineTotalAmount().add(lineTotalAmount);
-
- AmountType taxBasisTotalAmount = xmlFactory.createAmountType();
- taxBasisTotalAmount.setCurrencyID(currency);
- taxBasisTotalAmount.setValue(currencyFormat(totals.getTotalNet()));
- monetarySummation.getTaxBasisTotalAmount().add(taxBasisTotalAmount);
-
- AmountType taxTotalAmount = xmlFactory.createAmountType();
- taxTotalAmount.setCurrencyID(currency);
- taxTotalAmount.setValue(currencyFormat(totals.getTaxTotal()));
- monetarySummation.getTaxTotalAmount().add(taxTotalAmount);
-
- AmountType grandTotalAmount = xmlFactory.createAmountType();
- grandTotalAmount.setCurrencyID(currency);
- grandTotalAmount.setValue(currencyFormat(totals.getTotalGross()));
- monetarySummation.getGrandTotalAmount().add(grandTotalAmount);
-
- AmountType totalPrepaidAmount = xmlFactory.createAmountType();
- totalPrepaidAmount.setCurrencyID(currency);
- totalPrepaidAmount.setValue(currencyFormat(trans.getTotalPrepaidAmount()));
- monetarySummation.getTotalPrepaidAmount().add(totalPrepaidAmount);
-
- AmountType duePayableAmount = xmlFactory.createAmountType();
- duePayableAmount.setCurrencyID(currency);
- duePayableAmount.setValue(currencyFormat(totals.getTotalGross().subtract(trans.getTotalPrepaidAmount())));
- monetarySummation.getDuePayableAmount().add(duePayableAmount);
-
- return monetarySummation;
- }
-
-
- private Collection getLineItems() {
-
- ArrayList lineItems = new ArrayList<>();
- int lineID = 0;
- for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
- lineID++;
- LineCalc lc = new LineCalc(currentItem);
- SupplyChainTradeLineItemType lineItem = xmlFactory
- .createSupplyChainTradeLineItemType();
-
- DocumentLineDocumentType lineDocument = xmlFactory
- .createDocumentLineDocumentType();
- IDType lineNumber = xmlFactory.createIDType();
- lineNumber.setValue(Integer.toString(lineID));
- lineDocument.setLineID(lineNumber);
- lineItem.setAssociatedDocumentLineDocument(lineDocument);
-
- SupplyChainTradeAgreementType tradeAgreement = xmlFactory
- .createSupplyChainTradeAgreementType();
- TradePriceType grossTradePrice = xmlFactory.createTradePriceType();
- QuantityType grossQuantity = xmlFactory.createQuantityType();
- grossQuantity.setUnitCode(currentItem.getProduct().getUnit());
- grossQuantity.setValue(quantityFormat(BigDecimal.ONE));
- grossTradePrice.setBasisQuantity(grossQuantity);
-
- AmountType grossChargeAmount = xmlFactory.createAmountType();
- grossChargeAmount.setCurrencyID(currency);
- grossChargeAmount.setValue(priceFormat(currentItem.getPrice()));
- grossTradePrice.getChargeAmount().add(grossChargeAmount);
- tradeAgreement.getGrossPriceProductTradePrice()
- .add(grossTradePrice);
-
- if (currentItem.getItemAllowances() != null) {
- for (IZUGFeRDAllowanceCharge itemAllowance : currentItem
- .getItemAllowances()) {
- TradeAllowanceChargeType eItemAllowance = xmlFactory
- .createTradeAllowanceChargeType();
- IndicatorType chargeIndicator = xmlFactory
- .createIndicatorType();
- chargeIndicator.setIndicator(false);
- eItemAllowance.setChargeIndicator(chargeIndicator);
- AmountType actualAmount = xmlFactory.createAmountType();
- actualAmount.setCurrencyID(currency);
- actualAmount.setValue(priceFormat(itemAllowance
- .getTotalAmount().divide(currentItem.getQuantity(),
- 4, BigDecimal.ROUND_HALF_UP)));
- eItemAllowance.getActualAmount().add(actualAmount);
- TextType reason = xmlFactory.createTextType();
- reason.setValue(itemAllowance.getReason());
- eItemAllowance.setReason(reason);
- grossTradePrice.getAppliedTradeAllowanceCharge().add(
- eItemAllowance);
- }
- }
-
- if (currentItem.getItemCharges() != null) {
- for (IZUGFeRDAllowanceCharge itemCharge : currentItem
- .getItemCharges()) {
- TradeAllowanceChargeType eItemCharge = xmlFactory
- .createTradeAllowanceChargeType();
- AmountType actualAmount = xmlFactory.createAmountType();
- actualAmount.setCurrencyID(currency);
- actualAmount.setValue(priceFormat(itemCharge
- .getTotalAmount().divide(currentItem.getQuantity(),
- 4, BigDecimal.ROUND_HALF_UP)));
- eItemCharge.getActualAmount().add(actualAmount);
- TextType reason = xmlFactory.createTextType();
- reason.setValue(itemCharge.getReason());
- eItemCharge.setReason(reason);
- IndicatorType chargeIndicator = xmlFactory
- .createIndicatorType();
- chargeIndicator.setIndicator(true);
- eItemCharge.setChargeIndicator(chargeIndicator);
- grossTradePrice.getAppliedTradeAllowanceCharge().add(
- eItemCharge);
- }
- }
-
- TradePriceType netTradePrice = xmlFactory.createTradePriceType();
- QuantityType netQuantity = xmlFactory.createQuantityType();
- netQuantity.setUnitCode(currentItem.getProduct().getUnit());
- netQuantity.setValue(quantityFormat(BigDecimal.ONE));
- netTradePrice.setBasisQuantity(netQuantity);
-
- AmountType netChargeAmount = xmlFactory.createAmountType();
- netChargeAmount.setCurrencyID(currency);
- netChargeAmount.setValue(priceFormat(lc.getItemNetAmount()));
- netTradePrice.getChargeAmount().add(netChargeAmount);
- tradeAgreement.getNetPriceProductTradePrice().add(netTradePrice);
-
- lineItem.setSpecifiedSupplyChainTradeAgreement(tradeAgreement);
-
- SupplyChainTradeDeliveryType tradeDelivery = xmlFactory
- .createSupplyChainTradeDeliveryType();
- QuantityType billedQuantity = xmlFactory.createQuantityType();
- billedQuantity.setUnitCode(currentItem.getProduct().getUnit());
- billedQuantity.setValue(quantityFormat(currentItem.getQuantity()));
- tradeDelivery.setBilledQuantity(billedQuantity);
- lineItem.setSpecifiedSupplyChainTradeDelivery(tradeDelivery);
-
- SupplyChainTradeSettlementType tradeSettlement = xmlFactory
- .createSupplyChainTradeSettlementType();
- TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
-
- TaxCategoryCodeType taxCategoryCode = xmlFactory.createTaxCategoryCodeType();
- taxCategoryCode.setValue(currentItem.getCategoryCode());
- tradeTax.setCategoryCode(taxCategoryCode);
-
- TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType();
- taxCode.setValue(TaxTypeCodeTypeConstants.SALESTAX);
- tradeTax.setTypeCode(taxCode);
-
- PercentType taxPercent = xmlFactory.createPercentType();
- taxPercent.setValue(vatFormat(currentItem.getProduct()
- .getVATPercent()));
- tradeTax.setApplicablePercent(taxPercent);
- tradeSettlement.getApplicableTradeTax().add(tradeTax);
-
- TradeSettlementMonetarySummationType monetarySummation = xmlFactory
- .createTradeSettlementMonetarySummationType();
- AmountType itemAmount = xmlFactory.createAmountType();
- itemAmount.setCurrencyID(currency);
- itemAmount.setValue(currencyFormat(lc.getItemTotalNetAmount()));
- monetarySummation.getLineTotalAmount().add(itemAmount);
- tradeSettlement
- .setSpecifiedTradeSettlementMonetarySummation(monetarySummation);
-
- lineItem.setSpecifiedSupplyChainTradeSettlement(tradeSettlement);
-
- TradeProductType tradeProduct = xmlFactory.createTradeProductType();
- TextType productName = xmlFactory.createTextType();
- productName.setValue(currentItem.getProduct().getName());
- tradeProduct.getName().add(productName);
-
- TextType productDescription = xmlFactory.createTextType();
- productDescription.setValue(currentItem.getProduct()
- .getDescription());
- tradeProduct.getDescription().add(productDescription);
- lineItem.setSpecifiedTradeProduct(tradeProduct);
-
- lineItems.add(lineItem);
- }
-
- return lineItems;
- }
-
-
- private BigDecimal vatFormat(BigDecimal value) {
- return value.setScale(2, RoundingMode.HALF_UP);
- }
-
-
- private BigDecimal currencyFormat(BigDecimal value) {
- return value.setScale(2, RoundingMode.HALF_UP);
- }
-
-
- private BigDecimal priceFormat(BigDecimal value) {
- return value.setScale(4, RoundingMode.HALF_UP);
- }
-
-
- private BigDecimal quantityFormat(BigDecimal value) {
- return value.setScale(4, RoundingMode.HALF_UP);
- }
-
-
- /**
- * which taxes have been used with which amounts in this transaction, empty for no taxes, or e.g. 19=>190 and 7=>14 if 1000 Eur were applicable to 19% VAT
- * (=>190 EUR VAT) and 200 EUR were applicable to 7% (=>14 EUR VAT) 190 Eur
- *
- * @return HashMap which taxes have been used with which amounts
- */
- private HashMap getVATPercentAmountMap() {
- return getVATPercentAmountMap(false);
- }
-
-
- private HashMap getVATPercentAmountMap(Boolean itemOnly) {
- HashMap hm = new HashMap<>();
-
- for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
- BigDecimal percent = currentItem.getProduct().getVATPercent();
- LineCalc lc = new LineCalc(currentItem);
- VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(), lc.getCategoryCode());
- VATAmount current = hm.get(percent);
- if (current == null) {
- hm.put(percent, itemVATAmount);
- } else {
- hm.put(percent, current.add(itemVATAmount));
- }
- }
- if (itemOnly) {
- return hm;
- }
- if (trans.getZFAllowances() != null) {
- for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()) {
- BigDecimal percent = headerAllowance.getTaxPercent();
- VATAmount itemVATAmount = new VATAmount(
- headerAllowance.getTotalAmount(), headerAllowance
- .getTotalAmount().multiply(percent)
- .divide(new BigDecimal(100)),
- trans.getDocumentCode());
- VATAmount current = hm.get(percent);
- if (current == null) {
- hm.put(percent, itemVATAmount);
- } else {
- hm.put(percent, current.subtract(itemVATAmount));
- }
- }
- }
-
- if (trans.getZFLogisticsServiceCharges() != null) {
- for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans
- .getZFLogisticsServiceCharges()) {
- BigDecimal percent = logisticsServiceCharge.getTaxPercent();
- VATAmount itemVATAmount = new VATAmount(
- logisticsServiceCharge.getTotalAmount(),
- logisticsServiceCharge.getTotalAmount()
- .multiply(percent).divide(new BigDecimal(100)),
- logisticsServiceCharge.getCategoryCode());
- VATAmount current = hm.get(percent);
- if (current == null) {
- hm.put(percent, itemVATAmount);
- } else {
- hm.put(percent, current.add(itemVATAmount));
- }
- }
- }
-
- if (trans.getZFCharges() != null) {
- for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()) {
- BigDecimal percent = charge.getTaxPercent();
- VATAmount itemVATAmount = new VATAmount(
- charge.getTotalAmount(), charge.getTotalAmount()
- .multiply(percent).divide(new BigDecimal(100)),
- charge.getCategoryCode());
- VATAmount current = hm.get(percent);
- if (current == null) {
- hm.put(percent, itemVATAmount);
- } else {
- hm.put(percent, current.add(itemVATAmount));
- }
- }
- }
-
- return hm;
- }
-
-
- ZUGFeRDTransactionModelConverter withTest(boolean isTest) {
- this.isTest = isTest;
- return this;
- }
-
-
- public ZUGFeRDTransactionModelConverter withProfile(String profile) {
- this.profile = profile;
- return this;
- }
-
- private class LineCalc {
-
- private BigDecimal totalGross;
- private BigDecimal itemTotalNetAmount;
- private BigDecimal itemTotalVATAmount;
- private BigDecimal itemNetAmount;
- private String categoryCode;
-
-
- public LineCalc(IZUGFeRDExportableItem currentItem) {
- BigDecimal totalAllowance = BigDecimal.ZERO;
- BigDecimal totalCharge = BigDecimal.ZERO;
-
- if (currentItem.getItemAllowances() != null) {
- for (IZUGFeRDAllowanceCharge itemAllowance : currentItem
- .getItemAllowances()) {
- totalAllowance = itemAllowance.getTotalAmount().add(
- totalAllowance);
- }
- }
-
- if (currentItem.getItemCharges() != null) {
- for (IZUGFeRDAllowanceCharge itemCharge : currentItem
- .getItemCharges()) {
- totalCharge = itemCharge.getTotalAmount().add(totalCharge);
- }
- }
-
- BigDecimal multiplicator = currentItem.getProduct().getVATPercent()
- .divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP)
- .add(BigDecimal.ONE);
- // priceGross=currentItem.getPrice().multiply(multiplicator);
-
- totalGross = currentItem.getPrice()
- .multiply(currentItem.getQuantity())
- .subtract(totalAllowance).add(totalCharge)
- .multiply(multiplicator);
- itemTotalNetAmount = currentItem.getPrice()
- .multiply(currentItem.getQuantity())
- .subtract(totalAllowance).add(totalCharge)
- .setScale(2, BigDecimal.ROUND_HALF_UP);
- itemTotalVATAmount = totalGross.subtract(itemTotalNetAmount);
- itemNetAmount = currentItem
- .getPrice()
- .multiply(currentItem.getQuantity())
- .subtract(totalAllowance)
- .add(totalCharge)
- .divide(currentItem.getQuantity(), 4,
- BigDecimal.ROUND_HALF_UP);
- categoryCode = currentItem.getCategoryCode();
- }
-
-
- public BigDecimal getItemTotalNetAmount() {
- return itemTotalNetAmount;
- }
-
-
- public BigDecimal getItemTotalVATAmount() {
- return itemTotalVATAmount;
- }
-
-
- public BigDecimal getItemNetAmount() {
- return itemNetAmount;
- }
-
-
- public String getCategoryCode() {
- return categoryCode;
- }
-
- }
-
- private class Totals {
- private BigDecimal totalNetAmount;
- private BigDecimal totalGrossAmount;
- private BigDecimal lineTotalAmount;
- private BigDecimal totalTaxAmount;
-
-
- public Totals() {
- BigDecimal res = BigDecimal.ZERO;
- for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
- LineCalc lc = new LineCalc(currentItem);
- res = res.add(lc.getItemTotalNetAmount());
- }
- // Set line total
- lineTotalAmount = res;
-
- if (trans.getZFAllowances() != null) {
- for (IZUGFeRDAllowanceCharge headerAllowance : trans
- .getZFAllowances()) {
- res = res.subtract(headerAllowance.getTotalAmount());
- }
- }
-
- if (trans.getZFLogisticsServiceCharges() != null) {
- for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans
- .getZFLogisticsServiceCharges()) {
- res = res.add(logisticsServiceCharge.getTotalAmount());
- }
- }
-
- if (trans.getZFCharges() != null) {
- for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()) {
- res = res.add(charge.getTotalAmount());
- }
- }
-
- // Set total net amount
- totalNetAmount = res;
-
- HashMap vatAmountHashMap = getVATPercentAmountMap();
- for (VATAmount amount : vatAmountHashMap.values()) {
- res = res.add(amount.getCalculated());
- }
-
- // Set total gross amount
- totalGrossAmount = res;
-
- totalTaxAmount = totalGrossAmount
- .subtract(totalNetAmount);
- }
-
-
- public BigDecimal getTotalNet() {
- return totalNetAmount;
- }
-
-
- public BigDecimal getTotalGross() {
- return totalGrossAmount;
- }
-
-
- public BigDecimal getLineTotal() {
- return lineTotalAmount;
- }
-
-
- public BigDecimal getTaxTotal() {
- return totalTaxAmount;
- }
-
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java
deleted file mode 100644
index eb75f9dd..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD;
-
-import javax.xml.transform.*;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class ZUGFeRDVisualizer {
-
- static final ClassLoader CLASS_LOADER = ZUGFeRDVisualizer.class.getClassLoader();
- private static final String RESOURCE_PATH = ""; //$NON-NLS-1$
- private static final Logger LOG = Logger.getLogger(ZUGFeRDVisualizer.class.getName());
- // private static File createTempFileResult(final Transformer transformer, final
- // StreamSource toTransform,
- // final String suffix) throws TransformerException, IOException {
- // File result = File.createTempFile("ZUV_", suffix); //$NON-NLS-1$
- // result.deleteOnExit();
- //
- // try (FileOutputStream fos = new FileOutputStream(result)) {
- // transformer.transform(toTransform, new StreamResult(fos));
- // }
- // return result;
- // }
- private TransformerFactory mFactory = null;
- private Templates mXsltXRTemplate = null;
- private Templates mXsltHTMLTemplate = null;
- private Templates mXsltZF1HTMLTemplate = null;
-
- public ZUGFeRDVisualizer() {
- mFactory = new net.sf.saxon.TransformerFactoryImpl();
- // fact = TransformerFactory.newInstance();
- mFactory.setURIResolver(new ClasspathResourceURIResolver());
- try {
- mXsltXRTemplate = mFactory.newTemplates(
- new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "stylesheets/cii-xr.xsl")));
- mXsltHTMLTemplate = mFactory.newTemplates(new StreamSource(
- CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "stylesheets/xrechnung-html.xsl")));
- mXsltZF1HTMLTemplate = mFactory.newTemplates(new StreamSource(
- CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + "stylesheets/ZUGFeRD_1p0_c1p0_s1p0.xslt")));
- } catch (TransformerConfigurationException ex) {
- LOG.log(Level.SEVERE, null, ex);
- }
- }
-
- public String visualize(String xmlFilename)
- throws FileNotFoundException, TransformerException, UnsupportedEncodingException {
- /**
- * *
- * http://www.unece.org/fileadmin/DAM/cefact/xml/XML-Naming-And-Design-Rules-V2_1.pdf
- * http://www.ferd-net.de/upload/Dokumente/FACTUR-X_ZUGFeRD_2p0_Teil1_Profil_EN16931_1p03.pdf
- * http://countwordsfree.com/xmlviewer
- */
- FileInputStream fis=new FileInputStream(xmlFilename);
- String fileContent="";
- try {
- fileContent = new String(Files.readAllBytes(Paths.get(xmlFilename)));
- } catch (IOException e2) {
- LOG.log(Level.SEVERE, null, e2);
- }
-
- ByteArrayOutputStream iaos = new ByteArrayOutputStream();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- String zf1Signature = "rsm:CrossIndustryDocument";
- if (fileContent.contains(zf1Signature)) {
- applyZF1SchematronXsl(fis, baos);
-
- } else {
- //zf2 or fx
- applySchematronXsl(fis, iaos);
- // take the copy of the stream and re-write it to an InputStream
- PipedInputStream in = new PipedInputStream();
- PipedOutputStream out;
- try {
- out = new PipedOutputStream(in);
- new Thread(new Runnable() {
- public void run() {
- try {
- // write the original OutputStream to the PipedOutputStream
- // note that in order for the below method to work, you need
- // to ensure that the data has finished writing to the
- // ByteArrayOutputStream
- iaos.writeTo(out);
- } catch (IOException e) {
- LOG.log(Level.SEVERE, null, e);
- } finally {
- // close the PipedOutputStream here because we're done writing data
- // once this thread has completed its run
- if (out != null) {
- // close the PipedOutputStream cleanly
- try {
- out.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- LOG.log(Level.SEVERE, null, e);
- }
- }
- }
- }
- }).start();
- applySchematronXsl2(in, baos);
- } catch (IOException e1) {
- LOG.log(Level.SEVERE, null, e1);
- }
- }
-
- return baos.toString("UTF-8");
- }
-
- public void applySchematronXsl(final InputStream xmlFile, final OutputStream HTMLOutstream)
- throws TransformerException {
- Transformer transformer = mXsltXRTemplate.newTransformer();
-
- transformer.transform(new StreamSource(xmlFile), new StreamResult(HTMLOutstream));
- }
-
- public void applyZF1SchematronXsl(final InputStream xmlFile, final OutputStream HTMLOutstream)
- throws TransformerException {
- Transformer transformer = mXsltZF1HTMLTemplate.newTransformer();
-
- transformer.transform(new StreamSource(xmlFile), new StreamResult(HTMLOutstream));
- }
-
- public void applySchematronXsl2(final InputStream xmlFile, final OutputStream HTMLOutstream)
- throws TransformerException {
- Transformer transformer = mXsltHTMLTemplate.newTransformer();
-
- transformer.transform(new StreamSource(xmlFile), new StreamResult(HTMLOutstream));
- }
-
- private static class ClasspathResourceURIResolver implements URIResolver {
- ClasspathResourceURIResolver() {
- // Do nothing, just prevents synthetic access warning.
- }
-
- @Override
- public Source resolve(String href, String base) throws TransformerException {
- return new StreamSource(CLASS_LOADER.getResourceAsStream(RESOURCE_PATH + href));
- }
- }
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/DateTimeTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/DateTimeTypeConstants.java
deleted file mode 100644
index 895aa899..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/DateTimeTypeConstants.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class DateTimeTypeConstants {
- public static final String DATE = "102";
- public static final String MONTH = "610";
- public static final String WEEK = "616";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/DocumentCodeTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/DocumentCodeTypeConstants.java
deleted file mode 100644
index 028c7874..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/DocumentCodeTypeConstants.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class DocumentCodeTypeConstants {
- public static final String INVOICE = "380";
- public static final String DEBITNOTE = "84";
- public static final String CREDITNOTE = "389";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/DocumentContextParameterTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/DocumentContextParameterTypeConstants.java
deleted file mode 100644
index d90eabd1..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/DocumentContextParameterTypeConstants.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class DocumentContextParameterTypeConstants {
- public static final String BASIC = "urn:ferd:CrossIndustryDocument:invoice:1p0:basic";
- public static final String COMFORT = "urn:ferd:CrossIndustryDocument:invoice:1p0:comfort";
- public static final String EXTENDED = "urn:ferd:CrossIndustryDocument:invoice:1p0:extended";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/NoteTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/NoteTypeConstants.java
deleted file mode 100644
index 6b868dc6..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/NoteTypeConstants.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class NoteTypeConstants {
- public static final String GENERAL = "";
- public static final String REGULARINFO = "REG";
- public static final String PRICECONDITION = "AAK";
- public static final String CONDITIONS = "AAJ";
- public static final String PAYMENTINFO = "PMT";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/PaymentMeansCodeTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/PaymentMeansCodeTypeConstants.java
deleted file mode 100644
index fda92820..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/PaymentMeansCodeTypeConstants.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class PaymentMeansCodeTypeConstants {
- public static final String BANKACCOUNT = "42";
- public static final String NOTSPECIFIED = "1";
- public static final String AUTOMATICCLEARING = "3";
- public static final String CASH = "10";
- public static final String CHECK = "20";
- public static final String DEBITADVICE = "31";
- public static final String CREDITCARD = "48";
- public static final String DEBIT = "49";
- public static final String COMPENSATION = "97";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/QuantityTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/QuantityTypeConstants.java
deleted file mode 100644
index 99bc7033..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/QuantityTypeConstants.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class QuantityTypeConstants {
- public static final String PIECE = "C62";
- public static final String DAY = "DAY";
- public static final String HECTARE = "HAR";
- public static final String HOUR = "HUR";
- public static final String KILOGRAM = "KGM";
- public static final String KILOMETER = "KTM";
- public static final String KILOWATTHOUR = "KWH";
- public static final String FIXEDRATE = "LS";
- public static final String LITRE = "LTR";
- public static final String MINUTE = "MIN";
- public static final String SQUAREMILLIMETER = "MMK";
- public static final String MILLIMETER = "MMT";
- public static final String SQUAREMETER = "MTK";
- public static final String CUBICMETER = "MTQ";
- public static final String METER = "MTR";
- public static final String PRODUCTCOUNT = "NAR";
- public static final String PRODUCTPAIR = "NPR";
- public static final String PERCENT = "P1";
- public static final String SET = "SET";
- public static final String TON = "TNE";
- public static final String WEEK = "WEE";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/TaxCategoryCodeTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/TaxCategoryCodeTypeConstants.java
deleted file mode 100644
index 979207c8..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/TaxCategoryCodeTypeConstants.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class TaxCategoryCodeTypeConstants {
- public static final String STANDARDRATE = "S";
- public static final String REVERSECHARGE = "AE";
- public static final String TAXEXEMPT = "E";
- public static final String ZEROTAXPRODUCTS = "Z";
- public static final String UNTAXEDSERVICE = "O";
- public static final String INTRACOMMUNITY = "IC";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/TaxRegistrationTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/TaxRegistrationTypeConstants.java
deleted file mode 100644
index ff5c03f5..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/TaxRegistrationTypeConstants.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class TaxRegistrationTypeConstants {
- public static final String USTID = "VA";
- public static final String TAXID = "FC";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/TaxTypeCodeTypeConstants.java b/src/main/java/org/mustangproject/ZUGFeRD/model/TaxTypeCodeTypeConstants.java
deleted file mode 100644
index 46bb3e75..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/TaxTypeCodeTypeConstants.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-public class TaxTypeCodeTypeConstants {
- public static final String SALESTAX = "VAT";
- public static final String INSURANCETAX = "ZF_INSURANCE_TAX";
- public static final String OLDPART = "AAJ";
-}
diff --git a/src/main/java/org/mustangproject/ZUGFeRD/model/ZFNamespacePrefixMapper.java b/src/main/java/org/mustangproject/ZUGFeRD/model/ZFNamespacePrefixMapper.java
deleted file mode 100644
index 4b3f2915..00000000
--- a/src/main/java/org/mustangproject/ZUGFeRD/model/ZFNamespacePrefixMapper.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.ZUGFeRD.model;
-
-import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class ZFNamespacePrefixMapper extends NamespacePrefixMapper {
-
- private Map namespaceMap = new HashMap<>();
-
- /**
- * Create mappings.
- */
- public ZFNamespacePrefixMapper() {
-
- namespaceMap.put("urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:12", "ram");
- namespaceMap.put("urn:un:unece:uncefact:data:standard:UnqualifiedDataType:15", "udt");
- namespaceMap.put("urn:ferd:CrossIndustryDocument:invoice:1p0", "rsm");
- }
-
- /* (non-Javadoc)
- * Returning null when not found based on spec.
- * @see com.sun.xml.bind.marshaller.NamespacePrefixMapper#getPreferredPrefix(java.lang.String, java.lang.String, boolean)
- */
- @Override
- public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
- return namespaceMap.getOrDefault(namespaceUri, suggestion);
- }
-
-}
diff --git a/src/main/java/org/mustangproject/toecount/FileChecker.java b/src/main/java/org/mustangproject/toecount/FileChecker.java
deleted file mode 100755
index 27273e2e..00000000
--- a/src/main/java/org/mustangproject/toecount/FileChecker.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.toecount;
-
-import java.math.BigDecimal;
-
-import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
-
-public class FileChecker {
- String filename;
- StatRun thisRun;
- boolean isPDF = false;
-
- public FileChecker(String filename, StatRun statistics) {
- this.filename = filename;
- thisRun = statistics;
- thisRun.incFileCount();
- String extension = "";
- if (!thisRun.shallIgnoreFileExt()) {
- int extIndex = filename.lastIndexOf(".");
- if (extIndex >= 0) {
- extension = filename.substring(extIndex).toLowerCase();
- isPDF = extension.equals(".pdf");// alternative check for PDF: File starts with %PDF-
- if (isPDF) {
- thisRun.incPDFCount();
- }
- }
-
- } else {
- thisRun.incPDFCount();
- }
- }
-
- public boolean checkForZUGFeRD() {
- if ((!isPDF) && (!thisRun.shallIgnoreFileExt())) {
- return false;
- }
- ZUGFeRDImporter zi = new ZUGFeRDImporter(filename);
- try {
- if (zi.canParse()) {
- thisRun.incZUGFeRDCount(zi.getVersion());
- thisRun.incTotal(new BigDecimal(zi.getAmount()));
- return true;
- } else {
- return false;
- }
- } catch (NullPointerException e) {
- // something really rare happened -- corrupted ZF?
- /***
- * e.g. Exception in thread "main" java.lang.NullPointerException
- at org.mustangproject.ZUGFeRD.ZUGFeRDImporter.extractLowLevel(ZUGFeRDImporter.java:90)
- at org.mustangproject.ZUGFeRD.ZUGFeRDImporter.extract(ZUGFeRDImporter.java:64)
- at toecount.FileChecker.checkForZUGFeRD(FileChecker.java:33)
- at toecount.Toecount.main(Toecount.java:111)
- *
- */
- // Ignore nevertheless, most likely we're batch processing
- return false;
- } catch (Exception e2) {
- /**
- * probably thrown up from
- AM org.apache.pdfbox.pdfparser.PDFParser parse, most likely
- INFORMATION: Document is encrypted
- but also other internal PDF errors possible like
- ..Okt 23, 2015 11:17:53 AM org.apache.pdfbox.pdfparser.XrefTrailerResolver setStartxref
- */
- return false;
- }
- }
-
- public boolean isPDF() {
- return isPDF;
- }
-
- public String getOutputLine() {
- return thisRun.getOutputLine();
- }
-
-}
diff --git a/src/main/java/org/mustangproject/toecount/FileTraverser.java b/src/main/java/org/mustangproject/toecount/FileTraverser.java
deleted file mode 100755
index da530782..00000000
--- a/src/main/java/org/mustangproject/toecount/FileTraverser.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.toecount;
-
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-
-import static java.nio.file.FileVisitResult.CONTINUE;
-
-public class FileTraverser extends SimpleFileVisitor {
-
-
- private StatRun thisRun;
-
- public FileTraverser(StatRun statistics) {
- this.thisRun = statistics;
- }
-
- /**
- * check each file
- */
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
- if (attr.isSymbolicLink()) {
- // Not yet handled
- } else if (attr.isRegularFile()) {
- String filename = file.toString();
- FileChecker fc = new FileChecker(filename, thisRun);
- fc.checkForZUGFeRD();
- System.out.print(fc.getOutputLine());
-
- }
- return CONTINUE;
- }
-
- /**
- * for each directory
- */
- @Override
- public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
- // System.out.format("Directory: %s%n", dir);
- thisRun.incDirCount();
- return CONTINUE;
- }
-
-
- /**
- * show errors like file permission stacktraces
- */
- @Override
- public FileVisitResult visitFileFailed(Path file, IOException exc) {
- System.err.println(exc);
- return CONTINUE;
- }
-
-}
diff --git a/src/main/java/org/mustangproject/toecount/StatRun.java b/src/main/java/org/mustangproject/toecount/StatRun.java
deleted file mode 100755
index 8768850b..00000000
--- a/src/main/java/org/mustangproject/toecount/StatRun.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.toecount;
-
-import java.math.BigDecimal;
-
-public class StatRun {
- private int pdfCount = 0;
- private int horseCount = 0;
- private int fileCount = 0;
- private int dirCount = 0;
- private BigDecimal total = BigDecimal.ZERO;
- private boolean checkFileExt = true;
-
- public void ignoreFileExtension() {
- checkFileExt = false;
- }
-
- public boolean shallIgnoreFileExt() {
- return !checkFileExt;
- }
-
- public void incFileCount() {
- fileCount++;
- }
-
- public void incPDFCount() {
- pdfCount++;
- }
-
- public void incZUGFeRDCount(int version) {
- horseCount++;
- }
-
- public void incDirCount() {
- dirCount++;
- }
-
- public int getFileCount() {
- return fileCount;
- }
-
- public int getPDFCount() {
- return pdfCount;
- }
-
- public int getZUGFeRDCount() {
- return horseCount;
- }
-
- public int getDirCount() {
- return dirCount;
- }
-
- /**
- * returns final statistics
- *
- * @return english string with linefeeds detailling number of files, directories, number of pdfs and of zugferd files
- */
- public String getSummaryLine() {
-
- return "\r\n===================================================================\r\n" + String.format(
- "Files:\t%d\tDirs:\t%d\tPDF:\t%d\tZUGFeRD:\t%d\tTotal:\t%s\r\n",
- getFileCount(), getDirCount(), getPDFCount(), getZUGFeRDCount(), total.toString());
-
- }
-
- /**
- * show that something is happening
- *
- * @return String, usually a dot
- */
- public String getOutputLine() {
- return ".";
- }
-
- public void incTotal(BigDecimal delta) {
- total=total.add(delta);
-
- }
-
-
-}
diff --git a/src/main/java/org/mustangproject/toecount/Toecount.java b/src/main/java/org/mustangproject/toecount/Toecount.java
deleted file mode 100755
index a29e58c8..00000000
--- a/src/main/java/org/mustangproject/toecount/Toecount.java
+++ /dev/null
@@ -1,621 +0,0 @@
-/** **********************************************************************
- *
- * Copyright 2018 Jochen Staerk
- *
- * Use is subject to license terms.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *********************************************************************** */
-package org.mustangproject.toecount;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.transform.TransformerException;
-
-import org.mustangproject.ZUGFeRD.ZUGFeRDConformanceLevel;
-import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
-import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
-import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
-import org.mustangproject.ZUGFeRD.ZUGFeRDMigrator;
-
-/***
- * This is the command line interface to mustangproject
- *
- */
-
-import com.sanityinc.jargs.CmdLineParser;
-import com.sanityinc.jargs.CmdLineParser.Option;
-
-public class Toecount {
- // build with: /opt/local/bin/mvn clean compile assembly:single
- private static void printUsage() {
- System.err.println(getUsage());
- }
-
- private static String getUsage() {
- return "Usage: [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n"
- + "* Count operations\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n"
- + " If it is a directory, it will recurse.\n"
- + " -l, --listfromstdin count ZUGFeRD files from a list of linefeed separated files on runtime.\n"
- + " It will start once a blank line has been entered.\n" + "\n"
- + " Additional parameter for both count operations\n"
- + " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf)\n"
- + "\n" + "* Merge operations\n" + " -e, --extract extract ZUGFeRD PDF to XML file\n"
- + " Additional parameters (optional - user will be prompted if not defined)\n"
- + " [--source ]: set input PDF file\n"
- + " [--out ]: set output XML file\n"
- + " -u, --upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n"
- + " Additional parameters (optional - user will be prompted if not defined)\n"
- + " [--source ]: set input XML ZUGFeRD 1 file\n"
- + " [--out ]: set output XML ZUGFeRD 2 file\n"
- + " -a, --a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n"
- + " Additional parameters (optional - user will be prompted if not defined)\n"
- + " [--source ]: set input PDF file\n"
- + " [--out ]: set output PDF file\n"
- + " -c, --combine combine XML and PDF file to ZUGFeRD PDF file\n"
- + " Additional parameters (optional - user will be prompted if not defined)\n"
- + " [--source ]: set input PDF file\n"
- + " [--source-xml ]: set input XML file\n"
- + " [--out ]: set output PDF file\n"
- + " [--format ]: set ZUGFeRD or FacturX\n"
- + " [--version <1|2>]: set ZUGFeRD version\n"
- + " [--profile <...>]: set ZUGFeRD profile\n"
- + " For ZUGFeRD v1: ASIC, OMFORT or XTENDED\n"
- + " For ZUGFeRD v2: INIMUM, BASIC L, ASIC, IUS, N16931, ETENDED ";
- }
-
- private static void printHelp() {
- System.out.println("Mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + " \r\n"
- + "A Apache Public License library and command line tool for statistics on PDF invoices with\r\n"
- + "ZUGFeRD Metadata (http://www.zugferd.org)\r\n" + "\r\n" + getUsage() + "\r\n"
- + "* Count operations\r\n" + "\t-d, --directory\tcount ZUGFeRD files in directory to be scanned\r\n"
- + "\t\tIf it is a directory, it will recurse.\r\n"
- + "\t-l, --listfromstdin\tcount ZUGFeRD files from a list of linefeed separated files on runtime.\r\n"
- + "\t\tIt will start once a blank line has been entered.\r\n" + "\r\n"
- + "\tAdditional parameter for both count operations\r\n"
- + "\t[-i, --ignorefileextension]\tCheck for all files (*.*) instead of PDF files only (*.pdf)\r\n"
- + "\r\n" + "* Merge operations\r\n" + "\t-e, --extract\textract ZUGFeRD PDF to XML file\r\n"
- + "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
- + "\t\t[--source ]: set input PDF file\r\n"
- + "\t\t[--out ]: set output XML file\r\n"
- + "\t-u, --upgrade\tupgrade ZUGFeRD XML to ZUGFeRD 2 XML\r\n"
- + "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
- + "\t\t[--source ]: set input XML ZUGFeRD 1 file\r\n"
- + "\t\t[--out ]: set output XML ZUGFeRD 2 file\r\n"
- + "\t-a, --a3only\tupgrade from PDF/A1 to A3 only (no ZUGFeRD data attached) \r\n"
- + "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
- + "\t\t[--source ]: set input PDF file\r\n"
- + "\t\t[--out ]: set output PDF file\r\n"
- + "\t-c, --combine\tcombine XML and PDF file to ZUGFeRD PDF file\r\n"
- + "\t\tAdditional parameters (optional - user will be prompted if not defined)\r\n"
- + "\t\t[--source ]: set input PDF file\r\n"
- + "\t\t[--source-xml ]: set input XML file\r\n"
- + "\t\t[--out ]: set output PDF file\r\n"
- + "\t\t[--format ]: enable factur-x or ZUGFeRD\r\n"
- + "\t\t[--version <1|2>]: set ZUGFeRD version\r\n" + "\t\t[--profile <...>]: set ZUGFeRD profile\r\n"
- + "\t\t\tFor ZUGFeRD v1: ASIC, OMFORT or XTENDED\r\n"
- + "\t\t\tFor ZUGFeRD v2: INIMUM, BASIC L, ASIC, IUS, N16931, ETENDED\r\n");
- }
-
- /**
- * Asks the user (repeatedly, if neccessary) on the command line for a String
- * (offering a defaultValue) conforming to a Regex pattern
- *
- * @param prompt
- * the question to be asked to the user
- * @param defaultValue
- * the default return value if user hits enter
- * @param pattern
- * a regex of acceptable values
- * @return the user answer conforming to pattern
- * @throws Exception
- * if pattern not compielable or IOexception on input
- */
- protected static String getStringFromUser(String prompt, String defaultValue, String pattern) throws Exception {
- String input = "";
- if (!defaultValue.matches(pattern)) {
- throw new Exception("Default value must match pattern");
- }
- boolean firstInput = true;
- do {
- // for a more sophisticated dialogue maybe https://github.com/mabe02/lanterna/
- // could be taken into account
- System.out.print(prompt + " (default: " + defaultValue + ")");
- if (!firstInput) {
- System.out.print("\n(allowed pattern: " + pattern + ")");
-
- }
- System.out.print(":");
- BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
- try {
- input = buffer.readLine();
- } catch (IOException e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
-
- }
-
- if (input.isEmpty()) {
- // pressed return without entering anything
- input = defaultValue;
- }
-
- firstInput = false;
- } while (!input.matches(pattern));
-
- return input;
- }
-
- /**
- * Prompts the user for a input or output filename
- *
- * @param prompt the text the user is asked
- * @param defaultFilename a default Filename
- * @param expectedExtension will warn if filename does not match expected file extension
- * @param ensureFileExists will warn if file does NOT exist (for input files)
- * @param ensureFileNotExists will warn if file DOES exist (for output files)
- * @return String
- */
- protected static String getFilenameFromUser(String prompt, String defaultFilename, String expectedExtension,
- boolean ensureFileExists, boolean ensureFileNotExists) {
- boolean fileExistenceOK = false;
- String selectedName = "";
- do {
- // for a more sophisticated dialogue maybe https://github.com/mabe02/lanterna/
- // could be taken into account
- System.out.print(prompt + " (default: " + defaultFilename + "):");
- BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
- try {
- selectedName = buffer.readLine();
- } catch (IOException e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
-
- }
-
- if (selectedName.isEmpty()) {
- // pressed return without entering anything
- selectedName = defaultFilename;
- }
-
- // error cases
- if (!selectedName.toLowerCase().endsWith(expectedExtension.toLowerCase())) {
- System.err.println("Expected " + expectedExtension
- + " extension, this may corrupt your file. Do you still want to continue?(Y|N)");
- String selectedAnswer = "";
- try {
- selectedAnswer = buffer.readLine();
- } catch (IOException e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
- }
- if (!selectedAnswer.equals("Y") && !selectedAnswer.equals("y")) {
- System.err.println("Aborted by user");
- System.exit(-1);
- }
-
- } else if (ensureFileExists) {
- if (fileExists(selectedName)) {
- fileExistenceOK = true;
- } else {
- System.out.println("File does not exist, try again or CTRL+C to cancel");
- // discard the input, a scanner.reset is not sufficient
- fileExistenceOK = false;
- }
- } else {
- fileExistenceOK = true;
-
- if (ensureFileNotExists) {
- if (fileExists(selectedName)) {
- fileExistenceOK = false;
- System.out.println("Output file already exists, try again or CTRL+C to cancel");
- // discard the input, a scanner.reset is not sufficient
- }
- } else {
- fileExistenceOK = true;
- }
- }
-
- } while (!fileExistenceOK);
-
- return selectedName;
- }
-
- // /opt/local/bin/mvn clean compile assembly:single
- public static void main(String[] args) {
- try {
-
- CmdLineParser parser = new CmdLineParser();
-
- // Option: Help
- Option helpOption = parser.addBooleanOption('h', "help");
- // Option: Action
- Option actionOption = parser.addStringOption('a', "action");
-
- // Generic options available for multiple command
- // --source: input file
- Option sourceOption = parser.addStringOption("source");
- // --out: output file
- Option outOption = parser.addStringOption("out");
-
- // Command: Extract XML
- // --extract
- // (--source: input PDF file)
- // (--out: output XML file)
- Option extractOption = parser.addBooleanOption('e', "extract");
-
- // Command: Migrating ZUGFeRD 1 to 2
- // --upgrade
- // (--source: input XML ZUGFeRD 1 file)
- // (--out: output XML ZUGFeRD 2 file)
- Option upgradeOption = parser.addBooleanOption('u', "upgrade");
-
- // Command: Convert PDF/A-1 to PDF/A-3
- // --a3only
- // (--source: input PDF file)
- // (--out: output PDF file)
- Option a3onlyOption = parser.addBooleanOption('a', "a3only");
-
- // Command: Combining PDF and XML
- // --combine
- // (--source: input PDF file)
- // (--source-xml: input XML file)
- // (--out: output PDF file)
- // (--version: ZUGFeRD version)
- // (--profile: ZUGFeRD profile)
- Option combineOption = parser.addBooleanOption('c', "combine");
- Option sourceXmlOption = parser.addStringOption("source-xml");
- Option formatOption = parser.addStringOption('f', "format");
- Option zugferdVersionOption = parser.addStringOption("version");
- Option zugferdProfileOption = parser.addStringOption("profile");
-
- // Command: Show metrics in dir
- // --directory
- // (--ignorefileextension)
- Option dirnameOption = parser.addStringOption('d', "directory");
- Option ignoreFileExtOption = parser.addBooleanOption('i', "ignorefileextension");
-
- // Command: Show metrics from list from stdin
- // --listfromstdin
- Option filesFromStdInOption = parser.addBooleanOption('l', "listfromstdin");
-
- try {
- parser.parse(args);
- } catch (CmdLineParser.OptionException e) {
- System.err.println(e.getMessage());
- printUsage();
- System.exit(2);
- }
-
- // Retrieve all options
- String action = parser.getOptionValue(actionOption);
- String directoryName = parser.getOptionValue(dirnameOption);
- Boolean filesFromStdIn = parser.getOptionValue(filesFromStdInOption, Boolean.FALSE);
- Boolean combineRequested = parser.getOptionValue(combineOption, Boolean.FALSE) || ((action!=null)&&(action.equals("combine")));
- Boolean extractRequested = parser.getOptionValue(extractOption, Boolean.FALSE) || ((action!=null)&&(action.equals("extract")));
- Boolean helpRequested = parser.getOptionValue(helpOption, Boolean.FALSE) || ((action!=null)&&(action.equals("help")));
- Boolean upgradeRequested = parser.getOptionValue(upgradeOption, Boolean.FALSE) || ((action!=null)&&(action.equals("upgrade")));
- Boolean ignoreFileExt = parser.getOptionValue(ignoreFileExtOption, Boolean.FALSE);
- Boolean a3only = parser.getOptionValue(a3onlyOption, Boolean.FALSE) || ((action!=null)&&(action.equals("a3")));
- String sourceName = parser.getOptionValue(sourceOption);
- String sourceXMLName = parser.getOptionValue(sourceXmlOption);
- String outName = parser.getOptionValue(outOption);
- String format = parser.getOptionValue(formatOption);
- String zugferdVersion = parser.getOptionValue(zugferdVersionOption);
- String zugferdProfile = parser.getOptionValue(zugferdProfileOption);
-
- if (helpRequested) {
- printHelp();
- } else if (((directoryName != null) && (directoryName.length() > 0)) || filesFromStdIn.booleanValue()) {
- performMetrics(directoryName, filesFromStdIn, ignoreFileExt);
- } else if (combineRequested) {
- performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile);
- } else if (extractRequested) {
- performExtract(sourceName, outName);
- } else if (a3only) {
- performConvert(sourceName, outName);
- } else if (upgradeRequested) {
- performUpgrade(sourceName, outName);
- } else {
- // no argument or argument unknown
- printUsage();
- System.exit(2);
- }
- } catch (Exception e) {
-
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
- System.exit(-1);
- }
-
- }
-
- private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException {
-
- // Get params from user if not already defined
- if (xmlName == null) {
- xmlName = getFilenameFromUser("ZUGFeRD 1.0 XML source", "ZUGFeRD-invoice.xml", "xml", true, false);
- } else {
- System.out.println("ZUGFeRD 1.0 XML source set to " + xmlName);
- }
- if (outName == null) {
- outName = getFilenameFromUser("ZUGFeRD 2.0 XML target", "zugferd-invoice.xml", "xml", false, true);
- } else {
- System.out.println("ZUGFeRD 1.0 XML source set to " + outName);
- }
-
- // Verify params
- ensureFileExists(xmlName);
- ensureFileNotExists(outName);
-
- // All params are good! continue...
- ZUGFeRDMigrator zmi = new ZUGFeRDMigrator();
- String xml = null;
- xml = zmi.migrateFromV1ToV2(xmlName);
- Files.write(Paths.get(outName), xml.getBytes());
- System.out.println("Written to " + outName);
- /*
- * } catch (FileNotFoundException ex) {
- * Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
- */
- }
-
- private static void performConvert(String pdfName, String outName) throws IOException {
- /*
- * ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
- * .setProducer("toecount") .setCreator(System.getProperty("user.name"))
- * .loadFromPDFA1("invoice.pdf");
- */
- // Get params from user if not already defined
- if (pdfName == null) {
- pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
- } else {
- System.out.println("Source PDF set to " + pdfName);
- }
- if (outName == null) {
- outName = getFilenameFromUser("Target PDF", "invoice.a3.pdf", "pdf", false, true);
- } else {
- System.out.println("Target PDF set to " + outName);
- }
-
- // Verify params
- ensureFileExists(pdfName);
- ensureFileNotExists(outName);
-
- // All params are good! continue...
- ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setAttachZUGFeRDHeaders(false).load(pdfName);
-
- ze.export(outName);
- System.out.println("Written to " + outName);
- }
-
- private static void performExtract(String pdfName, String xmlName) throws IOException {
- // Get params from user if not already defined
- if (pdfName == null) {
- pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
- } else {
- System.out.println("Source PDF set to " + pdfName);
- }
- if (xmlName == null) {
- xmlName = getFilenameFromUser("ZUGFeRD XML", "ZUGFeRD-invoice.xml", "xml", false, true);
- } else {
- System.out.println("ZUGFeRD XML set to " + pdfName);
- }
-
- // Verify params
- ensureFileExists(pdfName);
- ensureFileNotExists(xmlName);
-
- // All params are good! continue...
- ZUGFeRDImporter zi = new ZUGFeRDImporter(pdfName);
- byte[] XMLContent = zi.getRawXML();
- if (XMLContent == null) {
- System.err.println("No ZUGFeRD XML found in PDF file");
-
- } else {
- Files.write(Paths.get(xmlName), XMLContent);
- System.out.println("Written to " + xmlName);
- }
- }
-
- private static void performCombine(String pdfName, String xmlName, String outName, String format, String zfVersion,
- String zfProfile) throws Exception {
- /*
- * ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
- * .setProducer("toecount") .setCreator(System.getProperty("user.name"))
- * .loadFromPDFA1("invoice.pdf");
- */
- try {
- int zfIntVersion = ZUGFeRDExporter.DefaultZUGFeRDVersion;
- ZUGFeRDConformanceLevel zfConformanceLevelProfile = ZUGFeRDConformanceLevel.EXTENDED;
-
- if (pdfName == null) {
- pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
- } else {
- System.out.println("Source PDF set to " + pdfName);
- }
-
- if (xmlName == null) {
- xmlName = getFilenameFromUser("ZUGFeRD XML", "ZUGFeRD-invoice.xml", "xml", true, false);
- } else {
- System.out.println("ZUGFeRD XML set to " + xmlName);
- }
-
- if (outName == null) {
- outName = getFilenameFromUser("Ouput PDF", "invoice.ZUGFeRD.pdf", "pdf", false, true);
- } else {
- System.out.println("Ouput PDF set to " + outName);
- }
-
- if (format == null) {
- try {
- format = getStringFromUser("Format (fx=Factur-X, zf=ZUGFeRD,)", "zf", "fx|zf");
- } catch (Exception e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
- }
- } else {
- System.out.println("Format set to " + format);
- }
-
- if (zfVersion == null) {
- try {
- zfVersion = getStringFromUser("Version (1 or 2)", "1", "1|2");
- } catch (Exception e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
- }
- } else {
- System.out.println("Version set to " + zfVersion);
- }
- zfIntVersion = Integer.valueOf(zfVersion);
-
- if (zfProfile == null) {
- try {
- if (format.equals("zf") && (zfIntVersion == 1)) {
- zfProfile = getStringFromUser("Profile b)asic, c)omfort or e)xtended", "e", "B|b|C|c|E|e");
- } else {
- zfProfile = getStringFromUser(
- "Profile [M]INIMUM, BASIC [W]L, [B]ASIC,\n" + "[C]IUS, [E]N16931, E[X]TENDED", "E",
- "M|m|W|w|B|b|C|c|E|e|X|x|");
- }
- } catch (Exception e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
-
- }
- } else {
- System.out.println("Profile set to " + zfProfile);
- }
- zfProfile = zfProfile.toLowerCase();
-
- // Verify params
- ensureFileExists(pdfName);
- ensureFileExists(xmlName);
- ensureFileNotExists(outName);
-
- if ((format.equals("fx")) && (zfIntVersion > 1)) {
- throw new Exception("Factur-X is only available in version 1 (roughly corresponding to ZF2)");
- }
-
- if ((format.equals("zf")) && (zfIntVersion == 1)) {
- if (zfProfile.equals("b")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.BASIC;
- } else if (zfProfile.equals("c")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.COMFORT;
- } else if (zfProfile.equals("e")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.EXTENDED;
- } else {
- throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile));
- }
- } else if (((format.equals("zf")) && (zfIntVersion == 2)) || (format.equals("fx"))) {
- if (zfProfile.equals("m")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.MINIMUM;
- } else if (zfProfile.equals("w")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.BASICWL;
- } else if (zfProfile.equals("b")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.BASIC;
- } else if (zfProfile.equals("c")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.CIUS;
- } else if (zfProfile.equals("e")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.EN16931;
- } else if (zfProfile.equals("x")) {
- zfConformanceLevelProfile = ZUGFeRDConformanceLevel.EXTENDED;
- } else {
- throw new Exception(String.format("Unknown ZUGFeRD profile '%s'", zfProfile));
- }
- } else {
- throw new Exception(String.format("Unknown version '%i'", zfIntVersion));
- }
-
- // All params are good! continue...
- ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setProducer("Toecount")
- .setZUGFeRDVersion(zfIntVersion)
- .setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile)
- .load(pdfName);
-
- if (format.equals("fx")) {
- ze.setFacturX();
- }
-
- ze.setZUGFeRDXMLData(Files.readAllBytes(Paths.get(xmlName)));
-
- ze.export(outName);
-
- System.out.println("Written to " + outName);
-
- } catch (IOException e) {
- Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
-
- }
- }
-
- private static void performMetrics(String directoryName, Boolean filesFromStdIn, Boolean ignoreFileExt)
- throws IOException {
-
- StatRun sr = new StatRun();
- if (ignoreFileExt) {
- sr.ignoreFileExtension();
- }
- if (directoryName != null) {
- Path startingDir = Paths.get(directoryName);
-
- if (Files.isRegularFile(startingDir)) {
- String filename = startingDir.toString();
- FileChecker fc = new FileChecker(filename, sr);
-
- fc.checkForZUGFeRD();
- System.out.print(fc.getOutputLine());
-
- } else if (Files.isDirectory(startingDir)) {
- FileTraverser pf = new FileTraverser(sr);
- Files.walkFileTree(startingDir, pf);
- }
- }
-
- if (filesFromStdIn) {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String s;
- while ((s = in.readLine()) != null && s.length() != 0) {
- FileChecker fc = new FileChecker(s, sr);
-
- fc.checkForZUGFeRD();
- System.out.print(fc.getOutputLine());
-
- }
-
- }
- System.out.println(sr.getSummaryLine());
- }
-
- private static void ensureFileExists(String fileName) throws IOException {
- if (!fileExists(fileName)) {
- throw new IOException(String.format("File %s does not exists", fileName));
- }
- }
-
- private static void ensureFileNotExists(String fileName) throws IOException {
- if (fileExists(fileName)) {
- throw new IOException(String.format("File %s does not exists", fileName));
- }
- }
-
- private static Boolean fileExists(String fileName) {
- if (fileName == null)
- return false;
- File f = new File(fileName);
- return f.exists();
- }
-
-}
diff --git a/src/main/resources/COMFORTtoEN16931.xsl b/src/main/resources/COMFORTtoEN16931.xsl
deleted file mode 100644
index c4f974a9..00000000
--- a/src/main/resources/COMFORTtoEN16931.xsl
+++ /dev/null
@@ -1,277 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <!--
-Migrated by Mustangproject XSLT
--->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/main/resources/schema/ZUGFeRD1p0.xsd b/src/main/resources/schema/ZUGFeRD1p0.xsd
deleted file mode 100644
index 41e2cc9c..00000000
--- a/src/main/resources/schema/ZUGFeRD1p0.xsd
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_QualifiedDataType_12.xsd b/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_QualifiedDataType_12.xsd
deleted file mode 100644
index 77d4e7ed..00000000
--- a/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_QualifiedDataType_12.xsd
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_ReusableAggregateBusinessInformationEntity_12.xsd b/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_ReusableAggregateBusinessInformationEntity_12.xsd
deleted file mode 100644
index c2647960..00000000
--- a/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_ReusableAggregateBusinessInformationEntity_12.xsd
+++ /dev/null
@@ -1,391 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_UnqualifiedDataType_15.xsd b/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_UnqualifiedDataType_15.xsd
deleted file mode 100644
index 9a8e41c4..00000000
--- a/src/main/resources/schema/ZUGFeRD1p0_urn_un_unece_uncefact_data_standard_UnqualifiedDataType_15.xsd
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/stylesheets/ZUGFeRD_1p0_c1p0_s1p0.xslt b/src/main/resources/stylesheets/ZUGFeRD_1p0_c1p0_s1p0.xslt
deleted file mode 100644
index 8b015f28..00000000
--- a/src/main/resources/stylesheets/ZUGFeRD_1p0_c1p0_s1p0.xslt
+++ /dev/null
@@ -1,3008 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [if IE]><STYLE type="text/css">.altova-rotate-left-textbox{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3)} .altova-rotate-right-textbox{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1)} </STYLE><![endif]
- [if !IE]><!
-
- <![endif]
-
-
-
-
-
-
- Stylesheet Lesbarmachung der XML-Daten von ZUGFeRD-Rechnungen
-
-
-
- ZUGFeRD-Version : 1.0 vom 25.06.2014
-
-
-
- Stylesheet-Version: 1.0 vom 25.06.2014
-
-
-
- Codelisten-Version: 1.0 vom 25.06.2014
-
-
-
- (c) AWV e.V. 2014
-
-
-