Search in sources :

Example 1 with ResultPath

use of jodd.madvoc.config.ResultPath in project jodd by oblac.

the class ActionResultTest method testAlias.

@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());
}
Also used : ActionsManager(jodd.madvoc.component.ActionsManager) ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Example 2 with ResultPath

use of jodd.madvoc.config.ResultPath in project jodd by oblac.

the class ActionResultTest method testMethodWithPrefix.

@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());
}
Also used : ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Example 3 with ResultPath

use of jodd.madvoc.config.ResultPath in project jodd by oblac.

the class ActionResultTest method testResolveResultPath.

@Test
void testResolveResultPath() {
    WebApp webapp = new WebApp();
    webapp.start();
    ResultMapper resultMapper = webapp.madvocContainer.lookupComponent(ResultMapper.class);
    String path = "/boo.foo.html";
    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());
    resultPath = resultMapper.resolveResultPath(path, "##.ok");
    assertEquals("/boo.ok", resultPath.pathValue());
    assertEquals("/boo", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok.do");
    assertEquals("/boo.ok.do", resultPath.pathValue());
    assertEquals("/boo.ok.do", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok..do");
    assertEquals("/boo.ok.do", resultPath.pathValue());
    assertEquals("/boo.ok", resultPath.path());
    assertEquals("do", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#");
    assertEquals("/boo.foo", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, null);
    assertEquals("/boo.foo.html", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "/xxx");
    assertEquals("/xxx", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "/xxx.ext");
    assertEquals("/xxx.ext", resultPath.path());
    assertNull(resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "/xxx..ext");
    assertEquals("/xxx", resultPath.path());
    assertEquals("ext", resultPath.value());
    path = "/boo.html";
    resultPath = resultMapper.resolveResultPath(path, "ok");
    assertEquals("/boo.html", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "#.ok");
    assertEquals("/boo", resultPath.path());
    assertEquals("ok", resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##ok");
    assertEquals("/ok", resultPath.path());
    assertEquals(null, resultPath.value());
    resultPath = resultMapper.resolveResultPath(path, "##.ok");
    assertEquals("/", resultPath.path());
    assertEquals("ok", resultPath.value());
}
Also used : ResultMapper(jodd.madvoc.component.ResultMapper) ResultPath(jodd.madvoc.config.ResultPath) Test(org.junit.jupiter.api.Test)

Example 4 with ResultPath

use of jodd.madvoc.config.ResultPath in project jodd by oblac.

the class ResultMapper method resolveResultPathString.

/**
 * 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);
}
Also used : ResultPath(jodd.madvoc.config.ResultPath)

Example 5 with ResultPath

use of jodd.madvoc.config.ResultPath in project jodd by oblac.

the class AbstractTemplateViewActionResult method resolveTarget.

/**
 * Locates the target file from action path and the result value.
 */
protected String resolveTarget(final ActionRequest actionRequest, final String resultValue) {
    final String resultBasePath = actionRequest.getActionRuntime().getResultBasePath();
    final ResultPath resultPath = resultMapper.resolveResultPath(resultBasePath, resultValue);
    final String actionPath = resultPath.path();
    String path = actionPath;
    String value = resultPath.value();
    if (StringUtil.isEmpty(value)) {
        value = null;
    }
    String target;
    while (true) {
        // variant #1: with value
        if (value != null) {
            if (path == null) {
                // only value remains
                final int lastSlashNdx = actionPath.lastIndexOf('/');
                if (lastSlashNdx != -1) {
                    target = actionPath.substring(0, lastSlashNdx + 1) + value;
                } else {
                    target = '/' + value;
                }
            } else {
                target = path + '.' + value;
            }
            target = locateTarget(actionRequest, target);
            if (target != null) {
                break;
            }
        }
        if (path != null) {
            // variant #2: without value
            target = locateTarget(actionRequest, path);
            if (target != null) {
                break;
            }
        }
        if (path == null) {
            // path not found
            return null;
        }
        final int dotNdx = MadvocUtil.lastIndexOfDotAfterSlash(path);
        if (dotNdx == -1) {
            path = null;
        } else {
            path = path.substring(0, dotNdx);
        }
    }
    return target;
}
Also used : ResultPath(jodd.madvoc.config.ResultPath)

Aggregations

ResultPath (jodd.madvoc.config.ResultPath)5 ResultMapper (jodd.madvoc.component.ResultMapper)3 Test (org.junit.jupiter.api.Test)3 ActionsManager (jodd.madvoc.component.ActionsManager)1