This commit is contained in:
Jochen Stärk
2017-11-19 18:29:27 +01:00
parent a2a7a85f05
commit d8a3e5d4f6
3 changed files with 12 additions and 4 deletions

View File

@@ -75,6 +75,8 @@ public class ZUGFeRDExporter implements Closeable {
private boolean disableAutoClose; private boolean disableAutoClose;
private boolean fileAttached=false;
public ZUGFeRDExporter() { public ZUGFeRDExporter() {
init(); init();
} }
@@ -274,7 +276,6 @@ public class ZUGFeRDExporter implements Closeable {
* <code>setZUGFeRDXMLData(byte[] zugferdData)</code> * <code>setZUGFeRDXMLData(byte[] zugferdData)</code>
*/ */
public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException { public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException {
xmlProvider.generateXML(trans); xmlProvider.generateXML(trans);
String filename = getFilenameForVersion(ZFVersion); String filename = getFilenameForVersion(ZFVersion);
PDFAttachGenericFile(doc, filename, "Alternative", PDFAttachGenericFile(doc, filename, "Alternative",
@@ -283,6 +284,9 @@ public class ZUGFeRDExporter implements Closeable {
} }
public void export(String ZUGFeRDfilename) throws IOException { public void export(String ZUGFeRDfilename) throws IOException {
if (!fileAttached) {
throw new IOException("File must be attached (usually with PDFattachZugferdFile) before perfoming this operation");
}
doc.save(ZUGFeRDfilename); doc.save(ZUGFeRDfilename);
if (!disableAutoClose) { if (!disableAutoClose) {
close(); close();
@@ -290,6 +294,9 @@ public class ZUGFeRDExporter implements Closeable {
} }
public void export(OutputStream output) throws IOException { public void export(OutputStream output) throws IOException {
if (!fileAttached) {
throw new IOException("File must be attached (usually with PDFattachZugferdFile) before perfoming this operation");
}
doc.save(output); doc.save(output);
if (!disableAutoClose) { if (!disableAutoClose) {
close(); close();
@@ -316,6 +323,8 @@ public class ZUGFeRDExporter implements Closeable {
*/ */
public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description, 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;
PDComplexFileSpecification fs = new PDComplexFileSpecification(); PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFile(filename); fs.setFile(filename);

View File

@@ -183,8 +183,7 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
+ "</ram:SpecifiedTradeProduct>\n" + "</ram:IncludedSupplyChainTradeLineItem>\n" + "</ram:SpecifiedTradeProduct>\n" + "</ram:IncludedSupplyChainTradeLineItem>\n"
+ "</rsm:SpecifiedSupplyChainTradeTransaction>\n" + "</rsm:CrossIndustryDocument>"; + "</rsm:SpecifiedSupplyChainTradeTransaction>\n" + "</rsm:CrossIndustryDocument>";
zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8")); zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8"));
zea1.PDFattachZugferdFile(null);
ByteArrayOutputStream baos=new ByteArrayOutputStream(); ByteArrayOutputStream baos=new ByteArrayOutputStream();
zea1.disableAutoClose(true); zea1.disableAutoClose(true);
zea1.export(TARGET_PDF); zea1.export(TARGET_PDF);

View File

@@ -412,7 +412,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
ze.setZUGFeRDVersion(1); 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"));
ze.export(TARGET_PDF); ze.export(TARGET_PDF);
} }