version 0.0.6

This commit is contained in:
Jochen Staerk
2015-10-22 15:06:54 +02:00
parent 4fb82f9a3a
commit 0efd9007f7
5 changed files with 20 additions and 30 deletions

4
mustang/toecount/pom.xml Normal file → Executable file
View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.mustangproject.ZUGFeRD</groupId> <groupId>org.mustangproject.ZUGFeRD</groupId>
<artifactId>toecount</artifactId> <artifactId>toecount</artifactId>
<version>0.0.5-SNAPSHOT</version> <version>0.0.6-SNAPSHOT</version>
<name>ZUGFeRD PDF checker</name> <name>ZUGFeRD PDF checker</name>
<description>Shows statistics on how many PDFs in a directory are ZUGFeRD-Compliant</description> <description>Shows statistics on how many PDFs in a directory are ZUGFeRD-Compliant</description>
<repositories> <repositories>
@@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>org.mustangproject.ZUGFeRD</groupId> <groupId>org.mustangproject.ZUGFeRD</groupId>
<artifactId>mustang</artifactId> <artifactId>mustang</artifactId>
<version>1.2.0</version> <version>1.2.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>

View File

@@ -6,14 +6,13 @@ public class FileChecker {
String filename; String filename;
StatRun thisRun; StatRun thisRun;
boolean isPDF=false; boolean isPDF=false;
boolean checkFileExt=true;
public FileChecker(String filename, StatRun statistics) { public FileChecker(String filename, StatRun statistics) {
this.filename=filename; this.filename=filename;
thisRun=statistics; thisRun=statistics;
thisRun.incFileCount(); thisRun.incFileCount();
String extension = ""; String extension = "";
if (checkFileExt) { if (!thisRun.shallIgnoreFileExt()) {
int extIndex = filename.lastIndexOf("."); int extIndex = filename.lastIndexOf(".");
if (extIndex >= 0) { if (extIndex >= 0) {
extension = filename.substring(extIndex).toLowerCase(); extension = filename.substring(extIndex).toLowerCase();
@@ -27,9 +26,9 @@ public class FileChecker {
} }
public boolean checkForZUGFeRD() { public boolean checkForZUGFeRD() {
if ((!isPDF)&&(checkFileExt)) { if ((!isPDF)&&(!thisRun.shallIgnoreFileExt())) {
return false; return false;
} }
ZUGFeRDImporter zi=new ZUGFeRDImporter(); ZUGFeRDImporter zi=new ZUGFeRDImporter();
zi.extract(filename); zi.extract(filename);
if (zi.canParse()) { if (zi.canParse()) {
@@ -47,9 +46,5 @@ public class FileChecker {
public String getOutputLine() { public String getOutputLine() {
return thisRun.getOutputLine(); return thisRun.getOutputLine();
} }
public void ignoreFileExtension() {
checkFileExt=false;
}
} }

View File

@@ -12,7 +12,6 @@ public class FileTraverser extends SimpleFileVisitor<Path> {
private StatRun thisRun; private StatRun thisRun;
private boolean checkFileExt=true;
public FileTraverser(StatRun statistics) { public FileTraverser(StatRun statistics) {
this.thisRun=statistics; this.thisRun=statistics;
} }
@@ -27,15 +26,10 @@ public class FileTraverser extends SimpleFileVisitor<Path> {
} else if (attr.isRegularFile()) { } else if (attr.isRegularFile()) {
String filename = file.toString(); String filename = file.toString();
FileChecker fc = new FileChecker(filename, thisRun); FileChecker fc = new FileChecker(filename, thisRun);
if (!checkFileExt) {
fc.ignoreFileExtension();
}
fc.checkForZUGFeRD(); fc.checkForZUGFeRD();
System.out.print(fc.getOutputLine()); System.out.print(fc.getOutputLine());
} else { }
// Not yet handled
}
return CONTINUE; return CONTINUE;
} }
@@ -59,7 +53,4 @@ public class FileTraverser extends SimpleFileVisitor<Path> {
return CONTINUE; return CONTINUE;
} }
public void ignoreFileExtension() {
checkFileExt=false;
}
} }

8
mustang/toecount/src/main/java/toecount/StatRun.java Normal file → Executable file
View File

@@ -5,7 +5,15 @@ public class StatRun {
private int horseCount = 0; private int horseCount = 0;
private int fileCount = 0; private int fileCount = 0;
private int dirCount = 0; private int dirCount = 0;
private boolean checkFileExt=true;
public void ignoreFileExtension() {
checkFileExt=false;
}
public boolean shallIgnoreFileExt() {
return !checkFileExt;
}
public void incFileCount(){ public void incFileCount(){
fileCount++; fileCount++;
} }

16
mustang/toecount/src/main/java/toecount/Toecount.java Normal file → Executable file
View File

@@ -22,7 +22,7 @@ public class Toecount {
} }
private static void printHelp() { private static void printHelp() {
System.out System.out
.println("Mustangproject.org's Toecount 0.0.5 \r\n" .println("Mustangproject.org's Toecount 0.0.6 \r\n"
+ "A Apache Public License command line tool for statistics on PDF invoices with\r\n" + "A Apache Public License command line tool for statistics on PDF invoices with\r\n"
+ "ZUGFeRD Metadata (http://www.zugferd.de)\r\n" + "ZUGFeRD Metadata (http://www.zugferd.de)\r\n"
+ "\r\n" + "\r\n"
@@ -75,23 +75,21 @@ public class Toecount {
} }
StatRun sr=new StatRun(); StatRun sr=new StatRun();
if (ignoreFileExt) {
sr.ignoreFileExtension();
}
if (directoryName != null) { if (directoryName != null) {
Path startingDir = Paths.get(directoryName); Path startingDir = Paths.get(directoryName);
if (Files.isRegularFile(startingDir)) { if (Files.isRegularFile(startingDir)) {
String filename = startingDir.toString(); String filename = startingDir.toString();
FileChecker fc = new FileChecker(filename, sr); FileChecker fc = new FileChecker(filename, sr);
if (ignoreFileExt) {
fc.ignoreFileExtension();
}
fc.checkForZUGFeRD(); fc.checkForZUGFeRD();
System.out.print(fc.getOutputLine()); System.out.print(fc.getOutputLine());
} else if (Files.isDirectory(startingDir)) { } else if (Files.isDirectory(startingDir)) {
FileTraverser pf = new FileTraverser(sr); FileTraverser pf = new FileTraverser(sr);
if (ignoreFileExt) {
pf.ignoreFileExtension();
}
try { try {
Files.walkFileTree(startingDir, pf); Files.walkFileTree(startingDir, pf);
} catch (IOException e) { } catch (IOException e) {
@@ -109,9 +107,7 @@ public class Toecount {
try { try {
while ((s = in.readLine()) != null && s.length() != 0) { while ((s = in.readLine()) != null && s.length() != 0) {
FileChecker fc = new FileChecker(s, sr); FileChecker fc = new FileChecker(s, sr);
if (ignoreFileExt) {
fc.ignoreFileExtension();
}
fc.checkForZUGFeRD(); fc.checkForZUGFeRD();
System.out.print(fc.getOutputLine()); System.out.print(fc.getOutputLine());