org.takes.facets.fork.RsFork Java Examples

The following examples show how to use org.takes.facets.fork.RsFork. 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: TkGzip.java    From takes with MIT License 6 votes vote down vote up
/**
 * Ctor.
 * @param take Original take
 */
public TkGzip(final Take take) {
    super(
        new Take() {
            @Override
            public Response act(final Request req) throws Exception {
                final Response response = take.act(req);
                return new RsFork(
                    req,
                    new FkEncoding("gzip", new RsGzip(response)),
                    new FkEncoding("", response)
                );
            }
        }
    );
}
 
Example #2
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 #3
Source File: RsPage.java    From jare with MIT License 4 votes vote down vote up
/**
 * Make it.
 * @param xsl XSL
 * @param req Request
 * @param src Source
 * @return Response
 * @throws IOException If fails
 */
private static Response make(final String xsl, final Request req,
    final Iterable<XeSource> src) throws IOException {
    final Response raw = new RsXembly(
        new XeStylesheet(xsl),
        new XeAppend(
            "page",
            new XeMillis(false),
            new XeChain(src),
            new XeLinkHome(req),
            new XeLinkSelf(req),
            new XeMillis(true),
            new XeDate(),
            new XeSla(),
            new XeLocalhost(),
            new XeFlash(req),
            new XeWhen(
                new RqAuth(req).identity().equals(Identity.ANONYMOUS),
                new XeChain(
                    new XeGithubLink(req, Manifests.read("Jare-GithubId"))
                )
            ),
            new XeWhen(
                !new RqAuth(req).identity().equals(Identity.ANONYMOUS),
                new XeChain(
                    new XeIdentity(req),
                    new XeLogoutLink(req),
                    new XeLink("domains", "/domains")
                )
            ),
            new XeAppend(
                "version",
                new XeAppend("name", Manifests.read("Jare-Version")),
                new XeAppend("revision", Manifests.read("Jare-Revision")),
                new XeAppend("date", Manifests.read("Jare-Date")),
                new XeAppend("heroku", RsPage.heroku())
            )
        )
    );
    return new RsFork(
        req,
        new FkTypes(
            "application/xml,text/xml",
            new RsPrettyXml(new RsWithType(raw, "text/xml"))
        ),
        new FkTypes(
            "*/*",
            new RsXslt(new RsWithType(raw, "text/html"))
        )
    );
}