Changeset de815e2
- Timestamp:
- Mar 10, 2011 11:06:13 PM (10 years ago)
- Branches:
- master
- Children:
- 7edbd3a
- Parents:
- ad24f14
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/susidns/src/java/src/i2p/susi/dns/AddressByNameSorter.java
rad24f14 rde815e2 27 27 import java.util.Comparator; 28 28 29 public class AddressByNameSorter implements Comparator 29 public class AddressByNameSorter implements Comparator<AddressBean> 30 30 { 31 public int compare( Object arg0, Object arg1)31 public int compare(AddressBean a, AddressBean b) 32 32 { 33 AddressBean a = (AddressBean)arg0;34 AddressBean b = (AddressBean)arg1;35 36 33 if( a == null ) 37 34 return 1; -
apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java
rad24f14 rde815e2 43 43 public class AddressbookBean 44 44 { 45 private String book, action, serial, lastSerial, filter, search, hostname, destination; 46 private int beginIndex, endIndex; 47 private Properties properties, addressbook; 45 protected String book, action, serial, lastSerial, filter, search, hostname, destination; 46 protected int beginIndex, endIndex; 47 protected final Properties properties; 48 private Properties addressbook; 48 49 private int trClass; 49 pr ivate LinkedListdeletionMarks;50 pr ivate static Comparatorsorter;50 protected final LinkedList<String> deletionMarks; 51 protected static final Comparator<AddressBean> sorter; 51 52 private static final int DISPLAY_SIZE=100; 52 53 … … 89 90 private static final String PRIVATE_BOOK = "private_addressbook"; 90 91 private static final String DEFAULT_PRIVATE_BOOK = "../privatehosts.txt"; 91 pr ivatevoid loadConfig()92 protected void loadConfig() 92 93 { 93 94 long currentTime = System.currentTimeMillis(); … … 124 125 return filename; 125 126 } 126 private Object[] entries; 127 public Object[] getEntries() 127 128 protected AddressBean[] entries; 129 130 public AddressBean[] getEntries() 128 131 { 129 132 return entries; 130 133 } 134 131 135 public String getAction() { 132 136 return action; … … 168 172 fis = new FileInputStream( getFileName() ); 169 173 addressbook.load( fis ); 170 LinkedList list = new LinkedList();174 LinkedList<AddressBean> list = new LinkedList(); 171 175 Enumeration e = addressbook.keys(); 172 176 while( e.hasMoreElements() ) { … … 190 194 list.addLast( new AddressBean( name, destination ) ); 191 195 } 192 Object array[] = list.toArray();196 AddressBean array[] = list.toArray(new AddressBean[list.size()]); 193 197 Arrays.sort( array, sorter ); 194 198 entries = array; 195 199 196 // Format a message about filtered addressbook size, and the number of displayed entries 197 // addressbook.jsp catches the case where the whole book is empty. 198 String filterArg = ""; 199 if( search != null && search.length() > 0 ) { 200 message = _("Search") + ' '; 201 } 202 if( filter != null && filter.length() > 0 ) { 203 if( search != null && search.length() > 0 ) 204 message = _("Search within filtered list") + ' '; 205 else 206 message = _("Filtered list") + ' '; 207 filterArg = "&filter=" + filter; 208 } 209 if (entries.length == 0) { 210 message += "- " + _("no matches") + '.'; 211 } else if (getBeginInt() == 0 && getEndInt() == entries.length - 1) { 212 if (message.length() == 0) 213 message = _("Addressbook") + ' '; 214 if (entries.length <= 0) 215 message += _("contains no entries"); 216 else if (entries.length == 1) 217 message += _("contains 1 entry"); 218 else 219 message += _("contains {0} entries", entries.length); 220 message += '.'; 221 } else { 222 if (getBeginInt() > 0) { 223 int newBegin = Math.max(0, getBeginInt() - DISPLAY_SIZE); 224 int newEnd = Math.max(0, getBeginInt() - 1); 225 message += "<a href=\"addressbook.jsp?book=" + getBook() + filterArg + 226 "&begin=" + newBegin + "&end=" + newEnd + "\">" + newBegin + 227 '-' + newEnd + "</a> | "; 228 } 229 message += _("Showing {0} of {1}", "" + getBegin() + '-' + getEnd(), entries.length); 230 if (getEndInt() < entries.length - 1) { 231 int newBegin = Math.min(entries.length - 1, getEndInt() + 1); 232 int newEnd = Math.min(entries.length, getEndInt() + DISPLAY_SIZE); 233 message += " | <a href=\"addressbook.jsp?book=" + getBook() + filterArg + 234 "&begin=" + newBegin + "&end=" + newEnd + "\">" + newBegin + 235 '-' + newEnd + "</a>"; 236 } 237 } 200 message = generateLoadMessage(); 238 201 } 239 202 catch (Exception e) { … … 247 210 return message; 248 211 } 212 213 /** 214 * Format a message about filtered addressbook size, and the number of displayed entries 215 * addressbook.jsp catches the case where the whole book is empty. 216 */ 217 protected String generateLoadMessage() { 218 String message = ""; 219 String filterArg = ""; 220 if( search != null && search.length() > 0 ) { 221 message = _("Search") + ' '; 222 } 223 if( filter != null && filter.length() > 0 ) { 224 if( search != null && search.length() > 0 ) 225 message = _("Search within filtered list") + ' '; 226 else 227 message = _("Filtered list") + ' '; 228 filterArg = "&filter=" + filter; 229 } 230 if (entries.length == 0) { 231 message += "- " + _("no matches") + '.'; 232 } else if (getBeginInt() == 0 && getEndInt() == entries.length - 1) { 233 if (message.length() == 0) 234 message = _("Addressbook") + ' '; 235 if (entries.length <= 0) 236 message += _("contains no entries"); 237 else 238 message += _(entries.length, "contains 1 entry", "contains {0} entries"); 239 message += '.'; 240 } else { 241 if (getBeginInt() > 0) { 242 int newBegin = Math.max(0, getBeginInt() - DISPLAY_SIZE); 243 int newEnd = Math.max(0, getBeginInt() - 1); 244 message += "<a href=\"addressbook.jsp?book=" + getBook() + filterArg + 245 "&begin=" + newBegin + "&end=" + newEnd + "\">" + newBegin + 246 '-' + newEnd + "</a> | "; 247 } 248 message += _("Showing {0} of {1}", "" + getBegin() + '-' + getEnd(), entries.length); 249 if (getEndInt() < entries.length - 1) { 250 int newBegin = Math.min(entries.length - 1, getEndInt() + 1); 251 int newEnd = Math.min(entries.length, getEndInt() + DISPLAY_SIZE); 252 message += " | <a href=\"addressbook.jsp?book=" + getBook() + filterArg + 253 "&begin=" + newBegin + "&end=" + newEnd + "\">" + newBegin + 254 '-' + newEnd + "</a>"; 255 } 256 } 257 return message; 258 } 259 249 260 /** Perform actions, returning messages about this. */ 250 261 public String getMessages() … … 256 267 if( lastSerial != null && serial != null && serial.compareTo( lastSerial ) == 0 ) { 257 268 boolean changed = false; 258 int deleted = 0;259 String name = null;260 269 if (action.equals(_("Add")) || action.equals(_("Replace"))) { 261 270 if( addressbook != null && hostname != null && destination != null ) { … … 292 301 search = null; 293 302 } else if (action.equals(_("Delete Selected"))) { 294 Iterator it = deletionMarks.iterator(); 295 while( it.hasNext() ) { 296 name = (String)it.next(); 297 addressbook.remove( name ); 298 changed = true; 299 deleted++; 303 String name = null; 304 int deleted = 0; 305 for (String n : deletionMarks) { 306 addressbook.remove(n); 307 if (deleted++ == 0) { 308 changed = true; 309 name = n; 310 } 300 311 } 301 312 if( changed ) { … … 338 349 } catch (IOException ioe) {} 339 350 } 351 340 352 public String getFilter() { 341 353 return filter; … … 383 395 this.hostname = DataHelper.stripHTML(hostname).trim(); // XSS 384 396 } 385 pr ivateint getBeginInt() {397 protected int getBeginInt() { 386 398 return Math.max(0, Math.min(entries.length - 1, beginIndex)); 387 399 } … … 394 406 } catch (NumberFormatException nfe) {} 395 407 } 396 pr ivateint getEndInt() {408 protected int getEndInt() { 397 409 return Math.max(0, Math.max(getBeginInt(), Math.min(entries.length - 1, endIndex))); 398 410 } … … 407 419 408 420 /** translate */ 409 pr ivatestatic String _(String s) {421 protected static String _(String s) { 410 422 return Messages.getString(s); 411 423 } 412 424 413 425 /** translate */ 414 pr ivatestatic String _(String s, Object o) {426 protected static String _(String s, Object o) { 415 427 return Messages.getString(s, o); 416 428 } 417 429 418 430 /** translate */ 419 pr ivatestatic String _(String s, Object o, Object o2) {431 protected static String _(String s, Object o, Object o2) { 420 432 return Messages.getString(s, o, o2); 421 433 } 434 435 /** translate (ngettext) @since 0.8.6 */ 436 protected static String _(int n, String s, String p) { 437 return Messages.getString(n, s, p); 438 } 422 439 } -
apps/susidns/src/java/src/i2p/susi/dns/Messages.java
rad24f14 rde815e2 32 32 return Translate.getString(s, o, o2, I2PAppContext.getGlobalContext(), BUNDLE_NAME); 33 33 } 34 35 /** translate (ngettext) @since 0.8.6 */ 36 public static String getString(int n, String s, String p) { 37 return Translate.getString(n, s, p, I2PAppContext.getGlobalContext(), BUNDLE_NAME); 38 } 34 39 } -
apps/susidns/src/jsp/addressbook.jsp
rad24f14 rde815e2 33 33 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 34 34 <jsp:useBean id="version" class="i2p.susi.dns.VersionBean" scope="application" /> 35 <jsp:useBean id="book" class="i2p.susi.dns. AddressbookBean" scope="session" />35 <jsp:useBean id="book" class="i2p.susi.dns.NamingServiceBean" scope="session" /> 36 36 <jsp:useBean id="intl" class="i2p.susi.dns.Messages" scope="application" /> 37 37 <jsp:setProperty name="book" property="*" /> … … 56 56 <p> 57 57 <%=intl._("addressbooks")%> 58 <a href="addressbook.jsp?book=private& filter=none&begin=0&end=99"><%=intl._("private")%></a> |59 <a href="addressbook.jsp?book=master& filter=none&begin=0&end=99"><%=intl._("master")%></a> |60 <a href="addressbook.jsp?book=router& filter=none&begin=0&end=99"><%=intl._("router")%></a> |61 <a href="addressbook.jsp?book=published& filter=none&begin=0&end=99"><%=intl._("published")%></a> *58 <a href="addressbook.jsp?book=private&filter=none&begin=0&end=99"><%=intl._("private")%></a> | 59 <a href="addressbook.jsp?book=master&filter=none&begin=0&end=99"><%=intl._("master")%></a> | 60 <a href="addressbook.jsp?book=router&filter=none&begin=0&end=99"><%=intl._("router")%></a> | 61 <a href="addressbook.jsp?book=published&filter=none&begin=0&end=99"><%=intl._("published")%></a> * 62 62 <a href="subscriptions.jsp"><%=intl._("subscriptions")%></a> * 63 63 <a href="config.jsp"><%=intl._("configuration")%></a> * … … 72 72 <div id="messages">${book.messages}</div> 73 73 74 <span>${book.loadBookMessages}</span> 74 ${book.loadBookMessages} 75 75 76 76 <c:if test="${book.notEmpty}"> 77 77 <div id="filter"> 78 78 <p><%=intl._("Filter")%>: 79 <a href="addressbook.jsp?filter=a& begin=0&end=99">a</a>80 <a href="addressbook.jsp?filter=b& begin=0&end=99">b</a>81 <a href="addressbook.jsp?filter=c& begin=0&end=99">c</a>82 <a href="addressbook.jsp?filter=d& begin=0&end=99">d</a>83 <a href="addressbook.jsp?filter=e& begin=0&end=99">e</a>84 <a href="addressbook.jsp?filter=f& begin=0&end=99">f</a>85 <a href="addressbook.jsp?filter=g& begin=0&end=99">g</a>86 <a href="addressbook.jsp?filter=h& begin=0&end=99">h</a>87 <a href="addressbook.jsp?filter=i& begin=0&end=99">i</a>88 <a href="addressbook.jsp?filter=j& begin=0&end=99">j</a>89 <a href="addressbook.jsp?filter=k& begin=0&end=99">k</a>90 <a href="addressbook.jsp?filter=l& begin=0&end=99">l</a>91 <a href="addressbook.jsp?filter=m& begin=0&end=99">m</a>92 <a href="addressbook.jsp?filter=n& begin=0&end=99">n</a>93 <a href="addressbook.jsp?filter=o& begin=0&end=99">o</a>94 <a href="addressbook.jsp?filter=p& begin=0&end=99">p</a>95 <a href="addressbook.jsp?filter=q& begin=0&end=99">q</a>96 <a href="addressbook.jsp?filter=r& begin=0&end=99">r</a>97 <a href="addressbook.jsp?filter=s& begin=0&end=99">s</a>98 <a href="addressbook.jsp?filter=t& begin=0&end=99">t</a>99 <a href="addressbook.jsp?filter=u& begin=0&end=99">u</a>100 <a href="addressbook.jsp?filter=v& begin=0&end=99">v</a>101 <a href="addressbook.jsp?filter=w& begin=0&end=99">w</a>102 <a href="addressbook.jsp?filter=x& begin=0&end=99">x</a>103 <a href="addressbook.jsp?filter=y& begin=0&end=99">y</a>104 <a href="addressbook.jsp?filter=z& begin=0&end=99">z</a>105 <a href="addressbook.jsp?filter=0-9& begin=0&end=99">0-9</a>106 <a href="addressbook.jsp?filter=none& begin=0&end=99"><%=intl._("all")%></a></p>79 <a href="addressbook.jsp?filter=a&begin=0&end=99">a</a> 80 <a href="addressbook.jsp?filter=b&begin=0&end=99">b</a> 81 <a href="addressbook.jsp?filter=c&begin=0&end=99">c</a> 82 <a href="addressbook.jsp?filter=d&begin=0&end=99">d</a> 83 <a href="addressbook.jsp?filter=e&begin=0&end=99">e</a> 84 <a href="addressbook.jsp?filter=f&begin=0&end=99">f</a> 85 <a href="addressbook.jsp?filter=g&begin=0&end=99">g</a> 86 <a href="addressbook.jsp?filter=h&begin=0&end=99">h</a> 87 <a href="addressbook.jsp?filter=i&begin=0&end=99">i</a> 88 <a href="addressbook.jsp?filter=j&begin=0&end=99">j</a> 89 <a href="addressbook.jsp?filter=k&begin=0&end=99">k</a> 90 <a href="addressbook.jsp?filter=l&begin=0&end=99">l</a> 91 <a href="addressbook.jsp?filter=m&begin=0&end=99">m</a> 92 <a href="addressbook.jsp?filter=n&begin=0&end=99">n</a> 93 <a href="addressbook.jsp?filter=o&begin=0&end=99">o</a> 94 <a href="addressbook.jsp?filter=p&begin=0&end=99">p</a> 95 <a href="addressbook.jsp?filter=q&begin=0&end=99">q</a> 96 <a href="addressbook.jsp?filter=r&begin=0&end=99">r</a> 97 <a href="addressbook.jsp?filter=s&begin=0&end=99">s</a> 98 <a href="addressbook.jsp?filter=t&begin=0&end=99">t</a> 99 <a href="addressbook.jsp?filter=u&begin=0&end=99">u</a> 100 <a href="addressbook.jsp?filter=v&begin=0&end=99">v</a> 101 <a href="addressbook.jsp?filter=w&begin=0&end=99">w</a> 102 <a href="addressbook.jsp?filter=x&begin=0&end=99">x</a> 103 <a href="addressbook.jsp?filter=y&begin=0&end=99">y</a> 104 <a href="addressbook.jsp?filter=z&begin=0&end=99">z</a> 105 <a href="addressbook.jsp?filter=0-9&begin=0&end=99">0-9</a> 106 <a href="addressbook.jsp?filter=none&begin=0&end=99"><%=intl._("all")%></a></p> 107 107 <c:if test="${book.hasFilter}"> 108 108 <p><%=intl._("Current filter")%>: ${book.filter} 109 (<a href="addressbook.jsp?filter=none& begin=0&end=99"><%=intl._("clear filter")%></a>)</p>109 (<a href="addressbook.jsp?filter=none&begin=0&end=99"><%=intl._("clear filter")%></a>)</p> 110 110 </c:if> 111 111 </div> … … 177 177 178 178 <div id="add"> 179 <h3><%=intl._("Add new destination")%>:</h3> 179 180 <p class="add"> 180 <h3><%=intl._("Add new destination")%>:</h3>181 181 <b><%=intl._("Hostname")%>:</b> <input type="text" name="hostname" value="${book.hostname}" size="20"> 182 182 <b><%=intl._("Destination")%>:</b> <textarea name="destination" rows="1" style="height: 3em;" cols="40" wrap="off" >${book.destination}</textarea><br/> -
core/java/src/net/i2p/client/naming/BlockfileNamingService.java
rad24f14 rde815e2 68 68 * </pre> 69 69 * 70 * All host names are converted to lower case. 70 71 */ 71 72 public class BlockfileNamingService extends DummyNamingService { … … 351 352 @Override 352 353 public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) { 353 Destination d = super.lookup(hostname );354 Destination d = super.lookup(hostname, null, null); 354 355 if (d != null) 355 356 return d; … … 461 462 } 462 463 return rv; 463 } catch (IOException re) { 464 } catch (IOException ioe) { 465 _log.error("DB remove error", ioe); 464 466 return false; 465 467 } catch (RuntimeException re) { 468 _log.error("DB remove error", re); 466 469 return false; 467 470 } … … 472 475 * @param options If non-null and contains the key "list", get 473 476 * from that list (default "hosts.txt", NOT all lists) 477 * Key "skip": skip that many entries 474 478 * Key "limit": max number to return 475 479 * Key "startsWith": return only those starting with … … 483 487 String beginWith = null; 484 488 int limit = Integer.MAX_VALUE; 489 int skip = 0; 485 490 if (options != null) { 486 listname = options.getProperty("list"); 491 String ln = options.getProperty("list"); 492 if (ln != null) 493 listname = ln; 487 494 startsWith = options.getProperty("startsWith"); 488 495 beginWith = options.getProperty("beginWith"); … … 493 500 limit = Integer.parseInt(lim); 494 501 } catch (NumberFormatException nfe) {} 495 } 502 String sk = options.getProperty("skip"); 503 try { 504 skip = Integer.parseInt(sk); 505 } catch (NumberFormatException nfe) {} 506 } 507 if (_log.shouldLog(Log.DEBUG)) 508 _log.debug("Searching " + listname + " beginning with " + beginWith + " starting with " + startsWith + " limit=" + limit + " skip=" + skip); 496 509 synchronized(_bf) { 497 510 try { 498 511 SkipList sl = _bf.getIndex(listname, _stringSerializer, _destSerializer); 499 if (sl == null) 512 if (sl == null) { 513 if (_log.shouldLog(Log.WARN)) 514 _log.warn("No skiplist found for lookup in " + listname); 500 515 return Collections.EMPTY_MAP; 516 } 501 517 SkipIterator iter; 502 if ( startsWith != null)518 if (beginWith != null) 503 519 iter = sl.find(beginWith); 504 520 else 505 521 iter = sl.iterator(); 506 522 Map<String, Destination> rv = new HashMap(); 523 for (int i = 0; i < skip && iter.hasNext(); i++) { 524 iter.next(); 525 } 507 526 for (int i = 0; i < limit && iter.hasNext(); i++) { 508 527 String key = (String) iter.nextKey(); … … 513 532 } 514 533 return rv; 515 } catch (IOException re) { 534 } catch (IOException ioe) { 535 _log.error("DB lookup error", ioe); 516 536 return Collections.EMPTY_MAP; 517 537 } catch (RuntimeException re) { 538 _log.error("DB lookup error", re); 518 539 return Collections.EMPTY_MAP; 519 540 } … … 540 561 return 0; 541 562 return sl.size(); 542 } catch (IOException re) { 563 } catch (IOException ioe) { 564 _log.error("DB size error", ioe); 543 565 return 0; 544 566 } catch (RuntimeException re) { 567 _log.error("DB size error", re); 545 568 return 0; 546 569 } … … 709 732 } 710 733 734 System.out.println("size() reports " + bns.size()); 735 System.out.println("getEntries() returns " + bns.getEntries().size()); 736 711 737 System.out.println("Testing with " + names.size() + " hostnames"); 712 738 int found = 0; -
core/java/src/net/i2p/client/naming/NamingService.java
rad24f14 rde815e2 84 84 return null; 85 85 } 86 } 87 88 @Override 89 public String toString() { 90 return getClass().getSimpleName(); 86 91 } 87 92
Note: See TracChangeset
for help on using the changeset viewer.