i2psnark: Consolidate code for creating img entities

This commit is contained in:
zzz
2014-09-13 18:09:48 +00:00
parent 5183b44d8b
commit 9a0f6490ba

View File

@ -310,7 +310,8 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<div class=\"snarknavbar\"><a href=\"" + _contextPath + "/\" title=\""); out.write("<div class=\"snarknavbar\"><a href=\"" + _contextPath + "/\" title=\"");
out.write(_("Torrents")); out.write(_("Torrents"));
out.write("\" class=\"snarkRefresh\">"); out.write("\" class=\"snarkRefresh\">");
out.write("<img alt=\"\" border=\"0\" src=\"" + _imgPath + "arrow_refresh.png\">&nbsp;&nbsp;"); out.write(toThemeImg("arrow_refresh"));
out.write(">&nbsp;&nbsp;");
if (_contextName.equals(DEFAULT_NAME)) if (_contextName.equals(DEFAULT_NAME))
out.write(_("I2PSnark")); out.write(_("I2PSnark"));
else else
@ -320,7 +321,8 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<div class=\"snarknavbar\"><a href=\"" + _contextPath + '/' + peerString + "\" title=\""); out.write("<div class=\"snarknavbar\"><a href=\"" + _contextPath + '/' + peerString + "\" title=\"");
out.write(_("Refresh page")); out.write(_("Refresh page"));
out.write("\" class=\"snarkRefresh\">"); out.write("\" class=\"snarkRefresh\">");
out.write("<img alt=\"\" border=\"0\" src=\"" + _imgPath + "arrow_refresh.png\">&nbsp;&nbsp;"); out.write(toThemeImg("arrow_refresh"));
out.write(">&nbsp;&nbsp;");
if (_contextName.equals(DEFAULT_NAME)) if (_contextName.equals(DEFAULT_NAME))
out.write(_("I2PSnark")); out.write(_("I2PSnark"));
else else
@ -375,9 +377,10 @@ public class I2PSnarkServlet extends BasicServlet {
out.write(peerString + "&amp;"); out.write(peerString + "&amp;");
else else
out.write("?"); out.write("?");
out.write("action=Clear&amp;nonce=" + _nonce + "\">" + out.write("action=Clear&amp;nonce=" + _nonce + "\">");
"<img src=\"" + _imgPath + "delete.png\" title=\"" + _("clear messages") + String tx = _("clear messages");
"\" alt=\"" + _("clear messages") + "\"></a>" + out.write(toThemeImg("delete", tx, tx));
out.write("</a>" +
"<ul>"); "<ul>");
for (int i = msgs.size()-1; i >= 0; i--) { for (int i = msgs.size()-1; i >= 0; i--) {
String msg = msgs.get(i); String msg = msgs.get(i);
@ -430,14 +433,10 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "status.png\" title=\""); String tx = _("Status");
if (showSort) out.write(toThemeImg("status", tx,
out.write(_("Sort by {0}", _("Status"))); showSort ? _("Sort by {0}", tx)
else : tx));
out.write(_("Status"));
out.write("\" alt=\"");
out.write(_("Status"));
out.write("\">");
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
out.write("</th>\n<th>"); out.write("</th>\n<th>");
@ -446,20 +445,14 @@ public class I2PSnarkServlet extends BasicServlet {
if (peerParam != null) { if (peerParam != null) {
// disable peer view // disable peer view
out.write("\">"); out.write("\">");
out.write("<img border=\"0\" src=\"" + _imgPath + "hidepeers.png\" title=\""); tx = _("Hide Peers");
out.write(_("Hide Peers")); out.write(toThemeImg("hidepeers", tx, tx));
out.write("\" alt=\"");
out.write(_("Hide Peers"));
out.write("\">");
} else { } else {
// enable peer view // enable peer view
out.write(getQueryString(req, "1", null, null)); out.write(getQueryString(req, "1", null, null));
out.write("\">"); out.write("\">");
out.write("<img border=\"0\" src=\"" + _imgPath + "showpeers.png\" title=\""); tx = _("Show Peers");
out.write(_("Show Peers")); out.write(toThemeImg("showpeers", tx, tx));
out.write("\" alt=\"");
out.write(_("Show Peers"));
out.write("\">");
} }
out.write("</a><br>\n"); out.write("</a><br>\n");
} }
@ -481,14 +474,10 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "torrent.png\" title=\""); tx = _("Torrent");
if (showSort) out.write(toThemeImg("torrent", tx,
out.write(_("Sort by {0}", (isTypeSort ? _("File type") : _("Torrent")))); showSort ? _("Sort by {0}", (isTypeSort ? _("File type") : tx))
else : tx));
out.write(_("Torrent"));
out.write("\" alt=\"");
out.write(_("Torrent"));
out.write("\">");
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
out.write("</th>\n<th align=\"center\">"); out.write("</th>\n<th align=\"center\">");
@ -502,15 +491,11 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "eta.png\" title=\"");
if (showSort)
out.write(_("Sort by {0}", _("Estimated time remaining")));
else
out.write(_("Estimated time remaining"));
out.write("\" alt=\"");
// Translators: Please keep short or translate as " " // Translators: Please keep short or translate as " "
out.write(_("ETA")); tx = _("ETA");
out.write("\">"); out.write(toThemeImg("eta", tx,
showSort ? _("Sort by {0}", _("Estimated time remaining"))
: _("Estimated time remaining")));
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
} }
@ -532,15 +517,11 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "head_rx.png\" title=\"");
if (showSort)
out.write(_("Sort by {0}", (isDlSort ? _("Downloaded") : _("Size"))));
else
out.write(_("Downloaded"));
out.write("\" alt=\"");
// Translators: Please keep short or translate as " " // Translators: Please keep short or translate as " "
out.write(_("RX")); tx = _("RX");
out.write("\">"); out.write(toThemeImg("head_rx", tx,
showSort ? _("Sort by {0}", (isDlSort ? _("Downloaded") : _("Size")))
: _("Downloaded")));
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
out.write("</th>\n<th align=\"right\">"); out.write("</th>\n<th align=\"right\">");
@ -567,15 +548,11 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "head_tx.png\" title=\"");
if (showSort)
out.write(_("Sort by {0}", (nextRatSort ? _("Upload ratio") : _("Uploaded"))));
else
out.write(_("Uploaded"));
out.write("\" alt=\"");
// Translators: Please keep short or translate as " " // Translators: Please keep short or translate as " "
out.write(_("TX")); tx = _("TX");
out.write("\">"); out.write(toThemeImg("head_tx", tx,
showSort ? _("Sort by {0}", (nextRatSort ? _("Upload ratio") : _("Uploaded")))
: _("Uploaded")));
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
} }
@ -586,15 +563,11 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "head_rxspeed.png\" title=\"");
if (showSort)
out.write(_("Sort by {0}", _("Down Rate")));
else
out.write(_("Down Rate"));
out.write("\" alt=\"");
// Translators: Please keep short or translate as " " // Translators: Please keep short or translate as " "
out.write(_("RX Rate")); tx = _("RX Rate");
out.write("\">"); out.write(toThemeImg("head_rxspeed", tx,
showSort ? _("Sort by {0}", _("Down Rate"))
: _("Down Rate")));
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
} }
@ -605,15 +578,11 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort)); out.write("<a href=\"" + _contextPath + '/' + getQueryString(req, null, null, sort));
out.write("\">"); out.write("\">");
} }
out.write("<img border=\"0\" src=\"" + _imgPath + "head_txspeed.png\" title=\"");
if (showSort)
out.write(_("Sort by {0}", _("Up Rate")));
else
out.write(_("Up Rate"));
out.write("\" alt=\"");
// Translators: Please keep short or translate as " " // Translators: Please keep short or translate as " "
out.write(_("TX Rate")); tx = _("TX Rate");
out.write("\">"); out.write(toThemeImg("head_txspeed", tx,
showSort ? _("Sort by {0}", _("Up Rate"))
: _("Up Rate")));
if (showSort) if (showSort)
out.write("</a>"); out.write("</a>");
} }
@ -825,10 +794,9 @@ public class I2PSnarkServlet extends BasicServlet {
// First // First
out.write("<a href=\"" + _contextPath); out.write("<a href=\"" + _contextPath);
out.write(getQueryString(req, null, "", null)); out.write(getQueryString(req, null, "", null));
out.write("\">" + out.write("\">");
"<img alt=\"" + _("First") + "\" title=\"" + _("First page") + "\" border=\"0\" src=\"" + out.write(toThemeImg("control_rewind_blue", _("First"), _("First page")));
_imgPath + "control_rewind_blue.png\">" + out.write("</a>&nbsp;");
"</a>&nbsp;");
int prev = Math.max(0, start - pageSize); int prev = Math.max(0, start - pageSize);
//if (prev > 0) { //if (prev > 0) {
if (true) { if (true) {
@ -836,10 +804,9 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("&nbsp;<a href=\"" + _contextPath); out.write("&nbsp;<a href=\"" + _contextPath);
String sprev = (prev > 0) ? Integer.toString(prev) : ""; String sprev = (prev > 0) ? Integer.toString(prev) : "";
out.write(getQueryString(req, null, sprev, null)); out.write(getQueryString(req, null, sprev, null));
out.write("\">" + out.write("\">");
"<img alt=\"" + _("Prev") + "\" title=\"" + _("Previous page") + "\" border=\"0\" src=\"" + out.write(toThemeImg("control_back_blue", _("Prev"), _("Previous page")));
_imgPath + "control_back_blue.png\">" + out.write("</a>&nbsp;");
"</a>&nbsp;");
} }
} else { } else {
out.write( out.write(
@ -870,19 +837,17 @@ public class I2PSnarkServlet extends BasicServlet {
// Next // Next
out.write("&nbsp;<a href=\"" + _contextPath); out.write("&nbsp;<a href=\"" + _contextPath);
out.write(getQueryString(req, null, Integer.toString(next), null)); out.write(getQueryString(req, null, Integer.toString(next), null));
out.write("\">" + out.write("\">");
"<img alt=\"" + _("Next") + "\" title=\"" + _("Next page") + "\" border=\"0\" src=\"" + out.write(toThemeImg("control_play_blue", _("Next"), _("Next page")));
_imgPath + "control_play_blue.png\">" + out.write("</a>&nbsp;");
"</a>&nbsp;");
} }
// Last // Last
int last = ((total - 1) / pageSize) * pageSize; int last = ((total - 1) / pageSize) * pageSize;
out.write("&nbsp;<a href=\"" + _contextPath); out.write("&nbsp;<a href=\"" + _contextPath);
out.write(getQueryString(req, null, Integer.toString(last), null)); out.write(getQueryString(req, null, Integer.toString(last), null));
out.write("\">" + out.write("\">");
"<img alt=\"" + _("Last") + "\" title=\"" + _("Last page") + "\" border=\"0\" src=\"" + out.write(toThemeImg("control_fastforward_blue", _("Last"), _("Last page")));
_imgPath + "control_fastforward_blue.png\">" + out.write("</a>&nbsp;");
"</a>&nbsp;");
} else { } else {
out.write("&nbsp;" + out.write("&nbsp;" +
"<img alt=\"\" border=\"0\" class=\"disable\" src=\"" + "<img alt=\"\" border=\"0\" class=\"disable\" src=\"" +
@ -1451,10 +1416,10 @@ public class I2PSnarkServlet extends BasicServlet {
String rowClass = (row % 2 == 0 ? "snarkTorrentEven" : "snarkTorrentOdd"); String rowClass = (row % 2 == 0 ? "snarkTorrentEven" : "snarkTorrentOdd");
String statusString; String statusString;
if (snark.isChecking()) { if (snark.isChecking()) {
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "stalled.png\" title=\"" + _("Checking") + "\"></td>" + statusString = toThemeImg("stalled", "", _("Checking")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Checking"); "<td class=\"snarkTorrentStatus\">" + _("Checking");
} else if (snark.isAllocating()) { } else if (snark.isAllocating()) {
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "stalled.png\" title=\"" + _("Allocating") + "\"></td>" + statusString = toThemeImg("stalled", "", _("Allocating")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Allocating"); "<td class=\"snarkTorrentStatus\">" + _("Allocating");
} else if (err != null && curPeers == 0) { } else if (err != null && curPeers == 0) {
// Also don't show if seeding... but then we won't see the not-registered error // Also don't show if seeding... but then we won't see the not-registered error
@ -1468,7 +1433,7 @@ public class I2PSnarkServlet extends BasicServlet {
// ngettext("1 peer", "{0} peers", knownPeers) + "</a>"; // ngettext("1 peer", "{0} peers", knownPeers) + "</a>";
//else if (isRunning) //else if (isRunning)
if (isRunning) if (isRunning)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "trackererror.png\" title=\"" + err + "\"></td>" + statusString = toThemeImg("trackererror", "", err) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Tracker Error") + "<td class=\"snarkTorrentStatus\">" + _("Tracker Error") +
": " + curPeers + thinsp(noThinsp) + ": " + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers); ngettext("1 peer", "{0} peers", knownPeers);
@ -1477,11 +1442,11 @@ public class I2PSnarkServlet extends BasicServlet {
err = DataHelper.escapeHTML(err.substring(0, MAX_DISPLAYED_ERROR_LENGTH)) + "&hellip;"; err = DataHelper.escapeHTML(err.substring(0, MAX_DISPLAYED_ERROR_LENGTH)) + "&hellip;";
else else
err = DataHelper.escapeHTML(err); err = DataHelper.escapeHTML(err);
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "trackererror.png\" title=\"" + err + "\"></td>" + statusString = toThemeImg("trackererror", "", err) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Tracker Error"); "<td class=\"snarkTorrentStatus\">" + _("Tracker Error");
} }
} else if (snark.isStarting()) { } else if (snark.isStarting()) {
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "stalled.png\" title=\"" + _("Starting") + "\"></td>" + statusString = toThemeImg("stalled", "", _("Starting")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Starting"); "<td class=\"snarkTorrentStatus\">" + _("Starting");
} else if (remaining == 0 || needed == 0) { // < 0 means no meta size yet } else if (remaining == 0 || needed == 0) { // < 0 means no meta size yet
// partial complete or seeding // partial complete or seeding
@ -1497,52 +1462,52 @@ public class I2PSnarkServlet extends BasicServlet {
txt = _("Complete"); txt = _("Complete");
} }
if (curPeers > 0 && !showPeers) if (curPeers > 0 && !showPeers)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + img + ".png\" title=\"" + txt + "\"></td>" + statusString = toThemeImg(img, "", txt) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + txt + "<td class=\"snarkTorrentStatus\">" + txt +
": <a href=\"" + uri + getQueryString(req, Base64.encode(snark.getInfoHash()), null, null) + "\">" + ": <a href=\"" + uri + getQueryString(req, Base64.encode(snark.getInfoHash()), null, null) + "\">" +
curPeers + thinsp(noThinsp) + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers) + "</a>"; ngettext("1 peer", "{0} peers", knownPeers) + "</a>";
else else
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + img + ".png\" title=\"" + txt + "\"></td>" + statusString = toThemeImg(img, "", txt) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + txt + "<td class=\"snarkTorrentStatus\">" + txt +
": " + curPeers + thinsp(noThinsp) + ": " + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers); ngettext("1 peer", "{0} peers", knownPeers);
} else { } else {
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "complete.png\" title=\"" + _("Complete") + "\"></td>" + statusString = toThemeImg("complete", "", _("Complete")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Complete"); "<td class=\"snarkTorrentStatus\">" + _("Complete");
} }
} else { } else {
if (isRunning && curPeers > 0 && downBps > 0 && !showPeers) if (isRunning && curPeers > 0 && downBps > 0 && !showPeers)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "downloading.png\" title=\"" + _("OK") + "\"></td>" + statusString = toThemeImg("downloading", "", _("OK")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("OK") + "<td class=\"snarkTorrentStatus\">" + _("OK") +
": <a href=\"" + uri + getQueryString(req, Base64.encode(snark.getInfoHash()), null, null) + "\">" + ": <a href=\"" + uri + getQueryString(req, Base64.encode(snark.getInfoHash()), null, null) + "\">" +
curPeers + thinsp(noThinsp) + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers) + "</a>"; ngettext("1 peer", "{0} peers", knownPeers) + "</a>";
else if (isRunning && curPeers > 0 && downBps > 0) else if (isRunning && curPeers > 0 && downBps > 0)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "downloading.png\" title=\"" + _("OK") + "\"></td>" + statusString = toThemeImg("downloading", "", _("OK")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("OK") + "<td class=\"snarkTorrentStatus\">" + _("OK") +
": " + curPeers + thinsp(noThinsp) + ": " + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers); ngettext("1 peer", "{0} peers", knownPeers);
else if (isRunning && curPeers > 0 && !showPeers) else if (isRunning && curPeers > 0 && !showPeers)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "stalled.png\" title=\"" + _("Stalled") + "\"></td>" + statusString = toThemeImg("stalled", "", _("Stalled")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Stalled") + "<td class=\"snarkTorrentStatus\">" + _("Stalled") +
": <a href=\"" + uri + getQueryString(req, Base64.encode(snark.getInfoHash()), null, null) + "\">" + ": <a href=\"" + uri + getQueryString(req, Base64.encode(snark.getInfoHash()), null, null) + "\">" +
curPeers + thinsp(noThinsp) + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers) + "</a>"; ngettext("1 peer", "{0} peers", knownPeers) + "</a>";
else if (isRunning && curPeers > 0) else if (isRunning && curPeers > 0)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "stalled.png\" title=\"" + _("Stalled") + "\"></td>" + statusString = toThemeImg("stalled", "", _("Stalled")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Stalled") + "<td class=\"snarkTorrentStatus\">" + _("Stalled") +
": " + curPeers + thinsp(noThinsp) + ": " + curPeers + thinsp(noThinsp) +
ngettext("1 peer", "{0} peers", knownPeers); ngettext("1 peer", "{0} peers", knownPeers);
else if (isRunning && knownPeers > 0) else if (isRunning && knownPeers > 0)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "nopeers.png\" title=\"" + _("No Peers") + "\"></td>" + statusString = toThemeImg("nopeers", "", _("No Peers")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("No Peers") + "<td class=\"snarkTorrentStatus\">" + _("No Peers") +
": 0" + thinsp(noThinsp) + knownPeers ; ": 0" + thinsp(noThinsp) + knownPeers ;
else if (isRunning) else if (isRunning)
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "nopeers.png\" title=\"" + _("No Peers") + "\"></td>" + statusString = toThemeImg("nopeers", "", _("No Peers")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("No Peers"); "<td class=\"snarkTorrentStatus\">" + _("No Peers");
else else
statusString = "<img alt=\"\" border=\"0\" src=\"" + _imgPath + "stopped.png\" title=\"" + _("Stopped") + "\"></td>" + statusString = toThemeImg("stopped", "", _("Stopped")) + "</td>" +
"<td class=\"snarkTorrentStatus\">" + _("Stopped"); "<td class=\"snarkTorrentStatus\">" + _("Stopped");
} }
@ -1949,9 +1914,9 @@ public class I2PSnarkServlet extends BasicServlet {
String linkUrl = getTrackerLinkUrl(announce, infohash); String linkUrl = getTrackerLinkUrl(announce, infohash);
if (linkUrl != null) { if (linkUrl != null) {
StringBuilder buf = new StringBuilder(128); StringBuilder buf = new StringBuilder(128);
buf.append(linkUrl) buf.append(linkUrl);
.append("<img alt=\"").append(_("Info")).append("\" border=\"0\" src=\"") toThemeImg(buf, "details", _("Info"), "");
.append(_imgPath).append("details.png\"></a>"); buf.append("</a>");
return buf.toString(); return buf.toString();
} }
return null; return null;
@ -2021,7 +1986,8 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<form action=\"_post\" method=\"POST\">\n"); out.write("<form action=\"_post\" method=\"POST\">\n");
writeHiddenInputs(out, req, "Add"); writeHiddenInputs(out, req, "Add");
out.write("<div class=\"addtorrentsection\"><span class=\"snarkConfigTitle\">"); out.write("<div class=\"addtorrentsection\"><span class=\"snarkConfigTitle\">");
out.write("<img alt=\"\" border=\"0\" src=\"" + _imgPath + "add.png\"> "); out.write(toThemeImg("add"));
out.write(' ');
out.write(_("Add Torrent")); out.write(_("Add Torrent"));
out.write("</span><hr>\n<table border=\"0\"><tr><td>"); out.write("</span><hr>\n<table border=\"0\"><tr><td>");
out.write(_("From URL")); out.write(_("From URL"));
@ -2048,7 +2014,8 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<form action=\"_post\" method=\"POST\">\n"); out.write("<form action=\"_post\" method=\"POST\">\n");
writeHiddenInputs(out, req, "Create"); writeHiddenInputs(out, req, "Create");
out.write("<span class=\"snarkConfigTitle\">"); out.write("<span class=\"snarkConfigTitle\">");
out.write("<img alt=\"\" border=\"0\" src=\"" + _imgPath + "create.png\"> "); out.write(toThemeImg("create"));
out.write(' ');
out.write(_("Create Torrent")); out.write(_("Create Torrent"));
out.write("</span><hr>\n<table border=\"0\"><tr><td>"); out.write("</span><hr>\n<table border=\"0\"><tr><td>");
//out.write("From file: <input type=\"file\" name=\"newFile\" size=\"50\" value=\"" + newFile + "\" /><br>\n"); //out.write("From file: <input type=\"file\" name=\"newFile\" size=\"50\" value=\"" + newFile + "\" /><br>\n");
@ -2114,8 +2081,9 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<form action=\"" + _contextPath + "/configure\" method=\"POST\">\n" + out.write("<form action=\"" + _contextPath + "/configure\" method=\"POST\">\n" +
"<div class=\"configsectionpanel\"><div class=\"snarkConfig\">\n"); "<div class=\"configsectionpanel\"><div class=\"snarkConfig\">\n");
writeHiddenInputs(out, req, "Save"); writeHiddenInputs(out, req, "Save");
out.write("<span class=\"snarkConfigTitle\">" + out.write("<span class=\"snarkConfigTitle\">");
"<img alt=\"\" border=\"0\" src=\"" + _imgPath + "config.png\"> "); out.write(toThemeImg("config"));
out.write(' ');
out.write(_("Configuration")); out.write(_("Configuration"));
out.write("</span><hr>\n" + out.write("</span><hr>\n" +
"<table border=\"0\"><tr><td>"); "<table border=\"0\"><tr><td>");
@ -2299,8 +2267,9 @@ public class I2PSnarkServlet extends BasicServlet {
buf.append("<form action=\"" + _contextPath + "/configure\" method=\"POST\">\n" + buf.append("<form action=\"" + _contextPath + "/configure\" method=\"POST\">\n" +
"<div class=\"configsectionpanel\"><div class=\"snarkConfig\">\n"); "<div class=\"configsectionpanel\"><div class=\"snarkConfig\">\n");
writeHiddenInputs(buf, req, "Save2"); writeHiddenInputs(buf, req, "Save2");
buf.append("<span class=\"snarkConfigTitle\">" + buf.append("<span class=\"snarkConfigTitle\">");
"<img alt=\"\" border=\"0\" src=\"" + _imgPath + "config.png\"> "); toThemeImg(buf, "config");
buf.append(' ');
buf.append(_("Trackers")); buf.append(_("Trackers"));
buf.append("</span><hr>\n" + buf.append("</span><hr>\n" +
"<table class=\"trackerconfig\"><tr><th>") "<table class=\"trackerconfig\"><tr><th>")
@ -2366,8 +2335,9 @@ public class I2PSnarkServlet extends BasicServlet {
private void writeConfigLink(PrintWriter out) throws IOException { private void writeConfigLink(PrintWriter out) throws IOException {
out.write("<div class=\"configsection\"><span class=\"snarkConfig\">\n" + out.write("<div class=\"configsection\"><span class=\"snarkConfig\">\n" +
"<span class=\"snarkConfigTitle\"><a href=\"configure\">" + "<span class=\"snarkConfigTitle\"><a href=\"configure\">");
"<img alt=\"\" border=\"0\" src=\"" + _imgPath + "config.png\"> "); out.write(toThemeImg("config"));
out.write(' ');
out.write(_("Configuration")); out.write(_("Configuration"));
out.write("</a></span></span></div>\n"); out.write("</a></span></span></div>\n");
} }
@ -2619,7 +2589,9 @@ public class I2PSnarkServlet extends BasicServlet {
if (showPriority) if (showPriority)
buf.append(" onload=\"setupbuttons()\""); buf.append(" onload=\"setupbuttons()\"");
buf.append(">\n<center><div class=\"snarknavbar\"><a href=\"").append(_contextPath).append("/\" title=\"Torrents\""); buf.append(">\n<center><div class=\"snarknavbar\"><a href=\"").append(_contextPath).append("/\" title=\"Torrents\"");
buf.append(" class=\"snarkRefresh\"><img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("arrow_refresh.png\">&nbsp;&nbsp;"); buf.append(" class=\"snarkRefresh\">");
toThemeImg(buf, "arrow_refresh");
buf.append("&nbsp;&nbsp;");
if (_contextName.equals(DEFAULT_NAME)) if (_contextName.equals(DEFAULT_NAME))
buf.append(_("I2PSnark")); buf.append(_("I2PSnark"));
else else
@ -2643,14 +2615,16 @@ public class I2PSnarkServlet extends BasicServlet {
String fullPath = snark.getName(); String fullPath = snark.getName();
String baseName = encodePath((new File(fullPath)).getName()); String baseName = encodePath((new File(fullPath)).getName());
buf.append("<tr><td>") buf.append("<tr><td>");
.append("<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("file.png\" >&nbsp;<b>") toThemeImg(buf, "file");
buf.append("&nbsp;<b>")
.append(_("Torrent file")) .append(_("Torrent file"))
.append(":</b> <a href=\"").append(_contextPath).append('/').append(baseName).append("\">") .append(":</b> <a href=\"").append(_contextPath).append('/').append(baseName).append("\">")
.append(DataHelper.escapeHTML(fullPath)) .append(DataHelper.escapeHTML(fullPath))
.append("</a></td></tr>\n"); .append("</a></td></tr>\n");
buf.append("<tr><td>") buf.append("<tr><td>");
.append("<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("file.png\" >&nbsp;<b>") toThemeImg(buf, "file");
buf.append("&nbsp;<b>")
.append(_("Data location")) .append(_("Data location"))
.append(":</b> ") .append(":</b> ")
.append(DataHelper.escapeHTML(snark.getStorage().getBase().getPath())) .append(DataHelper.escapeHTML(snark.getStorage().getBase().getPath()))
@ -2667,17 +2641,19 @@ public class I2PSnarkServlet extends BasicServlet {
buf.append("<tr><td>"); buf.append("<tr><td>");
String trackerLink = getTrackerLink(announce, snark.getInfoHash()); String trackerLink = getTrackerLink(announce, snark.getInfoHash());
if (trackerLink != null) if (trackerLink != null)
buf.append(trackerLink).append(' '); buf.append(trackerLink);
buf.append("<b>").append(_("Primary Tracker")).append(":</b> "); else
toThemeImg(buf, "details");
buf.append(" <b>").append(_("Primary Tracker")).append(":</b> ");
buf.append(getShortTrackerLink(announce, snark.getInfoHash())); buf.append(getShortTrackerLink(announce, snark.getInfoHash()));
buf.append("</td></tr>"); buf.append("</td></tr>");
} }
List<List<String>> alist = meta.getAnnounceList(); List<List<String>> alist = meta.getAnnounceList();
if (alist != null) { if (alist != null) {
buf.append("<tr><td>" + buf.append("<tr><td>");
"<img alt=\"\" border=\"0\" src=\"") toThemeImg(buf, "details");
.append(_imgPath).append("details.png\"> <b>"); buf.append(" <b>")
buf.append(_("Tracker List")).append(":</b> "); .append(_("Tracker List")).append(":</b> ");
for (List<String> alist2 : alist) { for (List<String> alist2 : alist) {
buf.append('['); buf.append('[');
boolean more = false; boolean more = false;
@ -2699,8 +2675,9 @@ public class I2PSnarkServlet extends BasicServlet {
if (com != null) { if (com != null) {
if (com.length() > 1024) if (com.length() > 1024)
com = com.substring(0, 1024); com = com.substring(0, 1024);
buf.append("<tr><td><img alt=\"\" border=\"0\" src=\"") buf.append("<tr><td>");
.append(_imgPath).append("details.png\"> <b>") toThemeImg(buf, "details");
buf.append(" <b>")
.append(_("Comment")).append(":</b> ") .append(_("Comment")).append(":</b> ")
.append(DataHelper.stripHTML(com)) .append(DataHelper.stripHTML(com))
.append("</td></tr>\n"); .append("</td></tr>\n");
@ -2708,8 +2685,9 @@ public class I2PSnarkServlet extends BasicServlet {
long dat = meta.getCreationDate(); long dat = meta.getCreationDate();
if (dat > 0) { if (dat > 0) {
String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(dat)); String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm")).format(new Date(dat));
buf.append("<tr><td><img alt=\"\" border=\"0\" src=\"") buf.append("<tr><td>");
.append(_imgPath).append("details.png\"> <b>") toThemeImg(buf, "details");
buf.append(" <b>")
.append(_("Created")).append(":</b> ") .append(_("Created")).append(":</b> ")
.append(date).append(" UTC") .append(date).append(" UTC")
.append("</td></tr>\n"); .append("</td></tr>\n");
@ -2718,8 +2696,9 @@ public class I2PSnarkServlet extends BasicServlet {
if (cby != null) { if (cby != null) {
if (cby.length() > 128) if (cby.length() > 128)
cby = com.substring(0, 128); cby = com.substring(0, 128);
buf.append("<tr><td><img alt=\"\" border=\"0\" src=\"") buf.append("<tr><td>");
.append(_imgPath).append("details.png\"> <b>") toThemeImg(buf, "details");
buf.append(" <b>")
.append(_("Created By")).append(":</b> ") .append(_("Created By")).append(":</b> ")
.append(DataHelper.stripHTML(cby)) .append(DataHelper.stripHTML(cby))
.append("</td></tr>\n"); .append("</td></tr>\n");
@ -2754,23 +2733,27 @@ public class I2PSnarkServlet extends BasicServlet {
//buf.append("<tr><td>").append(_("Maggot link")).append(": <a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">") //buf.append("<tr><td>").append(_("Maggot link")).append(": <a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">")
// .append(MAGGOT).append(hex).append(':').append(hex).append("</a></td></tr>"); // .append(MAGGOT).append(hex).append(':').append(hex).append("</a></td></tr>");
buf.append("<tr><td>") buf.append("<tr><td>");
.append("<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("size.png\" >&nbsp;<b>") toThemeImg(buf, "size");
buf.append("&nbsp;<b>")
.append(_("Size")) .append(_("Size"))
.append(":</b> ") .append(":</b> ")
.append(formatSize(snark.getTotalLength())); .append(formatSize(snark.getTotalLength()));
int pieces = snark.getPieces(); int pieces = snark.getPieces();
double completion = (pieces - snark.getNeeded()) / (double) pieces; double completion = (pieces - snark.getNeeded()) / (double) pieces;
buf.append("&nbsp;");
toThemeImg(buf, "head_rx");
buf.append("&nbsp;<b>");
if (completion < 1.0) if (completion < 1.0)
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" >&nbsp;<b>") buf.append(_("Completion"))
.append(_("Completion"))
.append(":</b> ") .append(":</b> ")
.append((new DecimalFormat("0.00%")).format(completion)); .append((new DecimalFormat("0.00%")).format(completion));
else else
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" >&nbsp;<b>") buf.append(_("Complete")).append("</b>");
.append(_("Complete")).append("</b>");
// up ratio // up ratio
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_tx.png\" >&nbsp;<b>") buf.append("&nbsp;");
toThemeImg(buf, "head_tx");
buf.append("&nbsp;<b>")
.append(_("Upload ratio")) .append(_("Upload ratio"))
.append(":</b> "); .append(":</b> ");
long uploaded = snark.getUploaded(); long uploaded = snark.getUploaded();
@ -2783,23 +2766,31 @@ public class I2PSnarkServlet extends BasicServlet {
} }
long needed = snark.getNeededLength(); long needed = snark.getNeededLength();
if (needed > 0) if (needed > 0)
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("head_rx.png\" >&nbsp;<b>") buf.append("&nbsp;");
toThemeImg(buf, "head_rx");
buf.append("&nbsp;<b>")
.append(_("Remaining")) .append(_("Remaining"))
.append(":</b> ") .append(":</b> ")
.append(formatSize(needed)); .append(formatSize(needed));
if (meta != null) { if (meta != null) {
List<List<String>> files = meta.getFiles(); List<List<String>> files = meta.getFiles();
int fileCount = files != null ? files.size() : 1; int fileCount = files != null ? files.size() : 1;
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("file.png\" >&nbsp;<b>") buf.append("&nbsp;");
toThemeImg(buf, "file");
buf.append("&nbsp;<b>")
.append(_("Files")) .append(_("Files"))
.append(":</b> ") .append(":</b> ")
.append(fileCount); .append(fileCount);
} }
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("file.png\" >&nbsp;<b>") buf.append("&nbsp;");
toThemeImg(buf, "file");
buf.append("&nbsp;<b>")
.append(_("Pieces")) .append(_("Pieces"))
.append(":</b> ") .append(":</b> ")
.append(pieces); .append(pieces);
buf.append("&nbsp;<img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("file.png\" >&nbsp;<b>") buf.append("&nbsp;");
toThemeImg(buf, "file");
buf.append("&nbsp;<b>")
.append(_("Piece size")) .append(_("Piece size"))
.append(":</b> ") .append(":</b> ")
.append(formatSize(snark.getPieceLength(0))) .append(formatSize(snark.getPieceLength(0)))
@ -2837,37 +2828,26 @@ public class I2PSnarkServlet extends BasicServlet {
// second table - dir info // second table - dir info
buf.append("<table class=\"snarkDirInfo\"><thead>\n"); buf.append("<table class=\"snarkDirInfo\"><thead>\n");
buf.append("<tr>\n") buf.append("<tr>\n")
.append("<th colspan=2>") .append("<th colspan=2>");
.append("<img border=\"0\" src=\"").append(_imgPath).append("file.png\" title=\"") String tx = _("Directory");
.append(_("Directory")) toThemeImg(buf, "file", tx, tx + ": " + directory);
.append(": ") buf.append("</th>\n<th align=\"right\">");
.append(directory) tx = _("Size");
.append("\" alt=\"") toThemeImg(buf, "size", tx, tx);
.append(_("Directory")) buf.append("</th>\n<th class=\"headerstatus\">");
.append("\"></th>\n"); tx = _("Status");
buf.append("<th align=\"right\">") toThemeImg(buf, "status", tx, tx);
.append("<img border=\"0\" src=\"").append(_imgPath).append("size.png\" title=\"") if (showPriority) {
.append(_("Size")) buf.append("</th>\n<th class=\"headerpriority\">");
.append("\" alt=\"") tx = _("Priority");
.append(_("Size")) toThemeImg(buf, "priority", tx, tx);
.append("\"></th>\n"); }
buf.append("<th class=\"headerstatus\">") buf.append("</th>\n</tr>\n</thead>\n");
.append("<img border=\"0\" src=\"").append(_imgPath).append("status.png\" title=\"")
.append(_("Status"))
.append("\" alt=\"")
.append(_("Status"))
.append("\"></th>\n");
if (showPriority)
buf.append("<th class=\"headerpriority\">")
.append("<img border=\"0\" src=\"").append(_imgPath).append("priority.png\" title=\"")
.append(_("Priority"))
.append("\" alt=\"")
.append(_("Priority"))
.append("\"></th>\n");
buf.append("</tr>\n</thead>\n");
buf.append("<tr><td colspan=\"" + (showPriority ? '5' : '4') + "\" class=\"ParentDir\"><A HREF=\""); buf.append("<tr><td colspan=\"" + (showPriority ? '5' : '4') + "\" class=\"ParentDir\"><A HREF=\"");
URIUtil.encodePath(buf, addPaths(decodedBase,"../")); URIUtil.encodePath(buf, addPaths(decodedBase,"../"));
buf.append("\"><img alt=\"\" border=\"0\" src=\"").append(_imgPath).append("up.png\"> ") buf.append("\">");
toThemeImg(buf, "up");
buf.append(' ')
.append(_("Up to higher level directory")) .append(_("Up to higher level directory"))
.append("</A></td></tr>\n"); .append("</A></td></tr>\n");
@ -3069,15 +3049,74 @@ public class I2PSnarkServlet extends BasicServlet {
return icon; return icon;
} }
/** @since 0.7.14 */ /**
* Icon file in the .war. Always 16x16.
*
* @param icon name without the ".png"
* @since 0.7.14
*/
private String toImg(String icon) { private String toImg(String icon) {
return toImg(icon, ""); return toImg(icon, "");
} }
/** @since 0.8.2 */ /**
* Icon file in the .war. Always 16x16.
*
* @param icon name without the ".png"
* @since 0.8.2
*/
private String toImg(String icon, String altText) { private String toImg(String icon, String altText) {
return "<img alt=\"" + altText + "\" height=\"16\" width=\"16\" src=\"" + _contextPath + WARBASE + "icons/" + icon + ".png\">"; return "<img alt=\"" + altText + "\" height=\"16\" width=\"16\" src=\"" + _contextPath + WARBASE + "icons/" + icon + ".png\">";
} }
/**
* Image file in the theme.
*
* @param image name without the ".png"
* @since 0.9.16
*/
private String toThemeImg(String image) {
return toThemeImg(image, "", "");
}
/**
* Image file in the theme.
*
* @param image name without the ".png"
* @since 0.9.16
*/
private void toThemeImg(StringBuilder buf, String image) {
toThemeImg(buf, image, "", "");
}
/**
* Image file in the theme.
*
* @param image name without the ".png"
* @param altText non-null
* @param titleText non-null
* @since 0.9.16
*/
private String toThemeImg(String image, String altText, String titleText) {
StringBuilder buf = new StringBuilder(128);
toThemeImg(buf, image, altText, titleText);
return buf.toString();
}
/**
* Image file in the theme.
*
* @param image name without the ".png"
* @param altText non-null
* @param titleText non-null
* @since 0.9.16
*/
private void toThemeImg(StringBuilder buf, String image, String altText, String titleText) {
buf.append("<img alt=\"").append(altText).append("\" src=\"").append(_imgPath).append(image).append(".png\"");
if (titleText.length() > 0)
buf.append(" title=\"").append(altText).append('"');
buf.append('>');
}
/** @since 0.8.1 */ /** @since 0.8.1 */
private void savePriorities(Snark snark, Map<String, String[]> postParams) { private void savePriorities(Snark snark, Map<String, String[]> postParams) {