From ac5d4fa9662834d1e85e30c0d78b83842974429b Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Thu, 19 Sep 2024 09:35:23 +0200 Subject: [PATCH] #343 Parameterize logger call and clean up surrounding method --- .../htmlsanitycheck/check/CheckerCreator.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/CheckerCreator.java b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/CheckerCreator.java index 9f9b3297..8477a27d 100644 --- a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/CheckerCreator.java +++ b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/CheckerCreator.java @@ -27,9 +27,13 @@ private static boolean isCase(Class caseValue, Class checkerClass, final Configuration pConfig) { - Checker checker; + public static Checker createSingleChecker(final Class checkerClass, + final Configuration configuration) { + if (null == checkerClass) { + throw new UnknownCheckerException("Checker Class must not be 'null'"); + } + Checker checker; // switch over all possible Checker classes // in case of new Checkers, this has to be adapted, // as Checker constructors will differ in minor details! @@ -37,21 +41,21 @@ public static Checker createSingleChecker(final Class checker // clearly violates the open-close principle if (isCase(BrokenCrossReferencesChecker.class, checkerClass)) { - checker = new BrokenCrossReferencesChecker(pConfig); + checker = new BrokenCrossReferencesChecker(configuration); } else if (isCase(BrokenHttpLinksChecker.class, checkerClass)) { - checker = new BrokenHttpLinksChecker(pConfig); + checker = new BrokenHttpLinksChecker(configuration); } else if (isCase(DuplicateIdChecker.class, checkerClass)) { - checker = new DuplicateIdChecker(pConfig); + checker = new DuplicateIdChecker(configuration); } else if (isCase(ImageMapChecker.class, checkerClass)) { - checker = new ImageMapChecker(pConfig); + checker = new ImageMapChecker(configuration); } else if (isCase(MissingAltInImageTagsChecker.class, checkerClass)) { - checker = new MissingAltInImageTagsChecker(pConfig); + checker = new MissingAltInImageTagsChecker(configuration); } else if (isCase(MissingImageFilesChecker.class, checkerClass)) { - checker = new MissingImageFilesChecker(pConfig); + checker = new MissingImageFilesChecker(configuration); } else if (isCase(MissingLocalResourcesChecker.class, checkerClass)) { - checker = new MissingLocalResourcesChecker(pConfig); + checker = new MissingLocalResourcesChecker(configuration); } else { - logger.warn("unknown Checker " + checkerClass.toString()); + logger.error("unknown Checker {}", checkerClass); throw new UnknownCheckerException(checkerClass.toString()); }