avoid deprecated ZUGFeRDExporter methods

In most cases this is achieved by using the corresponding factory methods.
Since they have to be set _somehow_, I introduced a new public method
`ZUGFeRDExporter.configure` to keep these calls local to the class.
This is called once in A3Factory.load(byte[]).

The deprecated Exporter setters could now be made private but that could
break existing code.
This commit is contained in:
Stefan Schmiedl
2019-08-07 14:53:39 +02:00
parent 2f3085e727
commit eaaf97eb6e
6 changed files with 26 additions and 26 deletions

View File

@@ -97,7 +97,7 @@ public class ZUGFeRDExporter implements Closeable {
*/ */
protected String producer = "mustangproject"; protected String producer = "mustangproject";
/** /**
* Author/Creator attribute for PDF for PDF * Author/Creator attribute for PDF
*/ */
protected String creator = "mustangproject"; protected String creator = "mustangproject";
/** /**
@@ -709,4 +709,17 @@ public class ZUGFeRDExporter implements Closeable {
this.attachZUGFeRDHeaders = attachZUGFeRDHeaders; this.attachZUGFeRDHeaders = attachZUGFeRDHeaders;
} }
/**
* encapsulate the deprecated setters
* @param zfVersion 1 or 2
* @param zugferdConformanceLevel BASIC, COMFORT, EN16931, etc.
* @param creator PDF creator
* @param producer PDF producer
*/
public void configure(int zfVersion, ZUGFeRDConformanceLevel zugferdConformanceLevel, String creator, String producer) {
setZUGFeRDVersion(zfVersion);
setZUGFeRDConformanceLevel(zugferdConformanceLevel);
setCreator(creator);
setProducer(producer);
}
} }

View File

@@ -63,20 +63,9 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
public ZUGFeRDExporter load(String pdfFilename) throws IOException { public ZUGFeRDExporter load(String pdfFilename) throws IOException {
ensurePDFIsValidPDFA(new FileDataSource(pdfFilename)); ensurePDFIsValidPDFA(new FileDataSource(pdfFilename));
ZUGFeRDExporter zugFeRDExporter; try (FileInputStream pdf = new FileInputStream(pdfFilename)) {
PDDocument doc = PDDocument.load(new File(pdfFilename)); return load(readAllBytes(pdf));
zugFeRDExporter = new ZUGFeRDExporter(doc); }
zugFeRDExporter.setZUGFeRDVersion(ZFVersion);
zugFeRDExporter.setZUGFeRDConformanceLevel(zugferdConformanceLevel);
zugFeRDExporter.setCreator(creator);
// Use creator as default for compatibility
zugFeRDExporter.setCreatorTool(creatorTool != null ? creatorTool : creator);
zugFeRDExporter.setProducer(producer);
zugFeRDExporter.setAttachZUGFeRDHeaders(attachZUGFeRDHeaders);
zugFeRDExporter.setPDFA3(ensurePDFisUpgraded);
return zugFeRDExporter;
} }
@@ -88,13 +77,9 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
*/ */
public ZUGFeRDExporter load(byte[] pdfBinary) throws IOException { public ZUGFeRDExporter load(byte[] pdfBinary) throws IOException {
ensurePDFIsValidPDFA(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary))); ensurePDFIsValidPDFA(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary)));
ZUGFeRDExporter zugFeRDExporter;
PDDocument doc = PDDocument.load(pdfBinary); PDDocument doc = PDDocument.load(pdfBinary);
zugFeRDExporter = new ZUGFeRDExporter(doc); ZUGFeRDExporter zugFeRDExporter = new ZUGFeRDExporter(doc);
zugFeRDExporter.setZUGFeRDVersion(ZFVersion); zugFeRDExporter.configure(ZFVersion, zugferdConformanceLevel, creator, producer);
zugFeRDExporter.setZUGFeRDConformanceLevel(zugferdConformanceLevel);
zugFeRDExporter.setCreator(creator);
zugFeRDExporter.setProducer(producer);
zugFeRDExporter.setAttachZUGFeRDHeaders(attachZUGFeRDHeaders); zugFeRDExporter.setAttachZUGFeRDHeaders(attachZUGFeRDHeaders);
zugFeRDExporter.setPDFA3(ensurePDFisUpgraded); zugFeRDExporter.setPDFA3(ensurePDFisUpgraded);

View File

@@ -541,10 +541,10 @@ public class Toecount {
// All params are good! continue... // All params are good! continue...
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setProducer("Toecount") ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setProducer("Toecount")
.setZUGFeRDVersion(zfIntVersion)
.setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile) .setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile)
.load(pdfName); .load(pdfName);
ze.setZUGFeRDVersion(zfIntVersion);
if (format.equals("fx")) { if (format.equals("fx")) {
ze.setFacturX(); ze.setFacturX();
} }

View File

@@ -300,7 +300,10 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
try { try {
InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf"); InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory().setProducer("My Application").setCreator("Test").setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.BASIC) ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory()
.setProducer("My Application")
.setCreator("Test")
.setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.BASIC)
.load(SOURCE_PDF); .load(SOURCE_PDF);
/* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */ /* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */
String ownZUGFeRDXML = "<rsm:CrossIndustryDocument xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ram=\"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:12\" xmlns:udt=\"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:15\" xmlns:rsm=\"urn:ferd:CrossIndustryDocument:invoice:1p0\">\n" String ownZUGFeRDXML = "<rsm:CrossIndustryDocument xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ram=\"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:12\" xmlns:udt=\"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:15\" xmlns:rsm=\"urn:ferd:CrossIndustryDocument:invoice:1p0\">\n"

View File

@@ -208,9 +208,9 @@ public class MustangReaderWriterEdgeTest extends MustangReaderTestCase {
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory() ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory()
.setProducer("My Application") .setProducer("My Application")
.setCreator(System.getProperty("user.name")) .setCreator(System.getProperty("user.name"))
.setZUGFeRDVersion(1)
.ignorePDFAErrors() .ignorePDFAErrors()
.load(SOURCE_PDF)) { .load(SOURCE_PDF)) {
ze.setZUGFeRDVersion(1);
ze.PDFattachZugferdFile(this); ze.PDFattachZugferdFile(this);
String theXML = new String(ze.getProvider().getXML()); String theXML = new String(ze.getProvider().getXML());
assertTrue(theXML.contains("<rsm:CrossIndustryDocument")); assertTrue(theXML.contains("<rsm:CrossIndustryDocument"));

View File

@@ -183,10 +183,9 @@ public class ZF2EdgeTest extends MustangReaderTestCase {
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory() ZUGFeRDExporter ze = new ZUGFeRDExporterFromA3Factory()
.setProducer("My Application") .setProducer("My Application")
.setCreator(System.getProperty("user.name")) .setCreator(System.getProperty("user.name"))
.setZUGFeRDVersion(2) .setZUGFeRDVersion(1)
.ignorePDFAErrors() .ignorePDFAErrors()
.load(SOURCE_PDF)) { .load(SOURCE_PDF)) {
ze.setZUGFeRDVersion(1);
ze.PDFattachZugferdFile(this); ze.PDFattachZugferdFile(this);
String theXML = new String(ze.getProvider().getXML()); String theXML = new String(ze.getProvider().getXML());
assertTrue(theXML.contains("<rsm:CrossIndustryDocument")); assertTrue(theXML.contains("<rsm:CrossIndustryDocument"));