/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocelotds.dashboard;

import java.io.IOException;
import java.net.URL;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.ocelotds.annotations.OcelotResource;

/**
 *
 * @author hhfrancois
 */
@RequestScoped
@OcelotResource
@Path("dashboard")
public class RsDashboard {

	@Context
	private UriInfo context;

	@GET
	@Path("{name}.{type}")
	public Response getRoot(@PathParam("type") String type) throws IOException {
		return getResponse(type);
	}
	@GET
	@Path("css/{name}.{type}")
	public Response getCss(@PathParam("type") String type) throws IOException {
		return getResponse(type);
	}
	@GET
	@Path("js/{name}.{type}")
	public Response getJs(@PathParam("type") String type) throws IOException {
		return getResponse(type);
	}
	@GET
	@Path("fonts/{name}.{type}")
	public Response getFonts(@PathParam("type") String type) throws IOException {
		return getResponse(type);
	}

	public Response getResponse(String type) throws IOException {
		MediaType mtype = new MediaType("text", "js".equals(type) ? "javascript" : type);
		return Response.ok((Object) getResource("/" + context.getPath()).openStream(), mtype).build();
	}

	/**
	 * GEt URL Resource
	 *
	 * @param name
	 * @return
	 */
	URL getResource(String name) {
		return RsDashboard.class.getResource(name);
	}
}

@@ -752,29 +752,16 @@
 %09@Path(%22
-%7Bname%7D.%7Btype%7D
 %22)%0A%09publ
@@ -839,309 +839,103 @@
 %7B%0A%09%09
-return getResponse(type);%0A%09%7D%0A%09@GET%0A%09@Path(%22css/%7Bname%7D.%7Btype%7D%22)%0A%09public Response getCss(@PathParam(%22type%22) String type) throws IOException %7B%0A%09%09return getResponse(type);%0A%09%7D%0A%09@GET%0A%09@Path(%22js/%7Bname%7D.%7Btype%7D%22)%0A%09public Response getJs(@PathParam(%22type%22) String type) throws IOException %7B%0A%09%09return getResponse(
+MediaType mtype = new MediaType(%22text%22, %22html%22);%0A%09%09return getResponse(%22dashboard/index.html%22, m
 type
@@ -940,16 +940,18 @@
 pe);%0A%09%7D%0A
+%09%0A
 %09@GET%0A%09@
@@ -960,19 +960,15 @@
 th(%22
-fonts/%7Bname
+%7Bres:.+
 %7D.%7Bt
@@ -998,13 +998,16 @@
  get
-Fonts
+Response
 (@Pa
@@ -1058,35 +1058,139 @@
 ion %7B%0A%09%09
-return getResponse(
+MediaType mtype = new MediaType(%22text%22, %22js%22.equals(type) ? %22javascript%22 : type);%0A%09%09return getResponse(context.getPath(), m
 type);%0A%09
@@ -1232,37 +1232,14 @@
 ing 
-type) throws IOException %7B%0A%09%09
+path, 
 Medi
@@ -1248,79 +1248,34 @@
 ype 
-m
 type
- = new MediaType(%22text%22, %22js%22.equals(type) ? %22javascript%22 : type);
+) throws IOException %7B
 %0A%09%09r
@@ -1319,33 +1319,20 @@
 e(%22/%22 + 
-context.getP
+p
 ath
-()
 ).openSt
@@ -1335,25 +1335,24 @@
 enStream(), 
-m
 type).build(

improve rest uri pattern