Java Code Examples for com.neovisionaries.i18n.CountryCode#getByCode()
The following examples show how to use
com.neovisionaries.i18n.CountryCode#getByCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultCheckoutAddressFormData.java From commercetools-sunrise-java with Apache License 2.0 | 6 votes |
@Override public Address shippingAddress() { final CountryCode country = CountryCode.getByCode(countryShipping); return AddressBuilder.of(country) .title(titleShipping) .firstName(firstNameShipping) .lastName(lastNameShipping) .streetName(streetNameShipping) .additionalStreetInfo(additionalStreetInfoShipping) .city(cityShipping) .postalCode(postalCodeShipping) .region(regionShipping) .phone(phoneShipping) .email(emailShipping) .build(); }
Example 2
Source File: DefaultCheckoutAddressFormData.java From commercetools-sunrise-java with Apache License 2.0 | 6 votes |
@Override @Nullable public Address billingAddress() { if (billingAddressDifferentToBillingAddress) { final CountryCode country = CountryCode.getByCode(countryBilling); return AddressBuilder.of(country) .title(titleBilling) .firstName(firstNameBilling) .lastName(lastNameBilling) .streetName(streetNameBilling) .additionalStreetInfo(additionalStreetInfoBilling) .city(cityBilling) .postalCode(postalCodeBilling) .region(regionBilling) .phone(phoneBilling) .email(emailBilling) .build(); } else { return null; } }
Example 3
Source File: CountryEndpoint.java From java-resource-server with Apache License 2.0 | 5 votes |
/** * Look up a {@link CountryCode} instance from an ISO 3166-1 code. * * @param code * ISO 3166-1 code (alpha-2, alpha-3, or numeric). * * @return * A {@link CountryCode} instance that corresponds to the * given code. If the given code is not valid, {@code null} * is returned. */ private CountryCode lookup(String code) { if (code == null) { // Not found. return null; } // Interpret the code as an ISO 3166-1 alpha-2 or alpha-3 code. CountryCode cc = CountryCode.getByCodeIgnoreCase(code); if (cc != null) { // Found. return cc; } try { // Interpret the code as an ISO 3166-1 numeric code. return CountryCode.getByCode(Integer.parseInt(code)); } catch (NumberFormatException e) { // Not found. return null; } }
Example 4
Source File: DefaultAddressFormData.java From commercetools-sunrise-java with Apache License 2.0 | 5 votes |
public String validate() { final CountryCode country = CountryCode.getByCode(this.country); if (country == null || country.equals(CountryCode.UNDEFINED)) { return "Invalid country"; // TODO use i18n version } return null; }
Example 5
Source File: DefaultAddressFormData.java From commercetools-sunrise-java with Apache License 2.0 | 5 votes |
@Override public Address address() { final CountryCode countryCode = CountryCode.getByCode(country); return AddressBuilder.of(countryCode) .title(title) .firstName(firstName) .lastName(lastName) .streetName(streetName) .additionalStreetInfo(additionalStreetInfo) .city(city) .postalCode(postalCode) .region(region) .build(); }
Example 6
Source File: DefaultCheckoutAddressFormData.java From commercetools-sunrise-java with Apache License 2.0 | 5 votes |
public String validate() { final CountryCode shippingCountry = CountryCode.getByCode(countryShipping); if (shippingCountry == null || shippingCountry.equals(CountryCode.UNDEFINED)) { return "Invalid shipping country"; // TODO use i18n version } if (billingAddressDifferentToBillingAddress) { final CountryCode billingCountry = CountryCode.getByCode(countryBilling); if (billingCountry == null || billingCountry.equals(CountryCode.UNDEFINED)) { return "Invalid billing country"; // TODO use i18n version } } return null; }
Example 7
Source File: ISO3166Utils.java From CLIFF with Apache License 2.0 | 5 votes |
public static String alpha3toAlpha2(String alpha3) throws UnknownCountryException { if(alpha3.length()==0) return " "; CountryCode countryCode = CountryCode.getByCode(alpha3); if(null==countryCode){ throw new UnknownCountryException("Can't find country "+alpha3, alpha3); } return countryCode.getAlpha2(); }
Example 8
Source File: CountryFormFieldViewModelFactory.java From commercetools-sunrise-java with Apache License 2.0 | 4 votes |
protected void fillList(final CountryFormFieldViewModel viewModel, final FormFieldWithOptions<CountryCode> formFieldWithOptions) { final CountryCode selectedCountry = CountryCode.getByCode(formFieldWithOptions.getFormField().value()); viewModel.setList(formFieldWithOptions.getFormOptions().stream() .map(country -> countryFormSelectableOptionViewModelFactory.create(country, selectedCountry)) .collect(toList())); }