org.takes.rs.xe.XeDirectives Java Examples

The following examples show how to use org.takes.rs.xe.XeDirectives. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TkMistakes.java    From jpeek with MIT License 6 votes vote down vote up
@Override
public Response act(final Request req) {
    return new RsPage(
        req, "mistakes",
        () -> new IterableOf<>(
            new XeAppend(
                "worst",
                new XeDirectives(
                    new Joined<>(
                        new HeadOf<Iterable<Directive>>(
                            // @checkstyle MagicNumber (1 line)
                            20, new Mistakes().worst()
                        )
                    )
                )
            )
        )
    );
}
 
Example #2
Source File: TkAll.java    From jpeek with MIT License 6 votes vote down vote up
@Override
public Response act(final Request req) {
    return new RsPage(
        req, "all",
        () -> new IterableOf<>(
            new XeAppend(
                "recent",
                new XeDirectives(
                    new Joined<>(
                        new Results().all()
                    )
                )
            )
        )
    );
}
 
Example #3
Source File: TkDomains.java    From jare with MIT License 6 votes vote down vote up
/**
 * Convert event to Xembly.
 * @param domain The event
 * @return Xembly
 * @throws IOException If fails
 */
private static XeSource source(final Domain domain) throws IOException {
    final String name = domain.name();
    final Usage usage = domain.usage();
    return new XeDirectives(
        new Directives()
            .add("domain")
            .add("name").set(name).up()
            .add("usage").set(usage.total()).up()
            .append(
                new XeLink(
                    "delete",
                    new Href("/delete").with("name", name)
                ).toXembly()
            )
            .up()
    );
}
 
Example #4
Source File: TkIndex.java    From jpeek with MIT License 5 votes vote down vote up
@Override
public Response act(final Request req) {
    return new RsPage(
        req, "index",
        () -> new IterableOf<>(
            new XeAppend(
                "best",
                new XeDirectives(
                    new Joined<>(
                        new HeadOf<>(
                            // @checkstyle MagicNumber (1 line)
                            20, new Results().best()
                        )
                    )
                )
            ),
            new XeAppend(
                "recent",
                new XeDirectives(
                    new Joined<>(
                        new HeadOf<>(
                            // @checkstyle MagicNumber (1 line)
                            25, new Results().recent()
                        )
                    )
                )
            )
        )
    );
}
 
Example #5
Source File: RsPage.java    From jpeek with MIT License 5 votes vote down vote up
/**
 * Make it.
 * @param req Request
 * @param xsl XSL stylesheet
 * @param src Sources
 * @return Response
 */
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
private static Response make(final Request req, final String xsl,
    final Scalar<Iterable<XeSource>> src) {
    final Response raw = new RsXembly(
        new XeChain(
            new XeStylesheet(
                String.format("/org/jpeek/web/%s.xsl", xsl)
            ),
            new XeAppend(
                "page",
                new XeChain(
                    new XeMillis(),
                    new XeDirectives(new Header()),
                    new XeChain(src),
                    new XeMillis(true)
                )
            )
        )
    );
    return new RsFork(
        req,
        new FkTypes(
            "text/html",
            new RsXslt(new RsWithType(raw, "text/html"))
        ),
        new FkTypes(
            "application/vnd.jpeek+xml",
            new RsPrettyXml(new RsWithType(raw, "text/xml"))
        ),
        new FkTypes("*/*", raw)
    );
}
 
Example #6
Source File: TkIndex.java    From jare with MIT License 5 votes vote down vote up
/**
 * Convert event to Xembly.
 * @param domain The event
 * @return Xembly
 * @throws IOException If fails
 */
private static XeSource source(final Domain domain) throws IOException {
    return new XeDirectives(
        new Directives()
            .add("domain")
            .add("name").set(domain.name()).up()
            .add("owner").set(domain.owner()).up()
            .add("usage").set(domain.usage().total()).up()
            .up()
    );
}
 
Example #7
Source File: PsGithubTest.java    From takes with MIT License 4 votes vote down vote up
/**
 * Performs the basic login.
 * @param directive The directive object.
 * @throws Exception If some problem inside.
 */
private void performLogin(final Directives directive) throws Exception {
    final String app = "app";
    final String key = "key";
    final Take take = new TkFork(
        new FkRegex(
            "/login/oauth/access_token",
            new Take() {
                @Override
                public Response act(final Request req) throws IOException {
                    final Request greq = new RqGreedy(req);
                    final String code = "code";
                    PsGithubTest.assertParam(greq, code, code);
                    PsGithubTest.assertParam(greq, "client_id", app);
                    PsGithubTest.assertParam(greq, "client_secret", key);
                    return new RsXembly(
                        new XeDirectives(directive.toString())
                    );
                }
            }
        ),
        new FkRegex(
            "/user",
            new TkFakeLogin()
        )
    );
    new FtRemote(take).exec(
        // @checkstyle AnonInnerLengthCheck (100 lines)
        new FtRemote.Script() {
            @Override
            public void exec(final URI home) throws IOException {
                final Identity identity = new PsGithub(
                    app,
                    key,
                    home.toString(),
                    home.toString()
                ).enter(new RqFake("GET", "?code=code")).get();
                MatcherAssert.assertThat(
                    identity.urn(),
                    Matchers.equalTo("urn:github:1")
                );
                MatcherAssert.assertThat(
                    identity.properties().get(PsGithubTest.LOGIN),
                    Matchers.equalTo(PsGithubTest.OCTOCAT)
                );
                MatcherAssert.assertThat(
                    identity.properties().get("avatar"),
                    Matchers.equalTo(PsGithubTest.OCTOCAT_GIF_URL)
                );
            }
        }
    );
}