corrected import sampe to new sample file, added getDueDate import
This commit is contained in:
@@ -49,10 +49,14 @@ public class ZUGFeRDImporter {
|
|||||||
private String IBAN;
|
private String IBAN;
|
||||||
private String holder;
|
private String holder;
|
||||||
private String amount;
|
private String amount;
|
||||||
|
private String dueDate;
|
||||||
/** Raw XML form of the extracted data - may be directly obtained. */
|
/** Raw XML form of the extracted data - may be directly obtained. */
|
||||||
private byte[] rawXML=null;
|
private byte[] rawXML=null;
|
||||||
private String bankName;
|
private String bankName;
|
||||||
private boolean amountFound;
|
private boolean amountFound;
|
||||||
|
private boolean extracted=false;
|
||||||
|
private boolean parsed=false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts a ZUGFeRD invoice from a PDF document represented by a file name.
|
* Extracts a ZUGFeRD invoice from a PDF document represented by a file name.
|
||||||
@@ -107,6 +111,7 @@ public class ZUGFeRDImporter {
|
|||||||
// FileOutputStream fos = new FileOutputStream(file);
|
// FileOutputStream fos = new FileOutputStream(file);
|
||||||
rawXML = embeddedFile.getByteArray();
|
rawXML = embeddedFile.getByteArray();
|
||||||
setMeta(new String(rawXML));
|
setMeta(new String(rawXML));
|
||||||
|
extracted=true;
|
||||||
// fos.write(embeddedFile.getByteArray());
|
// fos.write(embeddedFile.getByteArray());
|
||||||
// fos.close();
|
// fos.close();
|
||||||
}
|
}
|
||||||
@@ -130,6 +135,10 @@ public class ZUGFeRDImporter {
|
|||||||
DocumentBuilder builder = null;
|
DocumentBuilder builder = null;
|
||||||
Document document = null;
|
Document document = null;
|
||||||
|
|
||||||
|
if (!extracted) {
|
||||||
|
throw new RuntimeException("extract() or extractLowLevel() must be used before parsing.");
|
||||||
|
}
|
||||||
|
|
||||||
factory = DocumentBuilderFactory.newInstance();
|
factory = DocumentBuilderFactory.newInstance();
|
||||||
factory.setNamespaceAware(true); //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",...
|
factory.setNamespaceAware(true); //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",...
|
||||||
try {
|
try {
|
||||||
@@ -282,7 +291,25 @@ public class ZUGFeRDImporter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndList = document.getElementsByTagNameNS("*","SpecifiedTradePaymentTerms"); //$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.getLocalName()!=null)&&(detail.getLocalName().equals("DueDateDateTime"))) { //$NON-NLS-1$
|
||||||
|
setDueDate(detail.getTextContent().trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
parsed=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -291,7 +318,7 @@ public class ZUGFeRDImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getForeignReference() {
|
public String getForeignReference() {
|
||||||
if (rawXML==null) {
|
if (!parsed) {
|
||||||
throw new RuntimeException("use parse() before requesting a value");
|
throw new RuntimeException("use parse() before requesting a value");
|
||||||
}
|
}
|
||||||
return foreignReference;
|
return foreignReference;
|
||||||
@@ -306,7 +333,7 @@ public class ZUGFeRDImporter {
|
|||||||
|
|
||||||
|
|
||||||
public String getBIC() {
|
public String getBIC() {
|
||||||
if (rawXML==null) {
|
if (!parsed) {
|
||||||
throw new RuntimeException("use parse() before requesting a value");
|
throw new RuntimeException("use parse() before requesting a value");
|
||||||
}
|
}
|
||||||
return BIC;
|
return BIC;
|
||||||
@@ -319,6 +346,11 @@ public class ZUGFeRDImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setDueDate(String dueDate) {
|
||||||
|
this.dueDate = dueDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setBankName(String bankname) {
|
private void setBankName(String bankname) {
|
||||||
this.bankName = bankname;
|
this.bankName = bankname;
|
||||||
}
|
}
|
||||||
@@ -326,7 +358,7 @@ public class ZUGFeRDImporter {
|
|||||||
|
|
||||||
|
|
||||||
public String getIBAN() {
|
public String getIBAN() {
|
||||||
if (rawXML==null) {
|
if (!parsed) {
|
||||||
throw new RuntimeException("use parse() before requesting a value");
|
throw new RuntimeException("use parse() before requesting a value");
|
||||||
}
|
}
|
||||||
return IBAN;
|
return IBAN;
|
||||||
@@ -334,7 +366,7 @@ public class ZUGFeRDImporter {
|
|||||||
|
|
||||||
|
|
||||||
public String getBankName() {
|
public String getBankName() {
|
||||||
if (rawXML==null) {
|
if (!parsed) {
|
||||||
throw new RuntimeException("use parse() before requesting a value");
|
throw new RuntimeException("use parse() before requesting a value");
|
||||||
}
|
}
|
||||||
return bankName;
|
return bankName;
|
||||||
@@ -370,6 +402,12 @@ public class ZUGFeRDImporter {
|
|||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDueDate() {
|
||||||
|
if (rawXML==null) {
|
||||||
|
throw new RuntimeException("use parse() before requesting a value");
|
||||||
|
}
|
||||||
|
return dueDate;
|
||||||
|
}
|
||||||
|
|
||||||
private void setAmount(String amount) {
|
private void setAmount(String amount) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
|||||||
@Override
|
@Override
|
||||||
public String getOwnBIC()
|
public String getOwnBIC()
|
||||||
{
|
{
|
||||||
return "COBADEFXXX";
|
return "COBADEFFXXX";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -364,6 +364,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
|||||||
String iban = null;
|
String iban = null;
|
||||||
String holder = null;
|
String holder = null;
|
||||||
String ref = null;
|
String ref = null;
|
||||||
|
String dueDate = null;
|
||||||
|
|
||||||
if (zi.canParse())
|
if (zi.canParse())
|
||||||
{
|
{
|
||||||
@@ -372,6 +373,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
|||||||
bic = zi.getBIC();
|
bic = zi.getBIC();
|
||||||
iban = zi.getIBAN();
|
iban = zi.getIBAN();
|
||||||
holder = zi.getHolder();
|
holder = zi.getHolder();
|
||||||
|
dueDate = zi.getDueDate();
|
||||||
ref = zi.getForeignReference();
|
ref = zi.getForeignReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +381,8 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
|||||||
assertEquals(bic, getOwnBIC());
|
assertEquals(bic, getOwnBIC());
|
||||||
assertEquals(iban, getOwnIBAN());
|
assertEquals(iban, getOwnIBAN());
|
||||||
assertEquals(holder, getOwnOrganisationName());
|
assertEquals(holder, getOwnOrganisationName());
|
||||||
|
|
||||||
|
assertEquals(dueDate, "20141029");
|
||||||
assertEquals(ref, getNumber());
|
assertEquals(ref, getNumber());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user