package technology.tabula.tabula_web.routes;


import java.util.Scanner;

import spark.RouteGroup;
import technology.tabula.tabula_web.App;
import technology.tabula.tabula_web.workspace.WorkspaceDAO;

import static spark.Spark.*;


public class IndexRouteGroup implements RouteGroup {

	private String[] indexes = new String[] { "pdf/:file_id", "help", "about" };
	private WorkspaceDAO workspaceDAO; 
	
	public IndexRouteGroup(WorkspaceDAO workspaceDAO) {
		this.workspaceDAO = workspaceDAO;
	}

	@Override
	public void addRoutes() {
		for(String path: indexes) {
			get(path, (req, rsp) -> this.getIndex());
		}
		post("upload.json", new UploadRoute(workspaceDAO));
	}
	
	@SuppressWarnings("resource")
	private String getIndex() {
		String index = new Scanner(App.class.getClassLoader().getResourceAsStream("public/index.html"), "UTF-8").useDelimiter("\\A").next();
		return index;
	}
	
}
@@ -279,25 +279,28 @@
 roup %7B%0A%0A
-%09
+    
 private 
 String%5B%5D
@@ -287,24 +287,231 @@
     private 
+static final String index;%0A%0A    static %7B%0A        index = new Scanner(App.class.getClassLoader().getResourceAsStream(%22public/index.html%22), %22UTF-8%22).useDelimiter(%22%5C%5CA%22).next();%0A    %7D%0A%0A    private static final 
 String%5B%5D ind
@@ -567,17 +567,20 @@
 out%22 %7D;%0A
-%09
+    
 private 
@@ -609,13 +609,14 @@
 DAO;
- %0A%09%0A%09
+%0A%0A    
 publ
@@ -663,18 +663,24 @@
 eDAO) %7B%0A
-%09%09
+        
 this.wor
@@ -709,13 +709,19 @@
 AO;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Ove
@@ -726,17 +726,20 @@
 verride%0A
-%09
+    
 public v
@@ -756,18 +756,24 @@
 tes() %7B%0A
-%09%09
+        
 for(Stri
@@ -796,11 +796,20 @@
 ) %7B%0A
-%09%09%09
+            
 get(
@@ -832,32 +832,34 @@
  -%3E 
-this.getI
+i
 ndex
-()
 );%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 post
@@ -910,226 +910,11 @@
 ));%0A
-%09%7D%0A%09%0A%09@SuppressWarnings(%22resource%22)%0A%09private String getIndex() %7B%0A%09%09String index = new Scanner(App.class.getClassLoader().getResourceAsStream(%22public/index.html%22), %22UTF-8%22).useDelimiter(%22%5C%5CA%22).next();%0A%09%09return index;%0A%09%7D%0A%09
+    %7D
 %0A%7D

index as static string