Cleansing

This commit is contained in:
Philip Helger
2024-07-09 18:37:53 +02:00
parent 8b2a11c5da
commit 12a3abde66
46 changed files with 394 additions and 402 deletions

View File

@@ -332,7 +332,7 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
CommandLine cmd; CommandLine cmd;
CommandLineParser parser = new BasicParser(); CommandLineParser parser = new DefaultParser();
// create Options object // create Options object
Options options = new Options(); Options options = new Options();
@@ -427,7 +427,7 @@ public class Main {
performUBL(sourceName, outName); performUBL(sourceName, outName);
optionsRecognized = true; optionsRecognized = true;
} else if ((action != null) && (action.equals("validate"))) { } else if ((action != null) && (action.equals("validate"))) {
optionsRecognized = performValidate(sourceName, noNotices != null && noNotices, cmd.getOptionValue("logAppend")); optionsRecognized = performValidate(sourceName, noNotices, cmd.getOptionValue("logAppend"));
} else if ((action != null) && (action.equals("validateExpectValid"))) { } else if ((action != null) && (action.equals("validateExpectValid"))) {
optionsRecognized = performValidateExpect(true, directoryName); optionsRecognized = performValidateExpect(true, directoryName);
} else if ((action != null) && (action.equals("validateExpectInvalid"))) { } else if ((action != null) && (action.equals("validateExpectInvalid"))) {
@@ -585,7 +585,7 @@ public class Main {
if (attachmentFilenames == null) { if (attachmentFilenames == null) {
byte attachmentContents[] = null; byte attachmentContents[] = null;
String attachmentFilename, attachmentMime, attachmentDescription; String attachmentFilename, attachmentMime;
if (!noAttachments) { if (!noAttachments) {
attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", "", "pdf", true, false); attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", "", "pdf", true, false);
if (attachmentFilename.length() != 0) { if (attachmentFilename.length() != 0) {

View File

@@ -14,9 +14,6 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmlunit.builder.Input;
import org.xmlunit.xpath.JAXPXPathEngine;
import org.xmlunit.xpath.XPathEngine;
import org.mustangproject.validator.ZUGFeRDValidator; import org.mustangproject.validator.ZUGFeRDValidator;
import static org.xmlunit.assertj.XmlAssert.assertThat; import static org.xmlunit.assertj.XmlAssert.assertThat;
@@ -50,25 +47,23 @@ public class ValidatorFileWalker
Date date = new Date(); Date date = new Date();
String expectedString="valid"; String expectedString="valid";
if (!expectValid) { if (!expectValid) {
expectedString="invalid"; expectedString="invalid";
} }
if ((attr!=null)&&(attr.isRegularFile())) { if ((attr!=null)&&(attr.isRegularFile())) {
if (matcher.matches(file.getFileName())) { if (matcher.matches(file.getFileName())) {
boolean thisResultValid=true;
String thisResultString=" valid"; String thisResultString=" valid";
try { try {
assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status") assertThat(zul.validate(file.toAbsolutePath().toString())).valueByXPath("/validation/summary/@status")
.asString() .asString()
.isEqualTo(expectedString); .isEqualTo(expectedString);
} catch (AssertionError ae) { } catch (AssertionError ae) {
thisResultValid=false; thisResultString="invalid";
thisResultString="invalid"; allValid=false;
allValid=false; }
} LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));
LOGGER.info(String.format("\n@%s Testing file %d: %s (%s)", dateFormat.format(date), fileCount++, thisResultString, file));
}
}
} }
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }

View File

@@ -55,6 +55,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE --> <!-- https://mvnrepository.com/artifact/net.sf.saxon/Saxon-HE -->
<dependency> <dependency>
<groupId>net.sf.saxon</groupId> <groupId>net.sf.saxon</groupId>

View File

@@ -1,14 +1,11 @@
package org.mustangproject; package org.mustangproject;
import org.mustangproject.ZUGFeRD.IExportableTransaction;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import java.math.BigDecimal; import java.math.BigDecimal;
/*** /***
* (absolute) allowances on item and document level * (absolute) allowances on item and document level
*/ */
public class Allowance extends Charge implements IZUGFeRDAllowanceCharge { public class Allowance extends Charge {
/*** /***
* bean constructor * bean constructor

View File

@@ -5,8 +5,6 @@ import java.io.Serializable;
import com.helger.commons.error.list.ErrorList; import com.helger.commons.error.list.ErrorList;
import com.helger.en16931.cii2ubl.CIIToUBL23Converter; import com.helger.en16931.cii2ubl.CIIToUBL23Converter;
import com.helger.ubl21.UBL21Marshaller;
import com.helger.ubl22.UBL22Marshaller;
import com.helger.ubl23.UBL23Marshaller; import com.helger.ubl23.UBL23Marshaller;
/*** /***
@@ -23,31 +21,7 @@ public class CIIToUBL {
final ErrorList occurred=new ErrorList(); final ErrorList occurred=new ErrorList();
final CIIToUBL23Converter cc=new CIIToUBL23Converter(); final CIIToUBL23Converter cc=new CIIToUBL23Converter();
final Serializable aUBL = cc.convertCIItoUBL(input, occurred); final Serializable aUBL = cc.convertCIItoUBL(input, occurred);
if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType)
{
UBL21Marshaller.invoice ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType)
{
UBL21Marshaller.creditNote ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType)
{
UBL22Marshaller.invoice ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType)
{
UBL22Marshaller.creditNote ()
.setFormattedOutput (true)
.write ((oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) aUBL, output);
}
else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType)
{ {
UBL23Marshaller.invoice () UBL23Marshaller.invoice ()
.setFormattedOutput (true) .setFormattedOutput (true)

View File

@@ -1,9 +1,7 @@
package org.mustangproject; package org.mustangproject;
import org.mustangproject.ZUGFeRD.IAbsoluteValueProvider; import org.mustangproject.ZUGFeRD.IAbsoluteValueProvider;
import org.mustangproject.ZUGFeRD.IExportableTransaction;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import java.math.BigDecimal; import java.math.BigDecimal;

View File

@@ -547,7 +547,7 @@ public class Invoice implements IExportableTransaction {
return null; return null;
} }
return ((TradeParty) getSender()).getAsTradeSettlement(); return getSender().getAsTradeSettlement();
} }

View File

@@ -1,7 +1,6 @@
package org.mustangproject; package org.mustangproject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.fop.util.XMLUtil;
import org.mustangproject.ZUGFeRD.IReferencedDocument; import org.mustangproject.ZUGFeRD.IReferencedDocument;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
@@ -12,7 +11,6 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
/*** /***
* describes any invoice line * describes any invoice line
@@ -28,8 +26,8 @@ public class Item implements IZUGFeRDExportableItem {
protected Product product; protected Product product;
protected ArrayList<String> notes = null; protected ArrayList<String> notes = null;
protected ArrayList<ReferencedDocument> referencedDocuments = null; protected ArrayList<ReferencedDocument> referencedDocuments = null;
protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<IZUGFeRDAllowanceCharge>(), protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<>(),
Charges = new ArrayList<IZUGFeRDAllowanceCharge>(); Charges = new ArrayList<>();
/*** /***
* default constructor * default constructor
@@ -138,7 +136,7 @@ public class Item implements IZUGFeRDExportableItem {
ReferencedDocument rd = new ReferencedDocument(IssuerAssignedID, TypeCode, ReferencedDocument rd = new ReferencedDocument(IssuerAssignedID, TypeCode,
ReferenceTypeCode); ReferenceTypeCode);
if (rdocs == null) { if (rdocs == null) {
rdocs = new ArrayList<ReferencedDocument>(); rdocs = new ArrayList<>();
} }
rdocs.add(rd); rdocs.add(rd);
@@ -428,7 +426,7 @@ public class Item implements IZUGFeRDExportableItem {
*/ */
public Item addNote(String text) { public Item addNote(String text) {
if (notes == null) { if (notes == null) {
notes = new ArrayList<String>(); notes = new ArrayList<>();
} }
notes.add(text); notes.add(text);
return this; return this;
@@ -441,7 +439,7 @@ public class Item implements IZUGFeRDExportableItem {
*/ */
public Item addReferencedDocument(ReferencedDocument doc) { public Item addReferencedDocument(ReferencedDocument doc) {
if (referencedDocuments == null) { if (referencedDocuments == null) {
referencedDocuments = new ArrayList<ReferencedDocument>(); referencedDocuments = new ArrayList<>();
} }
referencedDocuments.add(doc); referencedDocuments.add(doc);
return this; return this;

View File

@@ -2,13 +2,6 @@ package org.mustangproject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.mustangproject.ZUGFeRD.*; import org.mustangproject.ZUGFeRD.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/*** /***
* A organisation, i.e. usually a company * A organisation, i.e. usually a company

View File

@@ -66,15 +66,15 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
//nodes.item(i).getTextContent())) { //nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(nodeIndex); Node currentItemNode = nodes.item(nodeIndex);
if (nodes.item(nodeIndex).getLocalName() != null) { if (currentItemNode.getLocalName() != null) {
String debcurrentChild = nodes.item(nodeIndex).getLocalName(); String debcurrentChild = currentItemNode.getLocalName();
if (nodes.item(nodeIndex).getLocalName().equals("Party")) { if (debcurrentChild.equals("Party")) {
NodeList party = nodes.item(nodeIndex).getChildNodes(); NodeList party = currentItemNode.getChildNodes();
for (int partyIndex = 0; partyIndex < party.getLength(); partyIndex++) { for (int partyIndex = 0; partyIndex < party.getLength(); partyIndex++) {
if (party.item(partyIndex).getLocalName() != null) { if (party.item(partyIndex).getLocalName() != null) {
String debCN = party.item(partyIndex).getLocalName(); String debCN = party.item(partyIndex).getLocalName();
if (party.item(partyIndex).getLocalName().equals("PartyName")) { if (debCN.equals("PartyName")) {
NodeList partyName = party.item(partyIndex).getChildNodes(); NodeList partyName = party.item(partyIndex).getChildNodes();
for (int partyNameIndex = 0; partyNameIndex < partyName.getLength(); partyNameIndex++) { for (int partyNameIndex = 0; partyNameIndex < partyName.getLength(); partyNameIndex++) {
@@ -87,7 +87,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
} }
} }
if (party.item(partyIndex).getLocalName().equals("PostalAddress")) { if (debCN.equals("PostalAddress")) {
NodeList postal = party.item(partyIndex).getChildNodes(); NodeList postal = party.item(partyIndex).getChildNodes();
for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) {
@@ -145,7 +145,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
} }
if (party.item(partyIndex).getLocalName().equals("Contact")) { if (debCN.equals("Contact")) {
NodeList contact = party.item(partyIndex).getChildNodes(); NodeList contact = party.item(partyIndex).getChildNodes();
setContact(new Contact(contact)); setContact(new Contact(contact));
@@ -156,19 +156,19 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
if (nodes.item(nodeIndex).getLocalName().equals("GlobalID")) { if (debcurrentChild.equals("GlobalID")) {
if (nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID") != null) { if (nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID") != null) {
SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent());
addGlobalID(gid); addGlobalID(gid);
} }
} }
if (nodes.item(nodeIndex).getLocalName().equals("DefinedTradeContact")) { if (debcurrentChild.equals("DefinedTradeContact")) {
NodeList contact = nodes.item(nodeIndex).getChildNodes(); NodeList contact = nodes.item(nodeIndex).getChildNodes();
setContact(new Contact(contact)); setContact(new Contact(contact));
} }
if (nodes.item(nodeIndex).getLocalName().equals("PostalTradeAddress")) { if (debcurrentChild.equals("PostalTradeAddress")) {
NodeList postal = nodes.item(nodeIndex).getChildNodes(); NodeList postal = nodes.item(nodeIndex).getChildNodes();
for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) {
if (postal.item(postalChildIndex).getLocalName() != null) { if (postal.item(postalChildIndex).getLocalName() != null) {
@@ -196,7 +196,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
if (nodes.item(nodeIndex).getLocalName().equals("SpecifiedTaxRegistration")) { if (debcurrentChild.equals("SpecifiedTaxRegistration")) {
NodeList taxChilds = nodes.item(nodeIndex).getChildNodes(); NodeList taxChilds = nodes.item(nodeIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if (taxChilds.item(taxChildIndex).getLocalName() != null) { if (taxChilds.item(taxChildIndex).getLocalName() != null) {
@@ -290,7 +290,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) { for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) { //nodes.item(i).getTextContent())) {
String debLN = nodes.item(nodeIndex).getLocalName(); String debLN = nodes.item(nodeIndex).getLocalName();
if (nodes.item(nodeIndex).getLocalName().equals("Party")) { if (debLN.equals("Party")) {
// take one step back and parse from top // take one step back and parse from top
parseFromUBL(nodes); parseFromUBL(nodes);
return; return;

View File

@@ -1,7 +1,5 @@
package org.mustangproject; package org.mustangproject;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -11,6 +9,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.RandomAccess; import java.util.RandomAccess;
import org.apache.commons.io.IOUtils;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
@@ -40,11 +39,13 @@ public class XMLTools extends XMLWriter {
list = l; list = l;
} }
public Node get(int index) { @Override
public Node get(int index) {
return list.item(index); return list.item(index);
} }
public int size() { @Override
public int size() {
return list.getLength(); return list.getLength();
} }
} }
@@ -127,6 +128,7 @@ public class XMLTools extends XMLWriter {
*/ */
public static byte[] removeBOM(byte[] zugferdRaw) { public static byte[] removeBOM(byte[] zugferdRaw) {
final byte[] zugferdData; final byte[] zugferdData;
// This handles the UTF-8 BOM
if ((zugferdRaw[0] == (byte) 0xEF) && (zugferdRaw[1] == (byte) 0xBB) && (zugferdRaw[2] == (byte) 0xBF)) { if ((zugferdRaw[0] == (byte) 0xEF) && (zugferdRaw[1] == (byte) 0xBB) && (zugferdRaw[2] == (byte) 0xBF)) {
// I don't like BOMs, lets remove it // I don't like BOMs, lets remove it
zugferdData = new byte[zugferdRaw.length - 3]; zugferdData = new byte[zugferdRaw.length - 3];
@@ -138,20 +140,7 @@ public class XMLTools extends XMLWriter {
} }
public static byte[] getBytesFromStream(InputStream fileinput) throws IOException { public static byte[] getBytesFromStream(InputStream fileinput) throws IOException {
return IOUtils.toByteArray (fileinput);
// we're on java 8 so we cant use inputstream.readallbytes
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
BufferedInputStream bufferedInput=new BufferedInputStream(fileinput);
while ((nRead = bufferedInput.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
return buffer.toByteArray();
// end of polyfill
} }
} }

View File

@@ -33,7 +33,7 @@ import org.mustangproject.FileAttachment;
import org.mustangproject.Invoice; import org.mustangproject.Invoice;
import org.mustangproject.XMLTools; import org.mustangproject.XMLTools;
public class DAPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider { public class DAPullProvider extends ZUGFeRD2PullProvider {
protected IExportableTransaction trans; protected IExportableTransaction trans;
private String paymentTermsDescription; private String paymentTermsDescription;

View File

@@ -29,10 +29,11 @@ import org.apache.pdfbox.preflight.parser.PreflightParser;
import jakarta.activation.DataSource; import jakarta.activation.DataSource;
public class DXExporterFromA1 extends DXExporterFromA3 implements IZUGFeRDExporter { public class DXExporterFromA1 extends DXExporterFromA3 {
protected boolean ignorePDFAErrors = false; protected boolean ignorePDFAErrors = false;
public DXExporterFromA1 ignorePDFAErrors() { @Override
public DXExporterFromA1 ignorePDFAErrors() {
this.ignorePDFAErrors = true; this.ignorePDFAErrors = true;
return this; return this;
} }
@@ -45,7 +46,8 @@ public class DXExporterFromA1 extends DXExporterFromA3 implements IZUGFeRDExport
* @param ver the delivery-x version * @param ver the delivery-x version
* @return the URN of the namespace * @return the URN of the namespace
*/ */
public String getNamespaceForVersion(int ver) { @Override
public String getNamespaceForVersion(int ver) {
// As of late 2022 the Delivery-X standard is not yet published. See specification: // As of late 2022 the Delivery-X standard is not yet published. See specification:
// Die digitale Ablösung des Papier-Lieferscheins, Version 1.1, April 2022 // Die digitale Ablösung des Papier-Lieferscheins, Version 1.1, April 2022
// Chapter 7.1 XMP-Erweiterungsschema für PDF/A-3 // Chapter 7.1 XMP-Erweiterungsschema für PDF/A-3
@@ -57,7 +59,8 @@ public class DXExporterFromA1 extends DXExporterFromA3 implements IZUGFeRDExport
* @param ver the ox version * @param ver the ox version
* @return the namespace prefix as string, without colon * @return the namespace prefix as string, without colon
*/ */
public String getPrefixForVersion(int ver) { @Override
public String getPrefixForVersion(int ver) {
return "fx"; return "fx";
} }
@@ -91,14 +94,17 @@ public class DXExporterFromA1 extends DXExporterFromA3 implements IZUGFeRDExport
} }
public DXExporterFromA1 setProfile(Profile p) { @Override
public DXExporterFromA1 setProfile(Profile p) {
return (DXExporterFromA1)super.setProfile(p); return (DXExporterFromA1)super.setProfile(p);
} }
public DXExporterFromA1 setProfile(String profileName) { @Override
public DXExporterFromA1 setProfile(String profileName) {
return (DXExporterFromA1)super.setProfile(profileName); return (DXExporterFromA1)super.setProfile(profileName);
} }
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException { @Override
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException {
if (!ignorePDFAErrors && !isValidA1(dataSource)) { if (!ignorePDFAErrors && !isValidA1(dataSource)) {
throw new IOException("File is not a valid PDF/A input file"); throw new IOException("File is not a valid PDF/A input file");
} }
@@ -110,32 +116,41 @@ public class DXExporterFromA1 extends DXExporterFromA3 implements IZUGFeRDExport
} }
public DXExporterFromA1 load(String pdfFilename) throws IOException { @Override
public DXExporterFromA1 load(String pdfFilename) throws IOException {
return (DXExporterFromA1) super.load(pdfFilename); return (DXExporterFromA1) super.load(pdfFilename);
} }
public DXExporterFromA1 load(byte[] pdfBinary) throws IOException { @Override
public DXExporterFromA1 load(byte[] pdfBinary) throws IOException {
return (DXExporterFromA1) super.load(pdfBinary); return (DXExporterFromA1) super.load(pdfBinary);
} }
public DXExporterFromA1 load(InputStream pdfSource) throws IOException{ @Override
public DXExporterFromA1 load(InputStream pdfSource) throws IOException{
return (DXExporterFromA1) super.load(pdfSource); return (DXExporterFromA1) super.load(pdfSource);
} }
public DXExporterFromA1 setCreator(String creator) { @Override
public DXExporterFromA1 setCreator(String creator) {
return (DXExporterFromA1) super.setCreator(creator); return (DXExporterFromA1) super.setCreator(creator);
} }
public DXExporterFromA1 setConformanceLevel(PDFAConformanceLevel newLevel) { @Override
public DXExporterFromA1 setConformanceLevel(PDFAConformanceLevel newLevel) {
return (DXExporterFromA1) super.setConformanceLevel(newLevel); return (DXExporterFromA1) super.setConformanceLevel(newLevel);
} }
public DXExporterFromA1 setProducer(String producer){ @Override
public DXExporterFromA1 setProducer(String producer){
return (DXExporterFromA1) super.setProducer(producer); return (DXExporterFromA1) super.setProducer(producer);
} }
public DXExporterFromA1 setZUGFeRDVersion(int version){ @Override
public DXExporterFromA1 setZUGFeRDVersion(int version){
return (DXExporterFromA1) super.setZUGFeRDVersion(version); return (DXExporterFromA1) super.setZUGFeRDVersion(version);
} }
public DXExporterFromA1 setXML(byte[] zugferdData) throws IOException{ @Override
public DXExporterFromA1 setXML(byte[] zugferdData) throws IOException{
return (DXExporterFromA1) super.setXML(zugferdData); return (DXExporterFromA1) super.setXML(zugferdData);
} }
public DXExporterFromA1 disableAutoClose(boolean disableAutoClose){ @Override
public DXExporterFromA1 disableAutoClose(boolean disableAutoClose){
return (DXExporterFromA1) super.disableAutoClose(disableAutoClose); return (DXExporterFromA1) super.disableAutoClose(disableAutoClose);
} }
public DXExporterFromA1 convertOnly() { public DXExporterFromA1 convertOnly() {

View File

@@ -71,7 +71,7 @@ import jakarta.activation.FileDataSource;
public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 { public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE; protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<FileAttachment>(); protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>();
/** /**
* This flag controls whether or not the metadata is overwritten, or kind of merged. * This flag controls whether or not the metadata is overwritten, or kind of merged.
@@ -127,7 +127,7 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
protected String despatchAdviceDocumentType = "DESPATCHADVICE"; protected String despatchAdviceDocumentType = "DESPATCHADVICE";
private HashMap<String, byte[]> additionalXMLs = new HashMap<String, byte[]>(); private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
private boolean attachZUGFeRDHeaders = true; private boolean attachZUGFeRDHeaders = true;
@@ -138,7 +138,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param pdfFilename filename of an PDF/A1 compliant document * @param pdfFilename filename of an PDF/A1 compliant document
*/ */
public DXExporterFromA3 load(String pdfFilename) throws IOException { @Override
public DXExporterFromA3 load(String pdfFilename) throws IOException {
ensurePDFIsValid(new FileDataSource(pdfFilename)); ensurePDFIsValid(new FileDataSource(pdfFilename));
try (FileInputStream pdf = new FileInputStream(pdfFilename)) { try (FileInputStream pdf = new FileInputStream(pdfFilename)) {
@@ -146,11 +147,13 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
} }
} }
public IXMLProvider getProvider() { @Override
public IXMLProvider getProvider() {
return xmlProvider; return xmlProvider;
} }
public DXExporterFromA3 setProfile(Profile p) { @Override
public DXExporterFromA3 setProfile(Profile p) {
this.profile = p; this.profile = p;
if (xmlProvider != null) { if (xmlProvider != null) {
xmlProvider.setProfile(p); xmlProvider.setProfile(p);
@@ -158,7 +161,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return this; return this;
} }
public DXExporterFromA3 setProfile(String profilename) { @Override
public DXExporterFromA3 setProfile(String profilename) {
this.profile = Profiles.getByName(profilename); this.profile = Profiles.getByName(profilename);
if (xmlProvider != null) { if (xmlProvider != null) {
@@ -167,7 +171,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return this; return this;
} }
public DXExporterFromA3 addAdditionalFile(String name, byte[] content) { @Override
public DXExporterFromA3 addAdditionalFile(String name, byte[] content) {
fileAttachments.add(new FileAttachment(name, "text/xml", "Supplement", content).setDescription("ZUGFeRD extension/additional data")); fileAttachments.add(new FileAttachment(name, "text/xml", "Supplement", content).setDescription("ZUGFeRD extension/additional data"));
return this; return this;
} }
@@ -180,7 +185,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param pdfBinary binary of a PDF/A1 compliant document * @param pdfBinary binary of a PDF/A1 compliant document
*/ */
public DXExporterFromA3 load(byte[] pdfBinary) throws IOException { @Override
public DXExporterFromA3 load(byte[] pdfBinary) throws IOException {
ensurePDFIsValid(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary))); ensurePDFIsValid(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary)));
doc = Loader.loadPDF(pdfBinary); doc = Loader.loadPDF(pdfBinary);
return this; return this;
@@ -190,11 +196,13 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
super(); super();
} }
public void attachFile(FileAttachment file) { @Override
public void attachFile(FileAttachment file) {
fileAttachments.add(file); fileAttachments.add(file);
} }
public void attachFile(String filename, byte[] data, String mimetype, String relation) { @Override
public void attachFile(String filename, byte[] data, String mimetype, String relation) {
FileAttachment fa = new FileAttachment(filename, mimetype, relation, data); FileAttachment fa = new FileAttachment(filename, mimetype, relation, data);
fileAttachments.add(fa); fileAttachments.add(fa);
} }
@@ -204,7 +212,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param ZUGFeRDfilename the pdf file name * @param ZUGFeRDfilename the pdf file name
* @throws IOException if anything is wrong in the target location * @throws IOException if anything is wrong in the target location
*/ */
public void export(String ZUGFeRDfilename) throws IOException { @Override
public void export(String ZUGFeRDfilename) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
@@ -231,7 +240,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param output the OutputStream * @param output the OutputStream
* @throws IOException if anything is wrong in the OutputStream * @throws IOException if anything is wrong in the OutputStream
*/ */
public void export(OutputStream output) throws IOException { @Override
public void export(OutputStream output) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
@@ -257,7 +267,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param data the binary data of the file/attachment * @param data the binary data of the file/attachment
* @throws IOException if anything is wrong with filename * @throws IOException if anything is wrong with filename
*/ */
public void PDFAttachGenericFile(String filename, String relationship, String description, @Override
public void PDFAttachGenericFile(String filename, String relationship, String description,
String subType, byte[] data) throws IOException { String subType, byte[] data) throws IOException {
PDFAttachGenericFile(this.doc, filename, relationship, description, subType, data); PDFAttachGenericFile(this.doc, filename, relationship, description, subType, data);
} }
@@ -274,7 +285,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param data the binary data of the file/attachment * @param data the binary data of the file/attachment
* @throws IOException if anything is wrong with filename * @throws IOException if anything is wrong with filename
*/ */
public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description, @Override
public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description,
String subType, byte[] data) throws IOException { String subType, byte[] data) throws IOException {
fileAttached = true; fileAttached = true;
@@ -293,7 +305,7 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
ef.setSize(data.length); ef.setSize(data.length);
ef.setCreationDate(new GregorianCalendar()); ef.setCreationDate(new GregorianCalendar());
ef.setModDate(GregorianCalendar.getInstance()); ef.setModDate(Calendar.getInstance());
fs.setEmbeddedFile(ef); fs.setEmbeddedFile(ef);
@@ -325,7 +337,7 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
doc.getDocumentCatalog().setNames(names); doc.getDocumentCatalog().setNames(names);
// AF entry (Array) in catalog with the FileSpec // AF entry (Array) in catalog with the FileSpec
COSBase AFEntry = (COSBase) doc.getDocumentCatalog().getCOSObject().getItem("AF"); COSBase AFEntry = doc.getDocumentCatalog().getCOSObject().getItem("AF");
if ((AFEntry == null)) { if ((AFEntry == null)) {
COSArray cosArray = new COSArray(); COSArray cosArray = new COSArray();
cosArray.add(fs); cosArray.add(fs);
@@ -351,7 +363,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param zugferdData XML data to be set as a byte array (XML file in raw form). * @param zugferdData XML data to be set as a byte array (XML file in raw form).
* @throws IOException (should not happen) * @throws IOException (should not happen)
*/ */
public DXExporterFromA3 setXML(byte[] zugferdData) throws IOException { @Override
public DXExporterFromA3 setXML(byte[] zugferdData) throws IOException {
CustomXMLProvider cus = new CustomXMLProvider(); CustomXMLProvider cus = new CustomXMLProvider();
// As of late 2022 the Delivery-X standard is not yet published. See specification: // As of late 2022 the Delivery-X standard is not yet published. See specification:
// Die digitale Ablösung des Papier-Lieferscheins, Version 1.1, April 2022 // Die digitale Ablösung des Papier-Lieferscheins, Version 1.1, April 2022
@@ -372,11 +385,13 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param pdfSource source to read a PDF/A1 compliant document from * @param pdfSource source to read a PDF/A1 compliant document from
*/ */
public DXExporterFromA3 load(InputStream pdfSource) throws IOException { @Override
public DXExporterFromA3 load(InputStream pdfSource) throws IOException {
return load(readAllBytes(pdfSource)); return load(readAllBytes(pdfSource));
} }
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException { @Override
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException {
return true; return true;
} }
@@ -399,23 +414,27 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* <p> * <p>
* Feel free to pass "A" as new level if you know what you are doing :-) * Feel free to pass "A" as new level if you know what you are doing :-)
*/ */
public DXExporterFromA3 setConformanceLevel(PDFAConformanceLevel newLevel) { @Override
public DXExporterFromA3 setConformanceLevel(PDFAConformanceLevel newLevel) {
conformanceLevel = newLevel; conformanceLevel = newLevel;
return this; return this;
} }
public DXExporterFromA3 setCreator(String creator) { @Override
public DXExporterFromA3 setCreator(String creator) {
this.creator = creator; this.creator = creator;
return this; return this;
} }
public DXExporterFromA3 setCreatorTool(String creatorTool) { @Override
public DXExporterFromA3 setCreatorTool(String creatorTool) {
this.creatorTool = creatorTool; this.creatorTool = creatorTool;
return this; return this;
} }
public DXExporterFromA3 setProducer(String producer) { @Override
public DXExporterFromA3 setProducer(String producer) {
this.producer = producer; this.producer = producer;
return this; return this;
} }
@@ -434,7 +453,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return this; return this;
} }
protected DXExporterFromA3 setAttachZUGFeRDHeaders(boolean attachHeaders) { @Override
protected DXExporterFromA3 setAttachZUGFeRDHeaders(boolean attachHeaders) {
this.attachZUGFeRDHeaders = attachHeaders; this.attachZUGFeRDHeaders = attachHeaders;
return this; return this;
} }
@@ -447,7 +467,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param metadata the PDFbox XMPMetadata object * @param metadata the PDFbox XMPMetadata object
*/ */
protected void addXMP(XMPMetadata metadata) { @Override
protected void addXMP(XMPMetadata metadata) {
if (attachZUGFeRDHeaders) { if (attachZUGFeRDHeaders) {
// As of late 2022 the Delivery-X standard is not yet published. See specification: // As of late 2022 the Delivery-X standard is not yet published. See specification:
@@ -478,12 +499,14 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* <code>setZUGFeRDXMLData(byte[] zugferdData)</code> * <code>setZUGFeRDXMLData(byte[] zugferdData)</code>
* @throws IOException if anything is wrong with already loaded PDF * @throws IOException if anything is wrong with already loaded PDF
*/ */
public IExporter setTransaction(IExportableTransaction trans) throws IOException { @Override
public IExporter setTransaction(IExportableTransaction trans) throws IOException {
this.trans = trans; this.trans = trans;
return prepare(); return prepare();
} }
public IExporter prepare() throws IOException { @Override
public IExporter prepare() throws IOException {
prepareDocument(); prepareDocument();
xmlProvider.generateXML(trans); xmlProvider.generateXML(trans);
String filename = "cida.xml"; String filename = "cida.xml";
@@ -502,7 +525,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* Reads the XMPMetadata from the PDDocument, if it exists. * Reads the XMPMetadata from the PDDocument, if it exists.
* Otherwise creates XMPMetadata. * Otherwise creates XMPMetadata.
*/ */
protected XMPMetadata getXmpMetadata() throws IOException { @Override
protected XMPMetadata getXmpMetadata() throws IOException {
PDMetadata meta = doc.getDocumentCatalog().getMetadata(); PDMetadata meta = doc.getDocumentCatalog().getMetadata();
if ((meta != null) && (meta.getLength() > 0)) { if ((meta != null) && (meta.getLength() > 0)) {
try { try {
@@ -515,7 +539,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return XMPMetadata.createXMPMetadata(); return XMPMetadata.createXMPMetadata();
} }
protected byte[] serializeXmpMetadata(XMPMetadata xmpMetadata) throws TransformerException { @Override
protected byte[] serializeXmpMetadata(XMPMetadata xmpMetadata) throws TransformerException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
new XmpSerializer().serialize(xmpMetadata, buffer, true); // see https://github.com/ZUGFeRD/mustangproject/issues/44 new XmpSerializer().serialize(xmpMetadata, buffer, true); // see https://github.com/ZUGFeRD/mustangproject/issues/44
return buffer.toByteArray(); return buffer.toByteArray();
@@ -525,7 +550,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* Sets the producer if the overwrite flag is set or the producer is not already set. * Sets the producer if the overwrite flag is set or the producer is not already set.
* Sets the PDFVersion to 1.4 if the field is empty. * Sets the PDFVersion to 1.4 if the field is empty.
*/ */
protected void writeAdobePDFSchema(XMPMetadata xmp) { @Override
protected void writeAdobePDFSchema(XMPMetadata xmp) {
AdobePDFSchema pdf = getAdobePDFSchema(xmp); AdobePDFSchema pdf = getAdobePDFSchema(xmp);
if (overwrite || isEmpty(pdf.getProducer())) if (overwrite || isEmpty(pdf.getProducer()))
pdf.setProducer(producer); pdf.setProducer(producer);
@@ -535,7 +561,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* Returns the AdobePDFSchema from the XMPMetadata if it exists. * Returns the AdobePDFSchema from the XMPMetadata if it exists.
* If the overwrite flag is set or no AdobePDFSchema exists in the XMPMetadata, it is created, added and returned. * If the overwrite flag is set or no AdobePDFSchema exists in the XMPMetadata, it is created, added and returned.
*/ */
protected AdobePDFSchema getAdobePDFSchema(XMPMetadata xmp) { @Override
protected AdobePDFSchema getAdobePDFSchema(XMPMetadata xmp) {
AdobePDFSchema pdf = xmp.getAdobePDFSchema(); AdobePDFSchema pdf = xmp.getAdobePDFSchema();
if (pdf != null) if (pdf != null)
if (overwrite) if (overwrite)
@@ -545,7 +572,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddAdobePDFSchema(); return xmp.createAndAddAdobePDFSchema();
} }
protected void writePDFAIdentificationSchema(XMPMetadata xmp) { @Override
protected void writePDFAIdentificationSchema(XMPMetadata xmp) {
PDFAIdentificationSchema pdfaid = getPDFAIdentificationSchema(xmp); PDFAIdentificationSchema pdfaid = getPDFAIdentificationSchema(xmp);
if (overwrite || isEmpty(pdfaid.getConformance())) { if (overwrite || isEmpty(pdfaid.getConformance())) {
try { try {
@@ -560,7 +588,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
pdfaid.setPart(3); pdfaid.setPart(3);
} }
protected PDFAIdentificationSchema getPDFAIdentificationSchema(XMPMetadata xmp) { @Override
protected PDFAIdentificationSchema getPDFAIdentificationSchema(XMPMetadata xmp) {
PDFAIdentificationSchema pdfaid = xmp.getPDFAIdentificationSchema(); PDFAIdentificationSchema pdfaid = xmp.getPDFAIdentificationSchema();
if (pdfaid != null) if (pdfaid != null)
if (overwrite) if (overwrite)
@@ -570,7 +599,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddPDFAIdentificationSchema(); return xmp.createAndAddPDFAIdentificationSchema();
} }
protected void writeDublinCoreSchema(XMPMetadata xmp) { @Override
protected void writeDublinCoreSchema(XMPMetadata xmp) {
DublinCoreSchema dc = getDublinCoreSchema(xmp); DublinCoreSchema dc = getDublinCoreSchema(xmp);
if (dc.getFormat() == null) if (dc.getFormat() == null)
dc.setFormat("application/pdf"); dc.setFormat("application/pdf");
@@ -593,7 +623,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
} }
} }
protected DublinCoreSchema getDublinCoreSchema(XMPMetadata xmp) { @Override
protected DublinCoreSchema getDublinCoreSchema(XMPMetadata xmp) {
DublinCoreSchema dc = xmp.getDublinCoreSchema(); DublinCoreSchema dc = xmp.getDublinCoreSchema();
if (dc != null) if (dc != null)
if (overwrite) if (overwrite)
@@ -603,15 +634,17 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddDublinCoreSchema(); return xmp.createAndAddDublinCoreSchema();
} }
protected void writeXMLBasicSchema(XMPMetadata xmp) { @Override
protected void writeXMLBasicSchema(XMPMetadata xmp) {
XMPBasicSchema xsb = getXmpBasicSchema(xmp); XMPBasicSchema xsb = getXmpBasicSchema(xmp);
if (overwrite || isEmpty(xsb.getCreatorTool()) || "UnknownApplication".equals(xsb.getCreatorTool())) if (overwrite || isEmpty(xsb.getCreatorTool()) || "UnknownApplication".equals(xsb.getCreatorTool()))
xsb.setCreatorTool(creatorTool); xsb.setCreatorTool(creatorTool);
if (overwrite || xsb.getCreateDate() == null) if (overwrite || xsb.getCreateDate() == null)
xsb.setCreateDate(GregorianCalendar.getInstance()); xsb.setCreateDate(Calendar.getInstance());
} }
protected XMPBasicSchema getXmpBasicSchema(XMPMetadata xmp) { @Override
protected XMPBasicSchema getXmpBasicSchema(XMPMetadata xmp) {
XMPBasicSchema xsb = xmp.getXMPBasicSchema(); XMPBasicSchema xsb = xmp.getXMPBasicSchema();
if (xsb != null) if (xsb != null)
if (overwrite) if (overwrite)
@@ -621,7 +654,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddXMPBasicSchema(); return xmp.createAndAddXMPBasicSchema();
} }
protected void writeDocumentInformation() { @Override
protected void writeDocumentInformation() {
String fullProducer = producer + " (via mustangproject.org " + Version.VERSION + ")"; String fullProducer = producer + " (via mustangproject.org " + Version.VERSION + ")";
PDDocumentInformation info = doc.getDocumentInformation(); PDDocumentInformation info = doc.getDocumentInformation();
if (overwrite || info.getCreationDate() == null) if (overwrite || info.getCreationDate() == null)
@@ -643,7 +677,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* Adds an OutputIntent and the sRGB color profile if no OutputIntent exist * Adds an OutputIntent and the sRGB color profile if no OutputIntent exist
*/ */
protected void addSRGBOutputIntend() throws IOException { @Override
protected void addSRGBOutputIntend() throws IOException {
if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) { if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) {
return; return;
} }
@@ -666,7 +701,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* Adds a MarkInfo element to the PDF if it doesn't already exist and sets it as marked. * Adds a MarkInfo element to the PDF if it doesn't already exist and sets it as marked.
*/ */
protected void setMarked() { @Override
protected void setMarked() {
PDDocumentCatalog catalog = doc.getDocumentCatalog(); PDDocumentCatalog catalog = doc.getDocumentCatalog();
if (catalog.getMarkInfo() == null) { if (catalog.getMarkInfo() == null) {
catalog.setMarkInfo(new PDMarkInfo(doc.getPages().getCOSObject())); catalog.setMarkInfo(new PDMarkInfo(doc.getPages().getCOSObject()));
@@ -677,7 +713,8 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* Adds a StructureTreeRoot element to the PDF if it doesn't already exist. * Adds a StructureTreeRoot element to the PDF if it doesn't already exist.
*/ */
protected void addStructureTreeRoot() { @Override
protected void addStructureTreeRoot() {
if (doc.getDocumentCatalog().getStructureTreeRoot() == null) { if (doc.getDocumentCatalog().getStructureTreeRoot() == null) {
doc.getDocumentCatalog().setStructureTreeRoot(new PDStructureTreeRoot()); doc.getDocumentCatalog().setStructureTreeRoot(new PDStructureTreeRoot());
} }
@@ -687,19 +724,22 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* @return if pdf file will be automatically closed after adding ZF * @return if pdf file will be automatically closed after adding ZF
*/ */
public boolean isAutoCloseDisabled() { @Override
public boolean isAutoCloseDisabled() {
return disableAutoClose; return disableAutoClose;
} }
/** /**
* @param disableAutoClose prevent PDF file from being closed after adding ZF * @param disableAutoClose prevent PDF file from being closed after adding ZF
*/ */
public DXExporterFromA3 disableAutoClose(boolean disableAutoClose) { @Override
public DXExporterFromA3 disableAutoClose(boolean disableAutoClose) {
this.disableAutoClose = disableAutoClose; this.disableAutoClose = disableAutoClose;
return this; return this;
} }
protected void setXMLProvider(IXMLProvider p) { @Override
protected void setXMLProvider(IXMLProvider p) {
this.xmlProvider = p; this.xmlProvider = p;
if (profile != null) { if (profile != null) {
xmlProvider.setProfile(profile); xmlProvider.setProfile(profile);

View File

@@ -141,6 +141,6 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
*/ */
default IZUGFeRDAllowanceCharge[] getItemTotalAllowances() { default IZUGFeRDAllowanceCharge[] getItemTotalAllowances() {
return null; return null;
}; }
} }

View File

@@ -29,10 +29,11 @@ import org.apache.pdfbox.preflight.parser.PreflightParser;
import jakarta.activation.DataSource; import jakarta.activation.DataSource;
public class OXExporterFromA1 extends OXExporterFromA3 implements IZUGFeRDExporter { public class OXExporterFromA1 extends OXExporterFromA3 {
protected boolean ignorePDFAErrors = false; protected boolean ignorePDFAErrors = false;
public OXExporterFromA1 ignorePDFAErrors() { @Override
public OXExporterFromA1 ignorePDFAErrors() {
this.ignorePDFAErrors = true; this.ignorePDFAErrors = true;
return this; return this;
} }
@@ -45,7 +46,8 @@ public class OXExporterFromA1 extends OXExporterFromA3 implements IZUGFeRDExport
* @param ver the order-x version * @param ver the order-x version
* @return the URN of the namespace * @return the URN of the namespace
*/ */
public String getNamespaceForVersion(int ver) { @Override
public String getNamespaceForVersion(int ver) {
return "urn:factur-x:pdfa:CrossIndustryDocument:1p0#"; return "urn:factur-x:pdfa:CrossIndustryDocument:1p0#";
} }
/*** /***
@@ -53,7 +55,8 @@ public class OXExporterFromA1 extends OXExporterFromA3 implements IZUGFeRDExport
* @param ver the ox version * @param ver the ox version
* @return the namespace prefix as string, without colon * @return the namespace prefix as string, without colon
*/ */
public String getPrefixForVersion(int ver) { @Override
public String getPrefixForVersion(int ver) {
return "fx"; return "fx";
} }
@@ -87,14 +90,17 @@ public class OXExporterFromA1 extends OXExporterFromA3 implements IZUGFeRDExport
} }
public OXExporterFromA1 setProfile(Profile p) { @Override
public OXExporterFromA1 setProfile(Profile p) {
return (OXExporterFromA1)super.setProfile(p); return (OXExporterFromA1)super.setProfile(p);
} }
public OXExporterFromA1 setProfile(String profileName) { @Override
public OXExporterFromA1 setProfile(String profileName) {
return (OXExporterFromA1)super.setProfile(profileName); return (OXExporterFromA1)super.setProfile(profileName);
} }
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException { @Override
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException {
if (!ignorePDFAErrors && !isValidA1(dataSource)) { if (!ignorePDFAErrors && !isValidA1(dataSource)) {
throw new IOException("File is not a valid PDF/A input file"); throw new IOException("File is not a valid PDF/A input file");
} }
@@ -106,32 +112,41 @@ public class OXExporterFromA1 extends OXExporterFromA3 implements IZUGFeRDExport
} }
public OXExporterFromA1 load(String pdfFilename) throws IOException { @Override
public OXExporterFromA1 load(String pdfFilename) throws IOException {
return (OXExporterFromA1) super.load(pdfFilename); return (OXExporterFromA1) super.load(pdfFilename);
} }
public OXExporterFromA1 load(byte[] pdfBinary) throws IOException { @Override
public OXExporterFromA1 load(byte[] pdfBinary) throws IOException {
return (OXExporterFromA1) super.load(pdfBinary); return (OXExporterFromA1) super.load(pdfBinary);
} }
public OXExporterFromA1 load(InputStream pdfSource) throws IOException{ @Override
public OXExporterFromA1 load(InputStream pdfSource) throws IOException{
return (OXExporterFromA1) super.load(pdfSource); return (OXExporterFromA1) super.load(pdfSource);
} }
public OXExporterFromA1 setCreator(String creator) { @Override
public OXExporterFromA1 setCreator(String creator) {
return (OXExporterFromA1) super.setCreator(creator); return (OXExporterFromA1) super.setCreator(creator);
} }
public OXExporterFromA1 setConformanceLevel(PDFAConformanceLevel newLevel) { @Override
public OXExporterFromA1 setConformanceLevel(PDFAConformanceLevel newLevel) {
return (OXExporterFromA1) super.setConformanceLevel(newLevel); return (OXExporterFromA1) super.setConformanceLevel(newLevel);
} }
public OXExporterFromA1 setProducer(String producer){ @Override
public OXExporterFromA1 setProducer(String producer){
return (OXExporterFromA1) super.setProducer(producer); return (OXExporterFromA1) super.setProducer(producer);
} }
public OXExporterFromA1 setZUGFeRDVersion(int version){ @Override
public OXExporterFromA1 setZUGFeRDVersion(int version){
return (OXExporterFromA1) super.setZUGFeRDVersion(version); return (OXExporterFromA1) super.setZUGFeRDVersion(version);
} }
public OXExporterFromA1 setXML(byte[] zugferdData) throws IOException{ @Override
public OXExporterFromA1 setXML(byte[] zugferdData) throws IOException{
return (OXExporterFromA1) super.setXML(zugferdData); return (OXExporterFromA1) super.setXML(zugferdData);
} }
public OXExporterFromA1 disableAutoClose(boolean disableAutoClose){ @Override
public OXExporterFromA1 disableAutoClose(boolean disableAutoClose){
return (OXExporterFromA1) super.disableAutoClose(disableAutoClose); return (OXExporterFromA1) super.disableAutoClose(disableAutoClose);
} }
public OXExporterFromA1 convertOnly() { public OXExporterFromA1 convertOnly() {

View File

@@ -71,7 +71,7 @@ import jakarta.activation.FileDataSource;
public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 { public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE; protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<FileAttachment>(); protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>();
/** /**
* This flag controls whether or not the metadata is overwritten, or kind of merged. * This flag controls whether or not the metadata is overwritten, or kind of merged.
@@ -127,7 +127,7 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
protected String orderXDocumentType = "ORDER"; protected String orderXDocumentType = "ORDER";
private HashMap<String, byte[]> additionalXMLs = new HashMap<String, byte[]>(); private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
private boolean attachZUGFeRDHeaders = true; private boolean attachZUGFeRDHeaders = true;
@@ -138,7 +138,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param pdfFilename filename of an PDF/A1 compliant document * @param pdfFilename filename of an PDF/A1 compliant document
*/ */
public OXExporterFromA3 load(String pdfFilename) throws IOException { @Override
public OXExporterFromA3 load(String pdfFilename) throws IOException {
ensurePDFIsValid(new FileDataSource(pdfFilename)); ensurePDFIsValid(new FileDataSource(pdfFilename));
try (FileInputStream pdf = new FileInputStream(pdfFilename)) { try (FileInputStream pdf = new FileInputStream(pdfFilename)) {
@@ -146,11 +147,13 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
} }
} }
public IXMLProvider getProvider() { @Override
public IXMLProvider getProvider() {
return xmlProvider; return xmlProvider;
} }
public OXExporterFromA3 setProfile(Profile p) { @Override
public OXExporterFromA3 setProfile(Profile p) {
this.profile = p; this.profile = p;
if (xmlProvider != null) { if (xmlProvider != null) {
xmlProvider.setProfile(p); xmlProvider.setProfile(p);
@@ -158,7 +161,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return this; return this;
} }
public OXExporterFromA3 setProfile(String profilename) { @Override
public OXExporterFromA3 setProfile(String profilename) {
this.profile = Profiles.getByName(profilename); this.profile = Profiles.getByName(profilename);
if (xmlProvider != null) { if (xmlProvider != null) {
@@ -167,7 +171,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return this; return this;
} }
public OXExporterFromA3 addAdditionalFile(String name, byte[] content) { @Override
public OXExporterFromA3 addAdditionalFile(String name, byte[] content) {
fileAttachments.add(new FileAttachment(name, "text/xml", "Supplement", content).setDescription("ZUGFeRD extension/additional data")); fileAttachments.add(new FileAttachment(name, "text/xml", "Supplement", content).setDescription("ZUGFeRD extension/additional data"));
return this; return this;
} }
@@ -180,7 +185,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param pdfBinary binary of a PDF/A1 compliant document * @param pdfBinary binary of a PDF/A1 compliant document
*/ */
public OXExporterFromA3 load(byte[] pdfBinary) throws IOException { @Override
public OXExporterFromA3 load(byte[] pdfBinary) throws IOException {
ensurePDFIsValid(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary))); ensurePDFIsValid(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary)));
doc = Loader.loadPDF(pdfBinary); doc = Loader.loadPDF(pdfBinary);
return this; return this;
@@ -190,11 +196,13 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
super(); super();
} }
public void attachFile(FileAttachment file) { @Override
public void attachFile(FileAttachment file) {
fileAttachments.add(file); fileAttachments.add(file);
} }
public void attachFile(String filename, byte[] data, String mimetype, String relation) { @Override
public void attachFile(String filename, byte[] data, String mimetype, String relation) {
FileAttachment fa = new FileAttachment(filename, mimetype, relation, data); FileAttachment fa = new FileAttachment(filename, mimetype, relation, data);
fileAttachments.add(fa); fileAttachments.add(fa);
} }
@@ -204,7 +212,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param ZUGFeRDfilename the pdf file name * @param ZUGFeRDfilename the pdf file name
* @throws IOException if anything is wrong in the target location * @throws IOException if anything is wrong in the target location
*/ */
public void export(String ZUGFeRDfilename) throws IOException { @Override
public void export(String ZUGFeRDfilename) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
@@ -231,7 +240,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param output the OutputStream * @param output the OutputStream
* @throws IOException if anything is wrong in the OutputStream * @throws IOException if anything is wrong in the OutputStream
*/ */
public void export(OutputStream output) throws IOException { @Override
public void export(OutputStream output) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
@@ -257,7 +267,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param data the binary data of the file/attachment * @param data the binary data of the file/attachment
* @throws java.io.IOException if anything is wrong with filename * @throws java.io.IOException if anything is wrong with filename
*/ */
public void PDFAttachGenericFile(String filename, String relationship, String description, @Override
public void PDFAttachGenericFile(String filename, String relationship, String description,
String subType, byte[] data) throws IOException { String subType, byte[] data) throws IOException {
PDFAttachGenericFile(this.doc, filename, relationship, description, subType, data); PDFAttachGenericFile(this.doc, filename, relationship, description, subType, data);
} }
@@ -274,7 +285,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param data the binary data of the file/attachment * @param data the binary data of the file/attachment
* @throws IOException if anything is wrong with filename * @throws IOException if anything is wrong with filename
*/ */
public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description, @Override
public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description,
String subType, byte[] data) throws IOException { String subType, byte[] data) throws IOException {
fileAttached = true; fileAttached = true;
@@ -293,7 +305,7 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
ef.setSize(data.length); ef.setSize(data.length);
ef.setCreationDate(new GregorianCalendar()); ef.setCreationDate(new GregorianCalendar());
ef.setModDate(GregorianCalendar.getInstance()); ef.setModDate(Calendar.getInstance());
fs.setEmbeddedFile(ef); fs.setEmbeddedFile(ef);
@@ -325,7 +337,7 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
doc.getDocumentCatalog().setNames(names); doc.getDocumentCatalog().setNames(names);
// AF entry (Array) in catalog with the FileSpec // AF entry (Array) in catalog with the FileSpec
COSBase AFEntry = (COSBase) doc.getDocumentCatalog().getCOSObject().getItem("AF"); COSBase AFEntry = doc.getDocumentCatalog().getCOSObject().getItem("AF");
if ((AFEntry == null)) { if ((AFEntry == null)) {
COSArray cosArray = new COSArray(); COSArray cosArray = new COSArray();
cosArray.add(fs); cosArray.add(fs);
@@ -351,7 +363,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* @param zugferdData XML data to be set as a byte array (XML file in raw form). * @param zugferdData XML data to be set as a byte array (XML file in raw form).
* @throws IOException (should not happen) * @throws IOException (should not happen)
*/ */
public OXExporterFromA3 setXML(byte[] zugferdData) throws IOException { @Override
public OXExporterFromA3 setXML(byte[] zugferdData) throws IOException {
CustomXMLProvider cus = new CustomXMLProvider(); CustomXMLProvider cus = new CustomXMLProvider();
cus.setXML(zugferdData); cus.setXML(zugferdData);
this.setXMLProvider(cus); this.setXMLProvider(cus);
@@ -366,11 +379,13 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param pdfSource source to read a PDF/A1 compliant document from * @param pdfSource source to read a PDF/A1 compliant document from
*/ */
public OXExporterFromA3 load(InputStream pdfSource) throws IOException { @Override
public OXExporterFromA3 load(InputStream pdfSource) throws IOException {
return load(readAllBytes(pdfSource)); return load(readAllBytes(pdfSource));
} }
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException { @Override
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException {
return true; return true;
} }
@@ -393,23 +408,27 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* <p> * <p>
* Feel free to pass "A" as new level if you know what you are doing :-) * Feel free to pass "A" as new level if you know what you are doing :-)
*/ */
public OXExporterFromA3 setConformanceLevel(PDFAConformanceLevel newLevel) { @Override
public OXExporterFromA3 setConformanceLevel(PDFAConformanceLevel newLevel) {
conformanceLevel = newLevel; conformanceLevel = newLevel;
return this; return this;
} }
public OXExporterFromA3 setCreator(String creator) { @Override
public OXExporterFromA3 setCreator(String creator) {
this.creator = creator; this.creator = creator;
return this; return this;
} }
public OXExporterFromA3 setCreatorTool(String creatorTool) { @Override
public OXExporterFromA3 setCreatorTool(String creatorTool) {
this.creatorTool = creatorTool; this.creatorTool = creatorTool;
return this; return this;
} }
public OXExporterFromA3 setProducer(String producer) { @Override
public OXExporterFromA3 setProducer(String producer) {
this.producer = producer; this.producer = producer;
return this; return this;
} }
@@ -428,7 +447,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return this; return this;
} }
protected OXExporterFromA3 setAttachZUGFeRDHeaders(boolean attachHeaders) { @Override
protected OXExporterFromA3 setAttachZUGFeRDHeaders(boolean attachHeaders) {
this.attachZUGFeRDHeaders = attachHeaders; this.attachZUGFeRDHeaders = attachHeaders;
return this; return this;
} }
@@ -441,7 +461,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* *
* @param metadata the PDFbox XMPMetadata object * @param metadata the PDFbox XMPMetadata object
*/ */
protected void addXMP(XMPMetadata metadata) { @Override
protected void addXMP(XMPMetadata metadata) {
if (attachZUGFeRDHeaders) { if (attachZUGFeRDHeaders) {
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, 1, true, xmlProvider.getProfile(), XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, 1, true, xmlProvider.getProfile(),
@@ -468,12 +489,14 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* <code>setZUGFeRDXMLData(byte[] zugferdData)</code> * <code>setZUGFeRDXMLData(byte[] zugferdData)</code>
* @throws IOException if anything is wrong with already loaded PDF * @throws IOException if anything is wrong with already loaded PDF
*/ */
public IExporter setTransaction(IExportableTransaction trans) throws IOException { @Override
public IExporter setTransaction(IExportableTransaction trans) throws IOException {
this.trans = trans; this.trans = trans;
return prepare(); return prepare();
} }
public IExporter prepare() throws IOException { @Override
public IExporter prepare() throws IOException {
prepareDocument(); prepareDocument();
xmlProvider.generateXML(trans); xmlProvider.generateXML(trans);
String filename = "order-x.xml"; String filename = "order-x.xml";
@@ -492,7 +515,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* Reads the XMPMetadata from the PDDocument, if it exists. * Reads the XMPMetadata from the PDDocument, if it exists.
* Otherwise creates XMPMetadata. * Otherwise creates XMPMetadata.
*/ */
protected XMPMetadata getXmpMetadata() throws IOException { @Override
protected XMPMetadata getXmpMetadata() throws IOException {
PDMetadata meta = doc.getDocumentCatalog().getMetadata(); PDMetadata meta = doc.getDocumentCatalog().getMetadata();
if ((meta != null) && (meta.getLength() > 0)) { if ((meta != null) && (meta.getLength() > 0)) {
try { try {
@@ -505,7 +529,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return XMPMetadata.createXMPMetadata(); return XMPMetadata.createXMPMetadata();
} }
protected byte[] serializeXmpMetadata(XMPMetadata xmpMetadata) throws TransformerException { @Override
protected byte[] serializeXmpMetadata(XMPMetadata xmpMetadata) throws TransformerException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
new XmpSerializer().serialize(xmpMetadata, buffer, true); // see https://github.com/ZUGFeRD/mustangproject/issues/44 new XmpSerializer().serialize(xmpMetadata, buffer, true); // see https://github.com/ZUGFeRD/mustangproject/issues/44
return buffer.toByteArray(); return buffer.toByteArray();
@@ -515,7 +540,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* Sets the producer if the overwrite flag is set or the producer is not already set. * Sets the producer if the overwrite flag is set or the producer is not already set.
* Sets the PDFVersion to 1.4 if the field is empty. * Sets the PDFVersion to 1.4 if the field is empty.
*/ */
protected void writeAdobePDFSchema(XMPMetadata xmp) { @Override
protected void writeAdobePDFSchema(XMPMetadata xmp) {
AdobePDFSchema pdf = getAdobePDFSchema(xmp); AdobePDFSchema pdf = getAdobePDFSchema(xmp);
if (overwrite || isEmpty(pdf.getProducer())) if (overwrite || isEmpty(pdf.getProducer()))
pdf.setProducer(producer); pdf.setProducer(producer);
@@ -525,7 +551,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
* Returns the AdobePDFSchema from the XMPMetadata if it exists. * Returns the AdobePDFSchema from the XMPMetadata if it exists.
* If the overwrite flag is set or no AdobePDFSchema exists in the XMPMetadata, it is created, added and returned. * If the overwrite flag is set or no AdobePDFSchema exists in the XMPMetadata, it is created, added and returned.
*/ */
protected AdobePDFSchema getAdobePDFSchema(XMPMetadata xmp) { @Override
protected AdobePDFSchema getAdobePDFSchema(XMPMetadata xmp) {
AdobePDFSchema pdf = xmp.getAdobePDFSchema(); AdobePDFSchema pdf = xmp.getAdobePDFSchema();
if (pdf != null) if (pdf != null)
if (overwrite) if (overwrite)
@@ -535,7 +562,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddAdobePDFSchema(); return xmp.createAndAddAdobePDFSchema();
} }
protected void writePDFAIdentificationSchema(XMPMetadata xmp) { @Override
protected void writePDFAIdentificationSchema(XMPMetadata xmp) {
PDFAIdentificationSchema pdfaid = getPDFAIdentificationSchema(xmp); PDFAIdentificationSchema pdfaid = getPDFAIdentificationSchema(xmp);
if (overwrite || isEmpty(pdfaid.getConformance())) { if (overwrite || isEmpty(pdfaid.getConformance())) {
try { try {
@@ -550,7 +578,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
pdfaid.setPart(3); pdfaid.setPart(3);
} }
protected PDFAIdentificationSchema getPDFAIdentificationSchema(XMPMetadata xmp) { @Override
protected PDFAIdentificationSchema getPDFAIdentificationSchema(XMPMetadata xmp) {
PDFAIdentificationSchema pdfaid = xmp.getPDFAIdentificationSchema(); PDFAIdentificationSchema pdfaid = xmp.getPDFAIdentificationSchema();
if (pdfaid != null) if (pdfaid != null)
if (overwrite) if (overwrite)
@@ -560,7 +589,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddPDFAIdentificationSchema(); return xmp.createAndAddPDFAIdentificationSchema();
} }
protected void writeDublinCoreSchema(XMPMetadata xmp) { @Override
protected void writeDublinCoreSchema(XMPMetadata xmp) {
DublinCoreSchema dc = getDublinCoreSchema(xmp); DublinCoreSchema dc = getDublinCoreSchema(xmp);
if (dc.getFormat() == null) if (dc.getFormat() == null)
dc.setFormat("application/pdf"); dc.setFormat("application/pdf");
@@ -583,7 +613,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
} }
} }
protected DublinCoreSchema getDublinCoreSchema(XMPMetadata xmp) { @Override
protected DublinCoreSchema getDublinCoreSchema(XMPMetadata xmp) {
DublinCoreSchema dc = xmp.getDublinCoreSchema(); DublinCoreSchema dc = xmp.getDublinCoreSchema();
if (dc != null) if (dc != null)
if (overwrite) if (overwrite)
@@ -593,15 +624,17 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddDublinCoreSchema(); return xmp.createAndAddDublinCoreSchema();
} }
protected void writeXMLBasicSchema(XMPMetadata xmp) { @Override
protected void writeXMLBasicSchema(XMPMetadata xmp) {
XMPBasicSchema xsb = getXmpBasicSchema(xmp); XMPBasicSchema xsb = getXmpBasicSchema(xmp);
if (overwrite || isEmpty(xsb.getCreatorTool()) || "UnknownApplication".equals(xsb.getCreatorTool())) if (overwrite || isEmpty(xsb.getCreatorTool()) || "UnknownApplication".equals(xsb.getCreatorTool()))
xsb.setCreatorTool(creatorTool); xsb.setCreatorTool(creatorTool);
if (overwrite || xsb.getCreateDate() == null) if (overwrite || xsb.getCreateDate() == null)
xsb.setCreateDate(GregorianCalendar.getInstance()); xsb.setCreateDate(Calendar.getInstance());
} }
protected XMPBasicSchema getXmpBasicSchema(XMPMetadata xmp) { @Override
protected XMPBasicSchema getXmpBasicSchema(XMPMetadata xmp) {
XMPBasicSchema xsb = xmp.getXMPBasicSchema(); XMPBasicSchema xsb = xmp.getXMPBasicSchema();
if (xsb != null) if (xsb != null)
if (overwrite) if (overwrite)
@@ -611,7 +644,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
return xmp.createAndAddXMPBasicSchema(); return xmp.createAndAddXMPBasicSchema();
} }
protected void writeDocumentInformation() { @Override
protected void writeDocumentInformation() {
String fullProducer = producer + " (via mustangproject.org " + Version.VERSION + ")"; String fullProducer = producer + " (via mustangproject.org " + Version.VERSION + ")";
PDDocumentInformation info = doc.getDocumentInformation(); PDDocumentInformation info = doc.getDocumentInformation();
if (overwrite || info.getCreationDate() == null) if (overwrite || info.getCreationDate() == null)
@@ -633,7 +667,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* Adds an OutputIntent and the sRGB color profile if no OutputIntent exist * Adds an OutputIntent and the sRGB color profile if no OutputIntent exist
*/ */
protected void addSRGBOutputIntend() throws IOException { @Override
protected void addSRGBOutputIntend() throws IOException {
if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) { if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) {
return; return;
} }
@@ -656,7 +691,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* Adds a MarkInfo element to the PDF if it doesn't already exist and sets it as marked. * Adds a MarkInfo element to the PDF if it doesn't already exist and sets it as marked.
*/ */
protected void setMarked() { @Override
protected void setMarked() {
PDDocumentCatalog catalog = doc.getDocumentCatalog(); PDDocumentCatalog catalog = doc.getDocumentCatalog();
if (catalog.getMarkInfo() == null) { if (catalog.getMarkInfo() == null) {
catalog.setMarkInfo(new PDMarkInfo(doc.getPages().getCOSObject())); catalog.setMarkInfo(new PDMarkInfo(doc.getPages().getCOSObject()));
@@ -667,7 +703,8 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* Adds a StructureTreeRoot element to the PDF if it doesn't already exist. * Adds a StructureTreeRoot element to the PDF if it doesn't already exist.
*/ */
protected void addStructureTreeRoot() { @Override
protected void addStructureTreeRoot() {
if (doc.getDocumentCatalog().getStructureTreeRoot() == null) { if (doc.getDocumentCatalog().getStructureTreeRoot() == null) {
doc.getDocumentCatalog().setStructureTreeRoot(new PDStructureTreeRoot()); doc.getDocumentCatalog().setStructureTreeRoot(new PDStructureTreeRoot());
} }
@@ -677,19 +714,22 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
/** /**
* @return if pdf file will be automatically closed after adding ZF * @return if pdf file will be automatically closed after adding ZF
*/ */
public boolean isAutoCloseDisabled() { @Override
public boolean isAutoCloseDisabled() {
return disableAutoClose; return disableAutoClose;
} }
/** /**
* @param disableAutoClose prevent PDF file from being closed after adding ZF * @param disableAutoClose prevent PDF file from being closed after adding ZF
*/ */
public OXExporterFromA3 disableAutoClose(boolean disableAutoClose) { @Override
public OXExporterFromA3 disableAutoClose(boolean disableAutoClose) {
this.disableAutoClose = disableAutoClose; this.disableAutoClose = disableAutoClose;
return this; return this;
} }
protected void setXMLProvider(IXMLProvider p) { @Override
protected void setXMLProvider(IXMLProvider p) {
this.xmlProvider = p; this.xmlProvider = p;
if (profile != null) { if (profile != null) {
xmlProvider.setProfile(profile); xmlProvider.setProfile(profile);

View File

@@ -37,7 +37,7 @@ import org.mustangproject.EStandard;
import org.mustangproject.FileAttachment; import org.mustangproject.FileAttachment;
import org.mustangproject.XMLTools; import org.mustangproject.XMLTools;
public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider { public class OXPullProvider extends ZUGFeRD2PullProvider {
protected IExportableTransaction trans; protected IExportableTransaction trans;
protected TransactionCalculator calc; protected TransactionCalculator calc;
@@ -329,7 +329,7 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
} }
} }
} }
if ((trans.getDocumentCode() == CORRECTEDINVOICE)/*||(trans.getDocumentCode() == DocumentCodeTypeConstants.CREDITNOTE)*/) { if ((trans.getDocumentCode().equals(CORRECTEDINVOICE))/*||(trans.getDocumentCode().equals (DocumentCodeTypeConstants.CREDITNOTE))*/) {
hasDueDate = false; hasDueDate = false;
} }

View File

@@ -2,19 +2,13 @@ package org.mustangproject.ZUGFeRD;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccessRead;
import org.apache.pdfbox.io.RandomAccessReadBuffer;
import org.apache.pdfbox.preflight.parser.PreflightParser; import org.apache.pdfbox.preflight.parser.PreflightParser;
import jakarta.activation.DataSource; import jakarta.activation.DataSource;

View File

@@ -40,7 +40,7 @@ import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import org.mustangproject.XMLTools; import org.mustangproject.XMLTools;
public class ZUGFeRD1PullProvider extends ZUGFeRD2PullProvider implements IXMLProvider { public class ZUGFeRD1PullProvider extends ZUGFeRD2PullProvider {
//// MAIN CLASS //// MAIN CLASS

View File

@@ -30,7 +30,7 @@ import org.mustangproject.EStandard;
import jakarta.activation.DataSource; import jakarta.activation.DataSource;
public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 implements IZUGFeRDExporter { public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 {
private static boolean isValidA1(DataSource dataSource) throws IOException { private static boolean isValidA1(DataSource dataSource) throws IOException {
return getPDFAParserValidationResult(PreflightParserHelper.createPreflightParser(dataSource)); return getPDFAParserValidationResult(PreflightParserHelper.createPreflightParser(dataSource));
@@ -66,14 +66,17 @@ public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 implements IZUG
} }
public ZUGFeRDExporterFromA1 setProfile(Profile p) { @Override
public ZUGFeRDExporterFromA1 setProfile(Profile p) {
return (ZUGFeRDExporterFromA1)super.setProfile(p); return (ZUGFeRDExporterFromA1)super.setProfile(p);
} }
public ZUGFeRDExporterFromA1 setProfile(String profileName) { @Override
public ZUGFeRDExporterFromA1 setProfile(String profileName) {
return (ZUGFeRDExporterFromA1)super.setProfile(profileName); return (ZUGFeRDExporterFromA1)super.setProfile(profileName);
} }
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException { @Override
public boolean ensurePDFIsValid(final DataSource dataSource) throws IOException {
if (!ignorePDFAErrors && !isValidA1(dataSource)) { if (!ignorePDFAErrors && !isValidA1(dataSource)) {
throw new IOException("File is not a valid PDF/A-1 input file"); throw new IOException("File is not a valid PDF/A-1 input file");
} }
@@ -81,35 +84,45 @@ public class ZUGFeRDExporterFromA1 extends ZUGFeRDExporterFromA3 implements IZUG
} }
public ZUGFeRDExporterFromA1 load(String pdfFilename) throws IOException { @Override
public ZUGFeRDExporterFromA1 load(String pdfFilename) throws IOException {
return (ZUGFeRDExporterFromA1) super.load(pdfFilename); return (ZUGFeRDExporterFromA1) super.load(pdfFilename);
} }
public ZUGFeRDExporterFromA1 load(byte[] pdfBinary) throws IOException { @Override
public ZUGFeRDExporterFromA1 load(byte[] pdfBinary) throws IOException {
return (ZUGFeRDExporterFromA1) super.load(pdfBinary); return (ZUGFeRDExporterFromA1) super.load(pdfBinary);
} }
public ZUGFeRDExporterFromA1 load(InputStream pdfSource) throws IOException{ @Override
public ZUGFeRDExporterFromA1 load(InputStream pdfSource) throws IOException{
return (ZUGFeRDExporterFromA1) super.load(pdfSource); return (ZUGFeRDExporterFromA1) super.load(pdfSource);
} }
public ZUGFeRDExporterFromA1 setCreator(String creator) { @Override
public ZUGFeRDExporterFromA1 setCreator(String creator) {
return (ZUGFeRDExporterFromA1) super.setCreator(creator); return (ZUGFeRDExporterFromA1) super.setCreator(creator);
} }
public ZUGFeRDExporterFromA1 setConformanceLevel(PDFAConformanceLevel newLevel) { @Override
public ZUGFeRDExporterFromA1 setConformanceLevel(PDFAConformanceLevel newLevel) {
return (ZUGFeRDExporterFromA1) super.setConformanceLevel(newLevel); return (ZUGFeRDExporterFromA1) super.setConformanceLevel(newLevel);
} }
public ZUGFeRDExporterFromA1 setProducer(String producer){ @Override
public ZUGFeRDExporterFromA1 setProducer(String producer){
return (ZUGFeRDExporterFromA1) super.setProducer(producer); return (ZUGFeRDExporterFromA1) super.setProducer(producer);
} }
public ZUGFeRDExporterFromA1 setZUGFeRDVersion(EStandard est, int version){ @Override
public ZUGFeRDExporterFromA1 setZUGFeRDVersion(EStandard est, int version){
return (ZUGFeRDExporterFromA1) super.setZUGFeRDVersion(est, version); return (ZUGFeRDExporterFromA1) super.setZUGFeRDVersion(est, version);
} }
public ZUGFeRDExporterFromA1 setZUGFeRDVersion(int version){ @Override
public ZUGFeRDExporterFromA1 setZUGFeRDVersion(int version){
return (ZUGFeRDExporterFromA1) super.setZUGFeRDVersion(version); return (ZUGFeRDExporterFromA1) super.setZUGFeRDVersion(version);
} }
public ZUGFeRDExporterFromA1 setXML(byte[] zugferdData) throws IOException{ @Override
public ZUGFeRDExporterFromA1 setXML(byte[] zugferdData) throws IOException{
return (ZUGFeRDExporterFromA1) super.setXML(zugferdData); return (ZUGFeRDExporterFromA1) super.setXML(zugferdData);
} }
public ZUGFeRDExporterFromA1 disableAutoClose(boolean disableAutoClose){ @Override
public ZUGFeRDExporterFromA1 disableAutoClose(boolean disableAutoClose){
return (ZUGFeRDExporterFromA1) super.disableAutoClose(disableAutoClose); return (ZUGFeRDExporterFromA1) super.disableAutoClose(disableAutoClose);
} }
public ZUGFeRDExporterFromA1 convertOnly() { public ZUGFeRDExporterFromA1 convertOnly() {

View File

@@ -22,7 +22,6 @@ package org.mustangproject.ZUGFeRD;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -76,7 +75,7 @@ import org.mustangproject.FileAttachment;
import jakarta.activation.DataSource; import jakarta.activation.DataSource;
import jakarta.activation.FileDataSource; import jakarta.activation.FileDataSource;
public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporter, IExporter, Closeable { public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporter {
private boolean isFacturX = true; private boolean isFacturX = true;
public static final int DefaultZUGFeRDVersion = 2; public static final int DefaultZUGFeRDVersion = 2;
@@ -87,7 +86,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
return this; return this;
} }
protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE; protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<FileAttachment>(); protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>();
/** /**
* This flag controls whether or not the metadata is overwritten, or kind of merged. * This flag controls whether or not the metadata is overwritten, or kind of merged.
@@ -139,7 +138,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
protected PDDocument doc; protected PDDocument doc;
private HashMap<String, byte[]> additionalXMLs = new HashMap<String, byte[]>(); private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
protected int ZFVersion = DefaultZUGFeRDVersion; protected int ZFVersion = DefaultZUGFeRDVersion;
@@ -248,9 +247,10 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* Generate ZF2.1 files with filename factur-x.xml * Generate ZF2.1 files with filename factur-x.xml
* *
* @return this (fluent setter) * @return this (fluent setter)
* @deprecated * @deprecated It's now the default anyway
*/ */
public ZUGFeRDExporterFromA3 setFacturX() { @Deprecated
public ZUGFeRDExporterFromA3 setFacturX() {
isFacturX = true; isFacturX = true;
return this; return this;
} }
@@ -310,7 +310,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @param ZUGFeRDfilename the pdf file name * @param ZUGFeRDfilename the pdf file name
* @throws IOException if anything is wrong in the target location * @throws IOException if anything is wrong in the target location
*/ */
public void export(String ZUGFeRDfilename) throws IOException { @Override
public void export(String ZUGFeRDfilename) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
@@ -337,7 +338,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @param output the OutputStream * @param output the OutputStream
* @throws IOException if anything is wrong in the OutputStream * @throws IOException if anything is wrong in the OutputStream
*/ */
public void export(OutputStream output) throws IOException { @Override
public void export(OutputStream output) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
@@ -399,7 +401,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
ef.setSize(data.length); ef.setSize(data.length);
ef.setCreationDate(new GregorianCalendar()); ef.setCreationDate(new GregorianCalendar());
ef.setModDate(GregorianCalendar.getInstance()); ef.setModDate(Calendar.getInstance());
fs.setEmbeddedFile(ef); fs.setEmbeddedFile(ef);
@@ -431,7 +433,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
doc.getDocumentCatalog().setNames(names); doc.getDocumentCatalog().setNames(names);
// AF entry (Array) in catalog with the FileSpec // AF entry (Array) in catalog with the FileSpec
COSBase AFEntry = (COSBase) doc.getDocumentCatalog().getCOSObject().getItem("AF"); COSBase AFEntry = doc.getDocumentCatalog().getCOSObject().getItem("AF");
if ((AFEntry == null)) { if ((AFEntry == null)) {
COSArray cosArray = new COSArray(); COSArray cosArray = new COSArray();
cosArray.add(fs); cosArray.add(fs);
@@ -636,7 +638,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* <code>setZUGFeRDXMLData(byte[] zugferdData)</code> * <code>setZUGFeRDXMLData(byte[] zugferdData)</code>
* @throws IOException if anything is wrong with already loaded PDF * @throws IOException if anything is wrong with already loaded PDF
*/ */
public IExporter setTransaction(IExportableTransaction trans) throws IOException { @Override
public IExporter setTransaction(IExportableTransaction trans) throws IOException {
this.trans = trans; this.trans = trans;
return prepare(); return prepare();
} }
@@ -788,7 +791,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
if (overwrite || isEmpty(xsb.getCreatorTool()) || "UnknownApplication".equals(xsb.getCreatorTool())) if (overwrite || isEmpty(xsb.getCreatorTool()) || "UnknownApplication".equals(xsb.getCreatorTool()))
xsb.setCreatorTool(creatorTool); xsb.setCreatorTool(creatorTool);
if (overwrite || xsb.getCreateDate() == null) if (overwrite || xsb.getCreateDate() == null)
xsb.setCreateDate(GregorianCalendar.getInstance()); xsb.setCreateDate(Calendar.getInstance());
} }
protected XMPBasicSchema getXmpBasicSchema(XMPMetadata xmp) { protected XMPBasicSchema getXmpBasicSchema(XMPMetadata xmp) {

View File

@@ -168,7 +168,7 @@ public class ZUGFeRDExporterFromPDFA implements IZUGFeRDExporter {
} }
public IZUGFeRDExporter setProfile(Profile p) { public IZUGFeRDExporter setProfile(Profile p) {
return (IZUGFeRDExporter) getExporter().setProfile(p); return getExporter().setProfile(p);
} }
public IZUGFeRDExporter setProfile(String profileName) { public IZUGFeRDExporter setProfile(String profileName) {
@@ -176,7 +176,7 @@ public class ZUGFeRDExporterFromPDFA implements IZUGFeRDExporter {
if (p==null) { if (p==null) {
throw new RuntimeException("Profile not found."); throw new RuntimeException("Profile not found.");
} }
return (IZUGFeRDExporter) getExporter().setProfile(p); return getExporter().setProfile(p);
} }
public IZUGFeRDExporter setConformanceLevel(PDFAConformanceLevel newLevel) { public IZUGFeRDExporter setConformanceLevel(PDFAConformanceLevel newLevel) {

View File

@@ -222,9 +222,8 @@ public class ZUGFeRDVisualizer {
} }
FileInputStream fis = new FileInputStream(xmlFilename); FileInputStream fis = new FileInputStream(xmlFilename);
String fileContent = "";
try { try {
fileContent = new String(Files.readAllBytes(Paths.get(xmlFilename)), StandardCharsets.UTF_8); new String(Files.readAllBytes(Paths.get(xmlFilename)), StandardCharsets.UTF_8);
} catch (IOException e2) { } catch (IOException e2) {
LOG.log(Level.SEVERE, null, e2); LOG.log(Level.SEVERE, null, e2);
} }
@@ -276,11 +275,8 @@ public class ZUGFeRDVisualizer {
public void toPDF(String xmlFilename, String pdfFilename) { public void toPDF(String xmlFilename, String pdfFilename) {
// the writing part // the writing part
CIIToUBL c2u = new CIIToUBL();
String sourceFilename = "factur-x.xml";
File CIIinputFile = new File(xmlFilename); File CIIinputFile = new File(xmlFilename);
String expected = null;
String result = null; String result = null;
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();

View File

@@ -316,7 +316,7 @@ public class BackwardCompatibilityTest extends TestCase implements IExportableTr
// //
public IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() { public IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() {
Payment P = new Payment(); Payment P = new Payment();
IZUGFeRDTradeSettlementPayment[] allP = new Payment[1]; IZUGFeRDTradeSettlementPayment[] allP = new Payment[1];
allP[0] = P; allP[0] = P;

View File

@@ -22,16 +22,7 @@ import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.mustangproject.XMLTools; import org.mustangproject.XMLTools;
public class BaseTest extends TestCase { public class BaseTest extends TestCase {

View File

@@ -45,7 +45,7 @@ import java.util.GregorianCalendar;
import static org.xmlunit.assertj.XmlAssert.assertThat; import static org.xmlunit.assertj.XmlAssert.assertThat;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DXTest extends MustangReaderTestCase implements IExportableTransaction { public class DXTest extends MustangReaderTestCase {
final String TARGET_PDF = "./target/testout-DX.pdf"; final String TARGET_PDF = "./target/testout-DX.pdf";
final String TARGET_XML = "./target/testout-DX.xml"; final String TARGET_XML = "./target/testout-DX.xml";

View File

@@ -21,12 +21,9 @@
*/ */
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.assertj.core.util.Lists;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.mustangproject.*; import org.mustangproject.*;

View File

@@ -26,6 +26,8 @@ import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.mustangproject.*; import org.mustangproject.*;
import com.helger.commons.io.file.SimpleFileIO;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;

View File

@@ -43,7 +43,7 @@ import java.util.GregorianCalendar;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MustangReaderWriterEdgeTest extends MustangReaderTestCase { public class MustangReaderWriterEdgeTest extends MustangReaderTestCase {
protected class EasyRecipientTradeParty extends RecipientTradeParty implements IZUGFeRDExportableTradeParty { protected class EasyRecipientTradeParty extends RecipientTradeParty {
// Not testing extended profile here, lineThree not possible // Not testing extended profile here, lineThree not possible
@Override @Override
public String getAdditionalAddressExtension() { public String getAdditionalAddressExtension() {

View File

@@ -28,7 +28,6 @@ import org.junit.runners.MethodSorters;
import org.mustangproject.*; import org.mustangproject.*;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -42,7 +41,7 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OXTest extends MustangReaderTestCase implements IExportableTransaction { public class OXTest extends MustangReaderTestCase {
final String TARGET_PDF = "./target/testout-OX.pdf"; final String TARGET_PDF = "./target/testout-OX.pdf";
final String TARGET_PDF_EDGE = "./target/testout-OX-edge.pdf"; final String TARGET_PDF_EDGE = "./target/testout-OX-edge.pdf";
final String TARGET_XML = "./target/testout-OX.xml"; final String TARGET_XML = "./target/testout-OX.xml";

View File

@@ -23,13 +23,10 @@ package org.mustangproject.ZUGFeRD;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.mustangproject.*; import org.mustangproject.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
/*** /***
* This is a test to confirm the minimum steps to implement a interface are still sufficient * This is a test to confirm the minimum steps to implement a interface are still sufficient

View File

@@ -19,24 +19,9 @@
*********************************************************************** */ *********************************************************************** */
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.mustangproject.Contact;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class UXTest extends TestCase { public class UXTest extends TestCase {

View File

@@ -69,8 +69,6 @@ public class VisualizationTest extends ResourceCase {
public void testUBLCreditNoteVisualizationBasic() { public void testUBLCreditNoteVisualizationBasic() {
// the writing part // the writing part
CIIToUBL c2u = new CIIToUBL();
String sourceFilename = "factur-x.xml";
File UBLinputFile = getResourceAsFile("ubl-creditnote.xml"); File UBLinputFile = getResourceAsFile("ubl-creditnote.xml");
String expected = null; String expected = null;
@@ -105,8 +103,6 @@ public class VisualizationTest extends ResourceCase {
public void testUBLVisualizationBasic() { public void testUBLVisualizationBasic() {
// the writing part // the writing part
CIIToUBL c2u = new CIIToUBL();
String sourceFilename = "factur-x.xml";
File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml");
String expected = null; String expected = null;

View File

@@ -32,9 +32,6 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date; import java.util.Date;
import static org.xmlunit.assertj.XmlAssert.assertThat; import static org.xmlunit.assertj.XmlAssert.assertThat;

View File

@@ -37,7 +37,7 @@ import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ZF2EdgeTest extends MustangReaderTestCase implements IExportableTransaction { public class ZF2EdgeTest extends MustangReaderTestCase {
final String TARGET_PDF = "./target/testout-ZF2newEdge.pdf"; final String TARGET_PDF = "./target/testout-ZF2newEdge.pdf";
protected class EdgeProduct implements IZUGFeRDExportableProduct { protected class EdgeProduct implements IZUGFeRDExportableProduct {
@@ -325,7 +325,7 @@ public class ZF2EdgeTest extends MustangReaderTestCase implements IExportableTra
assertTrue(resultXML.contains("<ram:IssuerAssignedID>123</ram:IssuerAssignedID>")); assertTrue(resultXML.contains("<ram:IssuerAssignedID>123</ram:IssuerAssignedID>"));
// Reading ZUGFeRD // Reading ZUGFeRD
assertEquals("337.60", zi.getAmount());; assertEquals("337.60", zi.getAmount());
assertEquals(zi.getHolder(), getOwnOrganisationName()); assertEquals(zi.getHolder(), getOwnOrganisationName());
assertEquals(zi.getForeignReference(), getNumber()); assertEquals(zi.getForeignReference(), getNumber());
try { try {

View File

@@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.mustangproject.*; import org.mustangproject.*;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
@@ -38,9 +37,6 @@ import org.junit.runners.MethodSorters;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.mustangproject.ZUGFeRD.model.EventTimeCodeTypeConstants; import org.mustangproject.ZUGFeRD.model.EventTimeCodeTypeConstants;
import org.xmlunit.builder.Input;
import org.xmlunit.xpath.JAXPXPathEngine;
import org.xmlunit.xpath.XPathEngine;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
@@ -138,7 +134,7 @@ public class ZF2PushTest extends TestCase {
byte[] b = {12, 13}; byte[] b = {12, 13};
ze.attachFile("one.pdf", b, "application/pdf", "Alternative"); ze.attachFile("one.pdf", b, "application/pdf", "Alternative");
ze.attachFile("two.pdf", b, "application/pdf", "Alternative"); ze.attachFile("two.pdf", b, "application/pdf", "Alternative");
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0))) ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).addVATID("DE0815")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))
); );
String theXML = new String(ze.getProvider().getXML()); String theXML = new String(ze.getProvider().getXML());
@@ -186,7 +182,7 @@ public class ZF2PushTest extends TestCase {
String IBAN = "DE999888777"; String IBAN = "DE999888777";
String BIC = "COBADEFXXX"; String BIC = "COBADEFXXX";
BankDetails bd = new BankDetails(IBAN, BIC); BankDetails bd = new BankDetails(IBAN, BIC);
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addBankDetails(bd).addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0))) ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addBankDetails(bd).addTaxID(taxID).addVATID("DE0815")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))
); );
String theXML = new String(ze.getProvider().getXML()); String theXML = new String(ze.getProvider().getXML());
@@ -226,7 +222,7 @@ public class ZF2PushTest extends TestCase {
// .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance().setPercent(new BigDecimal(50))))); // .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance().setPercent(new BigDecimal(50)))));
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE")).setOwnTaxID("4711").setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setContact(new Contact("contact testname", "123456", "contact.testemail@example.org").setFax("0911623562"))).setNumber(number) ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setContact(new Contact("contact testname", "123456", "contact.testemail@example.org").setFax("0911623562"))).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance(new BigDecimal("0.1")))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance(new BigDecimal("0.1"))))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance().setPercent(new BigDecimal(50)))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance().setPercent(new BigDecimal(50))))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(2.0)).addCharge(new Charge(new BigDecimal(1)))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(2.0)).addCharge(new Charge(new BigDecimal(1))))
@@ -280,7 +276,7 @@ public class ZF2PushTest extends TestCase {
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addVATID("DE0815")).setOwnTaxID("4711") .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addVATID("DE0815").addTaxID ("4711"))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0816").setContact(new Contact("contact testname", "123456", "contact.testemail@example.org").setFax("0911623562"))) .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0816").setContact(new Contact("contact testname", "123456", "contact.testemail@example.org").setFax("0911623562")))
.setDeliveryAddress(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0816")) .setDeliveryAddress(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0816"))
.setNumber(number) .setNumber(number)
@@ -335,7 +331,7 @@ public class ZF2PushTest extends TestCase {
// .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance().setPercent(new BigDecimal(50))))); // .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)).addAllowance(new Allowance().setPercent(new BigDecimal(50)))));
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addVATID("DE0815")).setOwnTaxID("4711").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0816").setContact(new Contact("contact testname", "123456", "contact.testemail@example.org").setFax("0911623562"))).setNumber(number) ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addVATID("DE0815").addTaxID("4711")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0816").setContact(new Contact("contact testname", "123456", "contact.testemail@example.org").setFax("0911623562"))).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).setReverseCharge(), amount, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).setReverseCharge(), amount, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).setReverseCharge(), amount, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).setReverseCharge(), amount, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).setReverseCharge(), amount, new BigDecimal(2.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)).setReverseCharge(), amount, new BigDecimal(2.0)))
@@ -384,7 +380,7 @@ public class ZF2PushTest extends TestCase {
ze.setProducer("My Application") ze.setProducer("My Application")
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("en16931")); .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("en16931"));
ze.setTransaction(new Invoice().setCurrency("CHF").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE")).setOwnTaxID("4711").setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number) ze.setTransaction(new Invoice().setCurrency("CHF").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)))
@@ -449,7 +445,7 @@ public class ZF2PushTest extends TestCase {
ze.setTransaction(new Invoice().setCurrency("CHF").addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) ze.setTransaction(new Invoice().setCurrency("CHF").addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSellerOrderReferencedDocumentID("9384").setBuyerOrderReferencedDocumentID("28934") .setSellerOrderReferencedDocumentID("9384").setBuyerOrderReferencedDocumentID("28934")
.setDetailedDeliveryPeriod(new SimpleDateFormat("yyyyMMdd").parse(occurrenceFrom), new SimpleDateFormat("yyyyMMdd").parse(occurrenceTo)) .setDetailedDeliveryPeriod(new SimpleDateFormat("yyyyMMdd").parse(occurrenceFrom), new SimpleDateFormat("yyyyMMdd").parse(occurrenceTo))
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).setEmail("sender@test.org").setID("0009845")) .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).setEmail("sender@test.org").setID("0009845").addVATID("DE0815"))
.setDeliveryAddress(new TradeParty("just the other side of the street", "teststr.12a", "55232", "Entenhausen", "DE").addVATID("DE47110")) .setDeliveryAddress(new TradeParty("just the other side of the street", "teststr.12a", "55232", "Entenhausen", "DE").addVATID("DE47110"))
.setContractReferencedDocument(contractID) .setContractReferencedDocument(contractID)
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addGlobalID(gln).setEmail("recipient@test.org").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3")) .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addGlobalID(gln).setEmail("recipient@test.org").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3"))
@@ -457,7 +453,7 @@ public class ZF2PushTest extends TestCase {
.addCharge(new Charge(new BigDecimal(0.5)).setReason("quick delivery charge").setTaxPercent(new BigDecimal(16))) .addCharge(new Charge(new BigDecimal(0.5)).setReason("quick delivery charge").setTaxPercent(new BigDecimal(16)))
.addAllowance(new Allowance(new BigDecimal(0.2)).setReason("discount").setTaxPercent(new BigDecimal(16))) .addAllowance(new Allowance(new BigDecimal(0.2)).setReason("discount").setTaxPercent(new BigDecimal(16)))
.addCashDiscount(new CashDiscount(new BigDecimal(2), 14)) .addCashDiscount(new CashDiscount(new BigDecimal(2), 14))
.setDeliveryDate(sdf.parse("2020-11-02")).setOwnVATID("DE0815").setNumber(number).setVATDueDateTypeCode(EventTimeCodeTypeConstants.PAYMENT_DATE) .setDeliveryDate(sdf.parse("2020-11-02")).setNumber(number).setVATDueDateTypeCode(EventTimeCodeTypeConstants.PAYMENT_DATE)
); );
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
@@ -535,7 +531,7 @@ public class ZF2PushTest extends TestCase {
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("en16931")); .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("en16931"));
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE")).setOwnTaxID("4711").setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number) ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal(500.0), qty).addAllowance(new Allowance(new BigDecimal(300)).setTaxPercent(new BigDecimal(19)))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal(500.0), qty).addAllowance(new Allowance(new BigDecimal(300)).setTaxPercent(new BigDecimal(19))))
.addAllowance(new Allowance(new BigDecimal(600)).setTaxPercent(new BigDecimal(19))) .addAllowance(new Allowance(new BigDecimal(600)).setTaxPercent(new BigDecimal(19)))
@@ -582,7 +578,7 @@ public class ZF2PushTest extends TestCase {
ze.setProducer("My Application") ze.setProducer("My Application")
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("extended")); .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("extended"));
ze.setTransaction(new Invoice().setCurrency("CHF").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE")).setOwnTaxID("4711").setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number) ze.setTransaction(new Invoice().setCurrency("CHF").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")).setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)).addCharge(new Charge().setPercent(new BigDecimal(50)).setTaxPercent(new BigDecimal(19)))) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)).addCharge(new Charge().setPercent(new BigDecimal(50)).setTaxPercent(new BigDecimal(19))))

View File

@@ -229,14 +229,14 @@ public class ZF2Test extends MustangReaderTestCase {
assertEquals(zi.getSellerTradePartyAddress().getCityName(), "Stadthausen"); assertEquals(zi.getSellerTradePartyAddress().getCityName(), "Stadthausen");
final List<org.mustangproject.Item> li = zi.getLineItemList(); final List<org.mustangproject.Item> li = zi.getLineItemList();
assertEquals(zi.getLineItemList().get(0).getId().toString(), "1"); assertEquals(li.get(0).getId().toString(), "1");
assertEquals(zi.getLineItemList().get(0).getProduct().getBuyerAssignedID(), ""); assertEquals(li.get(0).getProduct().getBuyerAssignedID(), "");
assertEquals(zi.getLineItemList().get(0).getProduct().getSellerAssignedID(), ""); assertEquals(li.get(0).getProduct().getSellerAssignedID(), "");
assertEquals(zi.getLineItemList().get(0).getLineTotalAmount().toString(), "160.00"); assertEquals(li.get(0).getLineTotalAmount().toString(), "160.00");
assertEquals(zi.getLineItemList().get(0).getQuantity().toString(), "1.0000"); assertEquals(li.get(0).getQuantity().toString(), "1.0000");
assertEquals(zi.getLineItemList().get(0).getProduct().getVATPercent().toString(), "7.00"); assertEquals(li.get(0).getProduct().getVATPercent().toString(), "7.00");
assertEquals(zi.getLineItemList().get(0).getProduct().getName(), "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung"); assertEquals(li.get(0).getProduct().getName(), "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung");
assertEquals(zi.getLineItemList().get(0).getProduct().getDescription(), ""); assertEquals(li.get(0).getProduct().getDescription(), "");
try { try {
assertEquals(zi.getVersion(), 2); assertEquals(zi.getVersion(), 2);

View File

@@ -21,16 +21,8 @@
*/ */
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
import org.mustangproject.Invoice; import org.mustangproject.Invoice;
import junit.framework.TestCase;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -39,7 +31,6 @@ import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Scanner;
/*** /***

View File

@@ -72,11 +72,6 @@
<version>2.10.0</version> <version>2.10.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.riversun</groupId>
<artifactId>bigdoc</artifactId>
<version>0.4.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>

View File

@@ -1,14 +1,16 @@
package org.mustangproject.validator; package org.mustangproject.validator;
import java.io.*; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@@ -20,20 +22,16 @@ import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter; import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
import org.riversun.bigdoc.bin.BigFileSearcher;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.verapdf.core.VeraPDFException;
import org.verapdf.features.FeatureExtractorConfig; import org.verapdf.features.FeatureExtractorConfig;
import org.verapdf.features.FeatureFactory; import org.verapdf.features.FeatureFactory;
import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider;
import org.verapdf.metadata.fixer.FixerFactory; import org.verapdf.metadata.fixer.FixerFactory;
import org.verapdf.metadata.fixer.MetadataFixerConfig; import org.verapdf.metadata.fixer.MetadataFixerConfig;
import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider;
import org.verapdf.pdfa.flavours.PDFAFlavour; import org.verapdf.pdfa.flavours.PDFAFlavour;
import org.verapdf.pdfa.validation.validators.ValidatorConfig; import org.verapdf.pdfa.validation.validators.ValidatorConfig;
import org.verapdf.pdfa.validation.validators.ValidatorFactory; import org.verapdf.pdfa.validation.validators.ValidatorFactory;
import org.verapdf.processor.BatchProcessor;
import org.verapdf.processor.FormatOption;
import org.verapdf.processor.ItemProcessor; import org.verapdf.processor.ItemProcessor;
import org.verapdf.processor.ProcessorConfig; import org.verapdf.processor.ProcessorConfig;
import org.verapdf.processor.ProcessorFactory; import org.verapdf.processor.ProcessorFactory;
@@ -95,7 +93,7 @@ public class PDFValidator extends Validator {
// Default fixer config // Default fixer config
final MetadataFixerConfig fixerConfig = FixerFactory.defaultConfig(); final MetadataFixerConfig fixerConfig = FixerFactory.defaultConfig();
// Tasks configuring // Tasks configuring
final EnumSet tasks = EnumSet.noneOf(TaskType.class); final EnumSet<TaskType> tasks = EnumSet.noneOf(TaskType.class);
tasks.add(TaskType.VALIDATE); tasks.add(TaskType.VALIDATE);
// tasks.add(TaskType.EXTRACT_FEATURES); // tasks.add(TaskType.EXTRACT_FEATURES);
// tasks.add(TaskType.FIX_METADATA); // tasks.add(TaskType.FIX_METADATA);
@@ -104,7 +102,6 @@ public class PDFValidator extends Validator {
fixerConfig, tasks fixerConfig, tasks
); );
// Creating processor and output stream. // Creating processor and output stream.
final ByteArrayOutputStream reportStream = new ByteArrayOutputStream();
final InputStream inputStream = new ByteArrayInputStream(fileContents); final InputStream inputStream = new ByteArrayInputStream(fileContents);
try (ItemProcessor processor = ProcessorFactory.createProcessor(processorConfig)) { try (ItemProcessor processor = ProcessorFactory.createProcessor(processorConfig)) {
// Generating list of files for processing // Generating list of files for processing

View File

@@ -1,23 +1,4 @@
package org.mustangproject.validator; package org.mustangproject.validator;
import com.helger.schematron.ISchematronResource;
import com.helger.schematron.svrl.SVRLHelper;
import com.helger.schematron.svrl.SVRLMarshaller;
import com.helger.schematron.svrl.jaxb.SchematronOutputType;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.helger.schematron.xslt.SchematronResourceXSLT;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.*;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringReader; import java.io.StringReader;
@@ -28,6 +9,29 @@ import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Calendar; import java.util.Calendar;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import com.helger.schematron.ISchematronResource;
import com.helger.schematron.svrl.SVRLMarshaller;
import com.helger.schematron.svrl.jaxb.SchematronOutputType;
import com.helger.schematron.xslt.SchematronResourceXSLT;
public class XMLValidator extends Validator { public class XMLValidator extends Validator {

View File

@@ -1,10 +1,5 @@
package org.mustangproject.validator; package org.mustangproject.validator;
import org.xmlunit.builder.Input;
import org.xmlunit.xpath.JAXPXPathEngine;
import org.xmlunit.xpath.XPathEngine;
import javax.xml.transform.Source;
import java.io.File; import java.io.File;
import static org.xmlunit.assertj.XmlAssert.assertThat; import static org.xmlunit.assertj.XmlAssert.assertThat;

View File

@@ -57,15 +57,13 @@ public class PDFValidatorTest extends ResourceCase {
byte [] contents = getResourceAsByteArray("XMLinvalidV2PDF.pdf");// need a more invalid file here byte [] contents = getResourceAsByteArray("XMLinvalidV2PDF.pdf");// need a more invalid file here
pv.setFilename("XMLinvalidV2PDF.pdf"); pv.setFilenameAndContents("XMLinvalidV2PDF.pdf", contents);
pv.setFileContents(contents);
pv.validate(); pv.validate();
// assertEquals("", pv.getXMLResult()); // assertEquals("", pv.getXMLResult());
// //
contents = getResourceAsByteArray("Facture_F20180027.pdf"); contents = getResourceAsByteArray("Facture_F20180027.pdf");
pv.setFilename("Facture_F20180027.pdf"); pv.setFilenameAndContents("Facture_F20180027.pdf", contents);
pv.setFileContents(contents);
pv.validate(); pv.validate();
String actual = pv.getXMLResult(); String actual = pv.getXMLResult();
assertEquals(true, actual.contains("summary status=\"valid")); assertEquals(true, actual.contains("summary status=\"valid"));
@@ -91,8 +89,7 @@ public class PDFValidatorTest extends ResourceCase {
// valid one // valid one
contents = getResourceAsByteArray("validV2PDF.pdf"); contents = getResourceAsByteArray("validV2PDF.pdf");
pv.setFilename("validV2PDF.pdf"); pv.setFilenameAndContents("validV2PDF.pdf", contents);
pv.setFileContents(contents);
vc.clear(); vc.clear();
pv.validate(); pv.validate();
actual = pv.getXMLResult(); actual = pv.getXMLResult();
@@ -115,8 +112,7 @@ public class PDFValidatorTest extends ResourceCase {
// invalid file here // invalid file here
byte [] contents = getResourceAsByteArray("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf"); byte [] contents = getResourceAsByteArray("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf");
pv.setFilename("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf"); pv.setFilenameAndContents("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf", contents);
pv.setFileContents(contents);
pv.validate(); pv.validate();
String pdfvres = pv.getXMLResult(); String pdfvres = pv.getXMLResult();
@@ -132,8 +128,7 @@ public class PDFValidatorTest extends ResourceCase {
vc.clear(); vc.clear();
contents = getResourceAsByteArray("validV1WithAdditionalData.pdf");// need a more invalid file here contents = getResourceAsByteArray("validV1WithAdditionalData.pdf");// need a more invalid file here
pv.setFilename("validV1WithAdditionalData.pdf"); pv.setFilenameAndContents("validV1WithAdditionalData.pdf", contents);
pv.setFileContents(contents);
pv.validate(); pv.validate();
pdfvres = pv.getXMLResult(); pdfvres = pv.getXMLResult();
@@ -157,8 +152,7 @@ public class PDFValidatorTest extends ResourceCase {
try { try {
byte [] contents = getResourceAsByteArray("invalidXMP.pdf"); byte [] contents = getResourceAsByteArray("invalidXMP.pdf");
pv.setFilename("invalidXMP.pdf"); pv.setFilenameAndContents("invalidXMP.pdf", contents);
pv.setFileContents(contents);
vc.clear(); vc.clear();
pv.validate(); pv.validate();
String actual = pv.getXMLResult(); String actual = pv.getXMLResult();
@@ -168,8 +162,7 @@ public class PDFValidatorTest extends ResourceCase {
contents = getResourceAsByteArray("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf"); contents = getResourceAsByteArray("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf");
pv.setFilename("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf"); pv.setFilenameAndContents("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf", contents);
pv.setFileContents(contents);
vc.clear(); vc.clear();
pv.validate(); pv.validate();
actual = pv.getXMLResult(); actual = pv.getXMLResult();

View File

@@ -1,7 +1,5 @@
package org.mustangproject.validator; package org.mustangproject.validator;
import static org.xmlunit.assertj.XmlAssert.assertThat;
import java.io.File; import java.io.File;
import javax.xml.transform.Source; import javax.xml.transform.Source;

View File

@@ -2,12 +2,6 @@ package org.mustangproject.validator;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.xmlunit.builder.Input;
import org.xmlunit.xpath.JAXPXPathEngine;
import org.xmlunit.xpath.XPathEngine;
import static org.xmlunit.assertj.XmlAssert.assertThat; import static org.xmlunit.assertj.XmlAssert.assertThat;