List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:pl.otros.logview.gui.message.update.LogDataFormatter.java
public java.util.List<TextChunkWithStyle> format() throws Exception { LOGGER.finer("Start do in background"); String s1 = "Date: " + dateFormat.format(ld.getDate()) + NEW_LINE; chunks.add(new TextChunkWithStyle(s1, mainStyle)); s1 = "Class: " + ld.getClazz() + NEW_LINE; chunks.add(new TextChunkWithStyle(s1, classMethodStyle)); s1 = "Method: " + ld.getMethod() + NEW_LINE; chunks.add(new TextChunkWithStyle(s1, classMethodStyle)); s1 = "Level: "; chunks.add(new TextChunkWithStyle(s1, classMethodStyle)); Icon levelIcon = LevelRenderer.getIconByLevel(ld.getLevel()); if (levelIcon != null) { chunks.add(new TextChunkWithStyle(levelIcon)); }//www.j a va 2 s .c om s1 = " " + ld.getLevel().getName() + NEW_LINE; chunks.add(new TextChunkWithStyle(s1, classMethodStyle)); chunks.add(new TextChunkWithStyle("Thread: " + ld.getThread() + NEW_LINE, classMethodStyle)); if (StringUtils.isNotBlank(ld.getFile())) { s1 = "File: " + ld.getFile(); if (StringUtils.isNotBlank(ld.getLine())) { s1 = s1 + ":" + ld.getLine(); } chunks.add(new TextChunkWithStyle(s1 + NEW_LINE, mainStyle)); } if (StringUtils.isNotBlank(ld.getNDC())) { chunks.add(new TextChunkWithStyle("NDC: " + ld.getNDC() + NEW_LINE, mainStyle)); } if (StringUtils.isNotBlank(ld.getLoggerName())) { chunks.add(new TextChunkWithStyle("Logger name: " + ld.getLoggerName() + NEW_LINE, mainStyle)); } Map<String, String> properties = ld.getProperties(); if (properties != null && properties.size() > 0) { chunks.add(new TextChunkWithStyle("Properties:\n", boldArialStyle)); ArrayList<String> keys = new ArrayList(properties.keySet()); Collections.sort(keys); for (String key : keys) { chunks.add(new TextChunkWithStyle(key + "=", propertyNameStyle)); chunks.add(new TextChunkWithStyle(properties.get(key) + "\n", propertyValueStyle)); } } s1 = "Message: "; chunks.add(new TextChunkWithStyle(s1, boldArialStyle)); s1 = ld.getMessage(); if (s1.length() > maximumMessageSize) { int removedCharsSize = s1.length() - maximumMessageSize; s1 = StringUtils.left(s1, maximumMessageSize) + String.format("%n...%n...(+%,d chars)", removedCharsSize); } Collection<MessageFormatter> formatters = formattersContainer.getElements(); int charsBeforeMessage = countCharsBeforeMessage(chunks); for (MessageFormatter messageFormatter : formatters) { if (cancelStatus.isCancelled()) { return chunks; } s1 = messageUtils.formatMessageWithTimeLimit(s1, messageFormatter, 5); s1 = StringUtils.remove(s1, '\r'); } chunks.add(new TextChunkWithStyle(s1, mainStyle)); Collection<MessageColorizer> colorizers = colorizersContainer.getElements(); ArrayList<MessageFragmentStyle> messageFragmentStyles = new ArrayList<MessageFragmentStyle>(); for (MessageColorizer messageColorizer : colorizers) { if (messageColorizer.getPluginableId().equals(SearchResultColorizer.class.getName())) { continue; } messageFragmentStyles .addAll(messageUtils.colorizeMessageWithTimeLimit(s1, charsBeforeMessage, messageColorizer, 5)); } for (MessageFragmentStyle messageFragmentStyle : messageFragmentStyles) { chunks.add(new TextChunkWithStyle(null, messageFragmentStyle)); } chunks.add(new TextChunkWithStyle("\nMarked: ", boldArialStyle)); if (ld.isMarked()) { MarkerColors markerColors = ld.getMarkerColors(); chunks.add(new TextChunkWithStyle(" " + markerColors.name() + NEW_LINE, getStyleForMarkerColor(markerColors))); } else { chunks.add(new TextChunkWithStyle("false\n", boldArialStyle)); } Note note = ld.getNote(); if (note != null && note.getNote() != null && note.getNote().length() > 0) { s1 = "Note: " + note.getNote(); chunks.add(new TextChunkWithStyle(s1, boldArialStyle)); } return chunks; }
From source file:play.modules.accesslog.AccessLogPlugin.java
private synchronized void log() { if (!_shouldLog2Play && !_canLog) { return;/*w w w.jav a 2 s . c om*/ } Http.Request request = Http.Request.current(); Http.Response response = Http.Response.current(); if (request == null || response == null) { return; } long requestProcessingTime = System.currentTimeMillis() - request.date.getTime(); Http.Header referrer = request.headers.get(HttpHeaders.Names.REFERER.toLowerCase()); Http.Header userAgent = request.headers.get(HttpHeaders.Names.USER_AGENT.toLowerCase()); String bytes = "-"; String status = "-"; /* It seems as though the Response.current() is only valid when the request is handled by a controller Serving static files, static 404's and 500's etc don't populate the same Response.current() This prevents us from getting the bytes sent and response status all of the time */ if (request.action != null && response.out.size() > 0) { bytes = String.valueOf(response.out.size()); status = response.status.toString(); } String line = FORMAT; line = StringUtils.replaceOnce(line, "%v", request.host); line = StringUtils.replaceOnce(line, "%h", request.remoteAddress); line = StringUtils.replaceOnce(line, "%u", (StringUtils.isEmpty(request.user)) ? "-" : request.user); line = StringUtils.replaceOnce(line, "%t", request.date.toString()); line = StringUtils.replaceOnce(line, "%r", request.url); line = StringUtils.replaceOnce(line, "%s", status); line = StringUtils.replaceOnce(line, "%b", bytes); line = StringUtils.replaceOnce(line, "%ref", (referrer != null) ? referrer.value() : ""); line = StringUtils.replaceOnce(line, "%ua", (userAgent != null) ? userAgent.value() : ""); line = StringUtils.replaceOnce(line, "%rt", String.valueOf(requestProcessingTime)); if (_shouldLogPost && request.method.equals("POST")) { String body = request.params.get("body"); if (StringUtils.isNotEmpty(body)) { line = StringUtils.replaceOnce(line, "%post", body); } else { // leave quotes in the logged string to show it was an empty POST request line = StringUtils.remove(line, "%post"); } } else { line = StringUtils.remove(line, "\"%post\""); } line = StringUtils.trim(line); if (_canLog) { _writer.println(line); } if (_shouldLog2Play) { play.Logger.info(line); } }
From source file:pt.ist.maidSyncher.domain.github.GHIssue.java
/** * /*from w w w .ja v a 2s . c o m*/ * @param body * @return A string with the getSubTaskBodyPrefix in the beginning, and the rest of the body there. * If we had the subTaskBodyPrefix in any other place of the body, it moves it to the beginning */ public String applySubTaskBodyPrefix(String body) { String subTaskBodyPrefixString = getSubTaskBodyPrefix(); String newBody = body; //let's try to find it if (StringUtils.contains(body, subTaskBodyPrefixString)) { //let's remove it. newBody = StringUtils.remove(body, subTaskBodyPrefixString); } newBody = subTaskBodyPrefixString + " " + newBody; return newBody; }
From source file:pt.ist.maidSyncher.domain.github.GHIssue.java
/** * /*from w ww . j a va2 s .c om*/ * @param body * @return A string with the getSubTaskBodyPrefix in the beginning, and the rest of the body there. * If we had the subTaskBodyPrefix in any other place of the body, it moves it to the beginning */ public static String applySubTaskBodyPrefix(String body, GHIssue parentGHIssue) { String subTaskBodyPrefixString = getSubTaskBodyPrefix(parentGHIssue); String newBody = body == null ? "" : body; //let's try to find it if (StringUtils.contains(body, subTaskBodyPrefixString)) { //let's remove it. newBody = StringUtils.remove(body, subTaskBodyPrefixString); } newBody = subTaskBodyPrefixString + " " + newBody; return newBody; }
From source file:pt.webdetails.cda.utils.NaturalOrderComparator.java
public int compareStrings(String a, String b) { if (a == null) { if (b == null) return 0; else// w w w. j a v a 2 s . c om return -1; } else if (b == null) return 1; Matcher matcherA = recognizeNbr.matcher(a); Matcher matcherB = recognizeNbr.matcher(b); int idxA = 0, idxB = 0; while (idxA < a.length() || idxB < b.length()) { boolean foundInA = matcherA.find(idxA); boolean foundInB = matcherB.find(idxB); if (!foundInA || !foundInB) {//then our job is over, return a regular string comparison return stringComparator.compare(a.substring(idxA), b.substring(idxB)); } //else found in both //1) compare unmatched bit as String String preA = StringUtils.substring(a, idxA, matcherA.start()); String preB = StringUtils.substring(b, idxB, matcherB.start()); int comparison = stringComparator.compare(preA, preB); if (comparison != 0) return comparison;//done! //2) get the number and compare it String matchA = StringUtils.substring(a, matcherA.start(), matcherA.end()); String matchB = StringUtils.substring(b, matcherB.start(), matcherB.end()); BigDecimal numberA = new BigDecimal(StringUtils.remove(matchA, ',').trim()); BigDecimal numberB = new BigDecimal(StringUtils.remove(matchB, ',').trim()); comparison = numberA.compareTo(numberB); if (comparison != 0) return comparison; //3) if inconclusive process the rest idxA = matcherA.end(); idxB = matcherB.end(); } return 0; }
From source file:raptor.chess.pgn.PgnUtils.java
/** * Prepends the game to the users game pgn file. *///from w ww. j ava 2 s .c o m public static void appendGameToFile(Game game) { if (Variant.isBughouse(game.getVariant())) { return; } if (game.getMoveList().getSize() == 0) { return; } String pgnFilePath = Raptor.getInstance().getPreferences().getString(PreferenceKeys.APP_PGN_FILE); if (StringUtils.isNotEmpty(pgnFilePath)) { // synchronized on PGN_APPEND_SYNCH so just one thread at a time // writes to the file. synchronized (PGN_APPEND_SYNCH) { if (game instanceof GameCursor) { game = ((GameCursor) game).getMasterGame(); } String whiteRating = game.getHeader(PgnHeader.WhiteElo); String blackRating = game.getHeader(PgnHeader.BlackElo); whiteRating = StringUtils.remove(whiteRating, 'E'); whiteRating = StringUtils.remove(whiteRating, 'P'); blackRating = StringUtils.remove(blackRating, 'E'); blackRating = StringUtils.remove(blackRating, 'P'); if (!NumberUtils.isDigits(whiteRating)) { game.removeHeader(PgnHeader.WhiteElo); } if (!NumberUtils.isDigits(blackRating)) { game.removeHeader(PgnHeader.BlackElo); } String pgn = game.toPgn(); File file = new File(pgnFilePath); FileWriter fileWriter = null; try { fileWriter = new FileWriter(file, true); fileWriter.append(pgn).append("\n\n"); fileWriter.flush(); } catch (IOException ioe) { LOG.error("Error saving game", ioe); } finally { try { if (fileWriter != null) { fileWriter.close(); } } catch (IOException ioe) { } } } } }
From source file:raptor.chess.util.SanUtils.java
/** * Removes all of the following characters (+,-,=,x,:,"e.p."). Replaces * (ACDEFGH) with (acdefgh)./*ww w . j ava 2s.c o m*/ * * @param unstrictSan * @return */ public static String toStrictSan(String unstrictSan) { String result = StringUtils.replaceChars(unstrictSan, ",+#=x:X", null); result = StringUtils.remove(result, "e.p."); result = StringUtils.replaceChars(result, "ACDEFGH", "acdefgh"); // System.err.println("SAN IN = " + unstrictSan + " SAN OUT=" + result); return result; }
From source file:raptor.connector.ics.chat.ChannelTellEventParser.java
/** * Returns null if text does not match the event this class produces. *///from w w w .java2 s . com @Override public ChatEvent parse(String text) { if (text.length() < 600) { int i = text.indexOf("): "); if (i != -1) { RaptorStringTokenizer stringtokenizer = new RaptorStringTokenizer(text, ":"); if (stringtokenizer.hasMoreTokens()) { String s1 = StringUtils.remove(stringtokenizer.nextToken().trim(), ":"); int j = s1.lastIndexOf(')'); int k = s1.lastIndexOf('('); if (k < j && k != -1 && j != -1) { ChatEvent event = new ChatEvent(IcsUtils.stripTitles(s1), ChatType.CHANNEL_TELL, text.trim()); String channel = s1.substring(k + 1, j); if (NumberUtils.isDigits(channel)) { event.setChannel(channel); return event; } else { return null; } } } } return null; } return null; }
From source file:raptor.connector.ics.IcsConnector.java
protected static boolean speak(String message) { message = StringUtils.remove(message, "fics%").trim(); return SoundService.getInstance().textToSpeech(message); }
From source file:raptor.connector.ics.IcsUtils.java
/** * Cleans up the message by ensuring only \n is used as a line terminator. * \r\n and \r may be used depending on the operating system. *///from ww w . j a v a2s . co m public static String cleanupMessage(String message) { return StringUtils.remove(message, '\r'); }