Adapt to refactored web link interfaces

Change-Id: I6e596526acb6e44f3f798829af36c76a15645945
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java
index 34224ea..65be419 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/Module.java
@@ -63,7 +63,7 @@
     DynamicSet.bind(binder(), BranchWebLink.class)
         .to(XDocWebLink.class);
     DynamicSet.bind(binder(), FileWebLink.class)
-        .to(XDocFileWebLink.class);
+        .to(XDocWebLink.class);
 
     DynamicSet.bind(binder(), TopMenu.class).toInstance(new TopMenu() {
       @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocFileWebLink.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocFileWebLink.java
deleted file mode 100644
index c0c35a3..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocFileWebLink.java
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2014 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.xdocs;
-
-import com.google.gerrit.extensions.annotations.PluginName;
-import com.google.gerrit.extensions.webui.FileWebLink;
-import com.google.gerrit.server.git.GitRepositoryManager;
-import com.google.gerrit.server.project.ProjectCache;
-import com.google.inject.Inject;
-
-import com.googlesource.gerrit.plugins.xdocs.formatter.Formatters;
-
-public class XDocFileWebLink extends XDocWebLink implements FileWebLink {
-
-  @Inject
-  XDocFileWebLink(
-      @PluginName String pluginName,
-      GitRepositoryManager repoManager,
-      XDocCache cache,
-      XDocProjectConfig.Factory cfgFactory,
-      ProjectCache projectCache,
-      Formatters formatters) {
-    super(pluginName, repoManager, cache, cfgFactory, projectCache, formatters);
-  }
-
-  @Override
-  public String getLinkName() {
-    return "preview";
-  }
-
-  @Override
-  public String getFileUrl(String projectName, String revision,
-      String fileName) {
-    return super.getPatchUrl(projectName, revision, fileName);
-  }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java
index 07460d8..400c5d7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocWebLink.java
@@ -15,9 +15,12 @@
 package com.googlesource.gerrit.plugins.xdocs;
 
 import com.google.gerrit.extensions.annotations.PluginName;
+import com.google.gerrit.extensions.common.WebLinkInfo;
 import com.google.gerrit.extensions.restapi.Url;
 import com.google.gerrit.extensions.webui.BranchWebLink;
+import com.google.gerrit.extensions.webui.FileWebLink;
 import com.google.gerrit.extensions.webui.ProjectWebLink;
+import com.google.gerrit.extensions.webui.WebLinkTarget;
 import com.google.gerrit.httpd.resources.Resource;
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.git.GitRepositoryManager;
@@ -38,10 +41,13 @@
 import java.io.IOException;
 
 @Singleton
-public class XDocWebLink implements ProjectWebLink, BranchWebLink {
+public class XDocWebLink implements ProjectWebLink, BranchWebLink, FileWebLink {
   private static final Logger log = LoggerFactory
       .getLogger(XDocWebLink.class);
 
+  private static final String README = "readme";
+  private static final String PREVIEW = "preview";
+
   private final String pluginName;
   private final GitRepositoryManager repoManager;
   private final XDocCache docCache;
@@ -66,27 +72,35 @@
   }
 
   @Override
-  public String getLinkName() {
-    return "readme";
+  public WebLinkInfo getBranchWebLink(String projectName, String branchName) {
+    return new WebLinkInfo(README, getImageUrl(),
+        getBranchUrl(projectName, branchName), WebLinkTarget.BLANK);
   }
 
   @Override
-  public String getProjectUrl(String projectName) {
-    return getBranchUrl(projectName, Constants.HEAD);
+  public WebLinkInfo getProjectWeblink(String projectName) {
+    return new WebLinkInfo(README, getImageUrl(),
+        getBranchUrl(projectName, Constants.HEAD), WebLinkTarget.BLANK);
   }
 
   @Override
-  public String getBranchUrl(String projectName, String branchName) {
+  public WebLinkInfo getFileWebLink(String projectName, String revision,
+      String fileName) {
+    return new WebLinkInfo(PREVIEW, getImageUrl(),
+        getFileUrl(projectName, revision, fileName), WebLinkTarget.BLANK);
+  }
+
+  private String getBranchUrl(String projectName, String branchName) {
     ProjectState state = projectCache.get(new Project.NameKey(projectName));
     if (state == null) {
       // project not found -> no link
       return null;
     }
-    return getPatchUrl(projectName, branchName,
+    return getFileUrl(projectName, branchName,
         cfgFactory.create(state).getIndexFile());
   }
 
-  public String getPatchUrl(String projectName, String revision,
+  public String getFileUrl(String projectName, String revision,
       String fileName) {
     FormatterProvider formatter = formatters.get(projectName, fileName);
     if (formatter == null) {
@@ -127,13 +141,7 @@
     }
   }
 
-  @Override
-  public String getImageUrl() {
+  private String getImageUrl() {
     return "plugins/" + pluginName + "/static/readme.png";
   }
-
-  @Override
-  public String getTarget() {
-    return Target.BLANK;
-  }
 }