Skip to content

Commit

Permalink
Bugfix .pdfa v1.7.9 erstellt
Browse files Browse the repository at this point in the history
============================
PDFTron validiert jetzt auch PDF mit der extension pdfa
v1.7.9
  • Loading branch information
Chlara committed Nov 22, 2016
1 parent 0402eef commit e9166f3
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 44 deletions.
32 changes: 25 additions & 7 deletions KOST-Val/src/main/java/ch/kostceco/tools/kostval/KOSTVal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* == KOST-Val ==================================================================================
* The KOST-Val v1.7.8 application is used for validate TIFF, SIARD, PDF/A, JP2, JPEG-Files and
* The KOST-Val v1.7.9 application is used for validate TIFF, SIARD, PDF/A, JP2, JPEG-Files and
* Submission Information Package (SIP). Copyright (C) 2012-2016 Claire Roethlisberger (KOST-CECO),
* Christian Eugster, Olivier Debenath, Peter Schneider (Staatsarchiv Aargau), Markus Hahn
* (coderslagoon), Daniel Ludin (BEDAG AG)
Expand Down Expand Up @@ -405,9 +405,27 @@ public static void main( String[] args ) throws IOException
boolean matchFound = matcher.find();
if ( matchFound ) {
LOGGER.logError( kostval.getTextResourceService().getText( ERROR_IOE,
kostval.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name ) ) );
System.out.println( kostval.getTextResourceService()
.getText( ERROR_SPECIAL_CHARACTER, name ) );
kostval.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name, matcher.group( i ) ) ) );
System.console().printf( kostval.getTextResourceService()
.getText( ERROR_SPECIAL_CHARACTER, name, matcher.group( i ) ) );
System.exit( 1 );
}
}

name = directoryOfLogfile.getAbsolutePath();

pathElements = name.split( "/" );
for ( int i = 0; i < pathElements.length; i++ ) {
String element = pathElements[i];

Matcher matcher = pattern.matcher( element );

boolean matchFound = matcher.find();
if ( matchFound ) {
LOGGER.logError( kostval.getTextResourceService().getText( ERROR_IOE,
kostval.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name, matcher.group( i ) ) ) );
System.console().printf( kostval.getTextResourceService()
.getText( ERROR_SPECIAL_CHARACTER, name, matcher.group( i ) ) );
System.exit( 1 );
}
}
Expand Down Expand Up @@ -516,9 +534,9 @@ public static void main( String[] args ) throws IOException
boolean matchFound = matcher.find();
if ( matchFound ) {
LOGGER.logError( kostval.getTextResourceService().getText( ERROR_IOE,
kostval.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name ) ) );
System.out.println( kostval.getTextResourceService()
.getText( ERROR_SPECIAL_CHARACTER, name ) );
kostval.getTextResourceService().getText( ERROR_SPECIAL_CHARACTER, name, matcher.group( i ) ) ) );
System.console().printf( kostval.getTextResourceService()
.getText( ERROR_SPECIAL_CHARACTER, name, matcher.group( i ) ) );
System.exit( 1 );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public interface MessageConstants
String ERROR_XML_A_PDFA_SERVICEFAILED = "error.xml.a.pdfa.servicefailed";
String ERROR_XML_PDFTRON_MISSING = "error.xml.pdftron.missing";
String ERROR_XML_A_PDFA_INIT = "error.xml.a.pdfa.init";
String ERROR_XML_A_PDFA_NOFAILORPASS = "error.xml.a.pdfa.nofailorpass";
String ERROR_XML_A_PDFA_NOCONFIG = "error.xml.a.pdfa.noconfig";
String ERROR_XML_A_PDFTOOLS_LICENSE = "error.xml.a.pdftools.license";
String ERROR_XML_A_PDFTOOLS_ENCRYPTED = "error.xml.a.pdftools.encrypted";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public boolean validate( File valDatei, File directoryOfLogfile )
// Ende der Erkennung

boolean isValid = false;
boolean isPdftron = false;
boolean dual = false;

// Initialisierung PDFTron -> überprüfen der Angaben: existiert die PdftronExe am angebenen Ort?
Expand Down Expand Up @@ -412,14 +413,19 @@ public boolean validate( File valDatei, File directoryOfLogfile )
File pdftronExe = new File( pathToPdftronExe );
File output = directoryOfLogfile;
String pathToPdftronOutput = output.getAbsolutePath();
String extension = ".pdf";
if ( (valDatei.getAbsolutePath().toLowerCase().endsWith( ".pdfa" )) ) {
extension = ".pdfa";
} else if ( (valDatei.getAbsolutePath().toLowerCase().endsWith( ".pdf" )) ) {
extension = ".pdf";
}
StringBuffer command = new StringBuffer( pdftronExe + " " );
command.append( "--extension " + extension + " " );
command.append( "-l " + level );
command.append( " -o " );
command.append( "\"" );
command.append( output.getAbsolutePath() );
command.append( "\"" );
command.append( " " );
command.append( "\"" );
command.append( "\" \"" );
command.append( valDatei.getAbsolutePath() );
command.append( "\"" );

Expand Down Expand Up @@ -482,13 +488,36 @@ public boolean validate( File valDatei, File directoryOfLogfile )

Integer passCount = new Integer( 0 );
NodeList nodeLstI = doc.getElementsByTagName( "Pass" );

// Valide pdfa-Dokumente enthalten "<Validation> <Pass FileName..." Anzahl pass = anzahl
// Valider pdfa
Integer failCount = new Integer( 0 );
NodeList nodeLstF = doc.getElementsByTagName( "Fail" );

/* Valide pdfa-Dokumente enthalten "<Validation> <Pass FileName..." Anzahl pass = anzahl
* Valider pdfa
*
* <Validation> <Fail FileName... ist wenn nicht bestanden
*
* TODO Neu muss auch der Fall abgefangen werden, dass weder pass noch fail existiert =>
* Problem bei der Initialisierung
*
* enthält nur <PDFAManagerReport RunDateTime="..."></PDFAManagerReport> */
for ( int s = 0; s < nodeLstI.getLength(); s++ ) {
passCount = passCount + 1;
// Valide PDFA-Datei Module A-J sind Valid
isValid = true;
// Validierung dieser Datei mit PDFTron hat funktioniert
isPdftron = true;
}
for ( int s = 0; s < nodeLstF.getLength(); s++ ) {
failCount = failCount + 1;
// Validierung dieser Datei mit PDFTron hat funktioniert
isPdftron = true;
}

if ( !isPdftron ) {
getMessageService().logError(
getTextResourceService().getText( MESSAGE_XML_MODUL_A_PDFA )
+ getTextResourceService().getText( ERROR_XML_A_PDFA_NOFAILORPASS ) );
return false;
}

if ( passCount == 0 ) {
Expand Down Expand Up @@ -747,14 +776,19 @@ public boolean validate( File valDatei, File directoryOfLogfile )
File pdftronExe = new File( pathToPdftronExe );
File output = directoryOfLogfile;
String pathToPdftronOutput = output.getAbsolutePath();
String extension = ".pdf";
if ( (valDatei.getAbsolutePath().toLowerCase().endsWith( ".pdfa" )) ) {
extension = ".pdfa";
} else if ( (valDatei.getAbsolutePath().toLowerCase().endsWith( ".pdf" )) ) {
extension = ".pdf";
}
StringBuffer command = new StringBuffer( pdftronExe + " " );
command.append( "--extension " + extension + " " );
command.append( "-l " + level );
command.append( " -o " );
command.append( "\"" );
command.append( output.getAbsolutePath() );
command.append( "\"" );
command.append( " " );
command.append( "\"" );
command.append( "\" \"" );
command.append( valDatei.getAbsolutePath() );
command.append( "\"" );

Expand Down Expand Up @@ -817,13 +851,25 @@ public boolean validate( File valDatei, File directoryOfLogfile )

Integer passCount = new Integer( 0 );
NodeList nodeLstI = doc.getElementsByTagName( "Pass" );
Integer failCount = new Integer( 0 );
NodeList nodeLstF = doc.getElementsByTagName( "Fail" );

/* Valide pdfa-Dokumente enthalten "<Validation> <Pass FileName..." Anzahl pass =
* anzahl Valider pdfa
*
* <Validation> <Fail FileName... ist wenn nicht bestanden
*
* TODO Neu muss auch der Fall abgefangen werden, dass weder pass noch fail existiert
* => Problem bei der Initialisierung
*
* enthält nur <PDFAManagerReport RunDateTime="..."></PDFAManagerReport> */

// Valide pdfa-Dokumente enthalten "<Validation> <Pass FileName..." Anzahl pass =
// anzahl Valider pdfa
for ( int s = 0; s < nodeLstI.getLength(); s++ ) {
passCount = passCount + 1;
// Valide PDFA-Datei Module A-J sind Valid
isValid = true;
// Validierung dieser Datei mit PDFTron hat funktioniert
isPdftron = true;

// Diskrepanz => PDF-Diagnosedaten
pdfTools = "<PDFTools><iCategory>" + iCategory + "</iCategory><iError>" + iError
Expand All @@ -838,6 +884,19 @@ public boolean validate( File valDatei, File directoryOfLogfile )
* aus performance-Gründen direkt in pdfDia integriert */

}

for ( int s = 0; s < nodeLstF.getLength(); s++ ) {
failCount = failCount + 1;
// Validierung dieser Datei mit PDFTron hat funktioniert
isPdftron = true;
}

if ( !isPdftron ) {
getMessageService().logError(
getTextResourceService().getText( MESSAGE_XML_MODUL_A_PDFA )
+ getTextResourceService().getText( ERROR_XML_A_PDFA_NOFAILORPASS ) );
}

if ( passCount == 0 ) {
// Invalide PDFA-Datei (doppelt bestätigt)
isValid = false;
Expand Down Expand Up @@ -987,7 +1046,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
File report = new File( directoryOfLogfile.getAbsolutePath(), "report.xml" );
Document doc = null;

if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// aus dem Output von Pdftron die Fehlercodes extrahieren und übersetzen

String pathToPdftronReport = report.getAbsolutePath();
Expand Down Expand Up @@ -1023,7 +1084,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
}
return false;
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// aus dem Output von Pdftron die Fehlercodes extrahieren und übersetzen

String errorDigitA = "Fehler";
Expand All @@ -1042,12 +1105,17 @@ public boolean validate( File valDatei, File directoryOfLogfile )
// e_PDF_Unknown ist meist ein korruptes oder verschlüsseltes Dokument
if ( errorDigitA.equals( "_" ) ) {
errorDigitA = "0";
}
if ( errorDigitA.equals( "U" ) ) {
} else if ( errorDigitA.equals( "U" ) ) {
errorDigitA = "0";
}
if ( errorDigitA.equals( "n" ) ) {
} else if ( errorDigitA.equals( "n" ) ) {
errorDigitA = "0";
} else if ( errorDigitA.equals( "Fehler" ) ) {
isValid = false;
getMessageService().logError(
getTextResourceService().getText( MESSAGE_XML_MODUL_A_PDFA )
+ getTextResourceService().getText( ERROR_XML_A_PDFA_INIT, errorCode ) );
return false;

}
String errorCodeMsg = "error.xml.ai." + errorCode.substring( 2 );
Node errorNodeM = nodeMap.getNamedItem( "Message" );
Expand Down Expand Up @@ -1103,7 +1171,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_B_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_18, "iCategory_18" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1163,7 +1233,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_C_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_6, "iCategory_6" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1202,7 +1274,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_D_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_9, "iCategory_9" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1236,7 +1310,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_E_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_10, "iCategory_10" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1285,7 +1361,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_F_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_14, "iCategory_14" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1319,7 +1397,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_G_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_15, "iCategory_15" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1361,7 +1441,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_H_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_16, "iCategory_16" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down Expand Up @@ -1395,7 +1477,9 @@ public boolean validate( File valDatei, File directoryOfLogfile )
getTextResourceService().getText( MESSAGE_XML_MODUL_I_PDFA )
+ getTextResourceService().getText( ERROR_XML_AI_17, "iCategory_17" ) );
}
if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
if ( !isPdftron ) {
// Fehler bereits ausgegeben
} else if ( producerFirstValidator.contentEquals( "PDFTron" ) || dual ) {
// Analog Modul A
NodeList nodeLst = doc.getElementsByTagName( "Error" );
for ( int s = 0; s < nodeLst.getLength(); s++ ) {
Expand Down
7 changes: 4 additions & 3 deletions KOST-Val/src/main/resources/de_messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ error.incorrectfileending = <Info><Message>Die Datei "{0}" ist kein TIFF, SIARD,
error.incorrectfileendings = <Info><Message>Es konnte keine Formatvalidierung durchgefuehrt werden (nur "{0}" werden gemaess Konfiguration validiert).</Message></Info>
error.nofileendings = <Info><Message>Es konnte keine Formatvalidierung durchgefuehrt werden (alle Formate in der Konfiguration ausgeschlossen).</Message></Info>
error.wrong.jdk = Die Version der Java Runtime Engine muss mindestens 1.6 sein. Bitte installieren Sie auf Ihrem Computer ein(e) ausreichende(s) JRE oder JDK. Die JRE kann von hier heruntergeladen werden\: http\://www.java.com/de/download/
error.special.character = Der Pfad "{0}" enthaelt ein Sonderzeichen (z.B. Umlaute), welches noch nicht unterstuetzt wird. Bitte normalisieren und revalidieren.
error.special.character = Der Pfad "{0}" enthaelt ein Sonderzeichen "{1}", welches noch nicht unterstuetzt wird. Bitte normalisieren und revalidieren.

# Globale Meldungen
message.xml.valfile = <ValFile>{0}</ValFile>
Expand All @@ -29,7 +29,7 @@ message.xml.formaton = <FormatValOn>{0}</FormatValOn>{1}
message.xml.summary.3c = <Message>Von den {0} Dateien sind {1} ({4}%) valid, {2} ({5}%) invalid und {3} ({6}%) wurden nicht validiert.</Message></Error>
message.xml.summary.format = Von den {0} Dateien sind {1} ({4}%) valid, {2} ({5}%) invalid und {3} ({6}%) wurden nicht validiert.
message.xml.summary = <Infos><Summary>Von den {0} Dateien sind {1} ({4}%) valid, {2} ({5}%) invalid und {3} ({6}%) wurden nicht validiert.</Summary><Info><Message>Folgende Dateien wurden nicht validiert:{7}</Message></Info></Infos>
message.xml.info = <Info>KOST-Val v1.7.8, Copyright (C) 2012-2016 Claire Roethlisberger (KOST-CECO), Christian Eugster, Olivier Debenath, Peter Schneider (Staatsarchiv Aargau), Markus Hahn (coderslagoon), Daniel Ludin (BEDAG AG). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.info = <Info>KOST-Val v1.7.9, Copyright (C) 2012-2016 Claire Roethlisberger (KOST-CECO), Christian Eugster, Olivier Debenath, Peter Schneider (Staatsarchiv Aargau), Markus Hahn (coderslagoon), Daniel Ludin (BEDAG AG). This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GPL-3.0_COPYING.txt for details</Info></Infos>
message.xml.valergebnis = <Validation>
message.tiffvalidation = Validierung: TIFF
message.siardvalidation = Validierung: SIARD
Expand Down Expand Up @@ -211,7 +211,8 @@ error.xml.a.pdfa.incorrectfile = <Message>Die Datei ist kein PDF (Header). Die D
error.xml.a.pdfa.isdirectory = <Message>Die angegebene PDF-Datei ist ein Ordner. -> Validierung abgebrochen!</Message></Error>
error.xml.a.pdfa.servicefailed = <Message>Bei der Verwendung von PDFTron ist eine unbekannter Fehler aufgetreten. -> Validierung abgebrochen! Fehler: {0}</Message></Error>
error.xml.pdftron.missing = <Message>pdfa.exe von PDFTron existiert nicht am angegebenen Ort. Bitte ueberpruefen Sie die Konfiguration. -> Validierung abgebrochen!</Message></Error>
error.xml.a.pdfa.init = <Message>PDFTron konnte nicht initialisiert werden. -> Validierung abgebrochen!</Message></Error>
error.xml.a.pdfa.init = <Message>PDFTron konnte nicht initialisiert werden. -> Validierung abgebrochen! Fehler: {0}</Message></Error>
error.xml.a.pdfa.nofailorpass = <Message>Datei konnte mit PDFTron nicht validiert werden (kein Fail oder Pass). -> Validierung abgebrochen!</Message></Error>
error.xml.a.pdfa.noconfig = <Message>Die PDF-Datei kann nicht validiert werden, da kein gueltiger Eintrag in der Konfiguration enthalten ist. -> Validierung abgebrochen!</Message></Error>
error.xml.a.pdftools.license = <Message>PDF-Tools Errormessage: Keine gueltige Lizenz gefunden.</Message></Error>
error.xml.a.pdftools.encrypted = <Message>Dokument ist verschluesselt. Passwort erforderlich.</Message></Error>
Expand Down
Loading

0 comments on commit e9166f3

Please sign in to comment.