Additional data amendments

This commit is contained in:
Jochen Stärk
2019-03-14 08:25:34 +01:00
parent ba5d55b678
commit 86dd42cf93
3 changed files with 30 additions and 2 deletions

View File

@@ -112,6 +112,9 @@ public class ZUGFeRDExporter implements Closeable {
protected boolean ensurePDFisUpgraded = true;
private PDDocument doc;
int ZFVersion;
private HashMap<String,byte[]> additionalXMLs=new HashMap<String,byte[]>();
private boolean disableAutoClose;
@@ -128,6 +131,10 @@ public class ZUGFeRDExporter implements Closeable {
doc = doc2;
init();
}
public void addAdditonalXML(String filename, byte[] xml) {
additionalXMLs.put(filename, xml);
}
public static String getNamespaceForVersion(int ver) {
if (ver == 1) {
@@ -340,6 +347,9 @@ public class ZUGFeRDExporter implements Closeable {
}
for (String filenameAdditional : additionalXMLs.keySet()) {
PDFAttachGenericFile(doc, filenameAdditional, "Supplement", "ZUGFeRD extension/additional data", "text/xml", additionalXMLs.get(filenameAdditional));
}
}
public void export(String ZUGFeRDfilename) throws IOException {
@@ -459,6 +469,7 @@ public class ZUGFeRDExporter implements Closeable {
cus.setXML(zugferdData);
this.xmlProvider = cus;
PDFattachZugferdFile(null);
}
/**

View File

@@ -23,6 +23,8 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import org.apache.pdfbox.io.IOUtils;
@@ -42,7 +44,10 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
protected String creator = "mustangproject";
/** Creator tool (attribute for PDF) */
protected String creatorTool = null;
private HashMap<String,byte[]> additionalXMLs=new HashMap<String,byte[]>();
protected int ZFVersion=ZUGFeRDExporter.DefaultZUGFeRDVersion;
protected boolean ensurePDFisUpgraded=false;
private boolean attachZUGFeRDHeaders=true;
@@ -123,7 +128,7 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
IOUtils.copy(in, buffer);
return buffer.toByteArray();
}
private static boolean isValidA1(DataSource dataSource) throws IOException {
private static boolean isValidA1(DataSource dataSource) throws IOException {
return getPDFAParserValidationResult(new PreflightParser(dataSource));
}

View File

@@ -31,6 +31,7 @@ import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -67,6 +68,7 @@ public class ZUGFeRDImporter {
private String holder;
private String amount;
private String dueDate;
private HashMap<String,byte[]> additionalXMLs=new HashMap<String,byte[]>();
/** Raw XML form of the extracted data - may be directly obtained. */
private byte[] rawXML = null;
private String bankName;
@@ -151,7 +153,6 @@ public class ZUGFeRDImporter {
private void extractFiles(Map<String, PDComplexFileSpecification> names) throws IOException {
for (String filename : names.keySet()) {
/**
* currently (in the release candidate of version 1) only one attached file with
* the name ZUGFeRD-invoice.xml is allowed
@@ -174,8 +175,19 @@ public class ZUGFeRDImporter {
// fos.write(embeddedFile.getByteArray());
// fos.close();
}
if (filename.startsWith("additional_data")) {
PDComplexFileSpecification fileSpec = names.get(filename);
PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
additionalXMLs.put(filename, embeddedFile.toByteArray());
}
}
}
public HashMap<String, byte[]> getAdditionalData() {
return additionalXMLs;
}
/**
* needs to be called to be able to call the getters