2004-07-24 02:06:07 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2010-03-25 19:04:45 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2004-07-24 02:06:07 +00:00
|
|
|
import java.util.Map;
|
2010-02-07 19:01:06 +00:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2004-07-24 02:06:07 +00:00
|
|
|
|
2010-02-07 19:01:06 +00:00
|
|
|
import net.i2p.I2PAppContext;
|
2004-07-24 02:06:07 +00:00
|
|
|
|
2010-02-07 19:01:06 +00:00
|
|
|
public class NavHelper {
|
2010-03-15 16:15:23 +00:00
|
|
|
private static Map<String, String> _apps = new ConcurrentHashMap(4);
|
2010-04-05 13:22:16 +00:00
|
|
|
private static Map<String, String> _tooltips = new ConcurrentHashMap(4);
|
2004-07-24 02:06:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* To register a new client application so that it shows up on the router
|
|
|
|
* console's nav bar, it should be registered with this singleton.
|
|
|
|
*
|
|
|
|
* @param name pretty name the app will be called in the link
|
|
|
|
* @param path full path pointing to the application's root
|
|
|
|
* (e.g. /i2ptunnel/index.jsp)
|
|
|
|
*/
|
|
|
|
public static void registerApp(String name, String path) {
|
|
|
|
_apps.put(name, path);
|
|
|
|
}
|
2010-04-05 13:22:16 +00:00
|
|
|
|
|
|
|
public static void registerApp(String name, String path, String tooltip) {
|
|
|
|
_apps.put(name, path);
|
|
|
|
_tooltips.put(name, tooltip);
|
|
|
|
}
|
|
|
|
|
2004-07-24 02:06:07 +00:00
|
|
|
public static void unregisterApp(String name) {
|
|
|
|
_apps.remove(name);
|
2010-04-05 13:22:16 +00:00
|
|
|
_tooltips.remove(name);
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 19:01:06 +00:00
|
|
|
/**
|
2010-02-08 16:15:23 +00:00
|
|
|
* Translated string is loaded by PluginStarter
|
2010-02-07 19:01:06 +00:00
|
|
|
*/
|
|
|
|
public static String getClientAppLinks(I2PAppContext ctx) {
|
2010-03-15 16:15:23 +00:00
|
|
|
if (_apps.isEmpty())
|
|
|
|
return "";
|
|
|
|
StringBuilder buf = new StringBuilder(256);
|
2010-03-25 19:04:45 +00:00
|
|
|
List<String> l = new ArrayList(_apps.keySet());
|
|
|
|
Collections.sort(l);
|
|
|
|
for (String name : l) {
|
2010-02-07 19:01:06 +00:00
|
|
|
String path = _apps.get(name);
|
2010-03-25 19:04:45 +00:00
|
|
|
if (path == null)
|
|
|
|
continue;
|
2010-04-05 13:22:16 +00:00
|
|
|
buf.append(" <a target=\"_blank\" href=\"").append(path).append("\" ");
|
|
|
|
String tip = _tooltips.get(name);
|
|
|
|
if (tip != null)
|
|
|
|
buf.append("title=\"").append(tip).append("\" ");
|
|
|
|
buf.append('>').append(name).append("</a>");
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
}
|