From 889903818ecf5a3ac76467486166f048d357fcd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Sta=CC=88rk?= Date: Sun, 15 Oct 2017 17:57:28 +0200 Subject: [PATCH] updated importer and exporter to ZF2 --- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 143 ++++++----- .../ZUGFeRD/ZUGFeRDImporter.java | 242 +++++++----------- .../org/mustangproject/toecount/Toecount.java | 2 +- .../ZUGFeRD/MustangReaderWriterTest.java | 3 +- 4 files changed, 166 insertions(+), 224 deletions(-) diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 5a388b11..0ea17a40 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -184,17 +184,17 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { String xml= "\n" //$NON-NLS-1$ - + "\n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ + + "\n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + " "+testBooleanStr+"\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " urn:ferd:CrossIndustryDocument:invoice:1p0:comfort\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + " "+trans.getNumber()+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " RECHNUNG\n" //$NON-NLS-1$ + " 380\n" //$NON-NLS-1$ @@ -212,9 +212,61 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { // + " \n" // + " AAK\n" // + " \n" - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " \n"; //$NON-NLS-1$ + int lineID=0; + for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { + lineID++; + + LineCalc lc=new LineCalc(currentItem); + xml=xml+ " \n"+ //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + + " "+lineID+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ +// + " 4012345001235\n" +// + " KR3M\n" +// + " 55T01\n" + + " "+currentItem.getProduct().getName()+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " "+currentItem.getProduct().getDescription()+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " \n" //$NON-NLS-1$ + + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " "+priceFormat(currentItem.getPrice())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " 1.0000\n" //$NON-NLS-1$ //$NON-NLS-2$ +// + " \n" +// + " false\n" +// + " 0.6667\n" +// + " Rabatt\n" +// + " \n" + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " "+priceFormat(currentItem.getPrice())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " 1.0000\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + + " \n" //$NON-NLS-1$ + + " "+quantityFormat(currentItem.getQuantity())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " VAT\n" //$NON-NLS-1$ + + " S\n" //$NON-NLS-1$ + + " "+vatFormat(currentItem.getProduct().getVATPercent())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " "+currencyFormat(lc.getItemTotalNetAmount())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " \n"; //$NON-NLS-1$ + + + + } + + xml=xml+ " \n" //$NON-NLS-1$ // + " AB-312\n" + " \n" //$NON-NLS-1$ // + " 4000001123452\n" @@ -253,8 +305,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { // + " 20130301\n" // + " 2013-471331\n" // + " \n" - + " \n" //$NON-NLS-1$ - + " \n" + + " \n" //$NON-NLS-1$ + + " \n" + " \n" + " "+zugferdDateFormat.format(trans.getDeliveryDate())+"\n" + " \n" @@ -263,8 +315,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + " 20130603\n" + " 2013-51112\n" + " \n" */ - + " \n" - + " \n" //$NON-NLS-1$ + + " \n" + + " \n" //$NON-NLS-1$ + " "+trans.getNumber()+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " EUR\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ @@ -290,7 +342,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + " VAT\n" //$NON-NLS-1$ + " "+currencyFormat(amount.getBasis())+"\n" + " S\n" //$NON-NLS-1$ - + " "+vatFormat(currentTaxPercent)+"\n" //$NON-NLS-1$ + + " "+vatFormat(currentTaxPercent)+"\n" //$NON-NLS-1$ + " \n"; //$NON-NLS-1$ @@ -334,7 +386,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + " Zahlbar ohne Abzug bis "+germanDateFormat.format(trans.getDueDate())+"\n" + " "+zugferdDateFormat.format(trans.getDueDate())+"\n"//20130704 //$NON-NLS-1$ //$NON-NLS-2$ + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + " "+currencyFormat(getTotal())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " 0.00\n" //$NON-NLS-1$ + " 0.00\n" //$NON-NLS-1$ @@ -345,8 +397,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + " "+currencyFormat(getTotalGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ // + " 0.00\n" + " "+currencyFormat(getTotalGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - + " \n"; //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " \n"; //$NON-NLS-1$ // + " \n" // + " \n" // + " \n" @@ -356,61 +408,10 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { // + " \n"; - int lineID=0; - for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { - lineID++; - - LineCalc lc=new LineCalc(currentItem); - xml=xml+ " \n"+ //$NON-NLS-1$ - " \n" //$NON-NLS-1$ - + " "+lineID+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " "+priceFormat(currentItem.getPrice())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " 1.0000\n" //$NON-NLS-1$ //$NON-NLS-2$ -// + " \n" -// + " false\n" -// + " 0.6667\n" -// + " Rabatt\n" -// + " \n" - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " "+priceFormat(currentItem.getPrice())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " 1.0000\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - - + " \n" //$NON-NLS-1$ - + " "+quantityFormat(currentItem.getQuantity())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " VAT\n" //$NON-NLS-1$ - + " S\n" //$NON-NLS-1$ - + " "+vatFormat(currentItem.getProduct().getVATPercent())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " "+currencyFormat(lc.getItemTotalNetAmount())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ -// + " 4012345001235\n" -// + " KR3M\n" -// + " 55T01\n" - + " "+currentItem.getProduct().getName()+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " "+currentItem.getProduct().getDescription()+"\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - + " \n"; //$NON-NLS-1$ - - } - - - xml=xml + " \n" //$NON-NLS-1$ - + ""; //$NON-NLS-1$ + xml=xml + " \n" //$NON-NLS-1$ + + ""; //$NON-NLS-1$ byte[] zugferdRaw; try { diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 45b56080..97454f60 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -33,28 +33,26 @@ import org.xml.sax.SAXException; public class ZUGFeRDImporter { /* - call extract(importFilename). - containsMeta() will return if ZUGFeRD data has been found, - afterwards you can call getBIC(), getIBAN() etc. + * call extract(importFilename). containsMeta() will return if ZUGFeRD data has + * been found, afterwards you can call getBIC(), getIBAN() etc. + * + */ -*/ - - /**@var if metadata has been found */ - private boolean containsMeta=false; - /**@var the reference (i.e. invoice number) of the sender */ + /** @var if metadata has been found */ + private boolean containsMeta = false; + /** @var the reference (i.e. invoice number) of the sender */ private String foreignReference; private String BIC; private String IBAN; private String holder; private String amount; - private String dueDate; + private String dueDate; /** Raw XML form of the extracted data - may be directly obtained. */ - private byte[] rawXML=null; + private byte[] rawXML = null; private String bankName; private boolean amountFound; - private boolean extracted=false; - private boolean parsed=false; - + private boolean extracted = false; + private boolean parsed = false; /** * Extracts a ZUGFeRD invoice from a PDF document represented by a file name. @@ -69,16 +67,16 @@ public class ZUGFeRDImporter { } /** - * Extracts a ZUGFeRD invoice from a PDF document represented by an input stream. - * Errors are reported via exception handling. + * Extracts a ZUGFeRD invoice from a PDF document represented by an input + * stream. Errors are reported via exception handling. */ - public void extractLowLevel(InputStream pdfStream) throws IOException { + public void extractLowLevel(InputStream pdfStream) throws IOException { PDEmbeddedFilesNameTreeNode etn; try (PDDocument doc = PDDocument.load(pdfStream)) { -// PDDocumentInformation info = doc.getDocumentInformation(); + // PDDocumentInformation info = doc.getDocumentInformation(); PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog()); etn = names.getEmbeddedFiles(); - if (etn == null) { + if (etn == null) { return; } @@ -86,10 +84,10 @@ public class ZUGFeRDImporter { // String filePath = "/tmp/"; for (String filename : efMap.keySet()) { /** - * currently (in the release candidate of version 1) only one - * attached file with the name ZUGFeRD-invoice.xml is allowed - * */ - if ((filename.equals("ZUGFeRD-invoice.xml")||filename.equals("factur-x.xml"))) { //$NON-NLS-1$ + * currently (in the release candidate of version 1) only one attached file with + * the name ZUGFeRD-invoice.xml is allowed + */ + if ((filename.equals("ZUGFeRD-invoice.xml") || filename.equals("factur-x.xml"))) { //$NON-NLS-1$ containsMeta = true; PDComplexFileSpecification fileSpec = efMap.get(filename); @@ -103,7 +101,7 @@ public class ZUGFeRDImporter { rawXML = embeddedFile.toByteArray(); setMeta(new String(rawXML)); - extracted=true; + extracted = true; // fos.write(embeddedFile.getByteArray()); // fos.close(); } @@ -121,7 +119,8 @@ public class ZUGFeRDImporter { } factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); //otherwise we can not act namespace independently, i.e. use document.getElementsByTagNameNS("*",... + factory.setNamespaceAware(true); // otherwise we can not act namespace independently, i.e. use + // document.getElementsByTagNameNS("*",... try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException ex3) { @@ -137,179 +136,139 @@ public class ZUGFeRDImporter { } catch (IOException ex2) { ex2.printStackTrace(); } - NodeList ndList ; + NodeList ndList; // rootNode = document.getDocumentElement(); // ApplicableSupplyChainTradeSettlement - ndList = document.getDocumentElement() - .getElementsByTagNameNS("*","PaymentReference"); //$NON-NLS-1$ + ndList = document.getDocumentElement().getElementsByTagNameNS("*", "PaymentReference"); //$NON-NLS-1$ - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // if there is a attribute in the tag number:value setForeignReference(booking.getTextContent()); } -/* - ndList = document - .getElementsByTagName("GermanBankleitzahlID"); //$NON-NLS-1$ + /* + * ndList = document .getElementsByTagName("GermanBankleitzahlID"); + * //$NON-NLS-1$ + * + * for (int bookingIndex = 0; bookingIndex < ndList .getLength(); + * bookingIndex++) { Node booking = ndList.item(bookingIndex); // if there is a + * attribute in the tag number:value setBIC(booking.getTextContent()); + * + * } + * + * ndList = document.getElementsByTagName("ProprietaryID"); //$NON-NLS-1$ + * + * for (int bookingIndex = 0; bookingIndex < ndList .getLength(); + * bookingIndex++) { Node booking = ndList.item(bookingIndex); // if there is a + * attribute in the tag number:value setIBAN(booking.getTextContent()); + * + * } DE1234 + * + * + * DE5656565 Commerzbank + * + * + */ - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { - Node booking = ndList.item(bookingIndex); - // if there is a attribute in the tag number:value - setBIC(booking.getTextContent()); - - } - - ndList = document.getElementsByTagName("ProprietaryID"); //$NON-NLS-1$ - - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { - Node booking = ndList.item(bookingIndex); - // if there is a attribute in the tag number:value - setIBAN(booking.getTextContent()); - - } - - DE1234 - - - DE5656565 - Commerzbank - - -*/ - - ndList = document.getElementsByTagNameNS("*","PayeePartyCICreditorFinancialAccount"); //ZF2 - if (ndList.getLength()==0) { - // try ZF1, it can not harm - ndList = document.getElementsByTagNameNS("*","PayeePartyCreditorFinancialAccount"); //$NON-NLS-1$ - } - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + ndList = document.getElementsByTagNameNS("*", "PayeePartyCreditorFinancialAccount"); //$NON-NLS-1$ + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // there are many "name" elements, so get the one below // SellerTradeParty NodeList bookingDetails = booking.getChildNodes(); - - for (int detailIndex = 0; detailIndex < bookingDetails - .getLength(); detailIndex++) { + for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) { Node detail = bookingDetails.item(detailIndex); - if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("IBANID"))) { //$NON-NLS-1$ + if ((detail.getLocalName() != null) && (detail.getLocalName().equals("IBANID"))) { //$NON-NLS-1$ setIBAN(detail.getTextContent()); } } } - - ndList = document.getElementsByTagNameNS("*","PayeeSpecifiedCICreditorFinancialInstitution");//ZF2 //$NON-NLS-1$ - if (ndList.getLength()==0) { - // try ZF1, it can not harm - ndList = document.getElementsByTagNameNS("*","PayeeSpecifiedCreditorFinancialInstitution");//ZF1 //$NON-NLS-1$ - } - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + ndList = document.getElementsByTagNameNS("*", "PayeeSpecifiedCreditorFinancialInstitution");// ZF1 //$NON-NLS-1$ + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // there are many "name" elements, so get the one below // SellerTradeParty NodeList bookingDetails = booking.getChildNodes(); - for (int detailIndex = 0; detailIndex < bookingDetails - .getLength(); detailIndex++) { + for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) { Node detail = bookingDetails.item(detailIndex); - if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("BICID"))) { //$NON-NLS-1$ + if ((detail.getLocalName() != null) && (detail.getLocalName().equals("BICID"))) { //$NON-NLS-1$ setBIC(detail.getTextContent()); } - if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("Name"))) { //$NON-NLS-1$ + if ((detail.getLocalName() != null) && (detail.getLocalName().equals("Name"))) { //$NON-NLS-1$ setBankName(detail.getTextContent()); } } } - - ndList = document.getElementsByTagNameNS("*","SellerCITradeParty"); //ZF2 - if (ndList.getLength()==0) { - // try ZF1, it can not harm - ndList = document.getElementsByTagNameNS("*","SellerTradeParty"); //$NON-NLS-1$ - } + ndList = document.getElementsByTagNameNS("*", "SellerTradeParty"); //$NON-NLS-1$ - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // there are many "name" elements, so get the one below // SellerTradeParty NodeList bookingDetails = booking.getChildNodes(); - for (int detailIndex = 0; detailIndex < bookingDetails - .getLength(); detailIndex++) { + for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) { Node detail = bookingDetails.item(detailIndex); - if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("Name"))) { //$NON-NLS-1$ + if ((detail.getLocalName() != null) && (detail.getLocalName().equals("Name"))) { //$NON-NLS-1$ setHolder(detail.getTextContent()); } } } - ndList = document.getElementsByTagNameNS("*","DuePayableAmount"); //$NON-NLS-1$ + ndList = document.getElementsByTagNameNS("*", "DuePayableAmount"); //$NON-NLS-1$ - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // if there is a attribute in the tag number:value - amountFound=true; + amountFound = true; setAmount(booking.getTextContent()); } - - if (!amountFound) { - /* there is apparently no requirement to mention DuePayableAmount,, - * if it's not there, check for GrandTotalAmount + if (!amountFound) { + /* + * there is apparently no requirement to mention DuePayableAmount,, if it's not + * there, check for GrandTotalAmount */ - ndList = document.getElementsByTagNameNS("*","GrandTotalAmount"); //$NON-NLS-1$ - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + ndList = document.getElementsByTagNameNS("*", "GrandTotalAmount"); //$NON-NLS-1$ + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // if there is a attribute in the tag number:value - amountFound=true; + amountFound = true; setAmount(booking.getTextContent()); } } - ndList = document.getElementsByTagNameNS("*","SpecifiedTradePaymentTerms"); //$NON-NLS-1$ - if (ndList.getLength()==0) { - // try ZF1, it can not harm - ndList = document.getElementsByTagNameNS("*","SpecifiedCITradePaymentTerms"); //$NON-NLS-1$ - } + ndList = document.getElementsByTagNameNS("*", "SpecifiedTradePaymentTerms"); //$NON-NLS-1$ - - for (int bookingIndex = 0; bookingIndex < ndList - .getLength(); bookingIndex++) { + for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); // there are many "name" elements, so get the one below // SellerTradeParty NodeList bookingDetails = booking.getChildNodes(); - for (int detailIndex = 0; detailIndex < bookingDetails - .getLength(); detailIndex++) { + for (int detailIndex = 0; detailIndex < bookingDetails.getLength(); detailIndex++) { Node detail = bookingDetails.item(detailIndex); - if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("DueDateDateTime"))) { //$NON-NLS-1$ + if ((detail.getLocalName() != null) && (detail.getLocalName().equals("DueDateDateTime"))) { //$NON-NLS-1$ setDueDate(detail.getTextContent().trim()); } } } - parsed=true; + parsed = true; } - public boolean containsMeta() { return containsMeta; } @@ -321,14 +280,10 @@ public class ZUGFeRDImporter { return foreignReference; } - - private void setForeignReference(String foreignReference) { this.foreignReference = foreignReference; } - - public String getBIC() { if (!parsed) { throw new RuntimeException("use parse() before requesting a value"); @@ -336,24 +291,18 @@ public class ZUGFeRDImporter { return BIC; } - - private void setBIC(String bic) { this.BIC = bic; } - private void setDueDate(String dueDate) { this.dueDate = dueDate; } - private void setBankName(String bankname) { this.bankName = bankname; } - - public String getIBAN() { if (!parsed) { throw new RuntimeException("use parse() before requesting a value"); @@ -361,7 +310,6 @@ public class ZUGFeRDImporter { return IBAN; } - public String getBankName() { if (!parsed) { throw new RuntimeException("use parse() before requesting a value"); @@ -369,38 +317,30 @@ public class ZUGFeRDImporter { return bankName; } - - private void setIBAN(String IBAN) { this.IBAN = IBAN; } - - public String getHolder() { - if (rawXML==null) { + if (rawXML == null) { throw new RuntimeException("use parse() before requesting a value"); } return holder; } - - private void setHolder(String holder) { this.holder = holder; } - - public String getAmount() { - if (rawXML==null) { + if (rawXML == null) { throw new RuntimeException("use parse() before requesting a value"); } return amount; } public String getDueDate() { - if (rawXML==null) { + if (rawXML == null) { throw new RuntimeException("use parse() before requesting a value"); } return dueDate; @@ -411,34 +351,34 @@ public class ZUGFeRDImporter { } public void setMeta(String meta) { - this.rawXML=meta.getBytes(); + this.rawXML = meta.getBytes(); } public String getMeta() { - if (rawXML==null){ + if (rawXML == null) { return null; } return new String(rawXML); } - /** * Returns the raw XML data as extracted from the ZUGFeRD PDF file. */ - public byte[] getRawXML() - { + public byte[] getRawXML() { return rawXML; } /** - * will return true if the metadata (just extract-ed or set with setMeta) contains ZUGFeRD XML - * */ + * will return true if the metadata (just extract-ed or set with setMeta) + * contains ZUGFeRD XML + */ public boolean canParse() { - - //SpecifiedExchangedDocumentContext is in the schema, so a relatively good indication if zugferd is present - better than just invoice - String meta=getMeta(); - return (meta!=null)&&( meta.length()>0)&&(( meta.contains("SpecifiedExchangedDocumentContext")/*ZF1*/||meta.contains("CIExchangedDocumentContext"))); //$NON-NLS-1$ + // SpecifiedExchangedDocumentContext is in the schema, so a relatively good + // indication if zugferd is present - better than just invoice + String meta = getMeta(); + return (meta != null) && (meta.length() > 0) && ((meta.contains("SpecifiedExchangedDocumentContext") //$NON-NLS-1$ + /* ZF1 */ || meta.contains("ExchangedDocumentContext") /*ZF2*/)); } } diff --git a/src/main/java/org/mustangproject/toecount/Toecount.java b/src/main/java/org/mustangproject/toecount/Toecount.java index 34887486..1d90d2e3 100755 --- a/src/main/java/org/mustangproject/toecount/Toecount.java +++ b/src/main/java/org/mustangproject/toecount/Toecount.java @@ -81,7 +81,7 @@ public class Toecount { } if (!selectedName.toLowerCase().endsWith(expectedExtension.toLowerCase())) { - System.err.println("Expected "+expectedExtension+" extension, this may corrupt your file. Do you still want to continue?"); + System.err.println("Expected "+expectedExtension+" extension, this may corrupt your file. Do you still want to continue?(Y|N)"); String selectedAnswer=""; try { selectedAnswer=buffer.readLine(); diff --git a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java index 2ed04904..f56d65ee 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java @@ -8,6 +8,8 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.logging.LogManager; +import java.util.logging.Logger; import javax.xml.transform.TransformerException; @@ -432,7 +434,6 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta String iban = null; String holder = null; String ref = null; - if (zi.canParse()) { zi.parse();