alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (BuildDocHandlerFactory.java)

This example Play Framework source code file (BuildDocHandlerFactory.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

aggregatefilerepository, api, builddochandler, builddochandlerfactory, core, documentationhandler, filerepository, filesystemrepository, jarfile, jarrepository, mvc, play, play framework, string

The BuildDocHandlerFactory.java Play Framework example source code

/*
 * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 */
package play.docs;

import java.io.File;
import java.util.jar.JarFile;

import play.api.mvc.RequestHeader;
import play.core.BuildDocHandler;
import play.doc.FileRepository;
import play.doc.FilesystemRepository;
import play.doc.JarRepository;
import scala.Option;

/**
 * Provides a way for build code to create BuildDocHandler objects.
 * <p/>
 * <p>This class is used by the Play build plugin run command (to serve
 * documentation from a JAR) and by the Play documentation project (to
 * serve documentation from the filesystem).
 * <p/>
 * <p>This class is written in Java and uses only Java types so that
 * communication can work even when the build code and the play-docs project
 * are built with different versions of Scala.
 */
public class BuildDocHandlerFactory {

    /**
     * Create an BuildDocHandler that serves documentation from a given directory by
     * wrapping a FilesystemRepository.
     *
     * @param directory The directory to serve the documentation from.
     */
    public static BuildDocHandler fromDirectory(File directory) {
        FileRepository repo = new FilesystemRepository(directory);
        return new DocumentationHandler(repo);
    }

    /**
     * Create an BuildDocHandler that serves the manual from a given directory by
     * wrapping a FilesystemRepository, and the API docs from a given JAR file by
     * wrapping a JarRepository
     *
     * @param directory The directory to serve the documentation from.
     * @param jarFile The JAR file to server the documentation from.
     * @param base    The directory within the JAR file to serve the documentation from, or null if the
     *                documentation should be served from the root of the JAR.
     */
    public static BuildDocHandler fromDirectoryAndJar(File directory, JarFile jarFile, String base) {
        return fromDirectoryAndJar(directory, jarFile, base, false);
    }

    /**
     * Create an BuildDocHandler that serves the manual from a given directory by
     * wrapping a FilesystemRepository, and the API docs from a given JAR file by
     * wrapping a JarRepository.
     *
     * @param directory The directory to serve the documentation from.
     * @param jarFile The JAR file to server the documentation from.
     * @param base    The directory within the JAR file to serve the documentation from, or null if the
     *                documentation should be served from the root of the JAR.
     * @param fallbackToJar Whether the doc handler should fall back to the jar repo for docs.
     */
    public static BuildDocHandler fromDirectoryAndJar(File directory, JarFile jarFile, String base, boolean fallbackToJar) {
        FileRepository fileRepo = new FilesystemRepository(directory);
        FileRepository jarRepo = new JarRepository(jarFile, Option.apply(base));
        FileRepository manualRepo;
        if (fallbackToJar) {
            manualRepo = new AggregateFileRepository(new FileRepository[] { fileRepo, jarRepo });
        } else {
            manualRepo = fileRepo;
        }

        return new DocumentationHandler(manualRepo, jarRepo);
    }

    /**
     * Create an BuildDocHandler that serves documentation from a given JAR file by
     * wrapping a JarRepository.
     *
     * @param jarFile The JAR file to server the documentation from.
     * @param base    The directory within the JAR file to serve the documentation from, or null if the
     *                documentation should be served from the root of the JAR.
     */
    public static BuildDocHandler fromJar(JarFile jarFile, String base) {
        FileRepository repo = new JarRepository(jarFile, Option.apply(base));
        return new DocumentationHandler(repo);
    }

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework BuildDocHandlerFactory.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.