Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZUGFeRD/mustangproject
Browse files Browse the repository at this point in the history
# Conflicts:
#	library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportablePostalTradeAddress.java
#	library/src/main/java/org/mustangproject/ZUGFeRD/PostalTradeAddress.java
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed May 24, 2020
2 parents fed2d08 + 6268f69 commit 9c94749
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 218 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.mustangproject.ZUGFeRD;

public interface IZUGFeRDExportablePostalTradeAddress {
default String getPostcodeCode(){return null;}
default String getLineOne() {return null;}
default String getLineTwo() {return null;}
default String getLineThree() {return null;}
default String getCityName() {return null;}
default String getCountryID() {return null;}
default String getCountrySubDivisionName() {return null;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.mustangproject.ZUGFeRD;

public class PostalTradeAddress implements IZUGFeRDExportablePostalTradeAddress {

private String postCodeCode;
private String lineOne;
private String lineTwo;
private String lineThree;
private String cityName;
private String countryID;
private String CountrySubDivisionName;

public void setPostCodeCode(String postCodeCode) {
this.postCodeCode = postCodeCode;
}

public void setLineOne(String lineOne) {
this.lineOne = lineOne;
}

public void setLineTwo(String lineTwo) {
this.lineTwo = lineTwo;
}

public void setLineThree(String lineThree) {
this.lineThree = lineThree;
}

public void setCityName(String cityName) {
this.cityName = cityName;
}

public void setCountryID(String countryID) {
this.countryID = countryID;
}

public void setCountrySubDivisionName(String countrySubDivisionName) {
CountrySubDivisionName = countrySubDivisionName;
}

@Override
public String getPostcodeCode() {
return this.postCodeCode;
}

@Override
public String getLineOne() {
return this.lineOne;
}

@Override
public String getLineTwo() {
return this.lineTwo;
}

@Override
public String getLineThree() {
return this.lineThree;
}

@Override
public String getCityName() {
return this.cityName;
}

@Override
public String getCountryID() {
return this.countryID;
}

@Override
public String getCountrySubDivisionName() {
return this.CountrySubDivisionName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.*;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
Expand All @@ -41,6 +39,8 @@
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class ZUGFeRDImporter {
Expand Down Expand Up @@ -234,6 +234,15 @@ protected String extractString(String xpathStr) {
}


/**
* Wrapper for protected method exracteString
* @return the extracted String for the specific path in the document
*/
public String wExtractString(String xpathStr) {
return extractString(xpathStr);
}


/**
* @return the reference (purpose) the sender specified for this invoice
*/
Expand Down Expand Up @@ -449,4 +458,73 @@ static String convertStreamToString(java.io.InputStream is) {
return s.hasNext() ? s.next() : "";
}

public PostalTradeAddress getSellerTradePartyAddress() {

NodeList nl = null;
PostalTradeAddress address = new PostalTradeAddress();

try {
if (getVersion() == 1) {
nl = getNodeListByPath("//CrossIndustryDocument//SpecifiedSupplyChainTradeTransaction//ApplicableSupplyChainTradeAgreement//SellerTradeParty//PostalTradeAddress");
} else {
nl = getNodeListByPath("//CrossIndustryInvoice//SupplyChainTradeTransaction//ApplicableHeaderTradeAgreement//SellerTradeParty//PostalTradeAddress");
}
} catch (Exception e) {
e.printStackTrace();
return address;
}

if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
NodeList nodes = n.getChildNodes();
for (int j = 0; j < nodes.getLength(); j++) {
n = nodes.item(j);
short nodeType = n.getNodeType();
if (nodeType==Node.ELEMENT_NODE){
switch (n.getNodeName()) {
case "ram:PostcodeCode":
address.setPostCodeCode(n.getFirstChild().getNodeValue());
break;
case "ram:LineOne":
address.setLineOne(n.getFirstChild().getNodeValue());
break;
case "ram:LineTwo":
address.setLineTwo(n.getFirstChild().getNodeValue());
break;
case "ram:LineThree":
address.setLineThree(n.getFirstChild().getNodeValue());
break;
case "ram:CityName":
address.setCityName(n.getFirstChild().getNodeValue());
break;
case "ram:CountryID":
address.setCountryID(n.getFirstChild().getNodeValue());
break;
case "ram:CountrySubDivisionName":
address.setCountrySubDivisionName(n.getFirstChild().getNodeValue());
break;
}
}
}
}
}
return address;
}

public NodeList getNodeListByPath(String path) {

XPathFactory xpathFact = XPathFactory.newInstance();
XPath xPath = xpathFact.newXPath();
String s = path;

try {
XPathExpression xpr = xPath.compile(s);
return (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ public void testAImport() {
assertEquals(zi.getHolder(), getOwnOrganisationName());
assertEquals(zi.getForeignReference(), "RE-20170509/505");
assertEquals(zi.getBankName(), "Commerzbank");
assertEquals(zi.getSellerTradePartyAddress().getCityName(), "Stadthausen");
assertEquals(zi.getSellerTradePartyAddress().getCountryID(), "DE");
assertEquals(zi.getSellerTradePartyAddress().getCountrySubDivisionName(), null);
assertEquals(zi.getSellerTradePartyAddress().getLineOne(), "Ecke 12");
assertEquals(zi.getSellerTradePartyAddress().getLineThree(), null);
assertEquals(zi.getSellerTradePartyAddress().getLineTwo(), null);
assertEquals(zi.getSellerTradePartyAddress().getPostcodeCode(), "12345");
}

public void testForeignImport() {
Expand Down
Loading

0 comments on commit 9c94749

Please sign in to comment.