diff --git a/mustang/pom.xml b/mustang/pom.xml index 3cc2ecd4..bc6150b5 100644 --- a/mustang/pom.xml +++ b/mustang/pom.xml @@ -4,7 +4,7 @@ org.mustangproject.ZUGFeRD mustang - 1.0.2 + 1.1.0.alpha jar mustang diff --git a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 1556e6cb..584f8ffe 100644 --- a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -28,6 +28,8 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +//root.setNamespace(Namespace.getNamespace("http://www.energystar.gov/manageBldgs/req")); + public class ZUGFeRDImporter { /* call extract(importFilename). @@ -110,6 +112,7 @@ public class ZUGFeRDImporter { Document document = null; factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",... try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException ex3) { @@ -125,10 +128,13 @@ public class ZUGFeRDImporter { } catch (IOException ex2) { ex2.printStackTrace(); } + NodeList ndList ; + // rootNode = document.getDocumentElement(); // ApplicableSupplyChainTradeSettlement - NodeList ndList = document - .getElementsByTagName("PaymentReference"); //$NON-NLS-1$ + ndList = document.getDocumentElement() + .getElementsByTagNameNS("*","PaymentReference"); //$NON-NLS-1$ + for (int bookingIndex = 0; bookingIndex < ndList .getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); @@ -158,26 +164,38 @@ public class ZUGFeRDImporter { setIBAN(booking.getTextContent()); } + + DE1234 + + + DE5656565 + Commerzbank + + */ - ndList = document.getElementsByTagName("PayeePartyCreditorFinancialAccount"); //$NON-NLS-1$ + 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++) { Node detail = bookingDetails.item(detailIndex); - if (detail.getNodeName().equals("IBANID")) { //$NON-NLS-1$ + if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("IBANID"))) { //$NON-NLS-1$ setIBAN(detail.getTextContent()); - } + + } } } - ndList = document.getElementsByTagName("PayeeSpecifiedCreditorFinancialInstitution"); //$NON-NLS-1$ + ndList = document.getElementsByTagNameNS("*","PayeeSpecifiedCreditorFinancialInstitution"); //$NON-NLS-1$ for (int bookingIndex = 0; bookingIndex < ndList .getLength(); bookingIndex++) { @@ -188,10 +206,10 @@ public class ZUGFeRDImporter { for (int detailIndex = 0; detailIndex < bookingDetails .getLength(); detailIndex++) { Node detail = bookingDetails.item(detailIndex); - if (detail.getNodeName().equals("BICID")) { //$NON-NLS-1$ + if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("BICID"))) { //$NON-NLS-1$ setBIC(detail.getTextContent()); } - if (detail.getNodeName().equals("Name")) { //$NON-NLS-1$ + if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("Name"))) { //$NON-NLS-1$ setBankName(detail.getTextContent()); } } @@ -199,7 +217,7 @@ public class ZUGFeRDImporter { } // - ndList = document.getElementsByTagName("SellerTradeParty"); //$NON-NLS-1$ + ndList = document.getElementsByTagNameNS("*","SellerTradeParty"); //$NON-NLS-1$ for (int bookingIndex = 0; bookingIndex < ndList .getLength(); bookingIndex++) { @@ -210,14 +228,14 @@ public class ZUGFeRDImporter { for (int detailIndex = 0; detailIndex < bookingDetails .getLength(); detailIndex++) { Node detail = bookingDetails.item(detailIndex); - if (detail.getNodeName().equals("Name")) { //$NON-NLS-1$ + if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("Name"))) { //$NON-NLS-1$ setHolder(detail.getTextContent()); } } } - ndList = document.getElementsByTagName("DuePayableAmount"); //$NON-NLS-1$ + ndList = document.getElementsByTagNameNS("*","DuePayableAmount"); //$NON-NLS-1$ for (int bookingIndex = 0; bookingIndex < ndList .getLength(); bookingIndex++) { @@ -233,7 +251,7 @@ public class ZUGFeRDImporter { /* there is apparently no requirement to mention DuePayableAmount,, * if it's not there, check for GrandTotalAmount */ - ndList = document.getElementsByTagName("GrandTotalAmount"); //$NON-NLS-1$ + ndList = document.getElementsByTagNameNS("*","GrandTotalAmount"); //$NON-NLS-1$ for (int bookingIndex = 0; bookingIndex < ndList .getLength(); bookingIndex++) { Node booking = ndList.item(bookingIndex); diff --git a/mustang/src/test/java/org/mustangproject/ZUGFeRD/AppTest.java b/mustang/src/test/java/org/mustangproject/ZUGFeRD/AppTest.java index a8cece5d..73ceb8b8 100644 --- a/mustang/src/test/java/org/mustangproject/ZUGFeRD/AppTest.java +++ b/mustang/src/test/java/org/mustangproject/ZUGFeRD/AppTest.java @@ -1,5 +1,7 @@ package org.mustangproject.ZUGFeRD; +import java.io.IOException; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -7,32 +9,54 @@ import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } +public class AppTest extends TestCase { + /** + * Create the test case + * + * @param testName + * name of the test case + */ + public AppTest(String testName) { + super(testName); + } - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(AppTest.class); + } - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } + /** + * Rigourous Test :-) + */ + public void testImport() { + ZUGFeRDImporter zi = new ZUGFeRDImporter(); + zi.extract("./src/test/java/org/mustangproject/ZUGFeRD/RE-20140628_9.pdf"); + // Reading ZUGFeRD + + String amount=null; + String bic=null; + String iban=null; + String holder=null; + String ref=null; + + if (zi.canParse()) { + zi.parse(); + amount=zi.getAmount(); + bic=zi.getBIC(); + iban=zi.getIBAN(); + holder=zi.getHolder(); + ref=zi.getForeignReference(); + } + + + assertEquals(amount, "1.19"); + assertEquals(bic, "DE5656565"); + assertEquals(iban, "DE1234"); + assertEquals(holder, "usegroup"); + assertEquals(ref, "RE-20140628/9"); + + + } } diff --git a/mustang/target/mustang-1.0.jar b/mustang/target/mustang-1.0.jar index 29d73aff..4c1c0e68 100644 Binary files a/mustang/target/mustang-1.0.jar and b/mustang/target/mustang-1.0.jar differ diff --git a/mustang/target/mustang-1.1.0.alpha.jar b/mustang/target/mustang-1.1.0.alpha.jar new file mode 100644 index 00000000..034e17ff Binary files /dev/null and b/mustang/target/mustang-1.1.0.alpha.jar differ