forked from I2P_Developers/i2p.i2p
basic IDN support
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
package i2p.susi.dns;
|
||||
|
||||
import java.net.IDN;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -36,6 +37,19 @@ public class AddressBean
|
||||
{
|
||||
private final String name, destination;
|
||||
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)
|
||||
{
|
||||
@@ -48,11 +62,34 @@ public class AddressBean
|
||||
return destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ASCII (Punycode) name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
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 */
|
||||
public String getB32()
|
||||
{
|
||||
|
@@ -36,6 +36,6 @@ public class AddressByNameSorter implements Comparator<AddressBean>
|
||||
if( b == null )
|
||||
return -1;
|
||||
|
||||
return a.getName().compareToIgnoreCase(b.getName());
|
||||
return a.getDisplayName().compareToIgnoreCase(b.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
package i2p.susi.dns;
|
||||
|
||||
import java.net.IDN;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
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);
|
||||
} else {
|
||||
try {
|
||||
String host = hostname;
|
||||
if (AddressBean.haveIDN) {
|
||||
try {
|
||||
host = IDN.toASCII(hostname, IDN.ALLOW_UNASSIGNED);
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
}
|
||||
Destination dest = new Destination(destination);
|
||||
nsOptions.setProperty("s", _("Manually added via SusiDNS"));
|
||||
boolean success = getNamingService().put(hostname, dest, nsOptions);
|
||||
boolean success = getNamingService().put(host, dest, nsOptions);
|
||||
if (success) {
|
||||
changed = true;
|
||||
if (oldDest == null)
|
||||
|
@@ -150,7 +150,7 @@ ${book.loadBookMessages}
|
||||
<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>
|
||||
</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">
|
||||
<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>
|
||||
|
@@ -82,8 +82,17 @@
|
||||
<table class="book" cellspacing="0" cellpadding="5">
|
||||
<tr class="list${book.trClass}">
|
||||
<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>
|
||||
</tr><tr class="list${book.trClass}">
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<td><%=intl._("Base 32 Address")%></td>
|
||||
<td><a href="http://<%=b32%>/"><%=b32%></a></td>
|
||||
</tr><tr class="list${book.trClass}">
|
||||
|
Reference in New Issue
Block a user