basic IDN support

This commit is contained in:
zzz
2011-03-24 05:30:33 +00:00
parent ca5484a984
commit 7751661f3d
5 changed files with 56 additions and 3 deletions

View File

@@ -24,6 +24,7 @@
package i2p.susi.dns; package i2p.susi.dns;
import java.net.IDN;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
@@ -36,6 +37,19 @@ public class AddressBean
{ {
private final String name, destination; private final String name, destination;
private Properties props; private Properties props;
/** available as of Java 6 */
static final boolean haveIDN;
static {
boolean h;
try {
Class.forName("java.net.IDN", false, ClassLoader.getSystemClassLoader());
h = true;
} catch (ClassNotFoundException cnfe) {
h = false;
}
haveIDN = h;
}
public AddressBean(String name, String destination) public AddressBean(String name, String destination)
{ {
@@ -48,11 +62,34 @@ public class AddressBean
return destination; return destination;
} }
/**
* The ASCII (Punycode) name
*/
public String getName() public String getName()
{ {
return name; return name;
} }
/**
* The Unicode name, translated from Punycode
* @since 0.8.6
*/
public String getDisplayName()
{
if (haveIDN)
return IDN.toUnicode(name);
return name;
}
/**
* Is the ASCII name Punycode-encoded?
* @since 0.8.6
*/
public boolean isIDN()
{
return haveIDN && !IDN.toUnicode(name).equals(name);
}
/** @since 0.8.6 */ /** @since 0.8.6 */
public String getB32() public String getB32()
{ {

View File

@@ -36,6 +36,6 @@ public class AddressByNameSorter implements Comparator<AddressBean>
if( b == null ) if( b == null )
return -1; return -1;
return a.getName().compareToIgnoreCase(b.getName()); return a.getDisplayName().compareToIgnoreCase(b.getDisplayName());
} }
} }

View File

@@ -22,6 +22,7 @@
package i2p.susi.dns; package i2p.susi.dns;
import java.net.IDN;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
@@ -222,9 +223,15 @@ public class NamingServiceBean extends AddressbookBean
message = _("Host name {0} is already in addressbook with a different destination. Click \"Replace\" to overwrite.", hostname); message = _("Host name {0} is already in addressbook with a different destination. Click \"Replace\" to overwrite.", hostname);
} else { } else {
try { try {
String host = hostname;
if (AddressBean.haveIDN) {
try {
host = IDN.toASCII(hostname, IDN.ALLOW_UNASSIGNED);
} catch (IllegalArgumentException iae) {}
}
Destination dest = new Destination(destination); Destination dest = new Destination(destination);
nsOptions.setProperty("s", _("Manually added via SusiDNS")); nsOptions.setProperty("s", _("Manually added via SusiDNS"));
boolean success = getNamingService().put(hostname, dest, nsOptions); boolean success = getNamingService().put(host, dest, nsOptions);
if (success) { if (success) {
changed = true; changed = true;
if (oldDest == null) if (oldDest == null)

View File

@@ -150,7 +150,7 @@ ${book.loadBookMessages}
<c:if test="${book.master || book.router || book.published || book.private}"> <c:if test="${book.master || book.router || book.published || book.private}">
<td class="checkbox"><input type="checkbox" name="checked" value="${addr.name}" title="<%=intl._("Mark for deletion")%>"></td> <td class="checkbox"><input type="checkbox" name="checked" value="${addr.name}" title="<%=intl._("Mark for deletion")%>"></td>
</c:if> </c:if>
<td class="names"><a href="http://${addr.name}/">${addr.name}</a> <td class="names"><a href="http://${addr.name}/">${addr.displayName}</a>
</td><td class="names"> </td><td class="names">
<span class="addrhlpr">(<a href="http://${addr.b32}/">b32</a>)</span> <span class="addrhlpr">(<a href="http://${addr.b32}/">b32</a>)</span>
<span class="addrhlpr">(<a href="details.jsp?h=${addr.name}"><%=intl._("details")%></a>)</span> <span class="addrhlpr">(<a href="details.jsp?h=${addr.name}"><%=intl._("details")%></a>)</span>

View File

@@ -82,8 +82,17 @@
<table class="book" cellspacing="0" cellpadding="5"> <table class="book" cellspacing="0" cellpadding="5">
<tr class="list${book.trClass}"> <tr class="list${book.trClass}">
<td><%=intl._("Host Name")%></td> <td><%=intl._("Host Name")%></td>
<td><a href="http://<%=addr.getName()%>/"><%=addr.getDisplayName()%></a></td>
</tr><tr class="list${book.trClass}">
<%
if (addr.isIDN()) {
%>
<td><%=intl._("Punycode Name")%></td>
<td><a href="http://<%=addr.getName()%>/"><%=addr.getName()%></a></td> <td><a href="http://<%=addr.getName()%>/"><%=addr.getName()%></a></td>
</tr><tr class="list${book.trClass}"> </tr><tr class="list${book.trClass}">
<%
}
%>
<td><%=intl._("Base 32 Address")%></td> <td><%=intl._("Base 32 Address")%></td>
<td><a href="http://<%=b32%>/"><%=b32%></a></td> <td><a href="http://<%=b32%>/"><%=b32%></a></td>
</tr><tr class="list${book.trClass}"> </tr><tr class="list${book.trClass}">