1.1 --- a/src/java/de/uapcore/lightpit/Functions.java Sat Dec 16 20:19:28 2017 +0100 1.2 +++ b/src/java/de/uapcore/lightpit/Functions.java Sun Dec 17 01:45:28 2017 +0100 1.3 @@ -28,6 +28,8 @@ 1.4 */ 1.5 package de.uapcore.lightpit; 1.6 1.7 +import java.util.Optional; 1.8 +import javax.servlet.http.HttpServletRequest; 1.9 import org.slf4j.Logger; 1.10 import org.slf4j.LoggerFactory; 1.11 1.12 @@ -42,12 +44,27 @@ 1.13 return Constants.JSP_PATH_PREFIX + filename; 1.14 } 1.15 1.16 - public static String fullyQualifiedName(String base, String name) { 1.17 + public static String fqn(String base, String name) { 1.18 return base+"."+name; 1.19 } 1.20 1.21 - public static String fullyQualifiedName(Class clazz, String name) { 1.22 - return fullyQualifiedName(clazz.getName(), name); 1.23 + public static String fqn(Class clazz, String name) { 1.24 + return fqn(clazz.getName(), name); 1.25 + } 1.26 + 1.27 + public static String fullPath(LightPITModule module, RequestMapping mapping) { 1.28 + StringBuilder sb = new StringBuilder(); 1.29 + sb.append(module.modulePath()); 1.30 + sb.append('/'); 1.31 + if (!mapping.requestPath().isEmpty()) { 1.32 + sb.append(mapping.requestPath().isEmpty()); 1.33 + sb.append('/'); 1.34 + } 1.35 + return sb.toString(); 1.36 + } 1.37 + 1.38 + public static String fullPath(HttpServletRequest req) { 1.39 + return req.getServletPath() + Optional.ofNullable(req.getPathInfo()).orElse(""); 1.40 } 1.41 1.42 /** 1.43 @@ -60,15 +77,15 @@ 1.44 * @return the module path 1.45 */ 1.46 public static String modulePathOf(Class<? extends AbstractLightPITServlet> clazz) { 1.47 - LightPITModule moduleInfo = clazz.getAnnotation(LightPITModule.class); 1.48 - if (moduleInfo == null) { 1.49 + Optional<LightPITModule> moduleInfo = Optional.ofNullable(clazz.getAnnotation(LightPITModule.class)); 1.50 + if (moduleInfo.isPresent()) { 1.51 + return moduleInfo.get().modulePath(); 1.52 + } else { 1.53 LOG.warn( 1.54 "{} is a LightPIT Servlet but is missing the module annotation.", 1.55 clazz.getName() 1.56 ); 1.57 return "/error/404.html"; 1.58 - } else { 1.59 - return moduleInfo.modulePath(); 1.60 } 1.61 } 1.62