mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Move getTldFromDomainName into DomainNameUtils
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=118475557
This commit is contained in:
parent
4442f4c31b
commit
b3125ae070
9 changed files with 34 additions and 58 deletions
|
@ -19,9 +19,9 @@ import static com.google.common.base.Strings.isNullOrEmpty;
|
|||
import static com.google.domain.registry.dns.DnsConstants.DNS_PULL_QUEUE_NAME;
|
||||
import static com.google.domain.registry.dns.DnsConstants.DNS_TARGET_NAME_PARAM;
|
||||
import static com.google.domain.registry.dns.DnsConstants.DNS_TARGET_TYPE_PARAM;
|
||||
import static com.google.domain.registry.model.domain.DomainUtils.getTldFromDomainName;
|
||||
import static com.google.domain.registry.model.registry.Registries.assertTldExists;
|
||||
import static com.google.domain.registry.request.RequestParameters.PARAM_TLD;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
import com.google.appengine.api.taskqueue.Queue;
|
||||
|
|
|
@ -17,9 +17,9 @@ package com.google.domain.registry.flows.domain;
|
|||
import static com.google.domain.registry.flows.domain.DomainFlowUtils.getReservationType;
|
||||
import static com.google.domain.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
|
||||
import static com.google.domain.registry.model.EppResourceUtils.checkResourcesExist;
|
||||
import static com.google.domain.registry.model.domain.DomainUtils.getTldFromDomainName;
|
||||
import static com.google.domain.registry.model.registry.label.ReservationType.UNRESERVED;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmpty;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
|
|
@ -13,15 +13,16 @@
|
|||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.model.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.collect.Sets.union;
|
||||
import static com.google.domain.registry.model.domain.DesignatedContact.Type.REGISTRANT;
|
||||
import static com.google.domain.registry.model.domain.DomainUtils.getTldFromDomainName;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
|
||||
import static com.google.domain.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
|
||||
import static com.google.domain.registry.util.CollectionUtils.union;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.model.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
||||
/**
|
||||
* Utility class for dealing with domains.
|
||||
*/
|
||||
public final class DomainUtils {
|
||||
|
||||
/**
|
||||
* Returns the canonicalized TLD part of a valid domain name (just an SLD, no subdomains) by
|
||||
* stripping off the leftmost part.
|
||||
*
|
||||
* <p>This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will
|
||||
* also work on domains for which the registry is not authoritative. If you are certain that the
|
||||
* input will be under a TLD this registry controls, then it is preferable to use
|
||||
* {@link com.google.domain.registry.model.registry.Registries#findTldForName(InternetDomainName)
|
||||
* Registries#findTldForName}, which will work on hostnames in addition to domains.
|
||||
*
|
||||
* @param fullyQualifiedDomainName must be a punycode SLD (not a host or unicode)
|
||||
* @throws IllegalArgumentException if there is no TLD
|
||||
*/
|
||||
public static String getTldFromDomainName(String fullyQualifiedDomainName) {
|
||||
checkArgument(
|
||||
!Strings.isNullOrEmpty(fullyQualifiedDomainName),
|
||||
"fullyQualifiedDomainName cannot be null or empty");
|
||||
InternetDomainName domainName = InternetDomainName.from(fullyQualifiedDomainName);
|
||||
checkArgument(domainName.hasParent(), "fullyQualifiedDomainName does not have a TLD");
|
||||
return domainName.parent().toString();
|
||||
}
|
||||
|
||||
private DomainUtils() {}
|
||||
}
|
|
@ -91,8 +91,8 @@ public final class Registries {
|
|||
*
|
||||
* <p><b>Note:</b> This routine will only work on names under TLDs for which this registry is
|
||||
* authoritative. To extract TLDs from domains (not hosts) that other registries control, use
|
||||
* {@link com.google.domain.registry.model.domain.DomainUtils#getTldFromDomainName(String)
|
||||
* DomainUtils#getTldFromDomainName}.
|
||||
* {@link com.google.domain.registry.util.DomainNameUtils#getTldFromDomainName(String)
|
||||
* DomainNameUtils#getTldFromDomainName}.
|
||||
*
|
||||
* @param domainName domain name or host name (but not TLD) under an authoritative TLD
|
||||
* @return TLD or absent if {@code domainName} has no labels under an authoritative TLD
|
||||
|
|
|
@ -17,10 +17,10 @@ package com.google.domain.registry.ui.server.api;
|
|||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Strings.nullToEmpty;
|
||||
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
|
||||
import static com.google.domain.registry.model.domain.DomainUtils.getTldFromDomainName;
|
||||
import static com.google.domain.registry.model.eppcommon.ProtocolDefinition.ServiceExtension.FEE_0_6;
|
||||
import static com.google.domain.registry.ui.server.SoyTemplateUtils.createTofuSupplier;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.canonicalizeDomainName;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.getTldFromDomainName;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.json.simple.JSONValue.toJSONString;
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
|
||||
package com.google.domain.registry.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
|
||||
/** Utility methods related to domain names. */
|
||||
|
@ -38,5 +41,27 @@ public final class DomainNameUtils {
|
|||
return Idn.toASCII(Ascii.toLowerCase(label));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the canonicalized TLD part of a valid domain name (just an SLD, no subdomains) by
|
||||
* stripping off the leftmost part.
|
||||
*
|
||||
* <p>This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will
|
||||
* also work on domains for which the registry is not authoritative. If you are certain that the
|
||||
* input will be under a TLD this registry controls, then it is preferable to use
|
||||
* {@link com.google.domain.registry.model.registry.Registries#findTldForName(InternetDomainName)
|
||||
* Registries#findTldForName}, which will work on hostnames in addition to domains.
|
||||
*
|
||||
* @param fullyQualifiedDomainName must be a punycode SLD (not a host or unicode)
|
||||
* @throws IllegalArgumentException if there is no TLD
|
||||
*/
|
||||
public static String getTldFromDomainName(String fullyQualifiedDomainName) {
|
||||
checkArgument(
|
||||
!Strings.isNullOrEmpty(fullyQualifiedDomainName),
|
||||
"fullyQualifiedDomainName cannot be null or empty");
|
||||
InternetDomainName domainName = InternetDomainName.from(fullyQualifiedDomainName);
|
||||
checkArgument(domainName.hasParent(), "fullyQualifiedDomainName does not have a TLD");
|
||||
return domainName.parent().toString();
|
||||
}
|
||||
|
||||
private DomainNameUtils() {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue