Skip to content

Commit

Permalink
see history
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed Aug 29, 2018
1 parent 3e9fb55 commit 8df75e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions History.md
@@ -1,3 +1,9 @@
1.5.4
=====
2018-08-29

Fixed #62 fail gracefully on commandline extraction of XML if none is present.
New public function: ZUGFeRDImporter.getUTF8 returns raw XML without Byte Order Mark, if one had been used.

1.5.3
=====
Expand Down
Binary file modified doc/MustangDev.en.odt
Binary file not shown.
30 changes: 30 additions & 0 deletions src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java
Expand Up @@ -495,7 +495,37 @@ public String getMeta() {
return new String(rawXML);
}


/**
*
* @return return UTF8 XML (without BOM) of the invoice
*/
public String getUTF8() {
if (rawXML == null) {
return null;
}
if (rawXML.length<3) {
return new String(rawXML);
}


byte[] bomlessData;

if ((rawXML[0] == (byte) 0xEF)
&& (rawXML[1] == (byte) 0xBB)
&& (rawXML[2] == (byte) 0xBF)) {
// I don't like BOMs, lets remove it
bomlessData = new byte[rawXML.length - 3];
System.arraycopy(rawXML, 3, bomlessData, 0,
rawXML.length - 3);
} else {
bomlessData = rawXML;
}

return new String(bomlessData);
}

/**
* Returns the raw XML data as extracted from the ZUGFeRD PDF file.
*/
public byte[] getRawXML() {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/mustangproject/toecount/Toecount.java
Expand Up @@ -368,11 +368,17 @@ else if (((directoryName != null) && (directoryName.length() > 0)) || filesFromS

zi.extract(pdfName);
try {
Files.write(Paths.get(xmlName), zi.getRawXML());
byte[] XMLContent=zi.getRawXML();
if (XMLContent==null) {
System.err.println("No ZUGFeRD XML found in PDF file");

} else {
Files.write(Paths.get(xmlName), XMLContent);
System.out.println("Written to " + xmlName);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Written to " + xmlName);

} else if (a3only) {
/*
Expand Down

0 comments on commit 8df75e2

Please sign in to comment.