diff -r 20a9b2bc9063 -r 89e3e6e28b69 src/java/de/uapcore/lightpit/Functions.java --- a/src/java/de/uapcore/lightpit/Functions.java Fri Dec 15 17:39:54 2017 +0100 +++ b/src/java/de/uapcore/lightpit/Functions.java Sat Dec 16 20:19:28 2017 +0100 @@ -28,12 +28,52 @@ */ package de.uapcore.lightpit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Contains common static functions. */ -public class Functions { +public final class Functions { + + private static final Logger LOG = LoggerFactory.getLogger(Functions.class); public static String jspPath(String filename) { return Constants.JSP_PATH_PREFIX + filename; } + + public static String fullyQualifiedName(String base, String name) { + return base+"."+name; + } + + public static String fullyQualifiedName(Class clazz, String name) { + return fullyQualifiedName(clazz.getName(), name); + } + + /** + * Returns the module path of the given LightPIT Servlet module. + * + * If you specify a malformed LightPIT servlet, which does not have a module + * annotation, the path to the /error/404.html page is returned. + * + * @param clazz the servlet class + * @return the module path + */ + public static String modulePathOf(Class clazz) { + LightPITModule moduleInfo = clazz.getAnnotation(LightPITModule.class); + if (moduleInfo == null) { + LOG.warn( + "{} is a LightPIT Servlet but is missing the module annotation.", + clazz.getName() + ); + return "/error/404.html"; + } else { + return moduleInfo.modulePath(); + } + } + + /** + * This class is not instantiatable. + */ + private Functions() {} }