List of usage examples for java.util ResourceBundle getString
public final String getString(String key)
From source file:com.evolveum.midpoint.report.impl.ReportUtils.java
public static String getPropertyString(String key, String defaultValue) { String val = (defaultValue == null) ? key : defaultValue; ResourceBundle bundle; try {/*from w w w . j a v a 2s .c o m*/ bundle = ResourceBundle.getBundle("localization/Midpoint", new Locale("en", "US")); } catch (MissingResourceException e) { return (defaultValue != null) ? defaultValue : key; //workaround for Jasper Studio } if (bundle != null && bundle.containsKey(key)) { val = bundle.getString(key); } return val; }
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Builds a Map<String,String> of services available (id, label example * 01-EXPRESS SHIPPING// w w w.ja v a2 s .c o m * * @param serviceline * @param moduleid * @param locale * @return */ public static Map<String, String> buildServiceMapLabelByCode(String moduleid, Locale locale) throws Exception { ReferenceService rservice = (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService); String country = locale.getCountry(); if (locale.getVariant().equals("EUR")) { country = "X1"; } ModuleConfiguration serviceconfig = rservice.getModuleConfiguration(moduleid, "service", country); if (serviceconfig == null) { serviceconfig = rservice.getModuleConfiguration(moduleid, "service", "XX");// generic } if (serviceconfig == null) { throw new Exception( "ModuleConfiguration does not exist for " + moduleid + "-service-XX-" + locale.getCountry()); } String serviceline = serviceconfig.getConfigurationValue(); Map amap = getConfigurationMap(serviceline, ";", "|"); Map returnMap = new HashMap(); ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale); if (amap != null) { Iterator i = amap.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); String pkg = bundle.getString("shipping.quote.services.label." + key); returnMap.put(key, pkg); } } return returnMap; }
From source file:fedora.client.FedoraClient.java
public static List<String> getCompatibleServerVersions() { ResourceBundle bundle = ResourceBundle.getBundle("fedora.client.resources.Client"); List<String> list = new ArrayList<String>(); String versions = bundle.getString("compatibleServerVersions"); if (versions != null && versions.trim().length() > 0) { String[] va = versions.trim().split(" "); for (String element : va) { list.add(element);/* w w w . java 2 s .com*/ } } String clientVersion = getVersion(); if (!list.contains(clientVersion)) { list.add(getVersion()); } return list; }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
public static boolean registerUser(LDAPUser lus, UserRequest userReq, String OrgDN, String OrgUDN) { boolean registration = false; DirContext ctx = null;//from w w w. j a va 2 s. co m try { ctx = getAuthContext(lus.getUsername(), lus.getPassword()); Attributes attrsBag = new BasicAttributes(); Attribute oc = new BasicAttribute("objectClass"); oc.add("inetOrgPerson"); oc.add("organizationalPerson"); oc.add("person"); oc.add("top"); attrsBag.put(oc); Attribute sn = new BasicAttribute("sn", userReq.getSurname()); attrsBag.put(sn); Attribute cn = new BasicAttribute("cn", userReq.getUsername()); attrsBag.put(cn); Attribute dispName = new BasicAttribute("displayName", userReq.getUsername()); attrsBag.put(dispName); Attribute uPass = new BasicAttribute("userPassword", userReq.getPassword()); attrsBag.put(uPass); Attribute regAdd = new BasicAttribute("registeredAddress", userReq.getPreferredMail()); attrsBag.put(regAdd); if (userReq.getTitle() != null && !userReq.getTitle().isEmpty()) { Attribute title = new BasicAttribute("title", userReq.getTitle()); attrsBag.put(title); } Attribute gName = new BasicAttribute("givenName", userReq.getGivenname()); attrsBag.put(gName); Attribute inits = new BasicAttribute("initials", userReq.getGivenname().substring(0, 1).toUpperCase() + userReq.getSurname().substring(0, 1).toUpperCase()); attrsBag.put(inits); Attribute mails = new BasicAttribute("mail"); mails.add(userReq.getPreferredMail()); for (String adMail : userReq.getAdditionalMails().split("[,\\s;]")) if (!adMail.isEmpty()) mails.add(adMail.trim()); attrsBag.put(mails); Attribute org = new BasicAttribute("o", OrgDN); attrsBag.put(org); if (OrgUDN != null && !OrgUDN.isEmpty()) { Attribute orgU = new BasicAttribute("ou", OrgUDN); attrsBag.put(orgU); } ResourceBundle rb = ResourceBundle.getBundle("ldap"); ctx.createSubcontext("cn=" + userReq.getUsername() + "," + rb.getString("peopleRoot"), attrsBag); ModificationItem[] modItems = new ModificationItem[1]; modItems[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("uniqueMember", "cn=" + userReq.getUsername() + "," + rb.getString("peopleRoot"))); ctx.modifyAttributes(rb.getString("usersGroup"), modItems); registration = true; } catch (NameNotFoundException ex) { _log.error(ex); } catch (NamingException e) { _log.error(e); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception e) { // Never mind this. } } } return registration; }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
public static boolean addOrganisation(LDAPUser lus, Organization org) { boolean registration = false; DirContext ctx = null;//ww w . j av a 2 s . co m try { ctx = getAuthContext(lus.getUsername(), lus.getPassword()); Attributes attrsBag = new BasicAttributes(); Attribute oc = new BasicAttribute("objectClass"); oc.add("organization"); oc.add("top"); attrsBag.put(oc); Attribute o = new BasicAttribute("o", org.getKey()); attrsBag.put(o); Attribute description = new BasicAttribute("description", org.getDescription()); attrsBag.put(description); if (org.getReference() != null && !org.getReference().isEmpty()) { Attribute registeredAddr = new BasicAttribute("registeredAddress", org.getReference()); attrsBag.put(registeredAddr); } ResourceBundle rb = ResourceBundle.getBundle("ldap"); ctx.createSubcontext( "o=" + org.getKey() + ",c=" + org.getCountryCode() + "," + rb.getString("organisationsRoot"), attrsBag); registration = true; } catch (NameNotFoundException ex) { _log.error(ex); } catch (NamingException e) { _log.error(e); } finally { if (ctx != null) { try { ctx.close(); } catch (Exception e) { // Never mind this. } } } return registration; }
From source file:de.gbv.ole.Marc21ToOleBulk.java
/** * Print usage to System.err and exit the program. *///from w w w.ja v a2 s . c om private static void usageExit() { ResourceBundle messages = ResourceBundle.getBundle("application"); System.err.println(messages.getString("usage")); System.exit(1); }
From source file:com.sunchenbin.store.feilong.core.util.ResourceBundleUtil.java
/** * ??,k/v ?map(HashMap).//from w ww . ja v a 2 s . c o m * * @param baseName * ?+??<span style="color:red">(??)</span>,the base name of the resource bundle, a fully qualified class name * @param locale * the locale ? * @return baseName key value,null,?,?keyvalue?HashMap * @see #getResourceBundle(String, Locale) * @see java.util.ResourceBundle#getKeys() * @see MapUtils#toMap(ResourceBundle) */ public static Map<String, String> readAllPropertiesToMap(String baseName, Locale locale) { ResourceBundle resourceBundle = getResourceBundle(baseName, locale); Enumeration<String> enumeration = resourceBundle.getKeys(); if (Validator.isNullOrEmpty(enumeration)) { return Collections.emptyMap(); } Map<String, String> propertyMap = new HashMap<String, String>(); while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); String value = resourceBundle.getString(key); propertyMap.put(key, value); } return propertyMap; }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
private static DirContext getContext() throws NamingException { ResourceBundle rb = ResourceBundle.getBundle("ldap"); Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, rb.getString("url")); env.put(Context.SECURITY_PRINCIPAL, rb.getString("rootDN")); env.put(Context.SECURITY_AUTHENTICATION, "none"); return new InitialDirContext(env); }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
public static List<LDAPUser> getIdPUserList() { List<LDAPUser> users = new ArrayList<LDAPUser>(); NamingEnumeration results = null; DirContext ctx;//w w w . j av a 2 s. co m ResourceBundle rb = ResourceBundle.getBundle("ldap"); try { ctx = getMainAuthContext(); String attrs[] = { "uniqueMember" }; Attribute userGAttr = ctx.getAttributes(rb.getString("usersGroup"), attrs).get("uniqueMember"); for (int i = 0; i < userGAttr.size(); i++) { String userDN = (String) userGAttr.get(i); users.add(getUser(userDN.substring(userDN.indexOf("=") + 1, userDN.indexOf(",")))); } } catch (NamingException ex) { _log.error(ex); } return users; }
From source file:it.infn.ct.security.utilities.LDAPUtils.java
private static DirContext getAuthContext(String userCN, String password, boolean dedicatedAdminUser) throws NamingException { ResourceBundle rb = ResourceBundle.getBundle("ldap"); Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, rb.getString("url")); env.put(Context.SECURITY_AUTHENTICATION, "simple"); if (dedicatedAdminUser) { env.put(Context.SECURITY_PRINCIPAL, rb.getString("bindDN")); env.put(Context.SECURITY_CREDENTIALS, rb.getString("bindPass")); } else {//from w ww . j a v a2 s. co m env.put(Context.SECURITY_PRINCIPAL, "cn=" + userCN + "," + rb.getString("peopleRoot")); env.put(Context.SECURITY_CREDENTIALS, password); } return new InitialDirContext(env); }