Class TaxIdFormatter

java.lang.Object
org.notima.util.TaxIdFormatter

public class TaxIdFormatter extends Object
Utility class to parse and print tax id:s in different formats. At the moment only Swedish tax id's are supported.
Author:
Daniel Tamm
  • Constructor Details

    • TaxIdFormatter

      public TaxIdFormatter()
  • Method Details

    • toDigitsOnly

      public static String toDigitsOnly(String cleanUp)
      Remove all non digit characters
      Parameters:
      cleanUp - String to be cleaned.
      Returns:
      A cleaned string.
    • hasDigitsOnly

      public static boolean hasDigitsOnly(String ref)
    • removeBlanks

      public static String removeBlanks(String cleanUp)
      Remove blanks from a string.
      Parameters:
      cleanUp - String to clean up.
      Returns:
      A string without blanks.
    • printTaxId

      public static String printTaxId(String srcFormat, String taxId, String dstFormat) throws UnknownTaxIdFormatException, InvalidTaxIdFormatException
      Print tax id in given format.
      Parameters:
      srcFormat - The format of the taxId-attribute. If null, the tax id format tries to be determined. Note, this can be lengthy.
      taxId - The actual tax id.
      dstFormat - The destination format.
      Returns:
      The tax id in the destination format
      Throws:
      UnknownTaxIdFormatException - if the dstFormat is not recognized.
      InvalidTaxIdFormatException - If the tax ID can't be parsed.
    • determineFormat

      public static String determineFormat(String countryCode, String taxId)
      Determines tax id format by applying a number of regular expressions to the tax id.
      Parameters:
      countryCode - If country code is supplied, only that country's tax id patterns are tried.
      taxId - The tax id to determine.
      Returns:
      The tax id format. If it can't be matched, TaxIdStructure.FMT_UNKNOWN is returned.