feature: pdf visualization translations
This commit is contained in:
@@ -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 <filename>]: set input PDF file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input PDF file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input PDF file\n"
|
||||
+ " [--source-xml <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: set output PDF file\n"
|
||||
+ " [--format <fx|zf|ox|da>]: 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: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
|
||||
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n"
|
||||
+ " [--attachments <filenames>]: 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 <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input XML ZUGFeRD 1 file\n"
|
||||
+ " [--out <filename>]: set output XML ZUGFeRD 2 file\n"
|
||||
+ " --action validate validate XML or PDF file \n"
|
||||
+ " [--no-notices]: refrain from reporting notices\n"
|
||||
+ " [--logAppend <text>]: text to be added to log line\n"
|
||||
+ " Additional parameters (optional - user will be prompted if not defined)\n"
|
||||
+ " [--source <filename>]: 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 <lang>]: set output lang (en, fr or de)\n"
|
||||
+ " [--source <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: set output HTML file\n"
|
||||
+ " --action pdf convert XML to PDF \n"
|
||||
+ " [--source <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input PDF file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input PDF file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input PDF file\n"
|
||||
+ " [--source-xml <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: set output PDF file\n"
|
||||
+ " [--format <fx|zf|ox|da>]: 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: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
|
||||
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n"
|
||||
+ " [--attachments <filenames>]: 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 <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: 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 <filename>]: set input XML ZUGFeRD 1 file\n"
|
||||
+ " [--out <filename>]: set output XML ZUGFeRD 2 file\n"
|
||||
+ " --action validate validate XML or PDF file \n"
|
||||
+ " [--no-notices]: refrain from reporting notices\n"
|
||||
+ " [--logAppend <text>]: text to be added to log line\n"
|
||||
+ " Additional parameters (optional - user will be prompted if not defined)\n"
|
||||
+ " [--source <filename>]: 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 <lang>]: set output lang (en, fr or de)\n"
|
||||
+ " [--source <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: set output HTML file\n"
|
||||
+ " --action pdf convert XML to PDF \n"
|
||||
+ " [--source <filename>]: set input XML file\n"
|
||||
+ " [--out <filename>]: 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<FileAttachment> 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<FileAttachment> attachments, Boolean noAttachments) throws Exception {
|
||||
String zfProfile, Boolean ignoreInputErrors, String[] attachmentFilenames,
|
||||
ArrayList<FileAttachment> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user