Preparing for dynamic GUI extensibility.
Change-Id: Ic25143bb9ad8919d7c9e70d932dde528a9227e6a
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainExtResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainExtResource.java
index a1eae41..1bf3d42 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainExtResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainExtResource.java
@@ -31,6 +31,7 @@
import static com.google.common.collect.ImmutableList.of;
import static com.google.common.io.ByteStreams.toByteArray;
+import static org.onosproject.ui.impl.MainViewResource.SCRIPT;
/**
* Resource for serving the dynamically composed onos.js.
@@ -38,30 +39,35 @@
@Path("/")
public class MainExtResource extends AbstractInjectionResource {
- private static final String MAIN_JS = "/onos-template.js";
- private static final String NAV_HTML = "/nav-template.html";
+ private static final String MAIN_JS = "templates/onos-template.js";
+ private static final String NAV_HTML = "templates/nav-template.html";
- private static final String INJECT_VIEW_IDS = "// {INJECTED-VIEW-IDS}";
- private static final String INJECT_VIEW_ITEMS = "<!-- {INJECTED-VIEW-NAV} -->";
+ private static final String INJECT_VIEW_IDS_START = "// {INJECTED-VIEW-IDS-START}";
+ private static final String INJECT_VIEW_IDS_END = "// {INJECTED-VIEW-IDS-END}";
+
+ private static final String INJECT_VIEW_ITEMS_START = "<!-- {INJECTED-VIEW-NAV-START} -->";
+ private static final String INJECT_VIEW_ITEMS_END = "<!-- {INJECTED-VIEW-NAV-END} -->";
+
private static final String NAV_FORMAT =
" <li> <a ng-click=\"navCtrl.hideNav()\" href=\"#/%s\">%s</a></li>";
@Path("/onos.js")
@GET
- @Produces(MediaType.TEXT_HTML)
+ @Produces(SCRIPT)
public Response getMainModule() throws IOException {
UiExtensionService service = get(UiExtensionService.class);
InputStream jsTemplate = getClass().getClassLoader().getResourceAsStream(MAIN_JS);
String js = new String(toByteArray(jsTemplate));
- int p1 = split(js, 0, INJECT_VIEW_IDS);
- int p2 = split(js, p1, null);
+ int p1s = split(js, 0, INJECT_VIEW_IDS_START);
+ int p1e = split(js, 0, INJECT_VIEW_IDS_END);
+ int p2s = split(js, p1e, null);
StreamEnumeration streams =
- new StreamEnumeration(of(stream(js, 0, p1),
+ new StreamEnumeration(of(stream(js, 0, p1s),
includeViewIds(service),
- stream(js, p1, p2)));
+ stream(js, p1e, p2s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
@@ -85,13 +91,14 @@
InputStream navTemplate = getClass().getClassLoader().getResourceAsStream(NAV_HTML);
String js = new String(toByteArray(navTemplate));
- int p1 = split(js, 0, INJECT_VIEW_ITEMS);
- int p2 = split(js, p1, null);
+ int p1s = split(js, 0, INJECT_VIEW_ITEMS_START);
+ int p1e = split(js, 0, INJECT_VIEW_ITEMS_END);
+ int p2s = split(js, p1e, null);
StreamEnumeration streams =
- new StreamEnumeration(of(stream(js, 0, p1),
+ new StreamEnumeration(of(stream(js, 0, p1s),
includeNavItems(service),
- stream(js, p1, p2)));
+ stream(js, p1e, p2s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
index da4079f..5f4158d 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainIndexResource.java
@@ -37,12 +37,14 @@
@Path("/")
public class MainIndexResource extends AbstractInjectionResource {
- private static final String INDEX = "/index-template.html";
+ private static final String INDEX = "templates/index-template.html";
- private static final String INJECT_CSS = "<!-- {INJECTED-STYLESHEETS} -->";
- private static final String INJECT_JS = "<!-- {INJECTED-JAVASCRIPT} -->";
+ private static final String INJECT_CSS_START = "<!-- {INJECTED-STYLESHEETS-START} -->";
+ private static final String INJECT_CSS_END = "<!-- {INJECTED-STYLESHEETS-END} -->";
- @Path("/")
+ private static final String INJECT_JS_START = "<!-- {INJECTED-JAVASCRIPT-START} -->";
+ private static final String INJECT_JS_END = "<!-- {INJECTED-JAVASCRIPT-END} -->";
+
@GET
@Produces(MediaType.TEXT_HTML)
public Response getMainIndex() throws IOException {
@@ -50,16 +52,18 @@
InputStream indexTemplate = getClass().getClassLoader().getResourceAsStream(INDEX);
String index = new String(toByteArray(indexTemplate));
- int p1 = split(index, 0, INJECT_JS);
- int p2 = split(index, p1, INJECT_CSS);
- int p3 = split(index, p2, null);
+ int p1s = split(index, 0, INJECT_JS_START);
+ int p1e = split(index, p1s, INJECT_JS_END);
+ int p2s = split(index, p1e, INJECT_CSS_START);
+ int p2e = split(index, p2s, INJECT_CSS_END);
+ int p3s = split(index, p2e, null);
StreamEnumeration streams =
- new StreamEnumeration(of(stream(index, 0, p1),
+ new StreamEnumeration(of(stream(index, 0, p1s),
includeJs(service),
- stream(index, p1, p2),
+ stream(index, p1e, p2s),
includeCss(service),
- stream(index, p2, p3)));
+ stream(index, p2e, p3s)));
return Response.ok(new SequenceInputStream(streams)).build();
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/MainViewResource.java b/web/gui/src/main/java/org/onosproject/ui/impl/MainViewResource.java
index 26b5d8c..e5bb126 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/MainViewResource.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/MainViewResource.java
@@ -33,9 +33,9 @@
@Path("/")
public class MainViewResource extends AbstractInjectionResource {
- private static final String CONTENT_TYPE = "Content-Type";
- private static final String STYLESHEET = "text/css";
- private static final String SCRIPT = "text/javascript";
+ static final String CONTENT_TYPE = "Content-Type";
+ static final String STYLESHEET = "text/css";
+ static final String SCRIPT = "text/javascript";
@Path("{view}/{resource}")
@GET
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
index 6ca1e21..3604919 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
@@ -54,7 +54,8 @@
new UiView("topo", "Topology View"),
new UiView("device", "Devices"));
- private final UiExtension core = new UiExtension(coreViews, getClass().getClassLoader());
+ private final UiExtension core = new UiExtension(coreViews, "core",
+ getClass().getClassLoader());
@Activate
public void activate() {