List of usage examples for org.apache.commons.lang WordUtils capitalize
public static String capitalize(String str)
Capitalizes all the whitespace separated words in a String.
From source file:com.txtweb.wikipedia.Wikipedia.java
@Override public void doGet(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException { String txtWebMessageParam = httpRequest.getParameter(HTTP_PARAM_TXTWEB_MESSAGE); String pageParam = httpRequest.getParameter(HTTP_PARAM_PAGE); String paragraphNumberParam = httpRequest.getParameter(HTTP_PARAM_PARAGRAPH_NUMBER); String page = ""; if (pageParam != null && !pageParam.isEmpty()) { // If we know what page to display, then disregard the user's message // and simply display the page. page = pageParam;/*ww w . j a va 2 s .co m*/ } else if (txtWebMessageParam != null && !txtWebMessageParam.isEmpty()) { txtWebMessageParam = StringUtils.strip(txtWebMessageParam); txtWebMessageParam = txtWebMessageParam.replaceAll("\\s+", " "); // Format the user's message to conform to wikipedia's URL naming conventions page = txtWebMessageParam; page = page.toLowerCase(); page = WordUtils.capitalize(page); page = page.replaceAll(" ", "_"); } else { // We don't know what page to display, and the user didn't send any message // Respond with a welcome message and instructions on how to use the service String response = getWelcomeMessage(); sendResponse(httpResponse, response); return; } int paragraphNumber = 1; if (paragraphNumberParam != null) { try { paragraphNumber = Integer.parseInt(paragraphNumberParam); } catch (NumberFormatException e) { // } } HttpClient httpclient = new DefaultHttpClient(); try { page = URLEncoder.encode(page, "UTF-8"); HttpGet httpGet = new HttpGet("http://en.wikipedia.org/wiki/" + page); HttpResponse Httpresponse = httpclient.execute(httpGet); String responseBody = EntityUtils.toString(Httpresponse.getEntity(), "UTF-8"); String responseWithoutInfoBoxes = removeInfoBoxes(responseBody); Source source = new Source(responseWithoutInfoBoxes); source.fullSequentialParse(); Element bodyContent = source.getElementById("bodyContent"); String response = ""; if (bodyContent != null) { response = parseHtmlNode(bodyContent, page, paragraphNumber); } if (!response.isEmpty()) { sendResponse(httpResponse, response); return; } } catch (MalformedURLException e) { // } catch (IOException e) { // } finally { httpclient.getConnectionManager().shutdown(); } if (pageParam != null && !pageParam.isEmpty()) { // Unknown error or no results. Respond with a nothing found message // and instructions on how to use the service. String response = getNothingFoundMessage(pageParam); sendResponse(httpResponse, response); return; } if (txtWebMessageParam != null && !txtWebMessageParam.isEmpty()) { // Unknown error or no results. Respond with a nothing found message // and instructions on how to use the service. String response = getNothingFoundMessage(txtWebMessageParam); sendResponse(httpResponse, response); return; } // Unknown error or no results. Respond with a welcome message // and instructions on how to use the service. String response = getWelcomeMessage(); sendResponse(httpResponse, response); return; }
From source file:com.stayuber.glow.commands.GlowCommand.java
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { config = plugin.getConfig();//from w ww. ja va 2 s . co m msgGlowAdded = config.getString("messages.glow-added"); msgGlowRemoved = config.getString("messages.glow-removed"); msgNeedPermission = config.getString("messages.need-permission"); msgInsufficientMoney = config.getString("messages.insufficient-money"); msgInsufficientMoney = config.getString("messages.insufficient-money"); msgDescriptionAdd = config.getString("messages.description-add"); msgDescriptionRemove = config.getString("messages.description-remove"); msgDescriptionReload = config.getString("messages.description-reload"); msgReloadSuccess = config.getString("messages.reload-success"); boolUseEconomy = config.getBoolean("economy.enabled"); dblCost = config.getDouble("economy.cost"); pluginVersion = plugin.getDescription().getVersion(); if (!(sender instanceof Player)) { sender.sendMessage(Glow.colorize("&7Glow &c> &fUse must be a player to use this command.")); return false; } player = (Player) sender; isOp = player.isOp(); itemInHand = player.getItemInHand(); itemMeta = itemInHand.getItemMeta(); itemName = itemInHand.getItemMeta().hasDisplayName() ? itemInHand.getItemMeta().getDisplayName() : WordUtils.capitalize(itemInHand.getType().name().replace("_", " ").toLowerCase()); if (isOp || player.hasPermission(permUse)) { if (args.length == 0) { player.sendMessage( Glow.colorize("&7Glow &b> Glow &7version &b" + pluginVersion + " &7by &bStayUber&7.")); player.sendMessage(Glow.colorize("&7Glow &b> &7Looking for help? /glow help")); } else if (args.length == 1) { if ((args[0].equalsIgnoreCase("help")) || (args[0].equalsIgnoreCase("?"))) { player.sendMessage(Glow.colorize("&7Glow &b> &7/&fglow &badd&7: " + msgDescriptionAdd)); player.sendMessage(Glow.colorize("&7Glow &b> &7/&fglow &bremove&7: " + msgDescriptionRemove)); if (isOp || player.hasPermission(permReload)) player.sendMessage( Glow.colorize("&7Glow &b> &7/&fglow &breload&7: " + msgDescriptionReload)); } else if (args[0].equalsIgnoreCase("add")) { if (isOp || player.hasPermission(permAdd)) { if (boolUseEconomy) { if (checkEconomy(player)) { if (!player.hasPermission(permFree)) { if (plugin.economy != null) plugin.economy.withdrawPlayer(player, dblCost); } } else { return false; } } if (itemInHand.getType().equals(Material.FISHING_ROD)) { itemMeta.addEnchant(Enchantment.THORNS, 1, true); } else { itemMeta.addEnchant(Enchantment.LUCK, 1, true); } itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); itemInHand.setItemMeta(itemMeta); if (msgGlowAdded.contains("{item}")) msgGlowAdded = msgGlowAdded.replace("{item}", itemName); player.sendMessage(Glow.colorize(msgGlowAdded)); } else { player.sendMessage(Glow.colorize(msgNeedPermission)); } } else if (args[0].equalsIgnoreCase("remove")) { if (isOp || player.hasPermission(permRemove)) { if (itemInHand.getType().equals(Material.FISHING_ROD)) { itemMeta.removeEnchant(Enchantment.THORNS); } else { itemMeta.removeEnchant(Enchantment.LUCK); } itemMeta.removeItemFlags(ItemFlag.HIDE_ENCHANTS); itemInHand.setItemMeta(itemMeta); if (msgGlowRemoved.contains("{item}")) msgGlowRemoved = msgGlowRemoved.replace("{item}", itemName); player.sendMessage(Glow.colorize(msgGlowRemoved)); } else { player.sendMessage(Glow.colorize(msgNeedPermission)); } } else if (args[0].equalsIgnoreCase("reload")) { if (isOp || player.hasPermission(permReload)) { } plugin.reloadConfig(); player.sendMessage(Glow.colorize(msgReloadSuccess)); } } } return false; }
From source file:com.tgn.ProjectApex.DestroyTheMonument.commands.StatsCommand.java
private void listStats(Player player, StatType[] stats) { String GRAY = ChatColor.GRAY.toString(); String DARK_AQUA = ChatColor.DARK_AQUA.toString(); String AQUA = ChatColor.AQUA.toString(); player.sendMessage(GRAY + "=========[ " + DARK_AQUA + _("INFO_COMMAND_STATS") + GRAY + " ]========="); for (StatType stat : stats) { if (stat == null) continue; String name = WordUtils.capitalize(stat.name().toLowerCase().replace('_', ' ')); player.sendMessage(DARK_AQUA + name + ": " + AQUA + manager.getStat(stat, player)); }/*from w ww . ja v a2 s . c o m*/ player.sendMessage(GRAY + "========================="); }
From source file:au.com.dw.testdatacapturej.builder.BuilderUtil.java
/** * Create a field name to be used in the generated log for code that is creating an array, e.g. * in a construction line./* w w w . j av a 2 s . co m*/ * * An example - * We want to generate a line in the log to create an array of the class org.test.Item, a * constructor line may be generated something like this: * org.test.Item[] [field name]0 = new org.test.Item[5]; * This method is responsible for creating the [field name] portion of that line, note that * it does not include the numerical index suffix which is generated elsewhere. * e.g. * org.test.Item[] itemArray0 = new org.test.Item[5]; * Here the method has created the field name fragment 'itemArray'. * * @param arrayType The fully qualified class name of the array type * @param fieldNamePrefix Any prefix to add to the field name * @param fieldNameSuffix Any suffix to add to the field name (not the index number) * @return The field name to be used for the array in the generated log, without the numerical index */ public static String createArrayClassFieldName(String arrayType, String fieldNamePrefix, String fieldNameSuffix) { String arrayFieldNameSuffix = "Array"; String objectType = arrayType; StringBuilder fieldNameBuilder = new StringBuilder(); // derive the class field name portion if (fieldNamePrefix != null) { fieldNameBuilder.append(fieldNamePrefix); objectType = WordUtils.capitalize(objectType.substring(objectType.lastIndexOf(".") + 1)); } else { objectType = WordUtils.uncapitalize(objectType.substring(objectType.lastIndexOf(".") + 1)); } fieldNameBuilder.append(objectType); fieldNameBuilder.append(arrayFieldNameSuffix); if (fieldNameSuffix != null) { fieldNameBuilder.append(fieldNameSuffix); } return fieldNameBuilder.toString(); }
From source file:io.github.apfelcreme.Guilds.Command.Guild.Command.LevelCommand.java
/** * executes the command/* w w w .j a v a2 s.com*/ * * @param commandSender the sender * @param strings the command args */ public void execute(CommandSender commandSender, String[] strings) { Player sender = (Player) commandSender; if (sender.hasPermission("Guilds.level")) { if (strings.length > 1) { GuildLevel level = null; if (GuildsUtil.isNumeric(strings[1])) { level = plugin.getGuildsConfig().getLevelData(Integer.parseInt(strings[1])); } else { level = plugin.getGuildsConfig().getLevelData(strings[1]); } if (level != null) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.head") .replace("{0}", level.getName())); if (plugin.getGuildsConfig().requireMoneyForUpgrade()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getText("info.guild.level.cost").replace("{0}", Double.toString(level.getCost()))); } if (plugin.getGuildsConfig().requireExpForUpgrade()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.expCost").replace("{0}", Integer.toString(level.getExpCost()))); } if (plugin.getGuildsConfig().requireMaterialForUpgrade()) { for (Map.Entry<Material, Integer> entry : level.getMaterialRequirements().entrySet()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.materialElement") .replace("{0}", WordUtils.capitalize( entry.getKey().name().toLowerCase().replace("_", " "))) .replace("{1}", entry.getValue().toString())); } } plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.head2")); plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.playerLimit").replace("{0}", Integer.toString(level.getPlayerLimit()))); if (plugin.getGuildsConfig().isEnchantmentBonusActivated()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.enchantmentCost").replace("{0}", Double.toString(level.getEnchantmentCost() * 100))); } if (plugin.getGuildsConfig().isDoubleCraftingBonusActivated()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.doubleCraftProbability") .replace("{0}", Double.toString(level.getDoubleCraftProbability() * 100))); } if (plugin.getGuildsConfig().isSpecialDropBonusActivated()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.specialDropChance") .replace("{0}", Double.toString(level.getSpecialDropChance() * 100))); } if (plugin.getGuildsConfig().isMoreFurnaceExpBonusActivated()) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("info.guild.level.furnaceExpGainRatio").replace( "{0}", Double.toString(Math.ceil((level.getFurnaceExpGainRatio() - 1) * 100)))); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.unknownLevel")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.wrongUsage.level")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noPermission")); } }
From source file:com.thoughtworks.twist.migration.brt.BRTMigrator.java
private String camelCase(String text) { String[] splits = text.split(" "); StringBuilder sb = new StringBuilder(); char[] chars = splits[0].toCharArray(); chars[0] = Character.toLowerCase(chars[0]); sb.append(String.valueOf(chars)); for (int i = 1; i < splits.length; i++) sb.append(WordUtils.capitalize(splits[i])); return sb.toString(); }
From source file:de.knowwe.rdfs.d3web.Rdf2GoPropertyHandler.java
public static String getD3webPropertyAsOntologyProperty(Property<?> property) { return "has" + WordUtils.capitalize(property.getName()); }
From source file:io.github.apfelcreme.Guilds.Command.Alliance.Command.CreateCommand.java
/** * executes the command//w w w . j a v a 2 s .com * * @param commandSender the sender * @param strings the command args */ public void execute(CommandSender commandSender, String[] strings) { Player sender = (Player) commandSender; if (sender.hasPermission("Guilds.createAlliance")) { if (strings.length >= 4) { String name = strings[1]; String tag = strings[2]; ChatColor color = plugin.getGuildsConfig().parseColor(strings[3]); if (name.length() <= plugin.getGuildsConfig().getGuildNameLength()) { if (GuildsUtil.strip(tag).length() <= plugin.getGuildsConfig().getGuildTagLength()) { if (color != null) { Guild guild = plugin.getGuildManager().getGuild(sender); if (guild != null) { if (plugin.getAllianceManager().getAlliance(sender) == null) { if (plugin.getAllianceManager().getAlliance(name) == null) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.alliance.create.name", color) .replace("{0}", GuildsUtil.replaceChatColors(name))); plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.alliance.create.tag", color) .replace("{0}", GuildsUtil.replaceChatColors(tag))); plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.alliance.create.color", color) .replace("{0}", WordUtils.capitalize( color.name().replace("_", " ").toLowerCase()))); plugin.getRequestController().addRequest( new CreateRequest(plugin, guild, sender, name, tag, color)); } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.allianceAlreadyExists")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.stillInAlliance")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noCurrentGuild")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getText("error.noValidColor").replace("{0}", strings[3])); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.tagTooLong")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.nameTooLong")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.wrongUsage.createAlliance")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noPermission")); } }
From source file:com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardMavenLibrary.java
/** * Certain maven versions like "LATEST" are displayed differently - e.g. "Latest", so we need to * reconstruct the maven display name manually *//* www. j a va 2 s.co m*/ public String toMavenDisplayVersion() { return groupId + ":" + artifactId + ":" + WordUtils.capitalize(version.toLowerCase()); }
From source file:io.github.apfelcreme.Guilds.Command.Guild.Command.CreateCommand.java
/** * executes the command/*ww w. j ava2s . c o m*/ * * @param commandSender the sender * @param strings the command args */ public void execute(final CommandSender commandSender, final String[] strings) { Player sender = (Player) commandSender; if (plugin.hasVault()) { if (sender.hasPermission("Guilds.createGuild")) { if (strings.length >= 4) { String name = strings[1]; String tag = strings[2]; ChatColor color = plugin.getGuildsConfig().parseColor(strings[3]); if (GuildsUtil.strip(name).length() <= plugin.getGuildsConfig().getGuildNameLength()) { if (GuildsUtil.strip(tag).length() <= plugin.getGuildsConfig().getGuildTagLength()) { if (color != null) { if (plugin.getGuildManager().getGuild(sender) == null) { if (plugin.getGuildManager().getGuild(name) == null) { if (plugin.getEconomy().has(sender, plugin.getGuildsConfig().getLevelData(1).getCost())) { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.guild.create.name", color) .replace("{0}", GuildsUtil.replaceChatColors(name))); plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.guild.create.tag", color) .replace("{0}", GuildsUtil.replaceChatColors(tag))); plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.guild.create.color", color) .replace("{0}", WordUtils.capitalize( color.name().replace("_", " ").toLowerCase()))); plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getColoredText("info.guild.create.price", color) .replace("{0}", new DecimalFormat("#.##").format( plugin.getGuildsConfig().getLevelData(1).getCost()))); plugin.getRequestController().addRequest( new CreateRequest(plugin, sender, name, tag, color)); } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getText("error.notEnoughMoneyFounding") .replace("{0}", Double.toString( plugin.getGuildsConfig().getLevelData(1).getCost()))); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.guildAlreadyExists")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.stillInGuild")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig() .getText("error.noValidColor").replace("{0}", strings[3])); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.tagTooLong")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.nameTooLong")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.wrongUsage.create")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noPermission")); } } else { plugin.getChat().sendMessage(sender, plugin.getGuildsConfig().getText("error.noVault")); } }