Additional cleanup

This commit is contained in:
Philip Helger
2024-07-09 19:23:24 +02:00
parent 8e20badf6e
commit 4ae6fd9ef0
18 changed files with 43 additions and 80 deletions

View File

@@ -22,11 +22,9 @@ package org.mustangproject.ZUGFeRD;
import static org.mustangproject.ZUGFeRD.ZUGFeRDDateFormat.DATE;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.mustangproject.EStandard;
import org.mustangproject.FileAttachment;
@@ -36,7 +34,6 @@ import org.mustangproject.XMLTools;
public class DAPullProvider extends ZUGFeRD2PullProvider {
protected IExportableTransaction trans;
private String paymentTermsDescription;
protected Profile profile = Profiles.getByName(EStandard.despatchadvice,"pilot", 1);
@@ -252,13 +249,9 @@ public class DAPullProvider extends ZUGFeRD2PullProvider {
+ "</SCRDMCCBDACIDAMessageStructure>";
final byte[] zugferdRaw;
try {
zugferdRaw = xml.getBytes("UTF-8");
zugferdRaw = xml.getBytes(StandardCharsets.UTF_8);
zugferdData = XMLTools.removeBOM(zugferdRaw);
} catch (final UnsupportedEncodingException e) {
Logger.getLogger(OXPullProvider.class.getName()).log(Level.SEVERE, null, e);
}
zugferdData = XMLTools.removeBOM(zugferdRaw);
}

View File

@@ -127,9 +127,6 @@ public class DXExporterFromA3 extends ZUGFeRDExporterFromA3 {
protected String despatchAdviceDocumentType = "DESPATCHADVICE";
private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
private boolean attachZUGFeRDHeaders = true;
/**

View File

@@ -1,6 +1,7 @@
package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal;
import java.math.RoundingMode;
/***
* the linecalculator does the math within an item line, and e.g. calculates quantity*price.
@@ -40,7 +41,7 @@ public class LineCalculator {
priceGross = currentItem.getPrice(); // see https://github.com/ZUGFeRD/mustangproject/issues/159
price = priceGross.subtract(allowance).add(charge);
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())
.subtract(allowanceItemTotal).setScale(2, BigDecimal.ROUND_HALF_UP);
.subtract(allowanceItemTotal).setScale(2, RoundingMode.HALF_UP);
itemTotalVATAmount = itemTotalNetAmount.multiply(multiplicator);
}

View File

@@ -127,9 +127,6 @@ public class OXExporterFromA3 extends ZUGFeRDExporterFromA3 {
protected String orderXDocumentType = "ORDER";
private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
private boolean attachZUGFeRDHeaders = true;
/**

View File

@@ -22,16 +22,13 @@ package org.mustangproject.ZUGFeRD;
import static org.mustangproject.ZUGFeRD.ZUGFeRDDateFormat.DATE;
import static org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants.CORRECTEDINVOICE;
import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATEGORY_CODES_WITH_EXEMPTION_REASON;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.mustangproject.EStandard;
import org.mustangproject.FileAttachment;
@@ -339,9 +336,9 @@ public class OXPullProvider extends ZUGFeRD2PullProvider {
for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
final VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
if (amount != null) {
final String amountCategoryCode = amount.getCategoryCode();
/*final String amountCategoryCode = amount.getCategoryCode();
final boolean displayExemptionReason = CATEGORY_CODES_WITH_EXEMPTION_REASON.contains(amountCategoryCode);
/* xml += "<ram:ApplicableTradeTax>\n"
xml += "<ram:ApplicableTradeTax>\n"
+ "<ram:CalculatedAmount>" + currencyFormat(amount.getCalculated())
+ "</ram:CalculatedAmount>\n" //currencyID=\"EUR\"
+ "<ram:TypeCode>VAT</ram:TypeCode>\n"
@@ -477,13 +474,9 @@ public class OXPullProvider extends ZUGFeRD2PullProvider {
+ "</rsm:SCRDMCCBDACIOMessageStructure>";
final byte[] zugferdRaw;
try {
zugferdRaw = xml.getBytes("UTF-8");
zugferdRaw = xml.getBytes(StandardCharsets.UTF_8);
zugferdData = XMLTools.removeBOM(zugferdRaw);
} catch (final UnsupportedEncodingException e) {
Logger.getLogger(OXPullProvider.class.getName()).log(Level.SEVERE, null, e);
}
zugferdData = XMLTools.removeBOM(zugferdRaw);
}

View File

@@ -22,7 +22,6 @@ package org.mustangproject.ZUGFeRD;
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
@@ -86,13 +85,9 @@ public class UBLDAPullProvider implements IXMLProvider {
}
xml += "</DespatchAdvice>\n";
final byte[] ublRaw;
try {
ublRaw = xml.getBytes("UTF-8");
ublRaw = xml.getBytes(StandardCharsets.UTF_8);
ublData = XMLTools.removeBOM(ublRaw);
} catch (final UnsupportedEncodingException e) {
Logger.getLogger(UBLDAPullProvider.class.getName()).log(Level.SEVERE, null, e);
}
ublData = XMLTools.removeBOM(ublRaw);
}
public String getPartyXML(IZUGFeRDExportableTradeParty tp) {

View File

@@ -5,7 +5,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
@@ -42,9 +42,8 @@ public class XMLUpgrader {
* @return String the updated XML
* @throws FileNotFoundException if the source could not be found
* @throws TransformerException if the source could not be transformed
* @throws UnsupportedEncodingException if the source was not utf8
*/
public String migrateFromV1ToV2(String xmlFilename) throws FileNotFoundException, TransformerException, UnsupportedEncodingException {
public String migrateFromV1ToV2(String xmlFilename) throws FileNotFoundException, TransformerException {
/**
* *
* http://www.unece.org/fileadmin/DAM/cefact/xml/XML-Naming-And-Design-Rules-V2_1.pdf
@@ -56,7 +55,7 @@ public class XMLUpgrader {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
applySchematronXsl(new FileInputStream(xmlFilename), baos);
String res = null;
res = baos.toString("UTF-8");
res = baos.toString(StandardCharsets.UTF_8);
return res;
}

View File

@@ -100,7 +100,7 @@ public class ZUGFeRD1PullProvider extends ZUGFeRD2PullProvider {
format.setTrimText(false);
final XMLWriter writer = new XMLWriter(sw, format);
writer.write(document);
res = sw.toString().getBytes("UTF-8");
res = sw.toString().getBytes(StandardCharsets.UTF_8);
} catch (final IOException e) {
Logger.getLogger(ZUGFeRD1PullProvider.class.getName()).log(Level.SEVERE, null, e);

View File

@@ -25,7 +25,6 @@ import static org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants.CATE
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
@@ -756,13 +755,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ "</rsm:CrossIndustryInvoice>";
final byte[] zugferdRaw;
try {
zugferdRaw = xml.getBytes("UTF-8");
zugferdRaw = xml.getBytes(StandardCharsets.UTF_8);
zugferdData = XMLTools.removeBOM(zugferdRaw);
} catch (final UnsupportedEncodingException e) {
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
}
zugferdData = XMLTools.removeBOM(zugferdRaw);
}
protected String buildItemNotes(IZUGFeRDExportableItem currentItem) {

View File

@@ -138,9 +138,6 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
protected PDDocument doc;
private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
protected int ZFVersion = DefaultZUGFeRDVersion;
private boolean attachZUGFeRDHeaders = true;
@@ -559,7 +556,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
metadata.addSchema(pdfaex);
}
private void removeCidSet(PDDocumentCatalog catalog, PDDocument doc)
private void removeCidSet(PDDocument doc)
throws IOException
{
// https://github.com/ZUGFeRD/mustangproject/issues/249
@@ -580,7 +577,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
PDType0Font typedFont = (PDType0Font) pdFont;
if (typedFont.getDescendantFont() instanceof PDCIDFontType2) {
PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont();
@SuppressWarnings ("unused")
PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont();
PDFontDescriptor fontDescriptor = pdFont.getFontDescriptor();
fontDescriptor.getCOSObject().removeItem(cidSet);
@@ -601,7 +599,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
metadata = new PDMetadata(doc);
cat.setMetadata(metadata);
removeCidSet(cat, doc);
removeCidSet(doc);
xmp = getXmpMetadata();
writeAdobePDFSchema(xmp);
writePDFAIdentificationSchema(xmp);

View File

@@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
@@ -785,9 +786,10 @@ public class ZUGFeRDImporter {
static String convertStreamToString(java.io.InputStream is) {
// TODO wouldn't we use IOUtils.toByteArray nowadays???
// source https://stackoverflow.com/questions/309424/how-do-i-read-convert-an-inputstream-into-a-string-in-java referring to
// https://community.oracle.com/blogs/pat/2004/10/23/stupid-scanner-tricks
final Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
final Scanner s = new Scanner(is, StandardCharsets.UTF_8).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}

View File

@@ -32,7 +32,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -62,7 +61,6 @@ import org.apache.fop.configuration.ConfigurationException;
import org.apache.fop.configuration.DefaultConfigurationBuilder;
import org.apache.xmlgraphics.util.MimeConstants;
import org.mustangproject.ClasspathResolverURIAdapter;
import org.mustangproject.CII.CIIToUBL;
public class ZUGFeRDVisualizer {
@@ -100,7 +98,7 @@ public class ZUGFeRDVisualizer {
}
public String visualize(String xmlFilename, Language lang)
throws FileNotFoundException, TransformerException, UnsupportedEncodingException {
throws FileNotFoundException, TransformerException {
try {
if (mXsltXRTemplate == null) {
@@ -202,11 +200,11 @@ public class ZUGFeRDVisualizer {
}
return baos.toString("UTF-8");
return baos.toString(StandardCharsets.UTF_8);
}
protected String toFOP(String xmlFilename)
throws FileNotFoundException, TransformerException, UnsupportedEncodingException {
throws FileNotFoundException, TransformerException {
try {
if (mXsltXRTemplate == null) {
@@ -269,7 +267,7 @@ public class ZUGFeRDVisualizer {
}
return baos.toString("UTF-8");
return baos.toString(StandardCharsets.UTF_8);
}
public void toPDF(String xmlFilename, String pdfFilename) {
@@ -285,11 +283,7 @@ public class ZUGFeRDVisualizer {
*/
try {
result = zvi.toFOP(CIIinputFile.getAbsolutePath());
} catch (FileNotFoundException e) {
Logger.getLogger(ZUGFeRDVisualizer.class.getName()).log(Level.SEVERE, null, e);
} catch (TransformerException e) {
Logger.getLogger(ZUGFeRDVisualizer.class.getName()).log(Level.SEVERE, null, e);
} catch (UnsupportedEncodingException e) {
} catch (FileNotFoundException | TransformerException e) {
Logger.getLogger(ZUGFeRDVisualizer.class.getName()).log(Level.SEVERE, null, e);
}
/*

View File

@@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -65,7 +66,7 @@ public class BackwardCompatibilityTest extends TestCase implements IExportableTr
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
// check for pdf-a schema extension
// assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);
@@ -105,7 +106,7 @@ public class BackwardCompatibilityTest extends TestCase implements IExportableTr
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
// check for pdf-a schema extension
// assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);
@@ -143,7 +144,7 @@ public class BackwardCompatibilityTest extends TestCase implements IExportableTr
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
// check for pdf-a schema extension
// assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);

View File

@@ -26,8 +26,6 @@ import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.mustangproject.*;
import com.helger.commons.io.file.SimpleFileIO;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

View File

@@ -256,13 +256,13 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
"</ram:ApplicableHeaderTradeSettlement>\n" +
"</rsm:SupplyChainTradeTransaction>\n" +
"</rsm:CrossIndustryInvoice>";
zea1.setXML(ownZUGFeRDXML.getBytes("UTF-8"));
zea1.setXML(ownZUGFeRDXML.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
assertFalse(pdfContent.indexOf("<fx:ConformanceLevel>EN 16931</fx:ConformanceLevel>") == -1);
@@ -437,14 +437,14 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
+ "<ram:Name>Heiße Luft pro Liter</ram:Name>\n" + "<ram:Description/>\n"
+ "</ram:SpecifiedTradeProduct>\n" + "</ram:IncludedSupplyChainTradeLineItem>\n"
+ "</rsm:SpecifiedSupplyChainTradeTransaction>\n" + "</rsm:CrossIndustryDocument>";
zea1.setXML(ownZUGFeRDXML.getBytes("UTF-8"));
zea1.setXML(ownZUGFeRDXML.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>BASIC</zf:ConformanceLevel>") == -1);

View File

@@ -39,6 +39,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -368,7 +369,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
// check for pdf-a schema extension
// assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);
@@ -412,7 +413,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf(DocumentContextParameterTypeConstants.BASIC) >= 0);
assertFalse(pdfContent.indexOf(DocumentContextParameterTypeConstants.EXTENDED) >= 0);
assertTrue(pdfContent.indexOf(DocumentContextParameterTypeConstants.COMFORT) >= 0);
@@ -448,7 +449,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
String pdfContent = baos.toString(StandardCharsets.UTF_8);
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
// check for pdf-a schema extension
assertFalse(pdfContent.indexOf("<fx:ConformanceLevel>EN 16931</fx:ConformanceLevel>") == -1);

View File

@@ -90,7 +90,7 @@ public class UBLTest extends ResourceCase {
final ByteArrayOutputStream baos=new ByteArrayOutputStream();
oe.export(baos);
final String theXML = baos.toString("UTF-8");
final String theXML = baos.toString(StandardCharsets.UTF_8);
assertTrue(theXML.contains("<DespatchAdvice"));
Files.write(Paths.get(TARGET_XML), theXML.getBytes(StandardCharsets.UTF_8));
} catch (final IOException e) {

View File

@@ -21,7 +21,6 @@ package org.mustangproject.ZUGFeRD;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.mustangproject.CII.CIIToUBL;
import javax.xml.transform.*;
import java.io.*;