public static StellarAddress parse()

in service/src/main/java/org/apache/fineract/cn/stellarbridge/service/internal/federation/StellarAddress.java [21:47]


  public static StellarAddress parse(final String address)
      throws InvalidStellarAddressException
  {
    //I chose not to use Pattern.UNICODE_CHARACTER_CLASS because of potential performance issues and
    //no current knowledge of use cases which require unicode addresses.  Certainly the domain
    //name can't contain unicode characters.  According to the federation servers specs at
    //Stellar, the part before the * might contain them.  Depending on what use cases we encounter,
    //we may need to adjust this.
    final Pattern stellarAddressPattern = Pattern.compile(
        "(?<name>^[^\\:\\*@\\p{Space}]+)(:(?<subname>[^\\:\\*@\\p{Space}]+))?+\\*(?<domain>[\\p{Alnum}-\\.]+)$");

    final Matcher addressMatcher = stellarAddressPattern.matcher(address);
    if (!addressMatcher.matches()) {
      throw InvalidStellarAddressException.nonConformantStellarAddress(address);
    }

    if (addressMatcher.group("subname") != null)
    {
      return new StellarAddress(getInternetDomainName(addressMatcher.group("domain")),
          addressMatcher.group("name"), Optional.of(addressMatcher.group("subname")));
    }
    else
    {
      return new StellarAddress(getInternetDomainName(addressMatcher.group("domain")),
          addressMatcher.group("name"), Optional.empty());
    }
  }