diff --git a/History.md b/History.md index 37500622..393decf7 100644 --- a/History.md +++ b/History.md @@ -6,6 +6,8 @@ - factory for xrechnung - new sample innvoice - complete or discard read into push provider +- validate as library doc +- javadoc export done - 2.1 now default @@ -15,6 +17,7 @@ done - integrates mustangserver - modular project setup - getSellerTradePartyAddress (PR #157 ) thanks to aberndt-hub +- switched from eclipse to IntelliJ 1.7.7 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 d5e7ad06..c56a0c55 100755 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java @@ -52,26 +52,26 @@ public class Main { } private static String getUsage() { - return "Usage: [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n" - + "* Count operations\n" + " -d, --directory count ZUGFeRD files in directory to be scanned\n" + return "Usage: --action metrics|combine|extract|a3only|upgrade|validate [-d,--directory] [-l,--listfromstdin] [-i,--ignorefileextension] | [-c,--combine] | [-e,--extract] | [-u,--upgrade] | [-a,--a3only] | [-h,--help] \r\n" + + "* merics\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)\n" - + "\n" + "* Merge operations\n" + " -e, --extract extract ZUGFeRD PDF to XML file\n" + + "\n" + "* Merge actions\n" + " extract extract ZUGFeRD 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" - + " -u, --upgrade upgrade ZUGFeRD XML to ZUGFeRD 2 XML\n" + + " 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" - + " -a, --a3only upgrade from PDF/A1 to A3 only (no ZUGFeRD data attached)\n" + + " 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" - + " -c, --combine combine XML and PDF file to ZUGFeRD PDF file\n" + + " combine combine XML and PDF file to ZUGFeRD 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" @@ -80,7 +80,11 @@ public class Main { + " [--version <1|2>]: set ZUGFeRD version\n" + " [--profile <...>]: set ZUGFeRD profile\n" + " For ZUGFeRD v1: ASIC, OMFORT or XTENDED\n" - + " For ZUGFeRD v2: INIMUM, BASIC L, ASIC, IUS, N16931, ETENDED "; + + " For ZUGFeRD v2: INIMUM, BASIC L, ASIC, IUS, N16931, ETENDED " + + " validate validate XML or PDF file \n" + + " Additional parameters (optional - user will be prompted if not defined)\n" + + " [--source ]: input PDF or XML file\n" + ; } private static void printHelp() { @@ -254,23 +258,6 @@ public class Main { // --out: output file Option outOption = parser.addStringOption("out"); - // Command: Extract XML - // --extract - // (--source: input PDF file) - // (--out: output XML file) - Option extractOption = parser.addBooleanOption('e', "extract"); - - // Command: Migrating ZUGFeRD 1 to 2 - // --upgrade - // (--source: input XML ZUGFeRD 1 file) - // (--out: output XML ZUGFeRD 2 file) - Option upgradeOption = parser.addBooleanOption('u', "upgrade"); - - // Command: Convert PDF/A-1 to PDF/A-3 - // --a3only - // (--source: input PDF file) - // (--out: output PDF file) - Option a3onlyOption = parser.addBooleanOption('a', "a3only"); // Command: Combining PDF and XML // --combine @@ -279,7 +266,6 @@ public class Main { // (--out: output PDF file) // (--version: ZUGFeRD version) // (--profile: ZUGFeRD profile) - Option combineOption = parser.addBooleanOption('c', "combine"); Option sourceXmlOption = parser.addStringOption("source-xml"); Option formatOption = parser.addStringOption('f', "format"); Option zugferdVersionOption = parser.addStringOption("version"); @@ -307,12 +293,8 @@ public class Main { String action = parser.getOptionValue(actionOption); String directoryName = parser.getOptionValue(dirnameOption); Boolean filesFromStdIn = parser.getOptionValue(filesFromStdInOption, Boolean.FALSE); - Boolean combineRequested = parser.getOptionValue(combineOption, Boolean.FALSE) || ((action!=null)&&(action.equals("combine"))); - Boolean extractRequested = parser.getOptionValue(extractOption, Boolean.FALSE) || ((action!=null)&&(action.equals("extract"))); Boolean helpRequested = parser.getOptionValue(helpOption, Boolean.FALSE) || ((action!=null)&&(action.equals("help"))); - Boolean upgradeRequested = parser.getOptionValue(upgradeOption, Boolean.FALSE) || ((action!=null)&&(action.equals("upgrade"))); Boolean ignoreFileExt = parser.getOptionValue(ignoreFileExtOption, Boolean.FALSE); - Boolean a3only = parser.getOptionValue(a3onlyOption, Boolean.FALSE) || ((action!=null)&&(action.equals("a3"))); String sourceName = parser.getOptionValue(sourceOption); String sourceXMLName = parser.getOptionValue(sourceXmlOption); String outName = parser.getOptionValue(outOption); @@ -323,29 +305,24 @@ public class Main { if (helpRequested) { printHelp(); optionsRecognized=true; - } else if (((directoryName != null) && (directoryName.length() > 0)) || filesFromStdIn.booleanValue()) { + } else if ((action!=null)&&(action.equals("metrics"))) { performMetrics(directoryName, filesFromStdIn, ignoreFileExt); optionsRecognized=true; - } else if (combineRequested) { + } else if ((action!=null)&&(action.equals("combine"))) { performCombine(sourceName, sourceXMLName, outName, format, zugferdVersion, zugferdProfile); optionsRecognized=true; - } else if (extractRequested) { + } else if ((action!=null)&&(action.equals("extract"))) { performExtract(sourceName, outName); optionsRecognized=true; - } else if (a3only) { + } else if ((action!=null)&&(action.equals("a3only"))) { performConvert(sourceName, outName); optionsRecognized=true; - } else if (upgradeRequested) { + } else if ((action!=null)&&(action.equals("upgrade"))) { performUpgrade(sourceName, outName); optionsRecognized=true; } else if ((action!=null)&&(action.equals("validate"))) { - ZUGFeRDValidator zfv=new ZUGFeRDValidator(); - System.out.println(zfv.validate(sourceName)); - optionsRecognized = !zfv.hasOptionsError(); - if (!zfv.wasCompletelyValid()) { - System.exit(-1); - } + optionsRecognized=performValidate(sourceName); } else { // no argument or argument unknown @@ -360,6 +337,23 @@ public class Main { } + private static boolean performValidate(String sourceName) { + boolean optionsRecognized; + if (sourceName == null) { + sourceName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false); + } else { + System.out.println("Source PDF set to " + sourceName); + } + + ZUGFeRDValidator zfv=new ZUGFeRDValidator(); + System.out.println(zfv.validate(sourceName)); + optionsRecognized = !zfv.hasOptionsError(); + if (!zfv.wasCompletelyValid()) { + System.exit(-1); + } + return optionsRecognized; + } + private static void performUpgrade(String xmlName, String outName) throws IOException, TransformerException { // Get params from user if not already defined diff --git a/library/pom.xml b/library/pom.xml index a063478c..b632ec22 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -11,7 +11,7 @@ library 2.0.0-SNAPSHOT jar - Library for to write and read FacturX 1.0 and ZUGFeRD 1.0 and 2.1 e-invoices. A PDF/A file is required, the XML can be generated or provided. + Library to write and read FacturX 1.0 and ZUGFeRD 1.0 and 2.1 e-invoices. A PDF/A file is required, the XML can be generated or provided. The Mustang project is a java library to read and write ZUGFeRD meta data inside your invoice PDFs http://www.mustangproject.org/