Fix indentation and move each option into sub functions
This commit is contained in:
@@ -232,53 +232,87 @@ public class Toecount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (((directoryName != null) && (directoryName.length() > 0)) || filesFromStdIn.booleanValue()) {
|
else if (((directoryName != null) && (directoryName.length() > 0)) || filesFromStdIn.booleanValue()) {
|
||||||
|
performMetrics(directoryName, filesFromStdIn, ignoreFileExt);
|
||||||
StatRun sr = new StatRun();
|
|
||||||
if (ignoreFileExt) {
|
|
||||||
sr.ignoreFileExtension();
|
|
||||||
}
|
|
||||||
if (directoryName != null) {
|
|
||||||
Path startingDir = Paths.get(directoryName);
|
|
||||||
|
|
||||||
if (Files.isRegularFile(startingDir)) {
|
|
||||||
String filename = startingDir.toString();
|
|
||||||
FileChecker fc = new FileChecker(filename, sr);
|
|
||||||
|
|
||||||
fc.checkForZUGFeRD();
|
|
||||||
System.out.print(fc.getOutputLine());
|
|
||||||
|
|
||||||
} else if (Files.isDirectory(startingDir)) {
|
|
||||||
FileTraverser pf = new FileTraverser(sr);
|
|
||||||
try {
|
|
||||||
Files.walkFileTree(startingDir, pf);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filesFromStdIn) {
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
|
||||||
String s;
|
|
||||||
try {
|
|
||||||
while ((s = in.readLine()) != null && s.length() != 0) {
|
|
||||||
FileChecker fc = new FileChecker(s, sr);
|
|
||||||
|
|
||||||
fc.checkForZUGFeRD();
|
|
||||||
System.out.print(fc.getOutputLine());
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println(sr.getSummaryLine());
|
|
||||||
} else if (combineRequested) {
|
} else if (combineRequested) {
|
||||||
|
performCombine();
|
||||||
|
} else if (extractRequested) {
|
||||||
|
performExtract();
|
||||||
|
} else if (a3only) {
|
||||||
|
performConvert();
|
||||||
|
} else if (upgradeRequested) {
|
||||||
|
performUpgrade();
|
||||||
|
} else {
|
||||||
|
// no argument or argument unknown
|
||||||
|
printUsage();
|
||||||
|
System.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void performUpgrade() {
|
||||||
|
try {
|
||||||
|
String xmlName = "";
|
||||||
|
String outName = "";
|
||||||
|
|
||||||
|
xmlName = getFilenameFromUser("ZUGFeRD 1.0 XML source", "ZUGFeRD-invoice.xml", "xml", true, false);
|
||||||
|
outName = getFilenameFromUser("ZUGFeRD 2.0 XML target", "factur-x.xml", "xml", false, true);
|
||||||
|
|
||||||
|
ZUGFeRDMigrator zmi = new ZUGFeRDMigrator();
|
||||||
|
String xml = null;
|
||||||
|
xml = zmi.migrateFromV1ToV2(xmlName);
|
||||||
|
Files.write(Paths.get(outName), xml.getBytes());
|
||||||
|
System.out.println("Written to " + outName);
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
} catch (TransformerException | UnsupportedEncodingException ex) {
|
||||||
|
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void performConvert() {
|
||||||
|
/*
|
||||||
|
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
|
||||||
|
* .setProducer("toecount") .setCreator(System.getProperty("user.name"))
|
||||||
|
* .loadFromPDFA1("invoice.pdf");
|
||||||
|
*/
|
||||||
|
String pdfName = "";
|
||||||
|
String outName = "";
|
||||||
|
try {
|
||||||
|
pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
|
||||||
|
outName = getFilenameFromUser("Target PDF", "invoice.a3.pdf", "pdf", false, true);
|
||||||
|
|
||||||
|
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setAttachZUGFeRDHeaders(false).load(pdfName);
|
||||||
|
|
||||||
|
ze.export(outName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println("Written to " + outName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void performExtract() {
|
||||||
|
|
||||||
|
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
||||||
|
String pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
|
||||||
|
String xmlName = getFilenameFromUser("ZUGFeRD XML", "ZUGFeRD-invoice.xml", "xml", false, true);
|
||||||
|
|
||||||
|
zi.extract(pdfName);
|
||||||
|
try {
|
||||||
|
byte[] XMLContent=zi.getRawXML();
|
||||||
|
if (XMLContent==null) {
|
||||||
|
System.err.println("No ZUGFeRD XML found in PDF file");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Files.write(Paths.get(xmlName), XMLContent);
|
||||||
|
System.out.println("Written to " + xmlName);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void performCombine() {
|
||||||
/*
|
/*
|
||||||
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
|
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
|
||||||
* .setProducer("toecount") .setCreator(System.getProperty("user.name"))
|
* .setProducer("toecount") .setCreator(System.getProperty("user.name"))
|
||||||
@@ -360,70 +394,58 @@ public class Toecount {
|
|||||||
// } catch (JAXBException e) {
|
// } catch (JAXBException e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Written to " + outName);
|
System.out.println("Written to " + outName);
|
||||||
} else if (extractRequested) {
|
|
||||||
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
|
||||||
String pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
|
|
||||||
String xmlName = getFilenameFromUser("ZUGFeRD XML", "ZUGFeRD-invoice.xml", "xml", false, true);
|
|
||||||
|
|
||||||
zi.extract(pdfName);
|
|
||||||
try {
|
|
||||||
byte[] XMLContent=zi.getRawXML();
|
|
||||||
if (XMLContent==null) {
|
|
||||||
System.err.println("No ZUGFeRD XML found in PDF file");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Files.write(Paths.get(xmlName), XMLContent);
|
|
||||||
System.out.println("Written to " + xmlName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void performMetrics(String directoryName, Boolean filesFromStdIn, Boolean ignoreFileExt) {
|
||||||
|
|
||||||
|
StatRun sr = new StatRun();
|
||||||
|
if (ignoreFileExt) {
|
||||||
|
sr.ignoreFileExtension();
|
||||||
|
}
|
||||||
|
if (directoryName != null) {
|
||||||
|
Path startingDir = Paths.get(directoryName);
|
||||||
|
|
||||||
|
if (Files.isRegularFile(startingDir)) {
|
||||||
|
String filename = startingDir.toString();
|
||||||
|
FileChecker fc = new FileChecker(filename, sr);
|
||||||
|
|
||||||
|
fc.checkForZUGFeRD();
|
||||||
|
System.out.print(fc.getOutputLine());
|
||||||
|
|
||||||
|
} else if (Files.isDirectory(startingDir)) {
|
||||||
|
FileTraverser pf = new FileTraverser(sr);
|
||||||
|
try {
|
||||||
|
Files.walkFileTree(startingDir, pf);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (a3only) {
|
}
|
||||||
/*
|
|
||||||
* ZUGFeRDExporter ze= new ZUGFeRDExporterFromA1Factory()
|
}
|
||||||
* .setProducer("toecount") .setCreator(System.getProperty("user.name"))
|
|
||||||
* .loadFromPDFA1("invoice.pdf");
|
if (filesFromStdIn) {
|
||||||
*/
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||||
String pdfName = "";
|
String s;
|
||||||
String outName = "";
|
|
||||||
try {
|
try {
|
||||||
pdfName = getFilenameFromUser("Source PDF", "invoice.pdf", "pdf", true, false);
|
while ((s = in.readLine()) != null && s.length() != 0) {
|
||||||
outName = getFilenameFromUser("Target PDF", "invoice.a3.pdf", "pdf", false, true);
|
FileChecker fc = new FileChecker(s, sr);
|
||||||
|
|
||||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setAttachZUGFeRDHeaders(false).load(pdfName);
|
fc.checkForZUGFeRD();
|
||||||
|
System.out.print(fc.getOutputLine());
|
||||||
|
|
||||||
ze.export(outName);
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
System.out.println("Written to " + outName);
|
|
||||||
} else if (upgradeRequested) {
|
|
||||||
try {
|
|
||||||
String xmlName = "";
|
|
||||||
String outName = "";
|
|
||||||
|
|
||||||
xmlName = getFilenameFromUser("ZUGFeRD 1.0 XML source", "ZUGFeRD-invoice.xml", "xml", true, false);
|
|
||||||
outName = getFilenameFromUser("ZUGFeRD 2.0 XML target", "factur-x.xml", "xml", false, true);
|
|
||||||
|
|
||||||
ZUGFeRDMigrator zmi = new ZUGFeRDMigrator();
|
|
||||||
String xml = null;
|
|
||||||
xml = zmi.migrateFromV1ToV2(xmlName);
|
|
||||||
Files.write(Paths.get(outName), xml.getBytes());
|
|
||||||
System.out.println("Written to " + outName);
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} catch (TransformerException | UnsupportedEncodingException ex) {
|
|
||||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Logger.getLogger(Toecount.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// no argument or argument unknown
|
|
||||||
printUsage();
|
|
||||||
System.exit(2);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
System.out.println(sr.getSummaryLine());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user