format output, some exception logging corrections

This commit is contained in:
Jochen Stärk
2019-06-10 11:57:20 +02:00
parent ee6335ab93
commit 6662f987f6
6 changed files with 397 additions and 348 deletions

View File

@@ -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() {
@@ -292,13 +326,13 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
xml = xml + " <ram:SellerTradeParty>\n" //$NON-NLS-1$
// + " <GlobalID schemeID=\"0088\">4000001123452</GlobalID>\n"
+ " <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>";
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>";
}
if (trans.getOwnContact() != null) {
xml = xml + "<ram:DefinedTradeContact>\n" + " <ram:PersonName>" + trans.getOwnContact().getName()
@@ -401,7 +435,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
}
}
/*
* xml+= " + " <SpecifiedTradeAllowanceCharge>\n" +
* xml+= " + " <SpecifiedTradeAllowanceCharge>\n" +
* " <ChargeIndicator>false</ChargeIndicator>\n" +
* " <BasisAmount currencyID=\"EUR\">10</BasisAmount>\n" +
* " <ActualAmount>1.00</ActualAmount>\n" +
@@ -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$
}

View File

@@ -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;

View File

@@ -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);
}
}