FIX: Support path-based project names.

Allow to correctly manage a hierarchy path project
name in the request URI. Previously only the last
part of the URI request after the forward slash
was taken into account; this was breaking in case
of path-based project names.

Example:
myprojects/project1 as project name => generated
a "cannot open repository" in branch-network.

Change-Id: Iec94112b9a807bea4661ea7a1f7a7ca88e80e18b
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/JsonService.java b/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/JsonService.java
index 282e12e..8f64110 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/JsonService.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/JsonService.java
@@ -58,9 +58,19 @@
   }
 
   protected String getProjectName(HttpServletRequest req) {
+    String servletPath = req.getServletPath();
     String reqURI = req.getRequestURI();
-    String[] reqParts = reqURI.split("/");
-    return reqParts[reqParts.length-1];
-  }
+    int servletPathPos = reqURI.indexOf(servletPath);
 
+    String projectName =
+        reqURI.substring(servletPathPos + servletPath.length());
+    if (projectName.startsWith("/")) {
+      projectName = projectName.substring(1);
+    }
+    if (projectName.endsWith("/")) {
+      projectName = projectName.substring(0, projectName.length() - 1);
+    }
+
+    return projectName;
+  }
 }