package org.sothis.mvc.util; import org.sothis.core.util.StringUtils; import org.sothis.mvc.ActionInvocation; public class MvcUtils { /** * <p> * 根据ActionInvocation及提供的path,解析出对应的路径。 * </p> * * <pre> * MockActionInvocation invocation = new MockActionInvocation(); * Controller controller = new DefaultController("", "test", TestController.class); * invocation.setAction(controller.getAction("test")); * * MvcUtils.resolvePath(null, invocation) = "/test/test" * MvcUtils.resolvePath("", invocation) = "/test/test" * MvcUtils.resolvePath("abcd", invocation) = "/test/abcd" * MvcUtils.resolvePath("/abcd", invocation) = "/abcd" * MvcUtils.resolvePath("/", invocation) = "/" * </pre> * * @param path * @param invocation * @return */ public static String resolvePath(String path, ActionInvocation invocation) { if (StringUtils.isEmpty(path)) { return invocation.getAction().getFullName(); } else { if (path.charAt(0) == '/') { return path; } else { return new StringBuilder().append(invocation.getAction().getController().getFullName()).append(path).toString(); } } } }