26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 * |
27 * |
28 */ |
28 */ |
29 package de.uapcore.lightpit; |
29 package de.uapcore.lightpit; |
30 |
30 |
|
31 import org.slf4j.Logger; |
|
32 import org.slf4j.LoggerFactory; |
|
33 |
31 /** |
34 /** |
32 * Contains common static functions. |
35 * Contains common static functions. |
33 */ |
36 */ |
34 public class Functions { |
37 public final class Functions { |
|
38 |
|
39 private static final Logger LOG = LoggerFactory.getLogger(Functions.class); |
35 |
40 |
36 public static String jspPath(String filename) { |
41 public static String jspPath(String filename) { |
37 return Constants.JSP_PATH_PREFIX + filename; |
42 return Constants.JSP_PATH_PREFIX + filename; |
38 } |
43 } |
|
44 |
|
45 public static String fullyQualifiedName(String base, String name) { |
|
46 return base+"."+name; |
|
47 } |
|
48 |
|
49 public static String fullyQualifiedName(Class clazz, String name) { |
|
50 return fullyQualifiedName(clazz.getName(), name); |
|
51 } |
|
52 |
|
53 /** |
|
54 * Returns the module path of the given LightPIT Servlet module. |
|
55 * |
|
56 * If you specify a malformed LightPIT servlet, which does not have a module |
|
57 * annotation, the path to the <code>/error/404.html</code> page is returned. |
|
58 * |
|
59 * @param clazz the servlet class |
|
60 * @return the module path |
|
61 */ |
|
62 public static String modulePathOf(Class<? extends AbstractLightPITServlet> clazz) { |
|
63 LightPITModule moduleInfo = clazz.getAnnotation(LightPITModule.class); |
|
64 if (moduleInfo == null) { |
|
65 LOG.warn( |
|
66 "{} is a LightPIT Servlet but is missing the module annotation.", |
|
67 clazz.getName() |
|
68 ); |
|
69 return "/error/404.html"; |
|
70 } else { |
|
71 return moduleInfo.modulePath(); |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 * This class is not instantiatable. |
|
77 */ |
|
78 private Functions() {} |
39 } |
79 } |