add zugferdimporter.getversion, add total amount in metrics
This commit is contained in:
@@ -111,7 +111,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
private PDDocument doc;
|
||||
int ZFVersion;
|
||||
|
||||
private HashMap<String, byte[]> additionalXMLs = new HashMap<String, byte[]>();
|
||||
private HashMap<String, byte[]> additionalFiles = new HashMap<String, byte[]>();
|
||||
|
||||
|
||||
private boolean disableAutoClose;
|
||||
@@ -130,10 +130,21 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
init();
|
||||
}
|
||||
|
||||
public void addAdditonalXML(String filename, byte[] xml) {
|
||||
additionalXMLs.put(filename, xml);
|
||||
/**
|
||||
* Adds additional file attachments into the ZF
|
||||
* @param filename
|
||||
* @param filecontent
|
||||
*/
|
||||
public void addAdditionalFile(String filename, byte[] xml) {
|
||||
additionalFiles.put(filename, xml);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* internal helper function: get namespace for given zugferd or factur-x version
|
||||
* @param ver
|
||||
* @return
|
||||
*/
|
||||
public String getNamespaceForVersion(int ver) {
|
||||
if (isFacturX) {
|
||||
return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";
|
||||
@@ -147,6 +158,11 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* internal helper: returns the namespace prefix for the given zf/fx version number
|
||||
* @param ver
|
||||
* @return
|
||||
*/
|
||||
public String getPrefixForVersion(int ver) {
|
||||
if (isFacturX) {
|
||||
return "fx";
|
||||
@@ -155,6 +171,11 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* internal helper: return the name of the file attachment for the given zf/fx version
|
||||
* @param ver
|
||||
* @return
|
||||
*/
|
||||
public String getFilenameForVersion(int ver) {
|
||||
if (isFacturX) {
|
||||
return "factur-x.xml";
|
||||
@@ -374,8 +395,8 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
PDFAttachGenericFile(doc, filename, "Alternative",
|
||||
"Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
|
||||
"text/xml", xmlProvider.getXML());
|
||||
for (String filenameAdditional : additionalXMLs.keySet()) {
|
||||
PDFAttachGenericFile(doc, filenameAdditional, "Supplement", "ZUGFeRD extension/additional data", "text/xml", additionalXMLs.get(filenameAdditional));
|
||||
for (String filenameAdditional : additionalFiles.keySet()) {
|
||||
PDFAttachGenericFile(doc, filenameAdditional, "Supplement", "ZUGFeRD extension/additional data", "text/xml", additionalFiles.get(filenameAdditional));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,7 +539,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ZUGFeRD conformance level (override).
|
||||
* Sets the ZUGFeRD profile.
|
||||
*
|
||||
* @param zUGFeRDConformanceLevel the new conformance level
|
||||
* @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
|
||||
@@ -532,7 +553,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ZUGFeRD conformance level (override).
|
||||
* Sets the ZUGFeRD profile.
|
||||
*
|
||||
* @param zUGFeRDConformanceLevel the new conformance level
|
||||
* @deprecated Use {@link #setConformanceLevel(PDFAConformanceLevel)} instead
|
||||
@@ -572,6 +593,10 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
XMPSchemaPDFAExtensions pdfaex = new XMPSchemaPDFAExtensions(this, metadata, ZFVersion, attachZUGFeRDHeaders);
|
||||
pdfaex.setZUGFeRDVersion(ZFVersion);
|
||||
metadata.addSchema(pdfaex);
|
||||
for (String filenameAdditional : additionalFiles.keySet()) {
|
||||
XMPSchemaPDFAExtensionsAdditionalData pdfaexadd = new XMPSchemaPDFAExtensionsAdditionalData(metadata);
|
||||
metadata.addSchema(pdfaexadd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
|
||||
import org.mustangproject.toecount.Toecount;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@@ -163,21 +162,6 @@ public class ZUGFeRDImporter {
|
||||
}
|
||||
}
|
||||
|
||||
private void prettyPrint(Document document) throws TransformerException {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = null;
|
||||
try {
|
||||
transformer = tf.newTransformer();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(new DOMSource(document), new StreamResult(writer));
|
||||
String output = writer.getBuffer().toString();//.replaceAll("\n|\r", "");
|
||||
System.err.println(output);
|
||||
}
|
||||
|
||||
private Document getDocument() { return document; }
|
||||
|
||||
private void setDocument() throws ParserConfigurationException, IOException, SAXException {
|
||||
@@ -368,6 +352,16 @@ public class ZUGFeRDImporter {
|
||||
}
|
||||
|
||||
|
||||
public int getVersion() throws Exception {
|
||||
if (!containsMeta) throw new Exception("Not yet parsed");
|
||||
if (getUTF8().contains("<rsm:CrossIndustryDocument")) {
|
||||
return 1;
|
||||
} else if (getUTF8().contains("<rsm:CrossIndustryInvoice")) {
|
||||
return 2;
|
||||
}
|
||||
throw new Exception("ZUGFeRD version could not be determined");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return return UTF8 XML (without BOM) of the invoice
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.toecount;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||
|
||||
public class FileChecker {
|
||||
@@ -53,6 +55,7 @@ public class FileChecker {
|
||||
try {
|
||||
if (zi.canParse()) {
|
||||
thisRun.incZUGFeRDCount();
|
||||
thisRun.incTotal(new BigDecimal(zi.getAmount()));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.toecount;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class StatRun {
|
||||
private int pdfCount = 0;
|
||||
private int horseCount = 0;
|
||||
private int fileCount = 0;
|
||||
private int dirCount = 0;
|
||||
private BigDecimal total = BigDecimal.ZERO;
|
||||
private boolean checkFileExt = true;
|
||||
|
||||
public void ignoreFileExtension() {
|
||||
@@ -73,8 +76,8 @@ public class StatRun {
|
||||
public String getSummaryLine() {
|
||||
|
||||
return "\r\n===================================================================\r\n" + String.format(
|
||||
"Files:\t%d\tDirs:\t%d\tPDF:\t%d\tZUGFeRD:\t%d\r\n",
|
||||
getFileCount(), getDirCount(), getPDFCount(), getZUGFeRDCount());
|
||||
"Files:\t%d\tDirs:\t%d\tPDF:\t%d\tZUGFeRD:\t%d\tTotal:\t%s\r\n",
|
||||
getFileCount(), getDirCount(), getPDFCount(), getZUGFeRDCount(), total.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -87,5 +90,10 @@ public class StatRun {
|
||||
return ".";
|
||||
}
|
||||
|
||||
public void incTotal(BigDecimal delta) {
|
||||
total=total.add(delta);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,24 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.toecount;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDConformanceLevel;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDImporter;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDMigrator;
|
||||
|
||||
/***
|
||||
* This is the command line interface to mustangproject
|
||||
*
|
||||
@@ -25,24 +43,6 @@ package org.mustangproject.toecount;
|
||||
|
||||
import com.sanityinc.jargs.CmdLineParser;
|
||||
import com.sanityinc.jargs.CmdLineParser.Option;
|
||||
import org.mustangproject.ZUGFeRD.*;
|
||||
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Toecount {
|
||||
// build with: /opt/local/bin/mvn clean compile assembly:single
|
||||
@@ -454,7 +454,7 @@ public class Toecount {
|
||||
} else {
|
||||
System.out.println("ZUGFeRD XML set to " + xmlName);
|
||||
}
|
||||
|
||||
|
||||
if (outName == null) {
|
||||
outName = getFilenameFromUser("Ouput PDF", "invoice.ZUGFeRD.pdf", "pdf", false, true);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user