forked from I2P_Developers/i2p.i2p
Moved rendering of news headings into SummaryBarRenderer
An instance of NewsHelper needs to be passed in to get output.
This commit is contained in:
@ -20,41 +20,8 @@ public class NewsHelper extends ContentHelper {
|
|||||||
|
|
||||||
/** @since 0.9.1 */
|
/** @since 0.9.1 */
|
||||||
public String getNewsHeadings() {
|
public String getNewsHeadings() {
|
||||||
StringBuilder buf = new StringBuilder(512);
|
SummaryBarRenderer renderer = new SummaryBarRenderer(_context, this);
|
||||||
String consoleNonce = System.getProperty("router.consoleNonce");
|
return renderer.renderNewsHeadingsHTML();
|
||||||
if (consoleNonce != null) {
|
|
||||||
// Set up string containing <a> to show news.
|
|
||||||
String newsUrl = "<a href=\"/?news=1&consoleNonce=" + consoleNonce + "\">";
|
|
||||||
// Set up title and pre-headings stuff.
|
|
||||||
buf.append("<h3><a href=\"/configupdate\">").append(_("News & Updates"))
|
|
||||||
.append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n");
|
|
||||||
// Get news content.
|
|
||||||
String newsContent = getContent();
|
|
||||||
if (newsContent != "") {
|
|
||||||
buf.append("<ul>\n");
|
|
||||||
// Parse news content for headings.
|
|
||||||
int start = newsContent.indexOf("<h3>");
|
|
||||||
while (start >= 0) {
|
|
||||||
// Add offset to start:
|
|
||||||
// 4 - gets rid of <h3>
|
|
||||||
// 16 - gets rid of the date as well (assuming form "<h3>yyyy-mm-dd: Foobarbaz...")
|
|
||||||
newsContent = newsContent.substring(start+16, newsContent.length());
|
|
||||||
int end = newsContent.indexOf("</h3>");
|
|
||||||
if (end >= 0) {
|
|
||||||
String heading = newsContent.substring(0, end);
|
|
||||||
buf.append("<li>").append(heading).append("</li>\n");
|
|
||||||
}
|
|
||||||
start = newsContent.indexOf("<h3>");
|
|
||||||
}
|
|
||||||
buf.append("</ul>\n");
|
|
||||||
buf.append(newsUrl).append(Messages.getString("Show news", _context)).append("</a>\n");
|
|
||||||
} else {
|
|
||||||
buf.append("<center><i>").append(_("none")).append("</i></center>");
|
|
||||||
}
|
|
||||||
// Add post-headings stuff.
|
|
||||||
buf.append("</div>\n");
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 0.8.12 */
|
/** @since 0.8.12 */
|
||||||
|
@ -14,10 +14,20 @@ import net.i2p.router.RouterContext;
|
|||||||
public class SummaryBarRenderer {
|
public class SummaryBarRenderer {
|
||||||
private final RouterContext _context;
|
private final RouterContext _context;
|
||||||
private final SummaryHelper _helper;
|
private final SummaryHelper _helper;
|
||||||
|
private final NewsHelper _newshelper;
|
||||||
|
|
||||||
public SummaryBarRenderer(RouterContext context, SummaryHelper helper) {
|
public SummaryBarRenderer(RouterContext context, SummaryHelper helper) {
|
||||||
|
this(context, helper, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SummaryBarRenderer(RouterContext context, NewsHelper newshelper) {
|
||||||
|
this(context, null, newshelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SummaryBarRenderer(RouterContext context, SummaryHelper helper, NewsHelper newshelper) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_helper = helper;
|
_helper = helper;
|
||||||
|
_newshelper = newshelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +93,7 @@ public class SummaryBarRenderer {
|
|||||||
.append("<hr>\n")
|
.append("<hr>\n")
|
||||||
.append(renderTunnelStatusHTML())
|
.append(renderTunnelStatusHTML())
|
||||||
.append("<hr>\n")
|
.append("<hr>\n")
|
||||||
.append(_helper.getDestinations())
|
.append(renderDestinationsHTML())
|
||||||
.append("<hr>\n");
|
.append("<hr>\n");
|
||||||
|
|
||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
@ -213,6 +223,7 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderGeneralHTML() {
|
public String renderGeneralHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append("<h3><a href=\"/help\" target=\"_top\" title=\"")
|
buf.append("<h3><a href=\"/help\" target=\"_top\" title=\"")
|
||||||
.append(_("I2P Router Help"))
|
.append(_("I2P Router Help"))
|
||||||
@ -255,6 +266,7 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderNetworkReachabilityHTML() {
|
public String renderNetworkReachabilityHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append("<h4><a href=\"/confignet#help\" target=\"_top\" title=\"")
|
buf.append("<h4><a href=\"/confignet#help\" target=\"_top\" title=\"")
|
||||||
.append(_("Help with configuring your firewall and router for optimal I2P performance"))
|
.append(_("Help with configuring your firewall and router for optimal I2P performance"))
|
||||||
@ -267,18 +279,21 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderUpdateStatusHTML() {
|
public String renderUpdateStatusHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append(_helper.getUpdateStatus());
|
buf.append(_helper.getUpdateStatus());
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String renderRestartStatusHTML() {
|
public String renderRestartStatusHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append(_helper.getRestartStatus());
|
buf.append(_helper.getRestartStatus());
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String renderPeersHTML() {
|
public String renderPeersHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append("<h3><a href=\"/peers\" target=\"_top\" title=\"")
|
buf.append("<h3><a href=\"/peers\" target=\"_top\" title=\"")
|
||||||
.append(_("Show all current peer connections"))
|
.append(_("Show all current peer connections"))
|
||||||
@ -326,12 +341,14 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderFirewallAndReseedStatusHTML() {
|
public String renderFirewallAndReseedStatusHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append(_helper.getFirewallAndReseedStatus());
|
buf.append(_helper.getFirewallAndReseedStatus());
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String renderBandwidthHTML() {
|
public String renderBandwidthHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append("<h3><a href=\"/config\" title=\"")
|
buf.append("<h3><a href=\"/config\" title=\"")
|
||||||
.append(_("Configure router bandwidth allocation"))
|
.append(_("Configure router bandwidth allocation"))
|
||||||
@ -375,6 +392,7 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderTunnelsHTML() {
|
public String renderTunnelsHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append("<h3><a href=\"/tunnels\" target=\"_top\" title=\"")
|
buf.append("<h3><a href=\"/tunnels\" target=\"_top\" title=\"")
|
||||||
.append(_("View existing tunnels and tunnel build status"))
|
.append(_("View existing tunnels and tunnel build status"))
|
||||||
@ -412,6 +430,7 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderCongestionHTML() {
|
public String renderCongestionHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
buf.append("<h3><a href=\"/jobs\" target=\"_top\" title=\"")
|
buf.append("<h3><a href=\"/jobs\" target=\"_top\" title=\"")
|
||||||
.append(_("What's in the router's job queue?"))
|
.append(_("What's in the router's job queue?"))
|
||||||
@ -451,6 +470,7 @@ public class SummaryBarRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderTunnelStatusHTML() {
|
public String renderTunnelStatusHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
StringBuilder buf = new StringBuilder(50);
|
StringBuilder buf = new StringBuilder(50);
|
||||||
buf.append("<h4>")
|
buf.append("<h4>")
|
||||||
.append(_(_helper.getTunnelStatus()))
|
.append(_(_helper.getTunnelStatus()))
|
||||||
@ -458,6 +478,61 @@ public class SummaryBarRenderer {
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String renderDestinationsHTML() {
|
||||||
|
if (_helper == null) return "";
|
||||||
|
StringBuilder buf = new StringBuilder(512);
|
||||||
|
buf.append(_helper.getDestinations());
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 0.9.1 */
|
||||||
|
public String renderNewsHeadingsHTML() {
|
||||||
|
if (_newshelper == null) return "";
|
||||||
|
StringBuilder buf = new StringBuilder(512);
|
||||||
|
String consoleNonce = System.getProperty("router.consoleNonce");
|
||||||
|
if (consoleNonce != null) {
|
||||||
|
// Set up title and pre-headings stuff.
|
||||||
|
buf.append("<h3><a href=\"/configupdate\">")
|
||||||
|
.append(_("News & Updates"))
|
||||||
|
.append("</a></h3><hr class=\"b\"><div class=\"newsheadings\">\n");
|
||||||
|
// Get news content.
|
||||||
|
String newsContent = _newshelper.getContent();
|
||||||
|
if (newsContent != "") {
|
||||||
|
buf.append("<ul>\n");
|
||||||
|
// Parse news content for headings.
|
||||||
|
int start = newsContent.indexOf("<h3>");
|
||||||
|
while (start >= 0) {
|
||||||
|
// Add offset to start:
|
||||||
|
// 4 - gets rid of <h3>
|
||||||
|
// 16 - gets rid of the date as well (assuming form "<h3>yyyy-mm-dd: Foobarbaz...")
|
||||||
|
newsContent = newsContent.substring(start+16, newsContent.length());
|
||||||
|
int end = newsContent.indexOf("</h3>");
|
||||||
|
if (end >= 0) {
|
||||||
|
String heading = newsContent.substring(0, end);
|
||||||
|
buf.append("<li>")
|
||||||
|
.append(heading)
|
||||||
|
.append("</li>\n");
|
||||||
|
}
|
||||||
|
start = newsContent.indexOf("<h3>");
|
||||||
|
}
|
||||||
|
buf.append("</ul>\n");
|
||||||
|
// Set up string containing <a> to show news.
|
||||||
|
buf.append("<a href=\"/?news=1&consoleNonce=")
|
||||||
|
.append(consoleNonce)
|
||||||
|
.append("\">")
|
||||||
|
.append(_("Show news"))
|
||||||
|
.append("</a>\n");
|
||||||
|
} else {
|
||||||
|
buf.append("<center><i>")
|
||||||
|
.append(_("none"))
|
||||||
|
.append("</i></center>");
|
||||||
|
}
|
||||||
|
// Add post-headings stuff.
|
||||||
|
buf.append("</div>\n");
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/** translate a string */
|
/** translate a string */
|
||||||
private String _(String s) {
|
private String _(String s) {
|
||||||
return Messages.getString(s, _context);
|
return Messages.getString(s, _context);
|
||||||
|
Reference in New Issue
Block a user