/** * Resolves result path as a string, when parts are not important * and when only full string matters. Additional alias resolving * on full path is done. */ public String resolveResultPathString(final String path, final String value) { final ResultPath resultPath = resolveResultPath(path, value); final String result = resultPath.pathValue(); return resolveAlias(result); }
String alias = lookupAlias(value); return (alias != null ? alias : value); } else { String alias = lookupAlias(aliasName); if (alias != null) { result.append(alias);
String resultBasePath = actionRequest.getActionRuntime().getResultBasePath(); ResultPath resultPath = resultMapper.resolveResultPath(resultBasePath, resultValue);
@Test void testMethodWithPrefix() { final WebApp webapp = new WebApp(); webapp.start(); final ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class); resultMapper.setResultPathPrefix("/WEB-INF"); String path = "/boo.foo"; ResultPath resultPath = resultMapper.resolveResultPath(path, "ok"); assertEquals("/WEB-INF/boo.foo.ok", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "doo.ok"); assertEquals("/WEB-INF/boo.foo.doo.ok", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "#ok"); assertEquals("/WEB-INF/boo.ok", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "#"); assertEquals("/WEB-INF/boo", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "#doo.ok"); assertEquals("/WEB-INF/boo.doo.ok", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, null); assertEquals("/WEB-INF/boo.foo", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "/xxx"); assertEquals("/xxx", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "/xxx.ext"); assertEquals("/xxx.ext", resultPath.pathValue()); }
/** * Sets the {@link jodd.madvoc.ActionRequest#setNextActionPath(String) next action request} for the chain. */ @Override public void render(final ActionRequest actionRequest, final Object resultValue) { final Chain chainResult; if (resultValue == null) { chainResult = Chain.to(StringPool.EMPTY); } else { if (resultValue instanceof String) { chainResult = Chain.to((String)resultValue); } else { chainResult = (Chain) resultValue; } } final String resultBasePath = actionRequest.getActionRuntime().getResultBasePath(); final String resultPath = resultMapper.resolveResultPathString(resultBasePath, chainResult.path()); actionRequest.setNextActionPath(resultPath); }
value = resolveAlias(value);
@Test void testAlias() { WebApp webapp = new WebApp(); webapp.start(); ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class); actionsManager.registerAction(BooAction.class, "foo5", null); actionsManager.registerPathAlias("ok", "xxx.jsp"); actionsManager.registerPathAlias("sok", "zzz"); ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class); String path = "/boo.foo.html"; ResultPath resultPath = resultMapper.resolveResultPath(path, "/<ok>?foo=1"); assertEquals("/xxx.jsp?foo=1", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "<sok>"); assertEquals("/boo.foo.html.zzz", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "#<sok>"); assertEquals("/boo.foo.zzz", resultPath.pathValue()); resultPath = resultMapper.resolveResultPath(path, "<dude>?foo=1"); assertEquals("/xxx.html?foo=1", resultPath.pathValue()); }
resultPath = resultMapper.resolveResultPathString(resultBasePath, redirectPath);
resultValue = resolveAlias(resultValue); resultPath = resolveAlias(resultPath);
ResultPath resultPath = resultMapper.resolveResultPath(path, "ok"); assertEquals("/boo.foo.html.ok", resultPath.pathValue()); assertEquals("/boo.foo.html", resultPath.path()); assertEquals("ok", resultPath.value()); resultPath = resultMapper.resolveResultPath(path, "doo.ok"); assertEquals("/boo.foo.html.doo.ok", resultPath.pathValue()); assertEquals("/boo.foo.html", resultPath.path()); assertEquals("doo.ok", resultPath.value()); resultPath = resultMapper.resolveResultPath(path, "#ok"); assertEquals("/boo.foo.ok", resultPath.pathValue()); assertEquals("/boo.foo.ok", resultPath.path()); assertNull(resultPath.value()); resultPath = resultMapper.resolveResultPath(path, "#.ok"); assertEquals("/boo.foo.ok", resultPath.pathValue()); assertEquals("/boo.foo", resultPath.path()); assertEquals("ok", resultPath.value()); resultPath = resultMapper.resolveResultPath(path, "#.ok.do"); assertEquals("/boo.foo.ok.do", resultPath.pathValue()); assertEquals("/boo.foo", resultPath.path()); assertEquals("ok.do", resultPath.value()); resultPath = resultMapper.resolveResultPath(path, "##ok"); assertEquals("/boo.ok", resultPath.pathValue()); assertEquals("/boo.ok", resultPath.path()); assertNull(resultPath.value());
/** * Redirects to the given location. Provided path is parsed, action is used as a value context. */ @Override public void render(final ActionRequest actionRequest, final Object resultValue) { final PermRedirect redirectResult; if (resultValue == null) { redirectResult = PermRedirect.to(StringPool.SLASH); } else { if (resultValue instanceof String) { redirectResult = PermRedirect.to((String)resultValue); } else { redirectResult = (PermRedirect) resultValue; } } final String resultBasePath = actionRequest.getActionRuntime().getResultBasePath(); final String redirectValue = redirectResult.path(); final String resultPath; if (redirectValue.startsWith("http://") || redirectValue.startsWith("https://")) { resultPath = redirectValue; } else { resultPath = resultMapper.resolveResultPathString(resultBasePath, redirectValue); } final HttpServletRequest request = actionRequest.getHttpServletRequest(); final HttpServletResponse response = actionRequest.getHttpServletResponse(); String path = beanTemplateParser.parseWithBean(resultPath, actionRequest.getAction()); DispatcherUtil.redirectPermanent(request, response, path); }
if ((target = targetCache.get(key)) == null) { ResultPath resultPath = resultMapper.resolveResultPath(actionRequest.getActionPath(), customPath);
@Test void testAlias2() { WebApp webapp = new WebApp(); webapp.start(); ActionsManager actionsManager = webapp.madvocContainer().lookupComponent(ActionsManager.class); actionsManager.registerAction(BooAction.class, "foo2", null); actionsManager.registerPathAlias("/boo.foo2.xxx", "/aliased"); ResultMapper resultMapper = webapp.madvocContainer().lookupComponent(ResultMapper.class); ActionMethodParser actionMethodParser = webapp.madvocContainer().lookupComponent(ActionMethodParser.class); ActionRuntime cfg = parse(actionMethodParser, "fixtures.tst.BooAction#foo2"); String path = cfg.getActionPath(); String resultPath = resultMapper.resolveResultPathString(path, null); assertEquals("/aliased", resultPath); }
ServletUtil.preventCaching(req.getHttpServletResponse()); String resultPath = resultMapper.resolveResultPath(req.getActionConfig(), resultValue); result.render(req, resultObject, resultValue, resultPath);