diff --git a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java index 429eb3d9..c3d71165 100755 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java @@ -44,74 +44,73 @@ public class Main { private static String getUsage() { return "Usage: --action metrics|combine|extract|a3only|ubl|validate|validateExpectInvalid|validateExpectValid|visualize [-d,--directory] [-l,--listfromstdin] [-i,--ignore fileextension, PDF/A errors] [--disable-file-logging] | [-h,--help] \r\n" - + " --action license display open source license and notice\n" - + " --action metrics\n" - + " -d, --directory count ZUGFeRD files in directory to be scanned\n" - + " If it is a directory, it will recurse.\n" - + " -l, --listfromstdin count ZUGFeRD files from a list of linefeed separated files on runtime.\n" - + " It will start once a blank line has been entered.\n" + "\n" - + " Additional parameter for both count operations\n" - + " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf) in metrics, ignore PDF/A input file errors in combine\n" - + " [--disable-file-logging] disable logging to file.\n" - + " --action extract extract Factur-X PDF to XML file\n" - + " Additional parameters (optional - user will be prompted if not defined)\n" - + " [--source ]: set input PDF file\n" - + " [--out ]: set output XML file\n" - + " --action a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n" - + " Additional parameters (optional - user will be prompted if not defined)\n" - + " [--source ]: set input PDF file\n" - + " [--out ]: set output PDF file\n" - + " --action combine combine XML and PDF file to Factur-X PDF file\n" - + " Additional parameters (optional - user will be prompted if not defined)\n" - + " [--source ]: set input PDF file\n" - + " [--source-xml ]: set input XML file\n" - + " [--out ]: set output PDF file\n" - + " [--format ]: set Factur-X, ZUGFeRD, Order-X or Cross Industry Despatch Advice\n" - + " [--version <1|2>]: set ZUGFeRD version\n" - + " [--profile <...>]: set ZUGFeRD profile\n" - + " For ZUGFeRD v1 or Order-X: ASIC, OMFORT or EXENDED\n" - + " For ZUGFeRD v2: INIMUM, BASIC L, ASIC, IUS, N16931, Rechnung, EXENDED\n" - + " [--attachments ]: list of file attachments (passing a single empty file name prevents prompting)\n" - + " [--no-additional-attachments]: prevent prompting for attachments\n" - + " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n" - + " [--source ]: set input XML file\n" - + " [--out ]: set output XML file\n" - + " --action upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n" - + " Additional parameters (optional - user will be prompted if not defined)\n" - + " [--source ]: set input XML ZUGFeRD 1 file\n" - + " [--out ]: set output XML ZUGFeRD 2 file\n" - + " --action validate validate XML or PDF file \n" - + " [--no-notices]: refrain from reporting notices\n" - + " [--logAppend ]: text to be added to log line\n" - + " Additional parameters (optional - user will be prompted if not defined)\n" - + " [--source ]: input PDF or XML file\n" - + " [--log-as-pdf]: save log output as pdf\n" - + " --action validateExpectInvalid validate directory recursively expecting negative results \n" - + " [--no-notices]: refrain from reporting notices\n" - + " Additional parameters (user will be prompted if not defined)\n" - + " -d, --directory to check recursively\n" - + " Additional parameters (optional)\n" - + " --exclude: comma-separated list of filenames to ignore\n" - + " --action validateExpectValid validate directory recursively expecting positive results \n" - + " [--no-notices]: refrain from reporting notices\n" - + " Additional parameters (user will be prompted if not defined)\n" - + " -d, --directory to check recursively \n" - + " Additional parameters (user will be prompted if not defined)\n" - + " --exclude: comma-separated list of filenames to ignore\n" - + " --action visualize convert XML to HTML \n" - + " [--language ]: set output lang (en, fr or de)\n" - + " [--source ]: set input XML file\n" - + " [--out ]: set output HTML file\n" - + " --action pdf convert XML to PDF \n" - + " [--source ]: set input XML file\n" - + " [--out ]: set output PDF file\n" - ; + + " --action license display open source license and notice\n" + + " --action metrics\n" + + " -d, --directory count ZUGFeRD files in directory to be scanned\n" + + " If it is a directory, it will recurse.\n" + + " -l, --listfromstdin count ZUGFeRD files from a list of linefeed separated files on runtime.\n" + + " It will start once a blank line has been entered.\n" + "\n" + + " Additional parameter for both count operations\n" + + " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf) in metrics, ignore PDF/A input file errors in combine\n" + + " [--disable-file-logging] disable logging to file.\n" + + " --action extract extract Factur-X PDF to XML file\n" + + " Additional parameters (optional - user will be prompted if not defined)\n" + + " [--source ]: set input PDF file\n" + + " [--out ]: set output XML file\n" + + " --action a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n" + + " Additional parameters (optional - user will be prompted if not defined)\n" + + " [--source ]: set input PDF file\n" + + " [--out ]: set output PDF file\n" + + " --action combine combine XML and PDF file to Factur-X PDF file\n" + + " Additional parameters (optional - user will be prompted if not defined)\n" + + " [--source ]: set input PDF file\n" + + " [--source-xml ]: set input XML file\n" + + " [--out ]: set output PDF file\n" + + " [--format ]: set Factur-X, ZUGFeRD, Order-X or Cross Industry Despatch Advice\n" + + " [--version <1|2>]: set ZUGFeRD version\n" + + " [--profile <...>]: set ZUGFeRD profile\n" + + " For ZUGFeRD v1 or Order-X: ASIC, OMFORT or EXENDED\n" + + " For ZUGFeRD v2: INIMUM, BASIC L, ASIC, IUS, N16931, Rechnung, EXENDED\n" + + " [--attachments ]: list of file attachments (passing a single empty file name prevents prompting)\n" + + " [--no-additional-attachments]: prevent prompting for attachments\n" + + " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n" + + " [--source ]: set input XML file\n" + + " [--out ]: set output XML file\n" + + " --action upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n" + + " Additional parameters (optional - user will be prompted if not defined)\n" + + " [--source ]: set input XML ZUGFeRD 1 file\n" + + " [--out ]: set output XML ZUGFeRD 2 file\n" + + " --action validate validate XML or PDF file \n" + + " [--no-notices]: refrain from reporting notices\n" + + " [--logAppend ]: text to be added to log line\n" + + " Additional parameters (optional - user will be prompted if not defined)\n" + + " [--source ]: input PDF or XML file\n" + + " [--log-as-pdf]: save log output as pdf\n" + + " --action validateExpectInvalid validate directory recursively expecting negative results \n" + + " [--no-notices]: refrain from reporting notices\n" + + " Additional parameters (user will be prompted if not defined)\n" + + " -d, --directory to check recursively\n" + + " Additional parameters (optional)\n" + + " --exclude: comma-separated list of filenames to ignore\n" + + " --action validateExpectValid validate directory recursively expecting positive results \n" + + " [--no-notices]: refrain from reporting notices\n" + + " Additional parameters (user will be prompted if not defined)\n" + + " -d, --directory to check recursively \n" + + " Additional parameters (user will be prompted if not defined)\n" + + " --exclude: comma-separated list of filenames to ignore\n" + + " --action visualize convert XML to HTML \n" + + " [--language ]: set output lang (en, fr or de)\n" + + " [--source ]: set input XML file\n" + + " [--out ]: set output HTML file\n" + + " --action pdf convert XML to PDF \n" + + " [--source ]: set input XML file\n" + + " [--out ]: set output PDF file\n"; } private static void printHelp() { System.out.println("Mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + " \r\n" - + "A Apache Public License tool for e-invoices with\r\n" - + "ZUGFeRD Metadata (http://www.zugferd.org)\r\n" + "\r\n" + getUsage() + "\r\n"); + + "A Apache Public License tool for e-invoices with\r\n" + + "ZUGFeRD Metadata (http://www.zugferd.org)\r\n" + "\r\n" + getUsage() + "\r\n"); } /** @@ -162,14 +161,16 @@ public class Main { * Prompts the user for a input or output filename * * @param prompt the text the user is asked - * @param defaultFilename a default Filename. Passing an empty string indicates that specifying a file is optional - * @param expectedExtension will warn if filename does not match expected file extension, "or" possible with e.g. pdf|xml + * @param defaultFilename a default Filename. Passing an empty string + * indicates that specifying a file is optional + * @param expectedExtension will warn if filename does not match expected file + * extension, "or" possible with e.g. pdf|xml * @param ensureFileExists will warn if file does NOT exist (for input files) * @param ensureFileNotExists will warn if file DOES exist (for output files) * @return String */ protected static String getFilenameFromUser(String prompt, String defaultFilename, String expectedExtension, - boolean ensureFileExists, boolean ensureFileNotExists) { + boolean ensureFileExists, boolean ensureFileNotExists) { boolean fileExistenceOK = false; String selectedName = ""; do { @@ -187,7 +188,7 @@ public class Main { if (selectedName.isEmpty()) { // pressed return without entering anything if (defaultFilename.isEmpty()) { - return ""; //no default -> this is an optional filename + return ""; // no default -> this is an optional filename } selectedName = defaultFilename; } @@ -211,7 +212,7 @@ public class Main { } } else if (!hasCorrectExtension) { System.err.println("Expected " + expectedExtension - + " extension, this may corrupt your file. Do you still want to continue?(Y|N)"); + + " extension, this may corrupt your file. Do you still want to continue?(Y|N)"); String selectedAnswer = ""; try { selectedAnswer = buffer.readLine(); @@ -270,6 +271,7 @@ public class Main { /*** * converts from CII to UBL + * * @param xmlName the name of the xml file * @param outName the name of the output file * @throws IOException @@ -309,7 +311,8 @@ public class Main { } // Plain Java - // based on https://mkyong.com/java/how-to-convert-inputstream-to-string-in-java/ + // based on + // https://mkyong.com/java/how-to-convert-inputstream-to-string-in-java/ private static String convertInputStreamToString(InputStream is) { try (InputStream inputStream = is) { int DEFAULT_BUFFER_SIZE = 8192; @@ -333,7 +336,9 @@ public class Main { /*** * the main function of the commandline tool... - * @param args the commandline args, see also https://www.mustangproject.org/commandline/#verbose + * + * @param args the commandline args, see also + * https://www.mustangproject.org/commandline/#verbose */ public static void main(String[] args) { try { @@ -347,12 +352,14 @@ public class Main { options.addOption(new Option("f", "format", true, "which format to output")); options.addOption(new Option("version", "version", true, "which version of the standard to use")); options.addOption(new Option("profile", "profile", true, "which profile of the standard to use")); - options.addOption(new Option("no-additional-attachments", "no-additional-attachments", false, "prevent prompting for attachments")); + options.addOption(new Option("no-additional-attachments", "no-additional-attachments", false, + "prevent prompting for attachments")); Option attachmentOpt = new Option("attachments", "attachments", true, "File attachments"); attachmentOpt.setValueSeparator(','); attachmentOpt.setArgs(Option.UNLIMITED_VALUES); options.addOption(attachmentOpt); - Option excludeOpt = new Option("exclude", "exclude", true, "Files to exclude from recursive directory traversal"); + Option excludeOpt = new Option("exclude", "exclude", true, + "Files to exclude from recursive directory traversal"); excludeOpt.setValueSeparator(','); excludeOpt.setArgs(Option.UNLIMITED_VALUES); options.addOption(excludeOpt); @@ -361,8 +368,10 @@ public class Main { options.addOption(new Option("language", "language", true, "output language (en, de or fr)")); options.addOption(new Option("out", "out", true, "which output file to write to")); options.addOption(new Option("no-notices", "no-notices", false, "suppress non-fatal errors")); - options.addOption(new Option("logAppend", "logAppend", true, "freeform text to be appended to log messages")); - options.addOption(new Option("disable-file-logging", "disable-file-logging", false, "suppress logging to file")); + options.addOption( + new Option("logAppend", "logAppend", true, "freeform text to be appended to log messages")); + options.addOption( + new Option("disable-file-logging", "disable-file-logging", false, "suppress logging to file")); options.addOption(new Option("d", "directory", true, "which directory to operate on")); options.addOption(new Option("i", "ignorefileextension", false, "ignore non-matching file extensions")); options.addOption(new Option("l", "listfromstdin", false, "take list of files from commandline")); @@ -378,7 +387,7 @@ public class Main { // Retrieve all options action = cmd.getOptionValue("action"); String directoryName = cmd.getOptionValue("directory"); - boolean filesFromStdIn = cmd.hasOption("listfromstdin");//((Number)cmdLine.getParsedOptionValue("integer-option")).intValue(); + boolean filesFromStdIn = cmd.hasOption("listfromstdin");// ((Number)cmdLine.getParsedOptionValue("integer-option")).intValue(); boolean ignoreFileExt = cmd.hasOption("ignorefileextension"); boolean noAttachments = cmd.hasOption("no-additional-attachments"); boolean helpRequested = cmd.hasOption("help") || ((action != null) && (action.equals("help"))); @@ -398,11 +407,10 @@ public class Main { String[] attachmentFilenames = cmd.hasOption("attachments") ? cmd.getOptionValues("attachments") : null; String[] excludedFilenames = cmd.hasOption("exclude") ? cmd.getOptionValues("exclude") : null; - ArrayList attachments = new ArrayList<>(); /* - setting system property to disable FILE appender and - suppress creation of files and folders. + * setting system property to disable FILE appender and + * suppress creation of files and folders. */ System.setProperty("FILE_APPENDER_ENABLED", ((Boolean) (disableFileLogging == false)).toString()); @@ -411,14 +419,17 @@ public class Main { if (helpRequested) { printHelp(); optionsRecognized = true; - } /* else if ((action!=null)&&(action.equals("license"))) { - printLicense(); - optionsRecognized=true; - } */ else if ((action != null) && (action.equals("metrics"))) { + } /* + * else if ((action!=null)&&(action.equals("license"))) { + * printLicense(); + * optionsRecognized=true; + * } + */ else if ((action != null) && (action.equals("metrics"))) { performMetrics(directoryName, filesFromStdIn, ignoreFileExt); optionsRecognized = true; } else if ((action != null) && (action.equals("combine"))) { - performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile, ignoreFileExt, attachmentFilenames, attachments, noAttachments); + performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile, + ignoreFileExt, attachmentFilenames, attachments, noAttachments); optionsRecognized = true; } else if ((action != null) && (action.equals("extract"))) { performExtract(sourceName, outName); @@ -439,7 +450,8 @@ public class Main { performUBL(sourceName, outName); optionsRecognized = true; } else if ((action != null) && (action.equals("validate"))) { - optionsRecognized = performValidate(sourceName, noNotices, cmd.getOptionValue("logAppend"), LogAsPDF); + optionsRecognized = performValidate(sourceName, noNotices, cmd.getOptionValue("logAppend"), + LogAsPDF); } else if ((action != null) && (action.equals("validateExpectValid"))) { optionsRecognized = performValidateExpect(true, directoryName, excludedFilenames); } else if ((action != null) && (action.equals("validateExpectInvalid"))) { @@ -466,7 +478,8 @@ public class Main { } - private static boolean performValidate(String sourceName, boolean noNotices, String logAppend, boolean createLogAsPDF) { + private static boolean performValidate(String sourceName, boolean noNotices, String logAppend, + boolean createLogAsPDF) { boolean optionsRecognized; if (sourceName == null) { sourceName = getFilenameFromUser("Source PDF or XML", "invoice.pdf", "pdf|xml", true, false); @@ -482,7 +495,7 @@ public class Main { String validationResultXML = zfv.validate(sourceName); System.out.println(validationResultXML); - if( createLogAsPDF) { + if (createLogAsPDF) { ValidationLogVisualizer vlvi = new ValidationLogVisualizer(); String fileBasename = FilenameUtils.getBaseName(sourceName); @@ -516,7 +529,6 @@ public class Main { return true; } - private static void performConvert(String pdfName, String outName) throws IOException { /* * ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory() @@ -541,9 +553,9 @@ public class Main { // All params are good! continue... try (ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()) { - ze.convertOnly().load(pdfName); - ze.export(outName); - System.out.println("Written to " + outName); + ze.convertOnly().load(pdfName); + ze.export(outName); + System.out.println("Written to " + outName); } } @@ -579,7 +591,8 @@ public class Main { } private static void performCombine(String pdfName, String xmlName, String outName, String format, String zfVersion, - String zfProfile, Boolean ignoreInputErrors, String[] attachmentFilenames, ArrayList attachments, Boolean noAttachments) throws Exception { + String zfProfile, Boolean ignoreInputErrors, String[] attachmentFilenames, + ArrayList attachments, Boolean noAttachments) throws Exception { /* * ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory() * .setProducer("toecount") .setCreator(System.getProperty("user.name")) @@ -611,11 +624,13 @@ public class Main { byte attachmentContents[] = null; String attachmentFilename, attachmentMime; if (!noAttachments) { - attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", "", "pdf", true, false); + attachmentFilename = getFilenameFromUser("Additional file attachments filename (empty for none)", + "", "pdf", true, false); if (attachmentFilename.length() != 0) { attachmentContents = Files.readAllBytes(Paths.get(attachmentFilename)); attachmentMime = Files.probeContentType(Paths.get(attachmentFilename)); - attachments.add(new FileAttachment(attachmentFilename, attachmentMime, "Data", attachmentContents)); + attachments.add( + new FileAttachment(attachmentFilename, attachmentMime, "Data", attachmentContents)); } } } else { @@ -624,15 +639,17 @@ public class Main { if (!attachmentFilename.isEmpty()) { byte[] attachmentContents = Files.readAllBytes(Paths.get(attachmentFilename)); String attachmentMime = Files.probeContentType(Paths.get(attachmentFilename)); - attachments.add(new FileAttachment(attachmentFilename, attachmentMime, "Data", attachmentContents)); + attachments.add( + new FileAttachment(attachmentFilename, attachmentMime, "Data", attachmentContents)); } } } - if (format == null) { try { - format = getStringFromUser("Format (fx=Factur-X, zf=ZUGFeRD, ox=Order-X, da=Cross Industry Despatch Advice)", "fx", "fx|zf|ox|da"); + format = getStringFromUser( + "Format (fx=Factur-X, zf=ZUGFeRD, ox=Order-X, da=Cross Industry Despatch Advice)", "fx", + "fx|zf|ox|da"); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } @@ -642,7 +659,7 @@ public class Main { if (zfVersion == null) { try { - zfVersion = getStringFromUser("Version (1 or 2)", "1", "1|2");//fx default version is 1 + zfVersion = getStringFromUser("Version (1 or 2)", "1", "1|2");// fx default version is 1 } catch (Exception e) { LOGGER.error(e.getMessage(), e); } @@ -659,8 +676,10 @@ public class Main { zfProfile = getStringFromUser("Profile (p)ilot", "p", "P|p"); } else { zfProfile = getStringFromUser( - "Profile [M]INIMUM, BASIC [W]L, [B]ASIC,\n" + "[C]IUS, [E]N16931, EX[T]ENDED or [X]RECHNUNG", "E", - "M|m|W|w|B|b|C|c|E|e|T|t|X|x|"); + "Profile [M]INIMUM, BASIC [W]L, [B]ASIC,\n" + + "[C]IUS, [E]N16931, EX[T]ENDED or [X]RECHNUNG", + "E", + "M|m|W|w|B|b|C|c|E|e|T|t|X|x|"); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); @@ -670,7 +689,6 @@ public class Main { } zfProfile = zfProfile.toLowerCase(); - // Verify params ensureFileExists(pdfName); ensureFileExists(xmlName); @@ -738,7 +756,8 @@ public class Main { } else { if (format.equals("fx")) { zfIntVersion = 2;// actually we are talking of generation, not version - // so even if someone correctly requested factur-x 1 internally we call it zugferd 2 :-( + // so even if someone correctly requested factur-x 1 internally we call it + // zugferd 2 :-( } ze = new ZUGFeRDExporterFromPDFA(); if (ignoreInputErrors) { @@ -748,16 +767,16 @@ public class Main { ze.load(pdfName); ze.setProducer("Mustang-cli") - .setZUGFeRDVersion(zfIntVersion) - .setCreator(System.getProperty("user.name")).setProfile(zfConformanceLevelProfile); + .setZUGFeRDVersion(zfIntVersion) + .setCreator(System.getProperty("user.name")).setProfile(zfConformanceLevelProfile); if (format.equals("zf")) { ze.disableFacturX(); } - for (FileAttachment attachment : attachments) { - ze.attachFile(attachment.getFilename(), attachment.getData(), attachment.getMimetype(), attachment.getRelation()); + ze.attachFile(attachment.getFilename(), attachment.getData(), attachment.getMimetype(), + attachment.getRelation()); } ze.setXML(Files.readAllBytes(Paths.get(xmlName))); @@ -774,7 +793,7 @@ public class Main { } private static void performMetrics(String directoryName, Boolean filesFromStdIn, Boolean ignoreFileExt) - throws IOException { + throws IOException { StatRun sr = new StatRun(); if (ignoreFileExt) { @@ -818,16 +837,14 @@ public class Main { } else { System.out.println("ZUGFeRD XML source set to " + sourceName); } - if (!intoPDF) { - if (lang == null) { - try { - lang = getStringFromUser("Output language", "en", "en|de|fr"); - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - } else { - System.out.println("Output language set to " + lang); + if (lang == null) { + try { + lang = getStringFromUser("Output language", "en", "en|de|fr"); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); } + } else { + System.out.println("Output language set to " + lang); } if (outName == null) { @@ -855,18 +872,18 @@ public class Main { ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); String xml = null; try { + ZUGFeRDVisualizer.Language langCode = ZUGFeRDVisualizer.Language.EN; + if (lang.equalsIgnoreCase("de")) { + langCode = ZUGFeRDVisualizer.Language.DE; + } + if (lang.equalsIgnoreCase("fr")) { + langCode = ZUGFeRDVisualizer.Language.FR; + } if (!intoPDF) { - ZUGFeRDVisualizer.Language langCode = ZUGFeRDVisualizer.Language.EN; - if (lang.equalsIgnoreCase("de")) { - langCode = ZUGFeRDVisualizer.Language.DE; - } - if (lang.equalsIgnoreCase("fr")) { - langCode = ZUGFeRDVisualizer.Language.FR; - } xml = zvi.visualize(sourceName, langCode); Files.write(Paths.get(outName), xml.getBytes()); } else { - zvi.toPDF(sourceName, outName); + zvi.toPDF(sourceName, outName, langCode); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); @@ -880,13 +897,13 @@ public class Main { ExportResource("/xrechnung-viewer.css"); ExportResource("/xrechnung-viewer.js"); - System.out.println("xrechnung-viewer.css and xrechnung-viewer.js written as well (to local working dir)"); + System.out + .println("xrechnung-viewer.css and xrechnung-viewer.js written as well (to local working dir)"); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } - } /** @@ -894,11 +911,14 @@ public class Main { * * @param resourceName ie.: "/SmartLibrary.dll" * @return The path to the exported resource - * @throws Exception e.g. if the specified resource does not exist at the specified location + * @throws Exception e.g. if the specified resource does not exist at the + * specified location */ static public String ExportResource(String resourceName) throws Exception { String jarFolder; - try (InputStream stream = Main.class.getResourceAsStream(resourceName)) {//note that each / is a directory down in the "jar tree" been the jar the root of the tree + try (InputStream stream = Main.class.getResourceAsStream(resourceName)) {// note that each / is a directory down + // in the "jar tree" been the jar + // the root of the tree if (stream == null) { throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); } @@ -907,9 +927,9 @@ public class Main { byte[] buffer = new byte[4096]; jarFolder = System.getProperty("user.dir"); try (FileOutputStream resStreamOut = new FileOutputStream(jarFolder + resourceName)) { - while ((readBytes = stream.read(buffer)) > 0) { - resStreamOut.write(buffer, 0, readBytes); - } + while ((readBytes = stream.read(buffer)) > 0) { + resStreamOut.write(buffer, 0, readBytes); + } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java index ec699252..9d24b7bc 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDVisualizer.java @@ -47,8 +47,6 @@ import javax.xml.transform.stream.StreamSource; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.EnumMap; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; @@ -252,7 +250,7 @@ public class ZUGFeRDVisualizer { } } - protected String toFOP(String xmlFilename) + protected String toFOP(String xmlFilename, Language lang) throws IOException, TransformerException, ParserConfigurationException { EStandard theStandard; try (FileInputStream fis = new FileInputStream(xmlFilename)) { @@ -260,11 +258,11 @@ public class ZUGFeRDVisualizer { } try (FileInputStream fis = new FileInputStream(xmlFilename)) { - return toFOP(fis, theStandard); + return toFOP(fis, theStandard, lang); } } - protected String toFOP(InputStream is, EStandard theStandard) + protected String toFOP(InputStream is, EStandard theStandard, Language lang) throws TransformerException, IOException { try { @@ -291,12 +289,16 @@ public class ZUGFeRDVisualizer { Optional in = copyStream(iaos); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (in.isPresent()) { - applyXSLTToPDF(in.get(), baos); + applyXSLTToPDF(in.get(), baos, lang); } return baos.toString(StandardCharsets.UTF_8); } public void toPDF(String xmlFilename, String pdfFilename) { + toPDF(xmlFilename, pdfFilename, Language.DE); + } + + public void toPDF(String xmlFilename, String pdfFilename, Language lang) { // the writing part File XMLinputFile = new File(xmlFilename); @@ -307,7 +309,7 @@ public class ZUGFeRDVisualizer { out from git with arbitrary options (which may include CSRF changes) */ try { - fopInput = this.toFOP(XMLinputFile.getAbsolutePath()); + fopInput = this.toFOP(XMLinputFile.getAbsolutePath(), lang); } catch (TransformerException | IOException | ParserConfigurationException e) { LOGGER.error("Failed to apply FOP", e); } @@ -321,8 +323,12 @@ public class ZUGFeRDVisualizer { return null; }, (OutputStream out) -> {}); } - + public byte[] toPDF(String xmlContent) { + return toPDF(xmlContent, Language.DE); + } + + public byte[] toPDF(String xmlContent, Language lang) { String fopInput = null; @@ -334,7 +340,7 @@ public class ZUGFeRDVisualizer { EStandard theStandard = findOutStandardFromRootNode(fis); fis = new ByteArrayInputStream(xmlContent.getBytes(StandardCharsets.UTF_8));//rewind :-( - fopInput = toFOP(fis, theStandard); + fopInput = toFOP(fis, theStandard, lang); } catch (TransformerException | IOException | ParserConfigurationException e) { LOGGER.error("Failed to apply FOP", e); } @@ -470,9 +476,10 @@ public class ZUGFeRDVisualizer { xmlFile.close(); } - protected void applyXSLTToPDF(final InputStream xmlFile, final OutputStream PDFOutstream) + protected void applyXSLTToPDF(final InputStream xmlFile, final OutputStream PDFOutstream, Language lang) throws TransformerException, IOException { Transformer transformer = mXsltPDFTemplate.newTransformer(); + transformer.setParameter("lang", lang.name().toLowerCase()); transformer.transform(new StreamSource(xmlFile), new StreamResult(PDFOutstream)); xmlFile.close(); diff --git a/library/src/main/resources/stylesheets/l10n/fr.xml b/library/src/main/resources/stylesheets/l10n/fr.xml new file mode 100644 index 00000000..647c908d --- /dev/null +++ b/library/src/main/resources/stylesheets/l10n/fr.xml @@ -0,0 +1,254 @@ + + + Référence acheteur + Nom + Adresse ligne 1 + Adresse ligne 2 + Adresse ligne 3 + Code postal + Ville + Code pays + Identifiant + Schéma de l'identifiant + Nom + Téléphone + Adresse e-mail + Raison sociale + Adresse ligne 1 + Adresse ligne 2 + Adresse ligne 3 + Code postal + Ville + Région + Code pays + Identifiant + Schéma de l'identifiant + Nom + Téléphone + Adresse e-mail + Numéro de facture + Date de facture + Type de facture + Devise + Numéro de projet + Numéro de contrat + Numéro de commande + Référence de commande client + + Du + Au + Numéro de facture + Date de facture + Total des lignes + Total des remises + Total des frais + Total HT + Total TVA + Total TVA en devise comptable + Total TTC + Montant payé + Montant d'arrondi + Montant dû + Catégorie de TVA + Total + Taux de TVA + Montant de TVA + Motif d'exonération + Code du motif d'exonération + + Catégorie de TVA de la remise + Montant de base + Pourcentage + Remise + Taux de TVA de la remise + Motif de la remise + Code du motif de la remise + + Catégorie de TVA des frais + Montant de base + Pourcentage + Frais + Taux de TVA des frais + Motif des frais + Code du motif des frais + Escompte ; autres conditions de paiement + Date d'échéance + Code du moyen de paiement + Moyen de paiement + Référence de paiement + Numéro de carte + Titulaire de la carte + + Référence du mandat + IBAN + Identifiant créancier + + Titulaire du compte + IBAN + BIC + Objet + Remarque + + Nom commercial + Adresse électronique + Schéma de l'adresse électronique + Numéro SIRET/SIREN + Schéma du numéro d'enregistrement + Numéro de TVA intracommunautaire + Numéro fiscal + Informations juridiques complémentaires + Code devise de la TVA + + Nom + Adresse ligne 1 + Adresse ligne 2 + Adresse ligne 3 + Code postal + Ville + Région + Code pays + Numéro de TVA intracommunautaire + + Nom commercial + Région + Adresse électronique + Schéma de l'adresse électronique + Numéro SIRET/SIREN + Schéma du numéro d'enregistrement + Numéro de TVA intracommunautaire + Date d'exigibilité de la TVA + Code de la date d'exigibilité de la TVA + Référence comptable + Identifiant du lieu de livraison + Schéma de l'identifiant + Date de livraison + Nom du destinataire + Adresse ligne 1 + Adresse ligne 2 + Adresse ligne 3 + Code postal + Ville + Région + Code pays + Numéro d'appel d'offres + Référence de l'avis de réception + Référence de l'avis d'expédition + Identifiant du processus + Identifiant de spécification + Identifiant de l'objet + Schéma de l'identifiant de l'objet + + Nom + Identifiant + Schéma de l'identifiant + Numéro SIRET/SIREN + Schéma du numéro d'enregistrement + + Identifiant + Description + Référence (ex. adresse Internet) + Document joint + Format du document joint + Nom du document joint + Date/Heure + Objet + Texte + Détails + Position + Texte libre + Identifiant de l'objet + Schéma de l'identifiant de l'objet + Numéro de ligne de commande + Référence comptable + Du + Au + Quantité + Unité + Prix unitaire (HT) + Prix total (HT) + Remise (HT) + Prix catalogue (HT) + Quantité de base + Code de l'unité de mesure + TVA + Taux de TVA + Désignation + Description + Référence article + Référence article acheteur + Identifiant article + Schéma de l'identifiant article + Code de classification article + Identifiant du schéma + Version du schéma + Code du pays d'origine + Montant de base (HT) + Pourcentage + Remise (HT) + Motif de la remise + Code du motif de la remise + Montant de base (HT) + Pourcentage + Frais (HT) + Motif des frais + Code du motif des frais + Type de créance tierce + Montant de la créance tierce + Description de la créance tierce + Données de la facture électronique + Informations sur l'acheteur + Informations sur le vendeur + Données de facturation + Totaux de la facture + Créance tierce + Ventilation de la TVA au niveau de la facture + Remise au niveau de la facture + Frais au niveau de la facture + Période de facturation + Factures précédentes + Informations de paiement + Informations carte + Prélèvement + Virement + Remarques sur la facture + Lignes de facture + Période de facturation + Détails du prix + Remises au niveau de la ligne de facture + Frais au niveau de la ligne de facture + Informations sur l'article + Caractéristiques de l'article + Compléments + Informations sur le vendeur + Représentant fiscal du vendeur + Informations sur l'acheteur + Informations de livraison + Informations contractuelles + Bénéficiaire différent du vendeur + Fiche de suivi + Historique de traitement + Pièces jointes + Documents justificatifs + [D]/[M]/[Y] + [D]/[M]/[Y] [H]:[m]:[s] + ###.##0,00 + ##0,00 + ###.##0,################# + + Total des créances tierces + + Nous déclinons toute responsabilité quant à l'exactitude des données. + Remarques sur la facture + Ouvrir + Aucune donnée disponible + HT + TTC + Les sections sans contenu ne sont pas affichées ! + Description + Prix + Unité de prix + Taux TVA + Code taxe + Total + Page + diff --git a/library/src/main/resources/stylesheets/xr-content.xsl b/library/src/main/resources/stylesheets/xr-content.xsl index 69f91322..fb42f8b8 100644 --- a/library/src/main/resources/stylesheets/xr-content.xsl +++ b/library/src/main/resources/stylesheets/xr-content.xsl @@ -8,6 +8,7 @@ xmlns:xrf="https://projekte.kosit.org/xrechnung/xrechnung-visualization/functions"> + diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java index db772ff1..a57d62a9 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java @@ -1,176 +1,210 @@ -/** - * ********************************************************************* - *

- * Copyright 2019 Jochen Staerk - *

- * Use is subject to license terms. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy - * of the License at http://www.apache.org/licenses/LICENSE-2.0. - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - *

- * See the License for the specific language governing permissions and - * limitations under the License. - *

- * ********************************************************************** - */ -package org.mustangproject.ZUGFeRD; - -import javax.xml.parsers.ParserConfigurationException; -import org.junit.FixMethodOrder; -import org.junit.runners.MethodSorters; -import org.mustangproject.ZUGFeRD.ZUGFeRDVisualizer.Language; -import org.mustangproject.util.ByteArraySearcher; - -import javax.xml.transform.TransformerException; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.SimpleDateFormat; -import java.util.Date; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class VisualizationTest extends ResourceCase { - - final String TARGET_PDF_CII = "./target/testout-Visualization-cii.pdf"; - final String TARGET_PDF_UBL = "./target/testout-Visualization-cii.pdf"; - - public void testCIIVisualizationBasic() { - this.runZUGFeRDVisualization("factur-x.xml", "factur-x-vis.fr.html", Language.FR); - } - - public void testCIIVisualizationExtended() { - this.runZUGFeRDVisualization("factur-x-extended.xml", "factur-x-vis-extended.de.html", Language.DE); - } - - public void testUBLCreditNoteVisualizationBasic() { - this.runZUGFeRDVisualization("ubl-creditnote.xml", "factur-x-vis-ubl-creditnote.en.html", Language.EN); - } - - public void testUBLVisualizationBasic() { - this.runZUGFeRDVisualization("ubl/01.01a-INVOICE.ubl.xml", "factur-x-vis-ubl.en.html", Language.EN); - } - - private void runZUGFeRDVisualization(String inputFilename, String resultFileName, Language lang) { - File CIIinputFile = getResourceAsFile(inputFilename); - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - result = zvi.visualize(CIIinputFile.getAbsolutePath(), lang); - Files.write(Paths.get("./target/testout-" + resultFileName), result.getBytes(StandardCharsets.UTF_8)); - - File expectedResult = getResourceAsFile(resultFileName); - expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) - ; - - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } catch (TransformerException e) { - fail("TransformerException should not happen: " + e.getMessage()); - } catch (IOException e) { - fail("IOException should not happen: " + e.getMessage()); - } catch (ParserConfigurationException e) { - fail("ParserConfigurationException should not happen: " + e.getMessage()); - } - - assertNotNull(result); - /* remove file endings so that tests can also pass after checking - out from git with arbitrary options (which may include CSRF changes) - */ - assertEquals(expected.replace("\r", "") - .replace("\n", "") - .replace("\t", "") - .replace(" ", ""), result.replace("\r", "") - .replace("\n", "") - .replace("\t", "") - .replace(" ", "")); - } - - - public void testPDFVisualizationCII() { - - File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); - - // the writing part - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII); - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } - - try { - assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); - } catch (IOException e) { - fail("IOException should not occur"); - } - } - - public void testPDFVisualizationUBL() { - - File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); - - // the writing part - String sourceFilename = "factur-x.xml"; - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } - - - try { - assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); - } catch (IOException e) { - fail("IOException should not occur"); - } - } - - public void testPDFVisualizationUBLCreditNote() { - - File UBLinputFile = getResourceAsFile("ubl/UBL-CreditNote-2.1-Example.ubl.xml"); - - // the writing part - String sourceFilename = "factur-x.xml"; - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } - - - try { - assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); - } catch (IOException e) { - fail("IOException should not occur"); - } - } - -} +/** + * ********************************************************************* + *

+ * Copyright 2019 Jochen Staerk + *

+ * Use is subject to license terms. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0. + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + *

+ * See the License for the specific language governing permissions and + * limitations under the License. + *

+ * ********************************************************************** + */ +package org.mustangproject.ZUGFeRD; + +import javax.xml.parsers.ParserConfigurationException; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; +import org.mustangproject.ZUGFeRD.ZUGFeRDVisualizer.Language; +import org.mustangproject.util.ByteArraySearcher; + +import javax.xml.transform.TransformerException; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class VisualizationTest extends ResourceCase { + + final String TARGET_PDF_CII = "./target/testout-Visualization-cii.pdf"; + final String TARGET_PDF_UBL = "./target/testout-Visualization-cii.pdf"; + + public void testCIIVisualizationBasic() { + this.runZUGFeRDVisualization("factur-x.xml", "factur-x-vis.fr.html", Language.FR); + } + + public void testCIIVisualizationExtended() { + this.runZUGFeRDVisualization("factur-x-extended.xml", "factur-x-vis-extended.de.html", Language.DE); + } + + public void testUBLCreditNoteVisualizationBasic() { + this.runZUGFeRDVisualization("ubl-creditnote.xml", "factur-x-vis-ubl-creditnote.en.html", Language.EN); + } + + public void testUBLVisualizationBasic() { + this.runZUGFeRDVisualization("ubl/01.01a-INVOICE.ubl.xml", "factur-x-vis-ubl.en.html", Language.EN); + } + + private void runZUGFeRDVisualization(String inputFilename, String resultFileName, Language lang) { + File CIIinputFile = getResourceAsFile(inputFilename); + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + result = zvi.visualize(CIIinputFile.getAbsolutePath(), lang); + Files.write(Paths.get("./target/testout-" + resultFileName), result.getBytes(StandardCharsets.UTF_8)); + + File expectedResult = getResourceAsFile(resultFileName); + expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) + ; + + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } catch (TransformerException e) { + fail("TransformerException should not happen: " + e.getMessage()); + } catch (IOException e) { + fail("IOException should not happen: " + e.getMessage()); + } catch (ParserConfigurationException e) { + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } + + assertNotNull(result); + /* remove file endings so that tests can also pass after checking + out from git with arbitrary options (which may include CSRF changes) + */ + assertEquals(expected.replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""), result.replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", "")); + } + + + public void testPDFVisualizationCII() { + File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); + + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + assertTrue(ByteArraySearcher.contains(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), "de".getBytes())); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + + public void testPDFVisualizationCIIEnglish() { + File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); + + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII, Language.EN); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + assertTrue(ByteArraySearcher.contains(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), "en".getBytes())); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + + public void testPDFVisualizationCIIFrench() { + File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); + + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII, Language.FR); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + assertTrue(ByteArraySearcher.contains(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), "fr".getBytes())); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + + public void testPDFVisualizationUBL() { + + File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); + + // the writing part + String sourceFilename = "factur-x.xml"; + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + + public void testPDFVisualizationUBLCreditNote() { + + File UBLinputFile = getResourceAsFile("ubl/UBL-CreditNote-2.1-Example.ubl.xml"); + + // the writing part + String sourceFilename = "factur-x.xml"; + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + +}