@@ -66,7 +66,7 @@ public PDFValidator(ValidationContext ctx) {
6666 private String Signature ;
6767
6868 private String zfXML = null ;
69- protected boolean autoload = true ;
69+ protected boolean autoload = true ;
7070
7171 protected static boolean stringArrayContains (String [] arr , String targetValue ) {
7272 return Arrays .asList (arr ).contains (targetValue );
@@ -134,8 +134,7 @@ public void validate() throws IrrecoverableValidationError {
134134 if (xmp == null || xmp .isEmpty ()) {
135135 context .addResultItem (new ValidationResultItem (ESeverity .error , "Invalid XMP Metadata not found" )
136136 .setSection (17 ).setPart (EPart .pdf ));
137- }
138- else {
137+ } else {
139138 /*
140139 * checking for sth like <zf:ConformanceLevel>EXTENDED</zf:ConformanceLevel>
141140 * <zf:DocumentType>INVOICE</zf:DocumentType>
@@ -150,14 +149,7 @@ public void validate() throws IrrecoverableValidationError {
150149
151150 final DocumentBuilder builder = factory .newDocumentBuilder ();
152151 final InputSource is = new InputSource (new StringReader (xmp ));
153- try {
154- docXMP = builder .parse (is );
155- } catch (Exception e ) {
156- context .addResultItem (
157- new ValidationResultItem (ESeverity .error , "XMP Metadata: Could not parse XMP metadata" )
158- .setSection (10 ).setPart (EPart .pdf ));
159- throw e ;
160- }
152+ docXMP = builder .parse (is );
161153
162154 final XPathFactory xpathFactory = XPathFactory .newInstance ();
163155
@@ -273,7 +265,11 @@ public void validate() throws IrrecoverableValidationError {
273265 .setSection (16 ).setPart (EPart .pdf ));
274266
275267 }
276- } catch (final SAXException | IOException | ParserConfigurationException | XPathExpressionException e ) {
268+ } catch (final SAXException e ) {
269+ context .addResultItem (
270+ new ValidationResultItem (ESeverity .error , "XMP Metadata: Could not parse XMP metadata (XML invalid)" )
271+ .setSection (28 ).setPart (EPart .pdf ));
272+ } catch (IOException | ParserConfigurationException | XPathExpressionException e ) {
277273 LOGGER .error (e .getMessage (), e );
278274 }
279275 }
@@ -288,7 +284,7 @@ public void validate() throws IrrecoverableValidationError {
288284 final byte [] pdfMachineSignature = "pdfMachine from Broadgun Software" .getBytes (StandardCharsets .UTF_8 );
289285 final byte [] ghostscriptSignature = "%%Invocation:" .getBytes (StandardCharsets .UTF_8 );
290286 final byte [] cibpdfbrewerSignature = "CIB pdf brewer" .getBytes (StandardCharsets .UTF_8 );
291- final byte [] lexofficeSignature = "lexoffice" .getBytes (StandardCharsets .UTF_8 );
287+ final byte [] lexofficeSignature = "lexoffice" .getBytes (StandardCharsets .UTF_8 );
292288 final byte [] s2IndustriesSignature = "s2industries.ZUGFeRD.PDF" .getBytes (StandardCharsets .UTF_8 ); // https://github.com/stephanstapel/ZUGFeRD-csharp
293289 final byte [] factoorSharpSignature = "FactoorSharp" .getBytes (StandardCharsets .UTF_8 ); // https://github.com/S2-Industries/FactoorSharp
294290 final byte [] sevdeskSignature = "sevdesk" .getBytes (StandardCharsets .UTF_8 );
@@ -354,23 +350,23 @@ public void validate() throws IrrecoverableValidationError {
354350 @ Override
355351 public void setFilename (String filename ) throws IrrecoverableValidationError {
356352 this .pdfFilename = filename ;
357- if (autoload ) {
353+ if (autoload ) {
358354 try {
359- fileContents = Files .readAllBytes (Paths .get (pdfFilename ));
355+ fileContents = Files .readAllBytes (Paths .get (pdfFilename ));
360356 } catch (IOException ex ) {
361357 throw new IrrecoverableValidationError ("Could not read file" );
362358 }
363359 }
364360 }
365361
366- public void setFileContents (byte [] fileContents ) {
367- this .fileContents = fileContents ;
368- }
362+ public void setFileContents (byte [] fileContents ) {
363+ this .fileContents = fileContents ;
364+ }
369365
370- public void setFilenameAndContents (String filename , byte [] fileContents ) {
371- this .pdfFilename = filename ;
372- this .fileContents = fileContents ;
373- }
366+ public void setFilenameAndContents (String filename , byte [] fileContents ) {
367+ this .pdfFilename = filename ;
368+ this .fileContents = fileContents ;
369+ }
374370
375371 public String getRawXML () {
376372 return zfXML ;
0 commit comments