| 1 |
/* |
| 2 |
* Copyright 2015-2020 the original author or authors |
| 3 |
* |
| 4 |
* This software is licensed under the Apache License, Version 2.0, |
| 5 |
* the GNU Lesser General Public License version 2 or later ("LGPL") |
| 6 |
* and the WTFPL. |
| 7 |
* You may choose either license to govern your use of this software only |
| 8 |
* upon the condition that you accept all of the terms of either |
| 9 |
* the Apache License 2.0, the LGPL 2.1+ or the WTFPL. |
| 10 |
*/ |
| 11 |
package org.minidns.dnslabel; |
| 12 |
|
| 13 |
import java.util.Locale; |
| 14 |
|
| 15 |
import org.minidns.idna.MiniDnsIdna; |
| 16 |
|
| 17 |
/** |
| 18 |
* A label that begins with "xn--" and follows the LDH rule. |
| 19 |
*/ |
| 20 |
public abstract class XnLabel extends ReservedLdhLabel { |
| 21 |
|
| 22 |
protected XnLabel(String label) { |
| 23 |
super(label); |
| 24 |
} |
| 25 |
|
| 26 |
protected static LdhLabel fromInternal(String label) { |
| 27 |
assert isIdnAcePrefixed(label); |
| 28 |
|
| 29 |
String uLabel = MiniDnsIdna.toUnicode(label); |
| 30 |
if (label.equals(uLabel)) { |
| 31 |
// No Punycode conversation to Unicode was performed, this is a fake A-label! |
| 32 |
return new FakeALabel(label); |
| 33 |
} else { |
| 34 |
return new ALabel(label); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
public static boolean isXnLabel(String label) { |
| 39 |
if (!isLdhLabel(label)) { |
| 40 |
return false; |
| 41 |
} |
| 42 |
return isXnLabelInternal(label); |
| 43 |
} |
| 44 |
|
| 45 |
static boolean isXnLabelInternal(String label) { |
| 46 |
return label.substring(0, 2).toLowerCase(Locale.US).equals("xn"); |
| 47 |
} |
| 48 |
} |