@@ -85,7 +85,11 @@ public void check()
85
85
// Check the OCF Container file structure
86
86
// --------------------------------------
87
87
//
88
- checkContainerStructure (state );
88
+ if (!checkContainerStructure (state ))
89
+ {
90
+ return ;
91
+ }
92
+ ;
89
93
OCFContainer container = state .getContainer ();
90
94
91
95
//
@@ -270,83 +274,92 @@ private boolean checkContainerFile(OCFCheckerState state)
270
274
return true ;
271
275
}
272
276
273
- private void checkContainerStructure (OCFCheckerState state )
277
+ private boolean checkContainerStructure (OCFCheckerState state )
274
278
{
275
- // Get a container
276
- Iterable <OCFResource > resourcesProvider ;
277
279
try
278
280
{
279
281
// FIXME 2022 build resourcesProvider depending on MIME type
280
- resourcesProvider = new OCFZipResources (context .url );
281
- } catch (IOException e )
282
- {
283
- // FIXME 2022 see how to propagate fatal IOError
284
- report .message (MessageId .PKG_008 , EPUBLocation .of (context ), e .getLocalizedMessage ());
285
- return ;
286
- }
287
- // Map to store the container resource files
288
- Map <String , OCFResource > resources = new HashMap <>();
289
- // List to store the container resource directories
290
- List <String > directories = new LinkedList <>();
291
-
292
- // Loop through the entries
293
- OCFFilenameChecker filenameChecker = new OCFFilenameChecker (state .context ().build ());
294
- for (OCFResource resource : resourcesProvider )
295
- {
296
- Preconditions .checkNotNull (resource .getPath ());
297
- Preconditions .checkNotNull (resource .getProperties ());
282
+ // Get a container
283
+ Iterable <OCFResource > resourcesProvider = new OCFZipResources (context .url );
284
+ // Map to store the container resource files
285
+ Map <String , OCFResource > resources = new HashMap <>();
286
+ // List to store the container resource directories
287
+ List <String > directories = new LinkedList <>();
288
+
289
+ // Loop through the entries
290
+ OCFFilenameChecker filenameChecker = new OCFFilenameChecker (state .context ().build ());
291
+ // FIXME catch IAE MALFORMED entries
292
+ for (OCFResource resource : resourcesProvider )
293
+ {
294
+ Preconditions .checkNotNull (resource .getPath ());
295
+ Preconditions .checkNotNull (resource .getProperties ());
298
296
299
- // FIXME 2022 report symbolic links and continue
297
+ // FIXME 2022 report symbolic links and continue
300
298
301
- // Check duplicate entries
302
- if (resources .containsKey (resource .getPath ().toLowerCase (Locale .ROOT )))
303
- {
304
- context .report .message (MessageId .OPF_060 , EPUBLocation .of (context ), resource .getPath ());
305
- }
306
- // Check duplicate entries after NFC normalization
307
- else if (resources .containsKey (
308
- Normalizer .normalize (resource .getPath ().toLowerCase (Locale .ROOT ), Normalizer .Form .NFC )))
309
- {
310
- context .report .message (MessageId .OPF_061 , EPUBLocation .of (context ), resource .getPath ());
311
- }
299
+ // Check duplicate entries
300
+ if (resources .containsKey (resource .getPath ().toLowerCase (Locale .ROOT )))
301
+ {
302
+ context .report .message (MessageId .OPF_060 , EPUBLocation .of (context ), resource .getPath ());
303
+ }
304
+ // Check duplicate entries after NFC normalization
305
+ else if (resources .containsKey (
306
+ Normalizer .normalize (resource .getPath ().toLowerCase (Locale .ROOT ), Normalizer .Form .NFC )))
307
+ {
308
+ context .report .message (MessageId .OPF_061 , EPUBLocation .of (context ), resource .getPath ());
309
+ }
312
310
313
- // Store the resource in the data structure
314
- if (resource .isDirectory ())
315
- {
316
- // the container resource is a directory,
317
- // store it for later checking of empty directories
318
- directories .add (resource .getPath ());
319
- }
320
- else
321
- {
322
- // Check file name requirements
323
- filenameChecker .checkCompatiblyEscaped (resource .getPath ());
324
-
325
- // report entry metadata
326
- reportFeatures (resource .getProperties ());
327
- // the container resource is a file,
328
- // add the resource to the container model
329
- resources .put (resource .getPath ().toLowerCase (Locale .ROOT ), resource );
330
- state .addResource (resource );
311
+ // Store the resource in the data structure
312
+ if (resource .isDirectory ())
313
+ {
314
+ // the container resource is a directory,
315
+ // store it for later checking of empty directories
316
+ directories .add (resource .getPath ());
317
+ }
318
+ else
319
+ {
320
+ // Check file name requirements
321
+ filenameChecker .checkCompatiblyEscaped (resource .getPath ());
322
+
323
+ // report entry metadata
324
+ reportFeatures (resource .getProperties ());
325
+ // the container resource is a file,
326
+ // add the resource to the container model
327
+ resources .put (resource .getPath ().toLowerCase (Locale .ROOT ), resource );
328
+ state .addResource (resource );
329
+ }
331
330
}
332
- }
333
331
334
- // Report empty directories
335
- for (String directory : directories )
336
- {
337
- boolean hasContents = false ;
338
- for (OCFResource resource : resources .values ())
332
+ // Report empty directories
333
+ for (String directory : directories )
339
334
{
340
- if (resource .getPath ().startsWith (directory ))
335
+ boolean hasContents = false ;
336
+ for (OCFResource resource : resources .values ())
337
+ {
338
+ if (resource .getPath ().startsWith (directory ))
339
+ {
340
+ hasContents = true ;
341
+ break ;
342
+ }
343
+ }
344
+ if (!hasContents )
341
345
{
342
- hasContents = true ;
343
- break ;
346
+ report .message (MessageId .PKG_014 , EPUBLocation .of (context ), directory );
344
347
}
345
348
}
346
- if (!hasContents )
349
+ return true ;
350
+ } catch (Exception e )
351
+ {
352
+ switch (e .getMessage ())
347
353
{
348
- report .message (MessageId .PKG_014 , EPUBLocation .of (context ), directory );
354
+ case "invalid CEN header (bad entry name)" : // reported by OpenJDK
355
+ case "MALFORMED" : // reported by Oracle JDK 1.8
356
+ report .message (MessageId .PKG_027 , EPUBLocation .of (context ), e .getLocalizedMessage ());
357
+ break ;
358
+ default :
359
+ report .message (MessageId .PKG_008 , EPUBLocation .of (context ), e .getLocalizedMessage ());
360
+ break ;
349
361
}
362
+ return false ;
350
363
}
351
364
}
352
365
0 commit comments