List of usage examples for org.apache.commons.lang3 StringUtils replaceOnce
public static String replaceOnce(final String text, final String searchString, final String replacement)
Replaces a String with another String inside a larger String, once.
A null reference passed to this method is a no-op.
StringUtils.replaceOnce(null, *, *) = null StringUtils.replaceOnce("", *, *) = "" StringUtils.replaceOnce("any", null, *) = "any" StringUtils.replaceOnce("any", *, null) = "any" StringUtils.replaceOnce("any", "", *) = "any" StringUtils.replaceOnce("aba", "a", null) = "aba" StringUtils.replaceOnce("aba", "a", "") = "ba" StringUtils.replaceOnce("aba", "a", "z") = "zba"
From source file:cn.wanghaomiao.seimi.utils.StrFormatUtil.java
public static String info(String pattern, Object... params) { for (Object p : params) { pattern = StringUtils.replaceOnce(pattern, "{}", p.toString()); }/*w w w. j a va 2 s. c om*/ return pattern; }
From source file:io.fabric8.che.starter.util.ProjectHelper.java
private String changeProtocolToHttpsIfNeeded(final String repositoryUrl) { if (repositoryUrl.startsWith(GIT_PROTOCOL)) { return StringUtils.replaceOnce(repositoryUrl.replace(":", "/"), GIT_PROTOCOL, HTTPS_PROTOCOL); }//from w w w . j ava 2 s . c o m return repositoryUrl; }
From source file:ch.cyberduck.core.TildePathExpander.java
protected Path expand(final Path remote, final String format) throws BackgroundException { if (remote.getAbsolute().startsWith(format)) { return new Path(StringUtils.replaceOnce(remote.getAbsolute(), format, workdir.getAbsolute()), remote.getType());/*from w ww . java 2 s .co m*/ } return remote; }
From source file:io.jexiletools.es.model.Mod.java
public String toDisplay() { String result = name;//from www . j a v a 2 s.co m if (isValueRanged) { String minStr = String.valueOf(range.getMin().intValue()); String maxStr = String.valueOf(range.getMax().intValue()); result = StringUtils.replaceOnce(result, "#", minStr); result = StringUtils.replaceOnce(result, "#", maxStr); } else if (isValueBoolean) { // mod name is good enough } else { String valueStr = String.valueOf(value.intValue()); result = StringUtils.replaceOnce(result, "#", valueStr); } return result; }
From source file:com.google.api.codegen.util.TypedValue.java
/** * Renders the value given the value pattern, and adds any necessary nicknames to the given type * table./*from w w w . ja v a 2 s . c om*/ */ public String getValueAndSaveTypeNicknameIn(TypeTable typeTable) { if (getValuePattern().contains("%s")) { String nickname = typeTable.getAndSaveNicknameFor(getTypeName()); return StringUtils.replaceOnce(getValuePattern(), "%s", nickname); } else { return getValuePattern(); } }
From source file:com.techcavern.wavetact.eventListeners.PrivMsgListener.java
@Override public void onPrivateMessage(PrivateMessageEvent event) throws Exception { class process implements Runnable { public void run() { String[] message = StringUtils.split(Colors.removeFormatting(event.getMessage()), " "); String commandchar = IRCUtils.getCommandChar(event.getBot(), null); String privcommand = message[0].toLowerCase(); IRCUtils.sendLogChanMsg(event.getBot(), "[PM] " + IRCUtils.noPing(event.getUser().getNick()) + "!" + event.getUser().getLogin() + "@" + event.getUser().getHostname() + ": " + event.getMessage()); if (commandchar != null) privcommand = StringUtils.replaceOnce(privcommand, commandchar, ""); IRCCommand Command = IRCUtils.getCommand(privcommand, IRCUtils.getNetworkNameByNetwork(event.getBot()), null); message = ArrayUtils.remove(message, 0); if (Command != null) { String logmsg = StringUtils.join(message, " "); if (Command.getChannelRequired()) { Channel channel = null; String prefix = null; if (message.length > 0) { prefix = IRCUtils.getPrefix(event.getBot(), message[0]); if (!prefix.isEmpty()) channel = IRCUtils.getChannelbyName(event.getBot(), message[0].replace(prefix, "")); else channel = IRCUtils.getChannelbyName(event.getBot(), message[0]); message = ArrayUtils.remove(message, 0); }// ww w . j a v a 2 s .co m if (channel != null) { int userPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), channel); if (userPermLevel >= Command.getPermLevel()) { try { Command.onCommand(privcommand, event.getUser(), event.getBot(), prefix, channel, true, userPermLevel, message); } catch (Exception e) { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Failed to execute command, please make sure you are using the correct syntax (" + Command.getSyntax() + ")", ""); e.printStackTrace(); } } else { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Permission denied", ""); } } else { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Please specify channel as argument #1 in front of all the other arguments", ""); } } else { int userPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), null); if (Command.getPermLevel() == 0) { try { Command.onCommand(privcommand, event.getUser(), event.getBot(), null, null, true, userPermLevel, message); } catch (Exception e) { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Failed to execute command, please make sure you are using the correct syntax (" + Command.getSyntax() + ")", ""); e.printStackTrace(); } } else if (Command.getPermLevel() <= 5 && userPermLevel >= 1) { try { Command.onCommand(privcommand, event.getUser(), event.getBot(), null, null, true, userPermLevel, message); } catch (Exception e) { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Failed to execute command, please make sure you are using the correct syntax (" + Command.getSyntax() + ")", ""); e.printStackTrace(); } } else { if (userPermLevel >= Command.getPermLevel()) { try { Command.onCommand(privcommand, event.getUser(), event.getBot(), null, null, true, userPermLevel, message); } catch (Exception e) { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Failed to execute command, please make sure you are using the correct syntax (" + Command.getSyntax() + ")", ""); e.printStackTrace(); } } else { IRCUtils.sendError(event.getUser(), event.getBot(), null, "Permission denied", ""); } } } } } } Registry.threadPool.execute(new process()); }
From source file:com.techcavern.wavetact.eventListeners.ChanMsgListener.java
@Override public void onMessage(MessageEvent event) throws Exception { class process implements Runnable { public void run() { //sends Relay Message if (PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), event.getChannel()) > -4 && IRCUtils.getPrefix(event.getBot(), event.getChannelSource()).isEmpty()) IRCUtils.sendRelayMessage(event.getBot(), event.getChannel(), IRCUtils.noPing(event.getUser().getNick()) + ": " + event.getMessage()); if (PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), event.getChannel()) > -3) { IRCUtils.addVoice(event.getBot(), event.getChannel(), event.getUser()); }/*from w w w .j av a 2s. co m*/ //Begin Input Parsing String[] message = StringUtils.split(Colors.removeFormatting(event.getMessage()), " "); String commandchar = IRCUtils.getCommandChar(event.getBot(), event.getChannel()); if (commandchar == null) { return; } if (event.getMessage().startsWith(commandchar)) { String chancommand = StringUtils.replaceOnce(message[0].toLowerCase(), commandchar, ""); message = ArrayUtils.remove(message, 0); IRCCommand Command = IRCUtils.getCommand(chancommand, IRCUtils.getNetworkNameByNetwork(event.getBot()), event.getChannel().getName()); if (Command != null) { int userPermLevel = PermUtils.getPermLevel(event.getBot(), event.getUser().getNick(), event.getChannel()); if (userPermLevel >= Command.getPermLevel()) { try { Command.onCommand(chancommand, event.getUser(), event.getBot(), IRCUtils.getPrefix(event.getBot(), event.getChannelSource()), event.getChannel(), false, userPermLevel, message); } catch (Exception e) { IRCUtils.sendError(event.getUser(), event.getBot(), event.getChannel(), "Failed to execute command, please make sure you are using the correct syntax (" + Command.getSyntax() + ")", IRCUtils.getPrefix(event.getBot(), event.getChannelSource())); e.printStackTrace(); } } else { IRCUtils.sendError(event.getUser(), event.getBot(), event.getChannel(), "Permission denied", IRCUtils.getPrefix(event.getBot(), event.getChannelSource())); } } } else { Record rec = DatabaseUtils.getChannelUserProperty( IRCUtils.getNetworkNameByNetwork(event.getBot()), event.getChannel().getName(), PermUtils.authUser(event.getBot(), event.getUser().getNick()), "relaybotsplit"); if (rec == null) return; String relaysplit = rec.getValue(CHANNELUSERPROPERTY.VALUE); String startingmessage = event.getMessage(); if (relaysplit != null) { Pattern r = Pattern.compile(relaysplit); Matcher matcher = r.matcher(startingmessage); matcher.find(); startingmessage = startingmessage.replaceFirst(matcher.group(0), ""); } else { return; } String[] relayedmessage = StringUtils.split(startingmessage, " "); if (relayedmessage[0].startsWith(commandchar)) { String relayedcommand = StringUtils.replaceOnce(relayedmessage[0], commandchar, ""); relayedmessage = ArrayUtils.remove(relayedmessage, 0); IRCCommand Command = IRCUtils.getCommand(relayedcommand, IRCUtils.getNetworkNameByNetwork(event.getBot()), event.getChannel().getName()); if (Command != null && Command.getPermLevel() == 0) { try { Command.onCommand(relayedcommand, event.getUser(), event.getBot(), IRCUtils.getPrefix(event.getBot(), event.getChannelSource()), event.getChannel(), false, 0, relayedmessage); } catch (Exception e) { IRCUtils.sendError(event.getUser(), event.getBot(), event.getChannel(), "Failed to execute command, please make sure you are using the correct syntax (" + Command.getSyntax() + ")", IRCUtils.getPrefix(event.getBot(), event.getChannelSource())); } } } } } } Registry.threadPool.execute(new process()); }
From source file:lti.oauth.OAuthFilter.java
@Override protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain fc) throws ServletException, IOException { LaunchRequest launchRequest = new LaunchRequest(req.getParameterMap()); SortedMap<String, String> alphaSortedMap = launchRequest.toSortedMap(); String signature = alphaSortedMap.remove(OAuthUtil.SIGNATURE_PARAM); String calculatedSignature = null; try {/*w w w .j av a 2 s.co m*/ calculatedSignature = new OAuthMessageSigner().sign(secret, OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST", req.getRequestURL().toString(), alphaSortedMap); } catch (Exception e) { log.error(e.getMessage(), e); res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value()); return; } if (!signature.equals(calculatedSignature)) { // try again with http String recalculatedSignature = null; if (StringUtils.startsWithIgnoreCase(req.getRequestURL().toString(), "https:")) { String url = StringUtils.replaceOnce(req.getRequestURL().toString(), "https:", "http:"); try { recalculatedSignature = new OAuthMessageSigner().sign(secret, OAuthUtil.mapToJava(alphaSortedMap.get(OAuthUtil.SIGNATURE_METHOD_PARAM)), "POST", url, alphaSortedMap); } catch (Exception e) { log.error(e.getMessage(), e); res.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value()); return; } } if (!signature.equals(recalculatedSignature)) { res.sendError(HttpStatus.UNAUTHORIZED.value()); return; } } fc.doFilter(req, res); }
From source file:com.google.api.codegen.util.TypeName.java
/** Renders the fully-qualified name of this type given its pattern. */ public String getFullName() { if (pattern == null) { return topLevelAlias.getFullName(); }//from w ww. j a v a 2s . com String result = StringUtils.replaceOnce(pattern, "%s", topLevelAlias.getFullName()); for (TypeName innerTypeName : innerTypeNames) { result = StringUtils.replaceOnce(result, "%i", innerTypeName.getFullName()); } return result; }
From source file:com.castlemock.core.basis.utility.parser.TextParser.java
/** * The parse method is responsible for parsing a provided text and transform the text * with the help of {@link Expression}. {@link Expression} in the texts will be transformed * and replaced with new values. The transformed text will be returned. * @param text The provided text that will be transformed. * @return A transformed text. All expressions will be replaced by new values. * Please note that the same text will be returned if no expressions * were found in the provided text. *//* w w w . j av a 2 s. c o m*/ public static String parse(final String text) { String output = text; Pattern pattern = Pattern.compile("(?=\\$\\{)(.*?)\\}"); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String match = matcher.group(); ExpressionInput expressionInput = ExpressionInputParser.parse(match); Expression expression = EXPRESSIONS.get(expressionInput.getName()); if (expression == null) { LOGGER.error("Unable to parse the following expression: " + expressionInput.getName()); continue; } String expressionResult = expression.transform(expressionInput); output = StringUtils.replaceOnce(output, match, expressionResult); } return output; }