Merge branch 'master' of github.com:ZUGFeRD/mustangproject

# Conflicts:
#	Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java
This commit is contained in:
jstaerk
2023-09-11 11:35:59 +02:00
2 changed files with 111 additions and 97 deletions

View File

@@ -43,65 +43,65 @@ import org.slf4j.LoggerFactory;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
public class Main { public class Main {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Validator.class.getCanonicalName()); // log output private static org.slf4j.Logger LOGGER; // log output
private static void printUsage() { private static void printUsage() {
System.err.println(getUsage()); System.err.println(getUsage());
} }
private static String getUsage() { 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] | [-h,--help] \r\n" 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 license display open source license and notice\n"
+ " --action metrics\n" + " --action metrics\n"
+ " -d, --directory count ZUGFeRD files in directory to be scanned\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n"
+ " If it is a directory, it will recurse.\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" + " -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" + " It will start once a blank line has been entered.\n" + "\n"
+ " Additional parameter for both count operations\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" + " [-i, --ignorefileextension] Check for all files (*.*) instead of PDF files only (*.pdf) in metrics, ignore PDF/A input file errors in combine\n"
+ " --action extract extract Factur-X PDF to XML file\n" + " [--disable-file-logging] disable logging to file.\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " --action extract extract Factur-X PDF to XML file\n"
+ " [--source <filename>]: set input PDF file\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--out <filename>]: set output XML file\n" + " [--source <filename>]: set input PDF file\n"
+ " --action a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n" + " [--out <filename>]: set output XML file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " --action a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n"
+ " [--source <filename>]: set input PDF file\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--out <filename>]: set output PDF file\n" + " [--source <filename>]: set input PDF file\n"
+ " --action combine combine XML and PDF file to Factur-X PDF file\n" + " [--out <filename>]: set output PDF file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " --action combine combine XML and PDF file to Factur-X PDF file\n"
+ " [--source <filename>]: set input PDF file\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--source-xml <filename>]: set input XML file\n" + " [--source <filename>]: set input PDF file\n"
+ " [--out <filename>]: set output PDF file\n" + " [--source-xml <filename>]: set input XML file\n"
+ " [--format <fx|zf|ox|da>]: set Factur-X, ZUGFeRD, Order-X or Cross Industry Despatch Advice\n" + " [--out <filename>]: set output PDF file\n"
+ " [--version <1|2>]: set ZUGFeRD version\n" + " [--format <fx|zf|ox|da>]: set Factur-X, ZUGFeRD, Order-X or Cross Industry Despatch Advice\n"
+ " [--profile <...>]: set ZUGFeRD profile\n" + " [--version <1|2>]: set ZUGFeRD version\n"
+ " For ZUGFeRD v1 or Order-X: <B>ASIC, <C>OMFORT or EX<T>ENDED\n" + " [--profile <...>]: set ZUGFeRD profile\n"
+ " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n" + " For ZUGFeRD v1 or Order-X: <B>ASIC, <C>OMFORT or EX<T>ENDED\n"
+ " [--attachments <filenames>]: list of file attachments (passing a single empty file name prevents prompting)\n" + " For ZUGFeRD v2: <M>INIMUM, BASIC <W>L, <B>ASIC, <C>IUS, <E>N16931, <X>Rechnung, EX<T>ENDED\n"
+ " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n" + " [--attachments <filenames>]: list of file attachments (passing a single empty file name prevents prompting)\n"
+ " [--source <filename>]: set input XML file\n" + " --action ubl convert UN/CEFACT 2016b CII XML to UBL XML\n"
+ " [--out <filename>]: set output XML file\n" + " [--source <filename>]: set input XML file\n"
+ " --action upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n" + " [--out <filename>]: set output XML file\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " --action upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n"
+ " [--source <filename>]: set input XML ZUGFeRD 1 file\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " [--out <filename>]: set output XML ZUGFeRD 2 file\n" + " [--source <filename>]: set input XML ZUGFeRD 1 file\n"
+ " --action validate validate XML or PDF file \n" + " [--out <filename>]: set output XML ZUGFeRD 2 file\n"
+ " [--no-notices]: refrain from reporting notices\n" + " --action validate validate XML or PDF file \n"
+ " [--logAppend <text>]: text to be added to log line\n" + " [--no-notices]: refrain from reporting notices\n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " [--logAppend <text>]: text to be added to log line\n"
+ " [--source <filename>]: input PDF or XML file\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " --action validateExpectInvalid validate directory expecting negative results \n" + " [--source <filename>]: input PDF or XML file\n"
+ " [--no-notices]: refrain from reporting notices\n" + " --action validateExpectInvalid validate directory expecting negative results \n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " [--no-notices]: refrain from reporting notices\n"
+ " -d, --directory to check recursively\n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " --action validateExpectValid validate directory expecting positive results \n" + " -d, --directory to check recursively\n"
+ " [--no-notices]: refrain from reporting notices\n" + " --action validateExpectValid validate directory expecting positive results \n"
+ " Additional parameters (optional - user will be prompted if not defined)\n" + " [--no-notices]: refrain from reporting notices\n"
+ " -d, --directory to check recursively \n" + " Additional parameters (optional - user will be prompted if not defined)\n"
+ " --action visualize convert XML to HTML \n" + " -d, --directory to check recursively \n"
+ " [--language <lang>]: set output lang (en, fr or de)\n" + " --action visualize convert XML to HTML \n"
+ " [--source <filename>]: set input XML file\n" + " [--language <lang>]: set output lang (en, fr or de)\n"
+ " [--out <filename>]: set output HTML file\n" + " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output HTML file\n"
+ " --action pdf convert XML to PDF \n" + " --action pdf convert XML to PDF \n"
+ " [--source <filename>]: set input XML file\n" + " [--source <filename>]: set input XML file\n"
+ " [--out <filename>]: set output PDF file\n" + " [--out <filename>]: set output PDF file\n"
@@ -351,17 +351,19 @@ public class Main {
attachmentOpt.setValueSeparator(','); attachmentOpt.setValueSeparator(',');
attachmentOpt.setArgs(Option.UNLIMITED_VALUES); attachmentOpt.setArgs(Option.UNLIMITED_VALUES);
options.addOption(attachmentOpt); options.addOption(attachmentOpt);
options.addOption(new Option("", "source", true, "which source file to use")); options.addOption(new Option("", "source",true, "which source file to use"));
options.addOption(new Option("", "source-xml", true, "which source file to use")); options.addOption(new Option("", "source-xml",true, "which source file to use"));
options.addOption(new Option("", "language", true, "output language (en, de or fr)")); options.addOption(new Option("", "language",true, "output language (en, de or fr)"));
options.addOption(new Option("", "out", true, "which output file to write to")); options.addOption(new Option("", "out",true, "which output file to write to"));
options.addOption(new Option("", "no-notices", false, "suppress non-fatal errors")); options.addOption(new Option("", "no-notices",false, "suppress non-fatal errors"));
options.addOption(new Option("", "logAppend", true, "freeform text to be appended to log messages")); options.addOption(new Option("", "logAppend",true, "freeform text to be appended to log messages"));
options.addOption(new Option("d", "directory", true, "which directory to operate on")); options.addOption(new Option("", "disable-file-logging", false, "suppress logging to file"));
options.addOption(new Option("i", "ignorefileextension", false, "ignore non-matching file extensions")); options.addOption(new Option("d", "directory",true, "which directory to operate on"));
options.addOption(new Option("l", "listfromstdin", false, "take list of files from commandline")); options.addOption(new Option("i", "ignorefileextension",false, "ignore non-matching file extensions"));
boolean optionsRecognized = false; options.addOption(new Option("l", "listfromstdin",false, "take list of files from commandline"));
boolean optionsRecognized=false;
String action = ""; String action = "";
Boolean disableFileLogging = false;
try { try {
cmd = parser.parse(options, args); cmd = parser.parse(options, args);
@@ -370,7 +372,8 @@ public class Main {
String directoryName = cmd.getOptionValue("directory"); 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 ignoreFileExt = cmd.hasOption("ignorefileextension");
Boolean helpRequested = cmd.hasOption("help") || ((action != null) && (action.equals("help"))); Boolean helpRequested = cmd.hasOption("help") || ((action!=null)&&(action.equals("help")));
disableFileLogging = cmd.hasOption("disable-file-logging");
String sourceName = cmd.getOptionValue("source"); String sourceName = cmd.getOptionValue("source");
String sourceXMLName = cmd.getOptionValue("source-xml"); String sourceXMLName = cmd.getOptionValue("source-xml");
@@ -385,7 +388,17 @@ 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 <>();
/*
setting system property to disable FILE appender and
suppress creation of files and folders.
*/
System.setProperty("FILE_APPENDER_ENABLED", ((Boolean)(disableFileLogging==false)).toString());
LOGGER = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
if (helpRequested) { if (helpRequested) {
printHelp(); printHelp();
optionsRecognized = true; optionsRecognized = true;

View File

@@ -1,37 +1,38 @@
<configuration> <configuration>
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<target>System.err</target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<if condition='!isDefined("disable-file-logging")'> <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
<then> <target>System.err</target>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>log/ZUV-%d{yyyy-MM}.log</fileNamePattern>
<!-- Keep 5 years worth of history -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder> <encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder> </encoder>
</appender> </appender>
</then>
</if>
<!-- Configure so that it outputs to both console and log file --> <if condition='property("FILE_APPENDER_ENABLED").contains("true")'>
<root level="INFO"> <then>
<if condition='!isDefined("disable-file-logging")'> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender" >
<then> <!--<appender name="FILE" class="org.mustangproject.commandline.LazyRollingFileAppender" >-->
<appender-ref ref="FILE" /> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
</then> <!-- Daily rollover -->
<fileNamePattern>log/ZUV-%d{yyyy-MM}.log</fileNamePattern>
<!-- Keep 5 years worth of history -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
</then>
</if> </if>
<appender-ref ref="STDERR" />
</root> <!-- Configure so that it outputs to both console and log file -->
<root level="INFO">
<if condition='property("FILE_APPENDER_ENABLED").contains("true")'>
<then>
<appender-ref ref="FILE" />
</then>
</if>
<appender-ref ref="STDERR" />
</root>
</configuration> </configuration>