##### Coverage Report - DocViewerPlugin

Classes in this File | Line Coverage | Branch Coverage | Complexity
DocViewerPlugin |
66 % | 10/15
25 % | 1/4
| 2.5;2,5

1 |  |
     import play.*;
2 |  |
     import play.mvc.Http.*;
3 |  |
     import play.mvc.*;
4 |  |
     import play.libs.*;
5 |  |
6 |  |
     import java.io.*;
7 |  |
8 | 2 |
     public class DocViewerPlugin extends PlayPlugin {
9 |  |
10 |  |
         @Override
11 |  |
         public boolean rawInvocation(Request request, Response response) throws Exception {
12 | 4 |
             if(request.path.startsWith("/@api/")) {
13 | 0 |
                 File f = new File(Play.frameworkPath, "documentation/api/"+request.path.substring(6));
14 | 0 |
                 if(f.exists()) {
15 | 0 |
                     response.contentType = MimeTypes.getMimeType(f.getName());
16 | 0 |
                     response.out.write(IO.readContent(f));
17 |  |
                 }
18 | 0 |
                 return true;
19 |  |
             }
20 | 4 |
             return false;
21 |  |
         }
22 |  |
23 |  |
         @Override
24 |  |
         public void onRoutesLoaded() {
25 | 1 |
             Router.addRoute("GET", "/@documentation/?", "PlayDocumentation.index");
26 | 1 |
             Router.addRoute("GET", "/@documentation/{id}", "PlayDocumentation.page");
27 | 1 |
             Router.addRoute("GET", "/@documentation/images/{name}", "PlayDocumentation.image");
28 | 1 |
             Router.addRoute("GET", "/@documentation/files/{name}", "PlayDocumentation.file");
29 | 1 |
             Router.addRoute("GET", "/@documentation/modules/{module}/{id}", "PlayDocumentation.page");
30 | 1 |
             Router.addRoute("GET", "/@documentation/modules/{module}/images/{name}", "PlayDocumentation.image");
31 | 1 |
         }
32 |  |
33 |  |
     }