2004-07-24 02:06:07 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
2004-09-29 22:49:19 +00:00
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.io.Writer;
|
2004-07-24 02:06:07 +00:00
|
|
|
|
|
|
|
import net.i2p.router.RouterContext;
|
|
|
|
|
2009-01-29 02:16:18 +00:00
|
|
|
public class NetDbHelper extends HelperBase {
|
2008-09-12 13:37:22 +00:00
|
|
|
private String _routerPrefix;
|
2009-01-24 20:07:41 +00:00
|
|
|
private boolean _full = false;
|
2004-07-24 02:06:07 +00:00
|
|
|
|
|
|
|
public NetDbHelper() {}
|
|
|
|
|
2008-09-12 13:37:22 +00:00
|
|
|
public void setRouter(String r) { _routerPrefix = r; }
|
2009-01-24 20:07:41 +00:00
|
|
|
public void setFull(String f) { _full = "1".equals(f); };
|
2004-09-29 22:49:19 +00:00
|
|
|
|
2004-07-24 02:06:07 +00:00
|
|
|
public String getNetDbSummary() {
|
|
|
|
try {
|
2004-09-29 22:49:19 +00:00
|
|
|
if (_out != null) {
|
2008-09-12 13:37:22 +00:00
|
|
|
if (_routerPrefix != null)
|
|
|
|
_context.netDb().renderRouterInfoHTML(_out, _routerPrefix);
|
|
|
|
else
|
2009-01-24 20:07:41 +00:00
|
|
|
_context.netDb().renderStatusHTML(_out, _full);
|
2004-09-29 22:49:19 +00:00
|
|
|
return "";
|
|
|
|
} else {
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(32*1024);
|
2008-09-12 13:37:22 +00:00
|
|
|
if (_routerPrefix != null)
|
|
|
|
_context.netDb().renderRouterInfoHTML(new OutputStreamWriter(baos), _routerPrefix);
|
|
|
|
else
|
2009-01-24 20:07:41 +00:00
|
|
|
_context.netDb().renderStatusHTML(new OutputStreamWriter(baos), _full);
|
2004-09-29 22:49:19 +00:00
|
|
|
return new String(baos.toByteArray());
|
|
|
|
}
|
2004-07-24 02:06:07 +00:00
|
|
|
} catch (IOException ioe) {
|
|
|
|
ioe.printStackTrace();
|
2004-09-29 22:49:19 +00:00
|
|
|
return "";
|
2004-07-24 02:06:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|