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 holder;
|
||||
private String amount;
|
||||
private String dueDate;
|
||||
/** Raw XML form of the extracted data - may be directly obtained. */
|
||||
private byte[] rawXML=null;
|
||||
private String bankName;
|
||||
private boolean amountFound;
|
||||
private boolean extracted=false;
|
||||
private boolean parsed=false;
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
rawXML = embeddedFile.getByteArray();
|
||||
setMeta(new String(rawXML));
|
||||
extracted=true;
|
||||
// fos.write(embeddedFile.getByteArray());
|
||||
// fos.close();
|
||||
}
|
||||
@@ -130,6 +135,10 @@ public class ZUGFeRDImporter {
|
||||
DocumentBuilder builder = null;
|
||||
Document document = null;
|
||||
|
||||
if (!extracted) {
|
||||
throw new RuntimeException("extract() or extractLowLevel() must be used before parsing.");
|
||||
}
|
||||
|
||||
factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true); //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",...
|
||||
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() {
|
||||
if (rawXML==null) {
|
||||
if (!parsed) {
|
||||
throw new RuntimeException("use parse() before requesting a value");
|
||||
}
|
||||
return foreignReference;
|
||||
@@ -306,7 +333,7 @@ public class ZUGFeRDImporter {
|
||||
|
||||
|
||||
public String getBIC() {
|
||||
if (rawXML==null) {
|
||||
if (!parsed) {
|
||||
throw new RuntimeException("use parse() before requesting a value");
|
||||
}
|
||||
return BIC;
|
||||
@@ -319,6 +346,11 @@ public class ZUGFeRDImporter {
|
||||
}
|
||||
|
||||
|
||||
private void setDueDate(String dueDate) {
|
||||
this.dueDate = dueDate;
|
||||
}
|
||||
|
||||
|
||||
private void setBankName(String bankname) {
|
||||
this.bankName = bankname;
|
||||
}
|
||||
@@ -326,7 +358,7 @@ public class ZUGFeRDImporter {
|
||||
|
||||
|
||||
public String getIBAN() {
|
||||
if (rawXML==null) {
|
||||
if (!parsed) {
|
||||
throw new RuntimeException("use parse() before requesting a value");
|
||||
}
|
||||
return IBAN;
|
||||
@@ -334,7 +366,7 @@ public class ZUGFeRDImporter {
|
||||
|
||||
|
||||
public String getBankName() {
|
||||
if (rawXML==null) {
|
||||
if (!parsed) {
|
||||
throw new RuntimeException("use parse() before requesting a value");
|
||||
}
|
||||
return bankName;
|
||||
@@ -370,6 +402,12 @@ public class ZUGFeRDImporter {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public String getDueDate() {
|
||||
if (rawXML==null) {
|
||||
throw new RuntimeException("use parse() before requesting a value");
|
||||
}
|
||||
return dueDate;
|
||||
}
|
||||
|
||||
private void setAmount(String amount) {
|
||||
this.amount = amount;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
@Override
|
||||
public String getOwnBIC()
|
||||
{
|
||||
return "COBADEFXXX";
|
||||
return "COBADEFFXXX";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -364,6 +364,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
String iban = null;
|
||||
String holder = null;
|
||||
String ref = null;
|
||||
String dueDate = null;
|
||||
|
||||
if (zi.canParse())
|
||||
{
|
||||
@@ -372,6 +373,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
bic = zi.getBIC();
|
||||
iban = zi.getIBAN();
|
||||
holder = zi.getHolder();
|
||||
dueDate = zi.getDueDate();
|
||||
ref = zi.getForeignReference();
|
||||
}
|
||||
|
||||
@@ -379,6 +381,8 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
assertEquals(bic, getOwnBIC());
|
||||
assertEquals(iban, getOwnIBAN());
|
||||
assertEquals(holder, getOwnOrganisationName());
|
||||
|
||||
assertEquals(dueDate, "20141029");
|
||||
assertEquals(ref, getNumber());
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user