diff --git a/History.md b/History.md index 8925439d..36878c7e 100644 --- a/History.md +++ b/History.md @@ -1,9 +1,12 @@ - #420 +- #441 - Enhance Charges/Allowances with reasonCode. #432 - Fix build warnings from editing and building. #415 - ZUGFeRDVisualizer.toPDF(): generate PDF/A-3b. #400 -- allow access to invoice attachments via ZUGFeRDInvoiceImporter zii.getEmbeddedFilenames()/zii.getEmbeddedFile(filename) - and XML (zii.getFileAttachments) +- allow access to invoice attachments via ZUGFeRDInvoiceImporter zii.getFileAttachmentsPDF() + and XML (zii.getFileAttachmentsXML) +- #436 and #370. (langfr) +- refactor(ZUGFeRDVisualizer): improve PDF visualization performance #438 2.12.0 diff --git a/doc/development_documentation.md b/doc/development_documentation.md index b69984df..5bcff291 100644 --- a/doc/development_documentation.md +++ b/doc/development_documentation.md @@ -5,7 +5,6 @@ To check if the necessary tools are there, the build is in a stable state and works on your platform, e.g. download and extract https://github.com/ZUGFeRD/mustangproject/archive/master.zip and run ./mvnw clean package -Mvnw is a maven wrapper which will download maven.Maven is the dependency management tool which will download all libraries, their dependencies, and build the whole thing. Mvnw is a maven wrapper which will download maven.Maven is the dependency management tool which will download all libraries, their dependencies, and build the whole thing. You will need a Java JDK, e.g. https://www.azul.com/downloads/zulu-community/?architecture=x86-64-bit&package=jdk @@ -60,7 +59,7 @@ to validate the XML part of the invoices. ## New build -Target platform is java 1.8 +Target platform is java 1.11 ## Build @@ -158,7 +157,7 @@ Sign in in GitHub and click on the profile picture -> Settings. Now just generat ![screenshot](development_documentation_screenshot_github_settings.png "Screenshot Github Settings") The Token-ID is the password. -In .m2 also need a toolchains.xml which defines a Sun JDK 1.8 target like the following: +In .m2 also need a toolchains.xml which defines a JDK 1.11 target like the following: ```xml @@ -185,11 +184,11 @@ maybe not yet even existing new release version: ``` cd validator/target -mvn install:install-file -Dfile=validator-2.5.5-SNAPSHOT-shaded.jar -DgroupId=org.mustangproject -DartifactId=validator -Dversion=2.5.5 -Dpackaging=jar -DgeneratePom=true +mvn install:install-file -Dfile=validator-2.12.0-SNAPSHOT-shaded.jar -Dclassifier=shaded -DgroupId=org.mustangproject -DartifactId=validator -Dversion=2.12.0 -Dpackaging=jar -DgeneratePom=true ``` In gradle you can use something like ``` -implementation files('libs/validator-2.5.6-shaded.jar') +implementation files('libs/validator-2.12.0-shaded.jar') ``` diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 6bf548a6..2029e854 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -40,10 +40,7 @@ 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.mustangproject.EStandard; -import org.mustangproject.Item; -import org.mustangproject.Product; -import org.mustangproject.XMLTools; +import org.mustangproject.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -65,7 +62,7 @@ public class ZUGFeRDImporter { /** * map filenames of all embedded files in the respective PDF */ - private final HashMap PDFAttachments = new HashMap<>(); + private final ArrayList PDFAttachments = new ArrayList<>(); /** * Raw XML form of the extracted data - may be directly obtained. */ @@ -107,25 +104,13 @@ public class ZUGFeRDImporter { /*** * return the file names of all files embedded into the PDF - * @see for XML embedded files please use ZUGFeRDInvoiceImporter.getFileAttachments - * @return a Stringset + * @see for XML embedded files please use ZUGFeRDInvoiceImporter.getFileAttachmentsXML + * @return a ArrayList of FileAttachments, empty if none */ - public Set getEmbeddedFilenames() { - return PDFAttachments.keySet(); + public List getFileAttachmentsPDF() { + return PDFAttachments; } - /*** - * returns the file contents of the specified filename embedded into the PDF - * @param filename String - * @return a bytearray, or null if the filename has not been fond - */ - public byte[] getEmbeddedFile(String filename) { - - if (PDFAttachments.containsKey(filename)) { - return PDFAttachments.get(filename); - } - return null; - } /** @@ -196,6 +181,7 @@ public class ZUGFeRDImporter { /** * filenames for invoice data (ZUGFeRD v1 and v2, Factur-X) */ + final PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile(); if ((filename.equals("ZUGFeRD-invoice.xml") || (filename.equals("zugferd-invoice.xml")) || filename.equals("factur-x.xml")) || filename.equals("xrechnung.xml") || filename.equals("order-x.xml") || filename.equals("cida.xml")) { containsMeta = true; @@ -215,7 +201,7 @@ public class ZUGFeRDImporter { if (filename.startsWith("additional_data")) { additionalXMLs.put(filename, embeddedFile.toByteArray()); } - PDFAttachments.put(filename, embeddedFile.toByteArray()); + PDFAttachments.add(new FileAttachment(filename, embeddedFile.getSubtype(), "Data", embeddedFile.toByteArray())); } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 3654cee3..45f36d55 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -345,7 +345,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { xpr = xpath.compile("//*[local-name()=\"AttachmentBinaryObject\"]|//*[local-name()=\"EmbeddedDocumentBinaryObject\"]"); NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); for (int i = 0; i < attachmentNodes.getLength(); i++) { - FileAttachment fa=new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(),attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(),"",Base64.getDecoder().decode(attachmentNodes.item(i).getTextContent())); + FileAttachment fa=new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(),attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(),"Data", Base64.getDecoder().decode(attachmentNodes.item(i).getTextContent())); fileAttachments.add(fa); // filename = "Aufmass.png" mimeCode = "image/png" //EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png" @@ -449,10 +449,10 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { /*** * - * @return the file attachments embedded in XML using base64, - * @see for PDF embedded files use getEmbeddedFilenames()/getEmbeddedFile() + * @return the file attachments embedded in XML (using base64) decoded as byte array, + * @see for PDF embedded files in FX use getFileAttachmentsPDF() */ - public List getFileAttachments() { + public List getFileAttachmentsXML() { return fileAttachments; } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java index a51642dc..56dfeb5e 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java @@ -133,7 +133,7 @@ public class XRTest extends TestCase { } catch (IOException e) { throw new RuntimeException(e); } - List attachedFiles=zii.getFileAttachments(); + List attachedFiles=zii.getFileAttachmentsXML(); assertNotNull(attachedFiles); assertEquals(attachedFiles.size(), 1); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 538cbbf9..b281a67c 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -21,6 +21,7 @@ */ package org.mustangproject.ZUGFeRD; +import org.mustangproject.FileAttachment; import org.mustangproject.Invoice; import javax.xml.xpath.XPathExpressionException; @@ -296,15 +297,12 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { byte[] fileB=null; ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushAttachments.pdf"); - for (String filename:zii.getEmbeddedFilenames() - ) { - if (filename.equals("one.pdf")) { - fileA=zii.getEmbeddedFile(filename); - } else if (filename.equals("two.pdf")) { - fileB=zii.getEmbeddedFile(filename); - + for (FileAttachment fa:zii.getFileAttachmentsPDF()) { + if (fa.getFilename().equals("one.pdf")) { + fileA=fa.getData(); + } else if (fa.getFilename().equals("two.pdf")) { + fileB=fa.getData(); } - } byte[] b = {12, 13}; // the sample data that was used to write the files