I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3485037f authored by zzz's avatar zzz
Browse files

SusiDNS: Implement sort-by-added-date

parent df1991d8
No related branches found
No related tags found
1 merge request!231SusiDNS: Implement sort-by-added-date
...@@ -266,10 +266,13 @@ public class AddressBean ...@@ -266,10 +266,13 @@ public class AddressBean
return stype.toString(); return stype.toString();
} }
/** @since 0.8.7 */ /**
private String getProp(String p) { * @return non-null, "" if not found
* @since 0.8.7, package private since 0.9.66
*/
String getProp(String p) {
if (props == null) if (props == null)
return ""; return "";
String rv = props.getProperty(p); String rv = props.getProperty(p);
return rv != null ? rv : ""; return rv != null ? rv : "";
} }
......
/*
* Created on Sep 02, 2005
*
* This file is part of susidns project, see http://susi.i2p/
*
* Copyright (C) 2005 <susi23@mail.i2p>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Revision: 1.2 $
*/
package i2p.susi.dns;
import java.io.Serializable;
import java.util.Comparator;
/**
* Newest first, then alphabetical
* @since 0.9.66
*/
public class AddressByDateSorter implements Comparator<AddressBean>, Serializable
{
public int compare(AddressBean a, AddressBean b)
{
String ad = a.getProp("a");
String bd = b.getProp("a");
long al;
long bl;
if (ad.length() > 0)
al = Long.parseLong(ad);
else
al = 0;
if (bd.length() > 0)
bl = Long.parseLong(bd);
else
bl = 0;
if (al < bl)
return 1;
if (al > bl)
return -1;
return a.getDisplayName().compareToIgnoreCase(b.getDisplayName());
}
}
...@@ -149,7 +149,7 @@ public class AddressbookBean extends BaseBean ...@@ -149,7 +149,7 @@ public class AddressbookBean extends BaseBean
String name = (String) entry.getKey(); String name = (String) entry.getKey();
String destination = (String) entry.getValue(); String destination = (String) entry.getValue();
if( filter != null && filter.length() > 0 ) { if( filter != null && filter.length() > 0 ) {
if( filter.compareTo( "0-9" ) == 0 ) { if( filter.equals("0-9")) {
char first = name.charAt(0); char first = name.charAt(0);
if( first < '0' || first > '9' ) if( first < '0' || first > '9' )
continue; continue;
......
...@@ -167,8 +167,9 @@ public class NamingServiceBean extends AddressbookBean ...@@ -167,8 +167,9 @@ public class NamingServiceBean extends AddressbookBean
Map<String, Destination> results; Map<String, Destination> results;
Properties searchProps = new Properties(); Properties searchProps = new Properties();
// only blockfile needs this // only blockfile needs this
boolean sortByDate = "latest".equals(filter);
searchProps.setProperty("list", getFileName()); searchProps.setProperty("list", getFileName());
if (filter != null) { if (filter != null && !sortByDate) {
String startsAt = filter.equals("0-9") ? "[0-9]" : filter; String startsAt = filter.equals("0-9") ? "[0-9]" : filter;
searchProps.setProperty("startsWith", startsAt); searchProps.setProperty("startsWith", startsAt);
} }
...@@ -188,7 +189,7 @@ public class NamingServiceBean extends AddressbookBean ...@@ -188,7 +189,7 @@ public class NamingServiceBean extends AddressbookBean
debug("Result count: " + results.size()); debug("Result count: " + results.size());
for (Map.Entry<String, Destination> entry : results.entrySet()) { for (Map.Entry<String, Destination> entry : results.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
if( filter != null && filter.length() > 0 ) { if (filter != null && filter.length() > 0 && !sortByDate) {
if (filter.equals("0-9")) { if (filter.equals("0-9")) {
char first = name.charAt(0); char first = name.charAt(0);
if( first < '0' || first > '9' ) if( first < '0' || first > '9' )
...@@ -205,15 +206,25 @@ public class NamingServiceBean extends AddressbookBean ...@@ -205,15 +206,25 @@ public class NamingServiceBean extends AddressbookBean
} }
String destination = entry.getValue().toBase64(); String destination = entry.getValue().toBase64();
if (destination != null) { if (destination != null) {
list.addLast( new AddressBean( name, destination ) ); AddressBean bean = new AddressBean(name, destination);
if (sortByDate) {
Properties p = new Properties();
Destination d = service.lookup(name, searchProps, p);
if (d != null && !p.isEmpty())
bean.setProperties(p);
}
list.addLast(bean);
} else { } else {
// delete it too? // delete it too?
System.err.println("Bad entry " + name + " in database " + service.getName()); System.err.println("Bad entry " + name + " in database " + service.getName());
} }
} }
AddressBean array[] = list.toArray(new AddressBean[list.size()]); AddressBean array[] = list.toArray(new AddressBean[list.size()]);
if (!(results instanceof SortedMap)) if (sortByDate) {
Arrays.sort( array, sorter ); Arrays.sort(array, new AddressByDateSorter());
} else if (!(results instanceof SortedMap)) {
Arrays.sort(array, sorter);
}
entries = array; entries = array;
message = generateLoadMessage(); message = generateLoadMessage();
......
...@@ -151,7 +151,15 @@ ${book.loadBookMessages} ...@@ -151,7 +151,15 @@ ${book.loadBookMessages}
<c:if test="${book.notEmpty}"> <c:if test="${book.notEmpty}">
<div id="filter"> <div id="filter">
<c:if test="${book.hasFilter}"> <c:if test="${book.hasFilter}">
<span><%=intl._t("Current filter")%>: <b>${book.filter}</b> <span><%=intl._t("Current filter")%>:
<%
String f = book.getFilter();
if ("latest".equals(f))
f = intl._t(f);
else if ("xn--".equals(f))
f = intl._t("other");
%>
<b><%=f%></b>
<a href="addressbook?filter=none&amp;begin=0&amp;end=49"><%=intl._t("clear filter")%></a></span> <a href="addressbook?filter=none&amp;begin=0&amp;end=49"><%=intl._t("clear filter")%></a></span>
</c:if> </c:if>
<c:if test="${!book.hasFilter}"> <c:if test="${!book.hasFilter}">
...@@ -186,6 +194,9 @@ ${book.loadBookMessages} ...@@ -186,6 +194,9 @@ ${book.loadBookMessages}
<a href="addressbook?filter=z&amp;begin=0&amp;end=49">z</a> <a href="addressbook?filter=z&amp;begin=0&amp;end=49">z</a>
<a href="addressbook?filter=0-9&amp;begin=0&amp;end=49">0-9</a> <a href="addressbook?filter=0-9&amp;begin=0&amp;end=49">0-9</a>
<a href="addressbook?filter=xn--&amp;begin=0&amp;end=49"><%=intl._t("other")%></a> <a href="addressbook?filter=xn--&amp;begin=0&amp;end=49"><%=intl._t("other")%></a>
<% if (!book.getBook().equals("published")) { %>
<a href="addressbook?filter=latest&amp;begin=0&amp;end=49"><%=intl._t("latest")%></a>
<% } %>
<a href="addressbook?filter=none&amp;begin=0&amp;end=49"><%=intl._t("all")%></a> <a href="addressbook?filter=none&amp;begin=0&amp;end=49"><%=intl._t("all")%></a>
</p> </p>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment