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

View File

@@ -6,14 +6,13 @@ public class FileChecker {
String filename;
StatRun thisRun;
boolean isPDF=false;
boolean checkFileExt=true;
public FileChecker(String filename, StatRun statistics) {
this.filename=filename;
thisRun=statistics;
thisRun.incFileCount();
String extension = "";
if (checkFileExt) {
if (!thisRun.shallIgnoreFileExt()) {
int extIndex = filename.lastIndexOf(".");
if (extIndex >= 0) {
extension = filename.substring(extIndex).toLowerCase();
@@ -27,9 +26,9 @@ public class FileChecker {
}
public boolean checkForZUGFeRD() {
if ((!isPDF)&&(checkFileExt)) {
if ((!isPDF)&&(!thisRun.shallIgnoreFileExt())) {
return false;
}
}
ZUGFeRDImporter zi=new ZUGFeRDImporter();
zi.extract(filename);
if (zi.canParse()) {
@@ -47,9 +46,5 @@ public class FileChecker {
public String 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 boolean checkFileExt=true;
public FileTraverser(StatRun statistics) {
this.thisRun=statistics;
}
@@ -27,15 +26,10 @@ public class FileTraverser extends SimpleFileVisitor<Path> {
} else if (attr.isRegularFile()) {
String filename = file.toString();
FileChecker fc = new FileChecker(filename, thisRun);
if (!checkFileExt) {
fc.ignoreFileExtension();
}
fc.checkForZUGFeRD();
System.out.print(fc.getOutputLine());
} else {
// Not yet handled
}
}
return CONTINUE;
}
@@ -59,7 +53,4 @@ public class FileTraverser extends SimpleFileVisitor<Path> {
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 fileCount = 0;
private int dirCount = 0;
private boolean checkFileExt=true;
public void ignoreFileExtension() {
checkFileExt=false;
}
public boolean shallIgnoreFileExt() {
return !checkFileExt;
}
public void incFileCount(){
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() {
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"
+ "ZUGFeRD Metadata (http://www.zugferd.de)\r\n"
+ "\r\n"
@@ -75,23 +75,21 @@ public class Toecount {
}
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);
if (ignoreFileExt) {
fc.ignoreFileExtension();
}
fc.checkForZUGFeRD();
System.out.print(fc.getOutputLine());
} else if (Files.isDirectory(startingDir)) {
FileTraverser pf = new FileTraverser(sr);
if (ignoreFileExt) {
pf.ignoreFileExtension();
}
try {
Files.walkFileTree(startingDir, pf);
} catch (IOException e) {
@@ -109,9 +107,7 @@ public class Toecount {
try {
while ((s = in.readLine()) != null && s.length() != 0) {
FileChecker fc = new FileChecker(s, sr);
if (ignoreFileExt) {
fc.ignoreFileExtension();
}
fc.checkForZUGFeRD();
System.out.print(fc.getOutputLine());