file attachments
This commit is contained in:
67
library/src/main/java/org/mustangproject/FileAttachment.java
Normal file
67
library/src/main/java/org/mustangproject/FileAttachment.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package org.mustangproject;
|
||||
|
||||
public class FileAttachment {
|
||||
|
||||
protected String filename;
|
||||
protected String mimetype;
|
||||
protected String relation;
|
||||
protected String description;
|
||||
protected byte[] data;
|
||||
|
||||
public FileAttachment(String filename, String mimetype, String relation, byte[] data) {
|
||||
this.filename = filename;
|
||||
this.mimetype = mimetype;
|
||||
this.relation = relation;
|
||||
this.data = data;
|
||||
description = "Additional file attachment";
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public FileAttachment setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public FileAttachment setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMimetype() {
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
public FileAttachment setMimetype(String mimetype) {
|
||||
this.mimetype = mimetype;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRelation() {
|
||||
return relation;
|
||||
}
|
||||
|
||||
public FileAttachment setRelation(String relation) {
|
||||
this.relation = relation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public FileAttachment setData(byte[] data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -37,11 +37,13 @@ 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 org.mustangproject.FileAttachment;
|
||||
|
||||
import javax.activation.DataSource;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -53,12 +55,10 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
|
||||
|
||||
protected Profiles profile = Profiles.EXTENDED;
|
||||
protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
|
||||
|
||||
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<FileAttachment>();
|
||||
|
||||
protected boolean ensurePDFisUpgraded = true;
|
||||
|
||||
private HashMap<String, byte[]> additionalFiles = new HashMap<String, byte[]>();
|
||||
|
||||
|
||||
private boolean disableAutoClose;
|
||||
private boolean fileAttached = false;
|
||||
@@ -114,8 +114,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
|
||||
}
|
||||
|
||||
public ZUGFeRDExporterFromA3 addAdditionalFile(String name, byte[] content) {
|
||||
|
||||
additionalFiles.put(name,content);
|
||||
fileAttachments.add(new FileAttachment(name, "text/xml", "Supplement", content).setDescription("ZUGFeRD extension/additional data"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -209,7 +208,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
|
||||
}
|
||||
|
||||
public void attachFile(String filename, byte[] data, String mimetype, String relation) {
|
||||
//throw new RuntimeException("Not implemented");
|
||||
FileAttachment fa=new FileAttachment(filename, mimetype, relation, data);
|
||||
fileAttachments.add(fa);
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -521,9 +521,10 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
|
||||
"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));
|
||||
for (FileAttachment attachment: fileAttachments) {
|
||||
PDFAttachGenericFile(doc, attachment.getFilename(), attachment.getRelation(), attachment.getDescription(), attachment.getMimetype(), attachment.getData());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user