Make America build again! ;-)

This commit is contained in:
Jochen Stärk
2017-05-28 12:59:55 +02:00
parent b640108b2b
commit b52d5b9e29
2 changed files with 26 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -63,6 +64,19 @@ import org.mustangproject.ZUGFeRD.model.*;
public class ZUGFeRDExporter implements Closeable { public class ZUGFeRDExporter implements Closeable {
private void init() {
try {
jaxbContext = JAXBContext
.newInstance("org.mustangproject.ZUGFeRD.model");
marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
} catch (JAXBException e) {
throw new ZUGFeRDExportException("Could not initialize JAXB", e);
}
}
/** /**
* * You will need Apache PDFBox. To use the ZUGFeRD exporter, implement * * You will need Apache PDFBox. To use the ZUGFeRD exporter, implement
* IZUGFeRDExportableTransaction in yourTransaction (which will require you * IZUGFeRDExportableTransaction in yourTransaction (which will require you
@@ -80,15 +94,13 @@ public class ZUGFeRDExporter implements Closeable {
* *
*/ */
public ZUGFeRDExporter() { public ZUGFeRDExporter() {
try { init();
jaxbContext = JAXBContext }
.newInstance("org.mustangproject.ZUGFeRD.model");
marshaller = jaxbContext.createMarshaller(); public ZUGFeRDExporter(PDDocument doc2) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); init();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); doc=doc2;
} catch (JAXBException e) {
throw new ZUGFeRDExportException("Could not initialize JAXB", e);
}
} }
private class LineCalc { private class LineCalc {
@@ -419,8 +431,8 @@ public class ZUGFeRDExporter implements Closeable {
public PDDocumentCatalog PDFmakeA3compliant(String filename, public PDDocumentCatalog PDFmakeA3compliant(String filename,
String producer, String creator, boolean attachZugferdHeaders) String producer, String creator, boolean attachZugferdHeaders)
throws IOException, TransformerException { throws IOException, TransformerException {
if (!ignoreA1Errors && !isValidA1(filename)) { if (!ignoreA1Errors && !isValidA1(new FileInputStream(filename))) {
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");
} }
loadPDFA3(filename); loadPDFA3(filename);
@@ -530,8 +542,8 @@ public class ZUGFeRDExporter implements Closeable {
} }
private static final ObjectFactory xmlFactory = new ObjectFactory(); private static final ObjectFactory xmlFactory = new ObjectFactory();
private final JAXBContext jaxbContext; private JAXBContext jaxbContext;
private final Marshaller marshaller; private Marshaller marshaller;
private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat( private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat(
"yyyyMMdd"); //$NON-NLS-1$ "yyyyMMdd"); //$NON-NLS-1$

View File

@@ -178,7 +178,7 @@ public class ZUGFeRDExporterFromA1Factory {
*/ */
private void addZugferdXMP(XMPMetadata metadata) { private void addZugferdXMP(XMPMetadata metadata) {
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, zugferdConformanceLevel.name()); XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, zugferdConformanceLevel);
metadata.addSchema(zf); metadata.addSchema(zf);