@Test void testLasNdx() { assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("")); assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("xxx")); assertEquals(0, MadvocUtil.lastIndexOfDotAfterSlash(".xxx")); assertEquals(3, MadvocUtil.lastIndexOfDotAfterSlash("xxx.")); assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("/xxx")); assertEquals(1, MadvocUtil.lastIndexOfDotAfterSlash("/.xxx")); assertEquals(4, MadvocUtil.lastIndexOfDotAfterSlash("/xxx.")); assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("/xxx/")); assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("/.xxx/")); assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("/xxx./")); assertEquals(-1, MadvocUtil.lastIndexOfDotAfterSlash("/xxx/xxx")); assertEquals(6, MadvocUtil.lastIndexOfDotAfterSlash("/.xxx/.xxx")); assertEquals(9, MadvocUtil.lastIndexOfDotAfterSlash("/xxx./xxx.")); }
break; int dotNdx = MadvocUtil.lastIndexOfSlashDot(path); if (dotNdx != -1) {
/** * Reads action path from class. If the class is annotated with {@link MadvocAction} annotation, * class action path will be read from annotation value. Otherwise, action class path will be built from the * class name. This is done by removing the package name and the last contained word * (if there is more then one) from the class name. Such name is finally uncapitalized. */ protected String[] readClassActionPath(final Class actionClass) { // read class annotation MadvocAction madvocActionAnnotation = ((Class<?>)actionClass).getAnnotation(MadvocAction.class); String classActionPath = madvocActionAnnotation != null ? madvocActionAnnotation.value().trim() : null; if (StringUtil.isEmpty(classActionPath)) { classActionPath = null; } String actionClassName = actionClass.getSimpleName(); actionClassName = StringUtil.uncapitalize(actionClassName); actionClassName = MadvocUtil.stripLastCamelWord(actionClassName); // removes 'Action' from the class name if (classActionPath == null) { classActionPath = actionClassName; } return ArraysUtil.array(actionClassName, classActionPath); }
name = MadvocUtil.stripLastCamelWord(name); resultValue = StringUtil.replace(resultValue, REPL_CLASS, name); int dotNdx = MadvocUtil.lastIndexOfDotAfterSlash(resultPath); if (dotNdx != -1) { resultPath = resultPath.substring(0, dotNdx); break; int dotNdx = MadvocUtil.lastIndexOfSlashDot(resultPath); if (dotNdx != -1) { resultPath = resultPath.substring(0, dotNdx);
public MyActionRequest(MadvocController madvocController, String actionPath, ActionRuntime config, Object action, HttpServletRequest servletRequest, HttpServletResponse servletResponse) { super(madvocController, actionPath, MadvocUtil.splitPathToChunks(actionPath), config, action, servletRequest, servletResponse); } @Override
@Test void testSplitActionPath() { assertTrue(Arrays.equals(new String[]{"qqq"}, MadvocUtil.splitActionPath("/qqq"))); assertTrue(Arrays.equals(new String[]{"qqq", "www"}, MadvocUtil.splitActionPath("/qqq/www"))); assertTrue(Arrays.equals(new String[]{"qqq", "www", "eee"}, MadvocUtil.splitActionPath("/qqq/www/eee"))); }
@Test void testFirstNdx() { assertEquals(-1, MadvocUtil.indexOfDotAfterSlash("xxx")); assertEquals(0, MadvocUtil.indexOfDotAfterSlash(".xxx")); assertEquals(3, MadvocUtil.indexOfDotAfterSlash("xxx.")); assertEquals(-1, MadvocUtil.indexOfDotAfterSlash("/xxx")); assertEquals(1, MadvocUtil.indexOfDotAfterSlash("/.xxx")); assertEquals(4, MadvocUtil.indexOfDotAfterSlash("/xxx.")); assertEquals(-1, MadvocUtil.indexOfDotAfterSlash("/xxx/")); assertEquals(-1, MadvocUtil.indexOfDotAfterSlash("/.xxx/")); assertEquals(-1, MadvocUtil.indexOfDotAfterSlash("/xxx./")); assertEquals(-1, MadvocUtil.indexOfDotAfterSlash("/xxx/xxx")); assertEquals(6, MadvocUtil.indexOfDotAfterSlash("/.xxx/.xxx")); assertEquals(9, MadvocUtil.indexOfDotAfterSlash("/xxx./xxx.")); }
protected ActionRequest createActionRequest(String actionPath) { HttpServletRequest servletRequest = mock(HttpServletRequest.class); HttpServletResponse servletResponse = mock(HttpServletResponse.class); HttpSession httpSession = mock(HttpSession.class); ServletContext servletContext = mock(ServletContext.class); when(servletRequest.getSession()).thenReturn(httpSession); when(httpSession.getServletContext()).thenReturn(servletContext); MadvocController madvocController = new MadvocController(); Object action = new Object(); ActionRuntime actionRuntime = new ActionRuntime( null, Action.class, ClassUtil.findMethod(Action.class, "view"), null, null, new ActionDefinition(actionPath, "GET"), ServletDispatcherActionResult.class, null, false, false, null, null); return new ActionRequest(madvocController, actionRuntime.getActionPath(), MadvocUtil.splitPathToChunks(actionRuntime.getActionPath()), actionRuntime, action, servletRequest, servletResponse); }
/** * Creates new action request and action object. */ public ActionRequest(String actionPath, ActionConfig config, Object action, HttpServletRequest servletRequest, HttpServletResponse servletResponse) { this.actionPath = actionPath; this.actionPathChunks = MadvocUtil.splitActionPath(actionPath); this.config = config; this.servletRequest = servletRequest; this.servletResponse = servletResponse; totalInterceptors = (this.config.interceptors != null ? this.config.interceptors.length : 0); interceptorIndex = 0; this.action = action; }
int dotNdx = MadvocUtil.lastIndexOfDotAfterSlash(path); if (dotNdx == -1) { path = null;
String[] actionPathChunks = MadvocUtil.splitPathToChunks(actionPath); actionPathChunks = MadvocUtil.splitPathToChunks(actionPath); actionRuntime = actionsManager.lookup(httpMethod, actionPathChunks);
@Test void testActionName() { assertEquals("foo", MadvocUtil.stripLastCamelWord("fooAction")); assertEquals("foo", MadvocUtil.stripLastCamelWord("foo")); assertEquals("fooBoo", MadvocUtil.stripLastCamelWord("fooBooAction")); assertEquals("fooBoo", MadvocUtil.stripLastCamelWord("fooBooZoooo")); }
@Test void testLasNdx2() { String s = "/xxx.zzzz.wwww"; int i = MadvocUtil.lastIndexOfSlashDot(s); assertEquals(9, i); s = s.substring(0, i); assertEquals("/xxx.zzzz", s); i = MadvocUtil.lastIndexOfSlashDot(s); assertEquals(4, i); s = s.substring(0, i); assertEquals("/xxx", s); i = MadvocUtil.lastIndexOfSlashDot(s); assertEquals(1, i); s = s.substring(0, i); assertEquals("/", s); i = MadvocUtil.lastIndexOfSlashDot(s); assertEquals(-1, i); assertEquals(-1, MadvocUtil.lastIndexOfSlashDot("")); assertEquals(-1, MadvocUtil.lastIndexOfSlashDot("xxx")); assertEquals(0, MadvocUtil.lastIndexOfSlashDot(".xxx")); assertEquals(3, MadvocUtil.lastIndexOfSlashDot("xxx.")); assertEquals(1, MadvocUtil.lastIndexOfSlashDot("/xxx")); assertEquals(1, MadvocUtil.lastIndexOfSlashDot("/.xxx")); assertEquals(4, MadvocUtil.lastIndexOfSlashDot("/xxx."));
public ActionConfigSet(String actionPath) { this.actionPath = actionPath; this.actionPathChunks = MadvocUtil.splitActionPath(actionPath); this.actionPathMacros = resolveMacros(actionPathChunks); }
int dotNdx = MadvocUtil.lastIndexOfDotAfterSlash(resultPath); if (dotNdx == -1) { response.sendError(SC_NOT_FOUND, "Result '" + originalResultPath + EXTENSION + "' or any its variant not found.");
@Test void testActionPathMacros1() { WebApp webapp = new WebApp(); webapp.start(); ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class); actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one}")); ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo")); assertNotNull(actionRuntime); actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo/boo")); assertNull(actionRuntime); actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo/boo/zoo")); assertNull(actionRuntime); }
/** * Reads action path from class. If the class is annotated with {@link MadvocAction} annotation, * class action path will be read from annotation value. Otherwise, action class path will be built from the * class name. This is done by removing the package name and the last contained word * (if there is more then one) from the class name. Such name is finally uncapitalized. * <p> * If this method returns <code>null</code> class will be ignored. */ protected String readClassActionPath(Class actionClass) { // read annotation MadvocAction madvocActionAnnotation = ((Class<?>)actionClass).getAnnotation(MadvocAction.class); String classActionPath = madvocActionAnnotation != null ? madvocActionAnnotation.value().trim() : null; if (StringUtil.isEmpty(classActionPath)) { classActionPath = null; } String name = actionClass.getSimpleName(); name = StringUtil.uncapitalize(name); name = MadvocUtil.stripLastCamelWord(name); // decide if (classActionPath == null) { classActionPath = name; } else { classActionPath = StringUtil.replace(classActionPath, REPL_CLASS, name); } return classActionPath; }
/** * Performs action config lookup from action path and http request method. * Lookups action configuration from action path and resolves * unregistered paths. Lookup may be optionally disabled if mapping is not used. */ public ActionConfig resolveActionConfig(String actionPath, String method) { String[] actionPathChunks = MadvocUtil.splitActionPath(actionPath); ActionConfig cfg = actionsManager.lookup(actionPath, actionPathChunks, method); if ((cfg == null) && madvocConfig.isActionPathMappingEnabled()) { String packageRoot = madvocConfig.getRootPackage(); if (packageRoot != null) { cfg = registerActionPath(actionPath, packageRoot); // cfg = actionsManager.lookup(actionPath, actionPathChunks); } } if ((cfg == null) && madvocConfig.getSupplementAction() != null) { cfg = registerSupplementAction(actionPath); // cfg = actionsManager.lookup(actionPath, actionPathChunks); } return cfg; }
int dotNdx = MadvocUtil.lastIndexOfDotAfterSlash(path); if (dotNdx == -1) { path = null;
@Test void testActionPathMacros2() { WebApp webapp = new WebApp(); webapp.start(); ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class); actionsManager.registerAction(FooAction.class, "two", new ActionDefinition("/xxx-{two}")); actionsManager.registerAction(FooAction.class, "one", new ActionDefinition("/{one}")); ActionRuntime actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo")); assertEquals("one", actionRuntime.getActionClassMethod().getName()); actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/foo/boo")); assertNull(actionRuntime); actionRuntime = actionsManager.routes.lookup(null, MadvocUtil.splitPathToChunks("/xxx-foo")); assertEquals("two", actionRuntime.getActionClassMethod().getName()); // best match! }