diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java index 925217ce..e5504667 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java @@ -134,32 +134,31 @@ public class ZUGFeRDExporter implements Closeable { } public static String getNamespaceForVersion(int ver) { - if (ver == 1) { + 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:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"; + return "urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#"; + } else { throw new IllegalArgumentException("Version not supported"); } } public static String getPrefixForVersion(int ver) { - if (ver == 1) { - return "zf"; - } else if (ver == 2) { + if (isFacturX) { return "fx"; } else { - throw new IllegalArgumentException("Version not supported"); + return "zf"; } } public static String getFilenameForVersion(int ver) { - if (ver == 1) { - return "ZUGFeRD-invoice.xml"; - } else if ((ver == 2) || (isFacturX)) { + if (isFacturX) { return "factur-x.xml"; } else { - throw new IllegalArgumentException("Version not supported"); + return "ZUGFeRD-invoice.xml"; } } diff --git a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java index c6f98cf7..e2fdc9f1 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java @@ -501,6 +501,62 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta ze.disableAutoClose(true); ze.export(TARGET_PDF); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ze.export(baos); + ze.close(); + String pdfContent = baos.toString("UTF-8"); + assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1); + // check for pdf-a schema extension + assertFalse(pdfContent.indexOf("EN 16931") == -1); + assertFalse(pdfContent.indexOf("zf") == -1); + assertFalse(pdfContent.indexOf("urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#") == -1); + + } + + // now check the contents (like MustangReaderTest) + ZUGFeRDImporter zi = new ZUGFeRDImporter(); + zi.extract(TARGET_PDF); + // Reading ZUGFeRD + + String amount = null; + String bic = null; + String iban = null; + String kto = null; + String holder = null; + String ref = null; + if (zi.canParse()) { + zi.parse(); + amount = zi.getAmount(); + bic = zi.getBIC(); + iban = zi.getIBAN(); + kto = zi.getKTO(); + holder = zi.getHolder(); + ref = zi.getForeignReference(); + } + + assertEquals(amount, "571.04"); + assertEquals(bic, getOwnBIC()); + assertEquals(iban, getOwnIBAN()); + assertEquals(kto, getOwnKto()); + assertEquals(holder, getOwnOrganisationName()); + assertEquals(ref, getNumber()); + + } + /* + public void testFXExport() throws Exception { + + final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506fx.pdf"; + + // the writing part + try (InputStream SOURCE_PDF = this.getClass() + .getResourceAsStream("/MustangGnuaccountingBeispielRE-20171118_506blanko.pdf"); + + ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(2).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) { + ze.setFacturX(); + ze.PDFattachZugferdFile(this); + ze.disableAutoClose(true); + ze.export(TARGET_PDF); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); ze.export(baos); ze.close(); @@ -523,7 +579,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta assertEquals(zi.getHolder(), getOwnOrganisationName()); assertEquals(zi.getForeignReference(), getNumber()); } - +*/ /** * @throws Exception * @Test(expected = IndexOutOfBoundsException.class)