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:
@@ -97,7 +97,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
*/
|
||||
protected String producer = "mustangproject";
|
||||
/**
|
||||
* Author/Creator attribute for PDF for PDF
|
||||
* Author/Creator attribute for PDF
|
||||
*/
|
||||
protected String creator = "mustangproject";
|
||||
/**
|
||||
@@ -709,4 +709,17 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,20 +63,9 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
|
||||
public ZUGFeRDExporter load(String pdfFilename) throws IOException {
|
||||
|
||||
ensurePDFIsValidPDFA(new FileDataSource(pdfFilename));
|
||||
ZUGFeRDExporter zugFeRDExporter;
|
||||
PDDocument doc = PDDocument.load(new File(pdfFilename));
|
||||
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;
|
||||
|
||||
try (FileInputStream pdf = new FileInputStream(pdfFilename)) {
|
||||
return load(readAllBytes(pdf));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,13 +77,9 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
|
||||
*/
|
||||
public ZUGFeRDExporter load(byte[] pdfBinary) throws IOException {
|
||||
ensurePDFIsValidPDFA(new ByteArrayDataSource(new ByteArrayInputStream(pdfBinary)));
|
||||
ZUGFeRDExporter zugFeRDExporter;
|
||||
PDDocument doc = PDDocument.load(pdfBinary);
|
||||
zugFeRDExporter = new ZUGFeRDExporter(doc);
|
||||
zugFeRDExporter.setZUGFeRDVersion(ZFVersion);
|
||||
zugFeRDExporter.setZUGFeRDConformanceLevel(zugferdConformanceLevel);
|
||||
zugFeRDExporter.setCreator(creator);
|
||||
zugFeRDExporter.setProducer(producer);
|
||||
ZUGFeRDExporter zugFeRDExporter = new ZUGFeRDExporter(doc);
|
||||
zugFeRDExporter.configure(ZFVersion, zugferdConformanceLevel, creator, producer);
|
||||
zugFeRDExporter.setAttachZUGFeRDHeaders(attachZUGFeRDHeaders);
|
||||
zugFeRDExporter.setPDFA3(ensurePDFisUpgraded);
|
||||
|
||||
|
||||
@@ -541,10 +541,10 @@ public class Toecount {
|
||||
|
||||
// All params are good! continue...
|
||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setProducer("Toecount")
|
||||
.setZUGFeRDVersion(zfIntVersion)
|
||||
.setCreator(System.getProperty("user.name")).setZUGFeRDConformanceLevel(zfConformanceLevelProfile)
|
||||
.load(pdfName);
|
||||
|
||||
ze.setZUGFeRDVersion(zfIntVersion);
|
||||
if (format.equals("fx")) {
|
||||
ze.setFacturX();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user