forked from I2P_Developers/i2p.i2p
SusiDNS: Implement sort-by-added-date
This commit is contained in:
@ -266,8 +266,11 @@ public class AddressBean
|
||||
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)
|
||||
return "";
|
||||
String rv = props.getProperty(p);
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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
|
||||
String name = (String) entry.getKey();
|
||||
String destination = (String) entry.getValue();
|
||||
if( filter != null && filter.length() > 0 ) {
|
||||
if( filter.compareTo( "0-9" ) == 0 ) {
|
||||
if( filter.equals("0-9")) {
|
||||
char first = name.charAt(0);
|
||||
if( first < '0' || first > '9' )
|
||||
continue;
|
||||
|
@ -167,8 +167,9 @@ public class NamingServiceBean extends AddressbookBean
|
||||
Map<String, Destination> results;
|
||||
Properties searchProps = new Properties();
|
||||
// only blockfile needs this
|
||||
boolean sortByDate = "latest".equals(filter);
|
||||
searchProps.setProperty("list", getFileName());
|
||||
if (filter != null) {
|
||||
if (filter != null && !sortByDate) {
|
||||
String startsAt = filter.equals("0-9") ? "[0-9]" : filter;
|
||||
searchProps.setProperty("startsWith", startsAt);
|
||||
}
|
||||
@ -188,7 +189,7 @@ public class NamingServiceBean extends AddressbookBean
|
||||
debug("Result count: " + results.size());
|
||||
for (Map.Entry<String, Destination> entry : results.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
if( filter != null && filter.length() > 0 ) {
|
||||
if (filter != null && filter.length() > 0 && !sortByDate) {
|
||||
if (filter.equals("0-9")) {
|
||||
char first = name.charAt(0);
|
||||
if( first < '0' || first > '9' )
|
||||
@ -205,15 +206,25 @@ public class NamingServiceBean extends AddressbookBean
|
||||
}
|
||||
String destination = entry.getValue().toBase64();
|
||||
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 {
|
||||
// delete it too?
|
||||
System.err.println("Bad entry " + name + " in database " + service.getName());
|
||||
}
|
||||
}
|
||||
AddressBean array[] = list.toArray(new AddressBean[list.size()]);
|
||||
if (!(results instanceof SortedMap))
|
||||
Arrays.sort( array, sorter );
|
||||
if (sortByDate) {
|
||||
Arrays.sort(array, new AddressByDateSorter());
|
||||
} else if (!(results instanceof SortedMap)) {
|
||||
Arrays.sort(array, sorter);
|
||||
}
|
||||
entries = array;
|
||||
|
||||
message = generateLoadMessage();
|
||||
|
@ -151,7 +151,15 @@ ${book.loadBookMessages}
|
||||
<c:if test="${book.notEmpty}">
|
||||
<div id="filter">
|
||||
<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&begin=0&end=49"><%=intl._t("clear filter")%></a></span>
|
||||
</c:if>
|
||||
<c:if test="${!book.hasFilter}">
|
||||
@ -186,6 +194,9 @@ ${book.loadBookMessages}
|
||||
<a href="addressbook?filter=z&begin=0&end=49">z</a>
|
||||
<a href="addressbook?filter=0-9&begin=0&end=49">0-9</a>
|
||||
<a href="addressbook?filter=xn--&begin=0&end=49"><%=intl._t("other")%></a>
|
||||
<% if (!book.getBook().equals("published")) { %>
|
||||
<a href="addressbook?filter=latest&begin=0&end=49"><%=intl._t("latest")%></a>
|
||||
<% } %>
|
||||
<a href="addressbook?filter=none&begin=0&end=49"><%=intl._t("all")%></a>
|
||||
</p>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user