src/java/de/uapcore/lightpit/Functions.java

changeset 10
89e3e6e28b69
parent 7
598670d5b0b8
child 11
737ab27e37b3
     1.1 --- a/src/java/de/uapcore/lightpit/Functions.java	Fri Dec 15 17:39:54 2017 +0100
     1.2 +++ b/src/java/de/uapcore/lightpit/Functions.java	Sat Dec 16 20:19:28 2017 +0100
     1.3 @@ -28,12 +28,52 @@
     1.4   */
     1.5  package de.uapcore.lightpit;
     1.6  
     1.7 +import org.slf4j.Logger;
     1.8 +import org.slf4j.LoggerFactory;
     1.9 +
    1.10  /**
    1.11   * Contains common static functions.
    1.12   */
    1.13 -public class Functions {
    1.14 +public final class Functions {
    1.15 +    
    1.16 +    private static final Logger LOG = LoggerFactory.getLogger(Functions.class);
    1.17  
    1.18      public static String jspPath(String filename) {
    1.19          return Constants.JSP_PATH_PREFIX + filename;
    1.20      }
    1.21 +    
    1.22 +    public static String fullyQualifiedName(String base, String name) {
    1.23 +        return base+"."+name;
    1.24 +    }
    1.25 +    
    1.26 +    public static String fullyQualifiedName(Class clazz, String name) {
    1.27 +        return fullyQualifiedName(clazz.getName(), name);
    1.28 +    }
    1.29 +    
    1.30 +    /**
    1.31 +     * Returns the module path of the given LightPIT Servlet module.
    1.32 +     * 
    1.33 +     * If you specify a malformed LightPIT servlet, which does not have a module
    1.34 +     * annotation, the path to the <code>/error/404.html</code> page is returned.
    1.35 +     * 
    1.36 +     * @param clazz the servlet class
    1.37 +     * @return the module path
    1.38 +     */
    1.39 +    public static String modulePathOf(Class<? extends AbstractLightPITServlet> clazz) {
    1.40 +        LightPITModule moduleInfo = clazz.getAnnotation(LightPITModule.class);
    1.41 +        if (moduleInfo == null) {
    1.42 +            LOG.warn(
    1.43 +                    "{} is a LightPIT Servlet but is missing the module annotation.",
    1.44 +                    clazz.getName()
    1.45 +            );
    1.46 +            return "/error/404.html";
    1.47 +        } else {
    1.48 +            return moduleInfo.modulePath();
    1.49 +        }
    1.50 +    }
    1.51 +    
    1.52 +    /**
    1.53 +     * This class is not instantiatable.
    1.54 +     */
    1.55 +    private Functions() {}
    1.56  }

mercurial