format output, some exception logging corrections
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
|
||||
1.7.2
|
||||
=====
|
||||
|
||||
Support BuyerReference (r+w), as well as SpecifiedLegalOrganization (w) and DefinedTradeContact (w)
|
||||
use dom4j to format output xml document
|
||||
corrected some exception logging glitches
|
||||
|
||||
|
||||
1.7.1
|
||||
=====
|
||||
2019-05-26
|
||||
|
||||
@@ -5,12 +5,15 @@ import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableProduct;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableTransaction;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRD2PullProvider;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporter;
|
||||
import org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA1Factory;
|
||||
|
||||
@@ -32,8 +35,7 @@ public class MustangWriter implements IZUGFeRDExportableTransaction {
|
||||
ze.export("./MustangGnuaccountingBeispielRE-20171118_506new.pdf");
|
||||
System.out.println("Done.");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(MustangWriter.class.getName()).log(Level.SEVERE, null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
pom.xml
11
pom.xml
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
||||
<artifactId>mustang</artifactId>
|
||||
@@ -75,6 +76,11 @@
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@@ -197,7 +203,8 @@
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.mustangproject.toecount.Toecount</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
@@ -25,6 +29,15 @@ import java.text.DecimalFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.mustangproject.toecount.Toecount;
|
||||
|
||||
public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
|
||||
@@ -121,7 +134,28 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
|
||||
@Override
|
||||
public byte[] getXML() {
|
||||
return zugferdData;
|
||||
|
||||
byte[] res = zugferdData;
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
Document document=null;
|
||||
try {
|
||||
document = DocumentHelper.parseText(new String(zugferdData));
|
||||
} catch (DocumentException e1) {
|
||||
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e1);
|
||||
}
|
||||
try {
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
XMLWriter writer = new XMLWriter(sw, format);
|
||||
writer.write(document);
|
||||
res = sw.toString().getBytes("UTF-8");
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal getTotalGross() {
|
||||
@@ -294,10 +328,10 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
+ " <ram:Name>" + trans.getOwnOrganisationName() + "</ram:Name>\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (trans.getOwnOrganization() != null) {
|
||||
|
||||
xml = xml + " <ram:SpecifiedLegalOrganization>\n" +
|
||||
" <ram:ID>"+trans.getOwnOrganization().getID()+"</ram:ID>\n" +
|
||||
" <ram:TradingBusinessName>"+trans.getOwnOrganization().getName()+"</ram:TradingBusinessName>\n" +
|
||||
" </ram:SpecifiedLegalOrganization>";
|
||||
xml = xml + " <ram:SpecifiedLegalOrganization>\n" + " <ram:ID>"
|
||||
+ trans.getOwnOrganization().getID() + "</ram:ID>\n" + " <ram:TradingBusinessName>"
|
||||
+ trans.getOwnOrganization().getName() + "</ram:TradingBusinessName>\n"
|
||||
+ " </ram:SpecifiedLegalOrganization>";
|
||||
|
||||
}
|
||||
if (trans.getOwnContact() != null) {
|
||||
@@ -485,8 +519,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
zugferdData = zugferdRaw;
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
} // $NON-NLS-1$
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ 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;
|
||||
|
||||
@@ -46,6 +47,8 @@ import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ZUGFeRDImporter {
|
||||
|
||||
@@ -69,7 +72,7 @@ public class ZUGFeRDImporter {
|
||||
extractLowLevel(bis);
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
throw new ZUGFeRDExportException(e);
|
||||
}
|
||||
}
|
||||
@@ -78,7 +81,7 @@ public class ZUGFeRDImporter {
|
||||
try {
|
||||
extractLowLevel(pdfStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
throw new ZUGFeRDExportException(e);
|
||||
}
|
||||
}
|
||||
@@ -161,7 +164,7 @@ public class ZUGFeRDImporter {
|
||||
try {
|
||||
transformer = tf.newTransformer();
|
||||
} catch (TransformerConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
StringWriter writer = new StringWriter();
|
||||
@@ -190,10 +193,10 @@ public class ZUGFeRDImporter {
|
||||
XPath xpath = xpathFact.newXPath();
|
||||
result = xpath.evaluate(xpathStr, document);
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
throw new ZUGFeRDExportException(e);
|
||||
} catch (IOException | SAXException | TransformerException | XPathExpressionException e) {
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
throw new ZUGFeRDExportException(e);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -139,8 +139,8 @@ public class Toecount {
|
||||
try {
|
||||
input = buffer.readLine();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
|
||||
}
|
||||
|
||||
if (input.isEmpty()) {
|
||||
@@ -176,8 +176,8 @@ public class Toecount {
|
||||
try {
|
||||
selectedName = buffer.readLine();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
|
||||
}
|
||||
|
||||
if (selectedName.isEmpty()) {
|
||||
@@ -193,8 +193,7 @@ public class Toecount {
|
||||
try {
|
||||
selectedAnswer = buffer.readLine();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
if (!selectedAnswer.equals("Y") && !selectedAnswer.equals("y")) {
|
||||
System.err.println("Aborted by user");
|
||||
@@ -326,7 +325,7 @@ public class Toecount {
|
||||
System.exit(2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
System.exit(-1);
|
||||
}
|
||||
@@ -454,8 +453,7 @@ public class Toecount {
|
||||
try {
|
||||
format = getStringFromUser("Format (fx=Factur-X, zf=ZUGFeRD,)", "zf", "fx|zf");
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Format set to " + format);
|
||||
@@ -466,8 +464,7 @@ public class Toecount {
|
||||
try {
|
||||
zfVersion = getStringFromUser("Version (1 or 2)", "1", "1|2");
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Version set to " + zfVersion);
|
||||
@@ -485,8 +482,8 @@ public class Toecount {
|
||||
"E", "M|m|W|w|B|b|C|c|E|e|X|x|");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
|
||||
}
|
||||
} else {
|
||||
System.out.println("Profile set to " + zfProfile);
|
||||
@@ -550,9 +547,8 @@ public class Toecount {
|
||||
System.out.println("Written to " + outName);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// } catch (JAXBException e) {
|
||||
// e.printStackTrace();
|
||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user