Example usage for java.util ResourceBundle getString

List of usage examples for java.util ResourceBundle getString

Introduction

In this page you can find the example usage for java.util ResourceBundle getString.

Prototype

public final String getString(String key) 

Source Link

Document

Gets a string for the given key from this resource bundle or one of its parents.

Usage

From source file:chatbot.Chatbot.java

/** **************************************************************************************************
 * Run with a given file//from  w  w w.  j a v a  2 s .  com
 */
private static void run(String fname) throws IOException {

    List<String> documents = null;

    try {
        if (asResource)
            documents = TextFileUtil.readLines(fname, false);
        //documents = TextFileUtil.readFile(fname, false);
    } catch (IOException e) {
        System.out.println("Couldn't read document: " + fname + ". Exiting");
        return;
    }
    Chatbot cb;
    ResourceBundle resourceBundle = ResourceBundle.getBundle("corpora");
    if (asResource)
        cb = new Chatbot(documents, resourceBundle.getString("stopWordsDirectoryName"));
    else {
        cb = new Chatbot(resourceBundle.getString("stopWordsDirectoryName"));
        cb.readFile(fname);
    }

    System.out.println("Hi, I'm Cloudio, tell/ask me something. Type 'quit' to exit");

    if (isDevelopment) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("User: ");
            String input = scanner.nextLine();
            if (input.toLowerCase().trim().equals("quit"))
                break;
            System.out.print("Cloudio: ");
            System.out.println(cb.matchBestInput(input));
        }
    } else {
        while (true) {
            Console c = System.console();
            if (c == null) {
                System.err.println("No console.");
                System.exit(1);
            }
            String input = c.readLine("> ");
            if (input.toLowerCase().trim().equals("quit"))
                System.exit(1);
            System.out.println("Cloudio:" + cb.matchBestInput(input));
        }
    }
}

From source file:net.sf.eclipsecs.core.config.meta.MetadataFactory.java

/**
 * Returns Checkstyles standard message for a given module and message key.
 *
 * @param messageKey//from w  w w.  ja  v  a2 s  .  c o  m
 *            the message key
 * @param rule
 *            the module metadata
 * @return Checkstyles standard message for this module and key
 */
public static String getStandardMessage(String messageKey, RuleMetadata rule) {

    // for some unknown reason there is no metadata or key
    if (messageKey == null || rule == null) {
        return null;
    }

    List<String> namesToCheck = new ArrayList<String>();
    namesToCheck.add(rule.getInternalName());
    namesToCheck.addAll(rule.getAlternativeNames());

    for (String moduleClass : namesToCheck) {
        try {

            int endIndex = moduleClass.lastIndexOf('.');
            String messages = "messages"; //$NON-NLS-1$
            if (endIndex >= 0) {
                String packageName = moduleClass.substring(0, endIndex);
                messages = packageName + "." + messages; //$NON-NLS-1$
            }
            ResourceBundle resourceBundle = ResourceBundle.getBundle(messages,
                    CheckstylePlugin.getPlatformLocale(), CheckstylePlugin.class.getClassLoader(),
                    new UTF8Control());

            String message = resourceBundle.getString(messageKey);
            return message;
        } catch (MissingResourceException e) {
            // let's continue to check the other alternative names
        }
    }
    return null;
}

From source file:fredboat.messaging.CentralMessaging.java

private static void handleInsufficientPermissionsException(@Nonnull MessageChannel channel,
        @Nonnull InsufficientPermissionException e) {
    final ResourceBundle i18n;
    if (channel instanceof TextChannel) {
        i18n = I18n.get(((TextChannel) channel).getGuild());
    } else {//ww  w . j  av  a  2 s. com
        i18n = I18n.DEFAULT.getProps();
    }
    //only ever try sending a simple string from here so we don't end up handling a loop of insufficient permissions
    sendMessage(channel, i18n.getString("permissionMissingBot") + " **" + e.getPermission().getName() + "**");
}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

public static boolean isMailUsed(String mail) {
    boolean registered = false;
    NamingEnumeration results = null;
    DirContext ctx = null;/*from w ww .j ava  2s .c o  m*/
    try {
        ctx = getContext();
        SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        ResourceBundle rb = ResourceBundle.getBundle("ldap");

        results = ctx.search(rb.getString("peopleRoot"), "(mail=" + mail + ")", controls);
        if (results.hasMore()) {
            registered = true;
        }
    } catch (NameNotFoundException ex) {
        _log.error(ex);
    } catch (NamingException e) {
        registered = true;
    } finally {
        if (results != null) {
            try {
                results.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
    }
    return registered;
}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

public static boolean isCNregistered(String cn) {
    boolean registered = false;
    NamingEnumeration results = null;
    DirContext ctx = null;// w  w w  . j  a  va  2  s. co m
    try {
        ctx = getContext();
        SearchControls controls = new SearchControls();
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        ResourceBundle rb = ResourceBundle.getBundle("ldap");

        results = ctx.search(rb.getString("peopleRoot"), "(cn=" + cn + ")", controls);
        if (results.hasMore()) {
            registered = true;
        }
    } catch (NameNotFoundException ex) {
        _log.error(ex);
    } catch (NamingException e) {
        registered = true;
    } finally {
        if (results != null) {
            try {
                results.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
    }

    return registered;
}

From source file:fedora.client.FedoraClient.java

public static String getVersion() {

    ResourceBundle bundle = ResourceBundle.getBundle("fedora.client.resources.Client");
    return bundle.getString("version");
}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

public static boolean resetPassword(String cn, String newPassword) {
    DirContext ctx = null;/*from   w  w  w.jav  a  2 s .  c  om*/
    try {
        ctx = getMainAuthContext();

        ModificationItem[] modItems = new ModificationItem[1];
        modItems[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
                new BasicAttribute("userPassword", newPassword));

        ResourceBundle rb = ResourceBundle.getBundle("ldap");

        ctx.modifyAttributes("cn=" + cn + "," + rb.getString("peopleRoot"), modItems);
    } catch (NamingException ex) {
        _log.error(ex);
        return false;
    }

    return true;
}

From source file:com.albert.util.StringUtilCommon.java

/**
 * Get message from resource bundle/*from  ww  w .  j a v  a 2s.c o  m*/
 * 
 * @param key
 * @param locale
 * @param bundleName
 * @param params
 * @return
 */
public static String getMessage(String key, Locale locale, String bundleName, Object params[]) {

    String text = null;

    ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale);

    try {
        text = bundle.getString(key);
    } catch (Exception e) {
        text = key;
    }

    if (params != null) {
        MessageFormat mf = new MessageFormat(text, locale);
        text = mf.format(params, new StringBuffer(), null).toString();
    }

    return text;
}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

private static boolean toggleUserIDPGroup(String cn, boolean activate) {
    ResourceBundle rb = ResourceBundle.getBundle("ldap");
    String userDN = "cn=" + cn + "," + rb.getString("peopleRoot");
    String idpUser = rb.getString("usersGroup");

    DirContext ctx = null;//w w  w.  ja  v a 2s  .  c o m
    try {
        ctx = getMainAuthContext();

        ModificationItem modAttrs[] = new ModificationItem[1];
        String attrsList[] = { "uniqueMember" };
        Attributes attributes = ctx.getAttributes(idpUser, attrsList);

        Attribute att = attributes.get("uniqueMember");
        if (activate) {
            att.add(userDN);
        } else {
            att.remove(userDN);
        }

        modAttrs[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, att);
        ctx.modifyAttributes(idpUser, modAttrs);
        return true;
    } catch (NamingException ex) {
        _log.error(ex);
    }

    return false;

}

From source file:it.infn.ct.security.utilities.LDAPUtils.java

public static LDAPUser findUserByMail(String mail) {
    NamingEnumeration results = null;
    DirContext ctx = null;/*from  w w  w.j av  a  2s. c o  m*/
    LDAPUser user = null;
    try {
        ctx = getContext();
        SearchControls controls = new SearchControls();
        String retAttrs[] = { "cn" };
        controls.setReturningAttributes(retAttrs);
        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        ResourceBundle rb = ResourceBundle.getBundle("ldap");

        results = ctx.search(rb.getString("peopleRoot"), "(mail=" + mail + ")", controls);
        if (results.hasMore()) {
            SearchResult searchResult = (SearchResult) results.next();
            Attributes attributes = searchResult.getAttributes();
            user = new LDAPUser();

            if (attributes.get("cn") != null)
                user = getUser((String) attributes.get("cn").get());
        }
    } catch (NameNotFoundException ex) {
        _log.error(ex);
    } catch (NamingException e) {
        _log.error(e);
    } finally {
        if (results != null) {
            try {
                results.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
        if (ctx != null) {
            try {
                ctx.close();
            } catch (Exception e) {
                // Never mind this.
            }
        }
    }
    return user;

}