From ecd41bbc34000ce15d804801b8dc37361a0e5988 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Wed, 18 Dec 2024 21:24:53 +0100 Subject: [PATCH] corrected parseException --- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index ffcfaac1..05aae56e 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -68,7 +68,6 @@ public class ZUGFeRDInvoiceImporter { protected CalculatedInvoice importedInvoice = null; protected boolean recalcPrice = false; protected boolean ignoreCalculationErrors = false; - protected ArrayList fileAttachments = new ArrayList<>(); public ZUGFeRDInvoiceImporter() { //constructor for extending classes @@ -239,7 +238,7 @@ public class ZUGFeRDInvoiceImporter { try { setDocument(); - } catch (ParserConfigurationException | SAXException e) { + } catch (ParserConfigurationException | SAXException | ParseException e) { LOGGER.error("Failed to parse XML", e); throw new ZUGFeRDExportException(e); } @@ -255,7 +254,7 @@ public class ZUGFeRDInvoiceImporter { setRawXML(rawXML, true); } - private void setDocument() throws ParserConfigurationException, IOException, SAXException { + private void setDocument() throws ParserConfigurationException, IOException, SAXException, ParseException { final DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance(); xmlFact.setNamespaceAware(true); final DocumentBuilder builder = xmlFact.newDocumentBuilder(); @@ -268,8 +267,6 @@ public class ZUGFeRDInvoiceImporter { extractInto(importedInvoice); } catch (XPathExpressionException e) { throw new RuntimeException(e); - } catch (ParseException e) { - throw new RuntimeException(e); } } } @@ -844,7 +841,7 @@ public class ZUGFeRDInvoiceImporter { NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); for (int i = 0; i < attachmentNodes.getLength(); i++) { FileAttachment fa = new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(), attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(), "Data", Base64.getDecoder().decode(XMLTools.trimOrNull(attachmentNodes.item(i)))); - fileAttachments.add(fa); + zpp.embedFileInXML(fa); // filename = "Aufmass.png" mimeCode = "image/png" //EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png" } @@ -1028,9 +1025,10 @@ public class ZUGFeRDInvoiceImporter { * * @return the file attachments embedded in XML (using base64) decoded as byte array, * for PDF embedded files in FX use getFileAttachmentsPDF() + * @deprecated use invoice.getAdditionalReferencedDocuments */ public List getFileAttachmentsXML() { - return fileAttachments; + return new ArrayList<>(Arrays.asList(importedInvoice.getAdditionalReferencedDocuments())); } /***