update command lines for xml to pdf
This commit is contained in:
@@ -102,6 +102,9 @@ public class Main {
|
|||||||
+ " [--language <lang>]: set output lang (en, fr or de)\n"
|
+ " [--language <lang>]: set output lang (en, fr or de)\n"
|
||||||
+ " [--source <filename>]: set input XML file\n"
|
+ " [--source <filename>]: set input XML file\n"
|
||||||
+ " [--out <filename>]: set output HTML 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"
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,15 +118,11 @@ public class Main {
|
|||||||
* Asks the user (repeatedly, if neccessary) on the command line for a String
|
* Asks the user (repeatedly, if neccessary) on the command line for a String
|
||||||
* (offering a defaultValue) conforming to a Regex pattern
|
* (offering a defaultValue) conforming to a Regex pattern
|
||||||
*
|
*
|
||||||
* @param prompt
|
* @param prompt the question to be asked to the user
|
||||||
* the question to be asked to the user
|
* @param defaultValue the default return value if user hits enter
|
||||||
* @param defaultValue
|
* @param pattern a regex of acceptable values
|
||||||
* the default return value if user hits enter
|
|
||||||
* @param pattern
|
|
||||||
* a regex of acceptable values
|
|
||||||
* @return the user answer conforming to pattern
|
* @return the user answer conforming to pattern
|
||||||
* @throws Exception
|
* @throws Exception if pattern not compielable or IOexception on input
|
||||||
* if pattern not compielable or IOexception on input
|
|
||||||
*/
|
*/
|
||||||
protected static String getStringFromUser(String prompt, String defaultValue, String pattern) throws Exception {
|
protected static String getStringFromUser(String prompt, String defaultValue, String pattern) throws Exception {
|
||||||
String input = "";
|
String input = "";
|
||||||
@@ -242,6 +241,7 @@ public class Main {
|
|||||||
|
|
||||||
return selectedName;
|
return selectedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException {
|
private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException {
|
||||||
|
|
||||||
// Get params from user if not already defined
|
// Get params from user if not already defined
|
||||||
@@ -330,6 +330,7 @@ public class Main {
|
|||||||
// return result.toString(StandardCharsets.UTF_8);
|
// return result.toString(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* the main function of the commandline tool...
|
* 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
|
||||||
@@ -384,8 +385,6 @@ public class Main {
|
|||||||
String[] attachmentFilenames = cmd.hasOption("attachments") ? cmd.getOptionValues("attachments") : null;
|
String[] attachmentFilenames = cmd.hasOption("attachments") ? cmd.getOptionValues("attachments") : null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ArrayList<FileAttachment> attachments = new ArrayList<>();
|
ArrayList<FileAttachment> attachments = new ArrayList<>();
|
||||||
if (helpRequested) {
|
if (helpRequested) {
|
||||||
printHelp();
|
printHelp();
|
||||||
@@ -405,8 +404,11 @@ public class Main {
|
|||||||
} else if ((action != null) && (action.equals("a3only"))) {
|
} else if ((action != null) && (action.equals("a3only"))) {
|
||||||
performConvert(sourceName, outName);
|
performConvert(sourceName, outName);
|
||||||
optionsRecognized = true;
|
optionsRecognized = true;
|
||||||
|
} else if ((action != null) && (action.equals("pdf"))) {
|
||||||
|
performVisualization(sourceName, lang, outName, true);
|
||||||
|
optionsRecognized = true;
|
||||||
} else if ((action != null) && (action.equals("visualize"))) {
|
} else if ((action != null) && (action.equals("visualize"))) {
|
||||||
performVisualization(sourceName, lang, outName);
|
performVisualization(sourceName, lang, outName, false);
|
||||||
optionsRecognized = true;
|
optionsRecognized = true;
|
||||||
} else if ((action != null) && (action.equals("upgrade"))) {
|
} else if ((action != null) && (action.equals("upgrade"))) {
|
||||||
performUpgrade(sourceName, outName);
|
performUpgrade(sourceName, outName);
|
||||||
@@ -629,7 +631,6 @@ public class Main {
|
|||||||
zfProfile = zfProfile.toLowerCase();
|
zfProfile = zfProfile.toLowerCase();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Verify params
|
// Verify params
|
||||||
ensureFileExists(pdfName);
|
ensureFileExists(pdfName);
|
||||||
ensureFileExists(xmlName);
|
ensureFileExists(xmlName);
|
||||||
@@ -647,8 +648,7 @@ public class Main {
|
|||||||
standard = EStandard.despatchadvice;
|
standard = EStandard.despatchadvice;
|
||||||
|
|
||||||
zfConformanceLevelProfile = Profiles.getByName(standard, "PILOT", 1);
|
zfConformanceLevelProfile = Profiles.getByName(standard, "PILOT", 1);
|
||||||
}
|
} else if (((format.equals("zf")) && (zfIntVersion == 1)) || (format.equals("ox"))) {
|
||||||
else if (((format.equals("zf")) && (zfIntVersion == 1))||(format.equals("ox"))) {
|
|
||||||
if (format.equals("ox")) {
|
if (format.equals("ox")) {
|
||||||
standard = EStandard.orderx;
|
standard = EStandard.orderx;
|
||||||
}
|
}
|
||||||
@@ -769,13 +769,14 @@ public class Main {
|
|||||||
System.out.println(sr.getSummaryLine());
|
System.out.println(sr.getSummaryLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void performVisualization(String sourceName, String lang, String outName) {
|
private static void performVisualization(String sourceName, String lang, String outName, boolean intoPDF) {
|
||||||
// Get params from user if not already defined
|
// Get params from user if not already defined
|
||||||
if (sourceName == null) {
|
if (sourceName == null) {
|
||||||
sourceName = getFilenameFromUser("ZUGFeRD XML source", "factur-x.xml", "xml", true, false);
|
sourceName = getFilenameFromUser("ZUGFeRD XML source", "factur-x.xml", "xml", true, false);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("ZUGFeRD XML source set to " + sourceName);
|
System.out.println("ZUGFeRD XML source set to " + sourceName);
|
||||||
}
|
}
|
||||||
|
if (!intoPDF) {
|
||||||
if (lang == null) {
|
if (lang == null) {
|
||||||
try {
|
try {
|
||||||
lang = getStringFromUser("Output language", "en", "en|de|fr");
|
lang = getStringFromUser("Output language", "en", "en|de|fr");
|
||||||
@@ -785,11 +786,18 @@ public class Main {
|
|||||||
} else {
|
} else {
|
||||||
System.out.println("Output language set to " + lang);
|
System.out.println("Output language set to " + lang);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (outName == null) {
|
if (outName == null) {
|
||||||
outName = getFilenameFromUser("HTML target file", "factur-x.html", "html", false, true);
|
String defaultFilename = "factur-x.html";
|
||||||
|
String defaultExtension = "html";
|
||||||
|
if (intoPDF) {
|
||||||
|
defaultFilename = "factur-x.pdf";
|
||||||
|
defaultExtension = "pdf";
|
||||||
|
}
|
||||||
|
outName = getFilenameFromUser("Target file", defaultFilename, defaultExtension, false, true);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("HTML target set to " + outName);
|
System.out.println("Target set to " + outName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify params
|
// Verify params
|
||||||
@@ -805,6 +813,7 @@ public class Main {
|
|||||||
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
|
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
|
||||||
String xml = null;
|
String xml = null;
|
||||||
try {
|
try {
|
||||||
|
if (!intoPDF) {
|
||||||
ZUGFeRDVisualizer.Language langCode = ZUGFeRDVisualizer.Language.EN;
|
ZUGFeRDVisualizer.Language langCode = ZUGFeRDVisualizer.Language.EN;
|
||||||
if (lang.equalsIgnoreCase("de")) {
|
if (lang.equalsIgnoreCase("de")) {
|
||||||
langCode = ZUGFeRDVisualizer.Language.DE;
|
langCode = ZUGFeRDVisualizer.Language.DE;
|
||||||
@@ -814,6 +823,9 @@ public class Main {
|
|||||||
}
|
}
|
||||||
xml = zvi.visualize(sourceName, langCode);
|
xml = zvi.visualize(sourceName, langCode);
|
||||||
Files.write(Paths.get(outName), xml.getBytes());
|
Files.write(Paths.get(outName), xml.getBytes());
|
||||||
|
} else {
|
||||||
|
zvi.toPDF(sourceName, outName);
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
LOGGER.error(e.getMessage(), e);
|
LOGGER.error(e.getMessage(), e);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
@@ -825,6 +837,8 @@ public class Main {
|
|||||||
}
|
}
|
||||||
System.out.println("Written to " + outName);
|
System.out.println("Written to " + outName);
|
||||||
|
|
||||||
|
if (!intoPDF) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ExportResource("/xrechnung-viewer.css");
|
ExportResource("/xrechnung-viewer.css");
|
||||||
ExportResource("/xrechnung-viewer.js");
|
ExportResource("/xrechnung-viewer.js");
|
||||||
@@ -833,6 +847,7 @@ public class Main {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage(), e);
|
LOGGER.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user