private void initCountries() { try { CountryHome countryHome = (CountryHome) IDOLookup.getHome(Country.class); Collection counts = countryHome.findAll(); countries = new Hashtable(counts.size()); for (Iterator iter = counts.iterator(); iter.hasNext(); ) { Country element = (Country) iter.next(); countries.put(element.getIsoAbbreviation(), element); } } catch (IDOLookupException e) { e.printStackTrace(); } catch (FinderException e) { e.printStackTrace(); } }
protected String getAttributeValue(IWContext iwc, User user, String alias, String type) { if (OpenIDConstants.ATTRIBUTE_ALIAS_EMAIL.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_EMAIL.equals(type)) { Email email = null; try { email = getUserBusiness(iwc).getUsersMainEmail(user); } catch (NoEmailFoundException e) { /*No action...*/ } catch (RemoteException e) { e.printStackTrace(); } return (email != null ? email.getEmailAddress() : ""); } else if (OpenIDConstants.ATTRIBUTE_ALIAS_PERSONAL_ID.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_PERSONAL_ID.equals(type)) { return (user.getPersonalID() != null ? user.getPersonalID() : ""); } else if (OpenIDConstants.ATTRIBUTE_ALIAS_FULL_NAME.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_FULL_NAME.equals(type)) { return user.getName(); } else if (OpenIDConstants.ATTRIBUTE_ALIAS_DATE_OF_BIRTH.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_DATE_OF_BIRTH.equals(type)) { return (user.getDateOfBirth() != null ? new IWTimestamp(user.getDateOfBirth()).toSQLDateString() : ""); } else if (OpenIDConstants.ATTRIBUTE_ALIAS_GENDER.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_GENDER.equals(type)) { return (user.getGender() != null ? (user.getGender().isMaleGender() ? "M" : "F") : ""); } else if (OpenIDConstants.ATTRIBUTE_ALIAS_NICKNAME.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_FRIENDLY_NAME.equals(type)) { return LoginDBHandler.getUserLogin(user).getUserLogin(); } else if (OpenIDConstants.ATTRIBUTE_ALIAS_POSTCODE.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_POSTAL_CODE.equals(type)) { try { Address address = getUserBusiness(iwc).getUsersMainAddress(user); if (address != null) { PostalCode postal = address.getPostalCode(); return postal != null ? postal.getPostalCode() : ""; } } catch (RemoteException re) { re.printStackTrace(); } } else if (OpenIDConstants.ATTRIBUTE_ALIAS_COUNTRY.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_COUNTRY.equals(type)) { try { Address address = getUserBusiness(iwc).getUsersMainAddress(user); if (address != null) { return address.getCountry().getIsoAbbreviation(); } } catch (RemoteException re) { re.printStackTrace(); } } else if (OpenIDConstants.ATTRIBUTE_ALIAS_LANGUAGE.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_LANGUAGE.equals(type)) { if (user.getPreferredLocale() != null) { Locale locale = LocaleUtil.getLocale(user.getPreferredLocale()); return locale.getLanguage() + "-" + locale.getCountry(); } else { try { Address address = getUserBusiness(iwc).getUsersMainAddress(user); if (address != null) { Country country = address.getCountry(); return country.getIsoAbbreviation().toLowerCase() + "-" + country.getIsoAbbreviation(); } } catch (RemoteException re) { re.printStackTrace(); } } } else if (OpenIDConstants.ATTRIBUTE_ALIAS_TIMEZONE.equals(alias) || OpenIDConstants.ATTRIBUTE_TYPE_TIMEZONE.equals(type)) { try { Address address = getUserBusiness(iwc).getUsersMainAddress(user); if (address != null) { Country country = address.getCountry(); Locale locale = new Locale(country.getIsoAbbreviation().toLowerCase(), country.getIsoAbbreviation()); Calendar calendar = new GregorianCalendar(locale); return calendar.getTimeZone().getDisplayName(Locale.ENGLISH); } } catch (RemoteException re) { re.printStackTrace(); } } return ""; }