List of usage examples for org.apache.commons.lang StringUtils replaceChars
public static String replaceChars(String str, String searchChars, String replaceChars)
Replaces multiple characters in a String in one go.
From source file:raptor.chess.util.SanUtils.java
/** * Removes all of the following characters (+,-,=,x,:,"e.p."). Replaces * (ACDEFGH) with (acdefgh).//ww w. j av a2 s.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.IcsConnector.java
/** * Processes a login message. Handles sending the user name and password * information and the enter if prompted to hit enter if logging in as a * guest.// w ww .j a v a 2 s. co m * * @param message * @param isLoginPrompt */ protected void onLoginEvent(String message, boolean isLoginPrompt) { String profilePrefix = context.getPreferencePrefix() + currentProfileName + "-"; message = StringUtils.replaceChars(message, LOGIN_CHARACTERS_TO_FILTER, ""); if (isLoginPrompt) { if (hasSentLogin) { isLoggingIn = false; } if (getPreferences().getBoolean(profilePrefix + "is-anon-guest") && !hasSentLogin) { parseMessage(message); hasSentLogin = true; sendMessage("guest", true); } else if (!hasSentLogin) { parseMessage(message); hasSentLogin = true; String handle = getPreferences().getString(profilePrefix + "user-name"); if (StringUtils.isNotBlank(handle)) { sendMessage(handle, true); } } else { parseMessage(message); } } else { if (hasSentPassword) { isLoggingIn = false; } if (getPreferences().getBoolean(profilePrefix + "is-anon-guest") && !hasSentPassword) { hasSentPassword = true; parseMessage(message); sendMessage("", true); } else if (getPreferences().getBoolean(profilePrefix + "is-named-guest") && !hasSentPassword) { hasSentPassword = true; parseMessage(message); sendMessage("", true); } else if (!hasSentPassword) { hasSentPassword = true; parseMessage(message); String password = getPreferences().getString(profilePrefix + "password"); if (StringUtils.isNotBlank(password)) { // Don't show the users password. sendMessage(password, true); } } else { parseMessage(message); } } }
From source file:raptor.connector.ics.IcsConnector.java
/** * This method is invoked by the run method when there is new text to be * handled. It buffers text until a prompt is found then invokes * parseMessage./* www. ja va 2 s .c o m*/ * * This method also handles login logic which is tricky. */ public void messageArrived(StringBuilder buffer) { // System.err.println("Message arrived (buffer): " + buffer); if (isLoggedIn) { isLoggingIn = false; // If we are logged in. Then parse out all the text between the // prompts. int promptIndex = -1; while ((promptIndex = buffer.indexOf(context.getRawPrompt())) != -1) { String message = drainInboundMessageBuffer(buffer, promptIndex + context.getRawPrompt().length()); parseMessage(message); } } else { // We are not logged in. // There are several complex cases here depending on the prompt // we are waiting on. // There is a login prompt, a password prompt, an enter prompt, // and also you have to handle invalid logins. int loggedInMessageIndex = buffer.indexOf(context.getLoggedInMessage()); if (loggedInMessageIndex != -1) { for (int i = 0; i < buffer.length(); i++) { char character = buffer.charAt(i); if (LOGIN_CHARACTERS_TO_FILTER.indexOf(character) != -1) { buffer.deleteCharAt(i); i--; } } int nameStartIndex = buffer.indexOf(context.getLoggedInMessage()) + context.getLoggedInMessage().length(); int endIndex = buffer.indexOf("****", nameStartIndex); if (endIndex != -1) { userName = IcsUtils.stripTitles(buffer.substring(nameStartIndex, endIndex).trim()); LOG.info(context.getShortName() + "Connector " + "login complete. userName=" + userName); isLoggedIn = true; onSuccessfulLogin(); restoreTabStates(); // Since we are now logged in, just buffer the text // received and // invoke parseMessage when the prompt arrives. } else { // We have yet to receive the **** closing message so // wait // until it arrives. } } else { int loginIndex = buffer.indexOf(context.getLoginPrompt()); if (loginIndex != -1) { String event = drainInboundMessageBuffer(buffer, loginIndex + context.getLoginPrompt().length()); onLoginEvent(event, true); } else { int enterPromptIndex = buffer.indexOf(context.getEnterPrompt()); if (enterPromptIndex != -1) { String event = drainInboundMessageBuffer(buffer, enterPromptIndex + context.getEnterPrompt().length()); onLoginEvent(event, false); } else { int passwordPromptIndex = buffer.indexOf(context.getPasswordPrompt()); if (passwordPromptIndex != -1) { String event = drainInboundMessageBuffer(buffer, passwordPromptIndex + context.getPasswordPrompt().length()); onLoginEvent(event, false); } else { int errorMessageIndex = buffer.indexOf(context.getLoginErrorMessage()); if (errorMessageIndex != -1) { String event = drainInboundMessageBuffer(buffer); event = StringUtils.replaceChars(event, "\uefbf\ubdef\ubfbd\uefbf\ubdef\ubfbd", ""); parseMessage(event); } } } } } } }
From source file:raptor.connector.ics.IcsUtils.java
/** * Maciejg format, named after him because of his finger notes. Unicode * chars are represented as α β γ δ ε ζ * unicode equivalent \u03B1,\U03B2,.../*from w w w .j av a 2 s . c om*/ */ public static String maciejgFormatToUnicode(String inputString) { StringBuilder builder = new StringBuilder(inputString); int unicodePrefix = 0; while ((unicodePrefix = builder.indexOf("&#x", unicodePrefix)) != -1) { int endIndex = builder.indexOf(";", unicodePrefix); if (endIndex == -1) { break; } String maciejgWord = builder.substring(unicodePrefix + 3, endIndex); maciejgWord = StringUtils.replaceChars(maciejgWord, " \\\n", "").toUpperCase(); if (maciejgWord.length() <= 5) { try { int intValue = Integer.parseInt(maciejgWord, 16); String unicode = new String(new char[] { (char) intValue }); builder.replace(unicodePrefix, endIndex + 1, unicode); } catch (NumberFormatException nfe) { unicodePrefix = endIndex + 1; } } else { unicodePrefix = endIndex + 1; } } return builder.toString(); }
From source file:raptor.connector.ics.IcsUtils.java
/** * Returns the word with all characters in STRIP_CHARS removed. If word * contains multiple tokens, the last word is returned. *///from w w w . j ava 2 s . c o m public static String stripWord(String word) { if (word != null) { word = stripTitles(word); return StringUtils.replaceChars(word, STRIP_CHARS, ""); } return null; }
From source file:raptor.swt.chat.ChatConsole.java
public void createControls() { addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (propertyChangeListener != null) { Raptor.getInstance().getPreferences().removePropertyChangeListener(propertyChangeListener); propertyChangeListener = null; }// w w w . j a v a 2s. c om if (controller != null) { controller.dispose(); } if (LOG.isInfoEnabled()) LOG.info("Disposed chat console."); } }); setLayout(new GridLayout(1, true)); Raptor.getInstance().getPreferences().addPropertyChangeListener(propertyChangeListener); inputText = new RaptorStyledText(this, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER); inputText.setLayoutData(new GridData(GridData.FILL_BOTH)); inputText.setEditable(false); inputText.setWordWrap(true); inputText.setLineSpacing(1); inputText.setLeftMargin(3); southControlsComposite = new Composite(this, SWT.NONE); southControlsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout gridLayout = new GridLayout(5, false); gridLayout.marginBottom = 0; gridLayout.marginHeight = 0; gridLayout.marginRight = 0; gridLayout.marginLeft = 0; gridLayout.marginTop = 0; southControlsComposite.setLayout(gridLayout); promptLabel = new Label(southControlsComposite, SWT.NONE); promptLabel.setText(controller.getPrompt()); outputText = new StyledText(southControlsComposite, SWT.MULTI | SWT.BORDER); outputText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Removes \n\r when text is pasted. outputText.addListener(SWT.Verify, new Listener() { public void handleEvent(Event e) { String string = e.text; if (e.text.contains("\n") || e.text.contains("\r")) { e.doit = false; outputText.insert(StringUtils.replaceChars(string, "\n\r", "")); } } }); outputText.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { outputText.setFocus(); } public void widgetSelected(SelectionEvent e) { } }); updateFromPrefs(); }
From source file:raptor.util.ConvertECOTxt.java
public static void main(String args[]) throws IOException { BufferedReader reader = new BufferedReader(new FileReader("projectFiles/ECO.txt")); FileWriter writer = new FileWriter("resources/ECOFen.txt"); String currentLine = null;/*from w w w .j ava 2s . c o m*/ int lineNumber = 0; while ((currentLine = reader.readLine()) != null) { lineNumber++; System.err.println("Parsing line number: " + lineNumber); if (StringUtils.isNotBlank(currentLine) && !currentLine.startsWith("//")) { RaptorStringTokenizer lineTok = new RaptorStringTokenizer(currentLine, "|"); String moves = lineTok.nextToken(); Game game = GameFactory.createStartingPosition(Variant.classic); RaptorStringTokenizer movesTokenizer = new RaptorStringTokenizer(moves, " ", true); while (movesTokenizer.hasMoreTokens()) { String currentSan = movesTokenizer.nextToken(); try { game.makeSanMove(currentSan); } catch (IllegalArgumentException iae) { currentSan = StringUtils.replaceChars(currentSan, 'B', 'b'); try { game.makeSanMove(currentSan); } catch (IllegalArgumentException iae2) { currentSan = StringUtils.replaceChars(currentSan, 'b', 'B'); game.makeSanMove(currentSan); } } } String fenPosition = game.toFenPosition() + " " + (game.isWhitesMove() ? 'w' : 'b'); writer.write(fenPosition + "|"); while (lineTok.hasMoreTokens()) { writer.write(lineTok.nextToken() + "|"); } writer.write("\n"); } } writer.flush(); writer.close(); reader.close(); }
From source file:raptor.util.RatingComparator.java
public static int getRatingAsInt(String string) { if (string.equals("----")) { return 0; } else if (string.equals("++++")) { return 1; } else {// w w w. ja v a2 s . c om int result = 0; try { result = Integer.parseInt(StringUtils.replaceChars(string, "EP", "")); } catch (NumberFormatException nfe) { } return result; } }
From source file:technology.tikal.string.util.StringNormalizer.java
/** * remplazar acentos/*from w w w.j av a 2 s.c o m*/ * todo a minusculas * quita los espacios extras. * elimina los signos de puntuacion: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ */ public static String normalize(String input) { if (input == null) { return null; } String result = input; result = UNDESIRABLES.matcher(result).replaceAll(""); result = result.toLowerCase(); result = StringUtils.normalizeSpace(result); result = StringUtils.replaceChars(result, '\u00E1', 'a'); result = StringUtils.replaceChars(result, '\u00ED', 'i'); result = StringUtils.replaceChars(result, '\u00FA', 'u'); result = StringUtils.replaceChars(result, '\u00E9', 'e'); result = StringUtils.replaceChars(result, '\u00F3', 'o'); return result; }
From source file:ubic.gemma.analysis.report.DatabaseViewGeneratorImpl.java
@Override public void generateDatasetView(int limit) throws FileNotFoundException, IOException { log.info("Generating dataset summary view"); /*//from w w w . ja va 2 s . c om * Get handle to output file */ File file = getViewFile(DATASET_SUMMARY_VIEW_BASENAME); log.info("Writing to " + file); Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file))); /* * Load all the data sets */ Collection<ExpressionExperiment> vos = expressionExperimentService.loadAll(); writer.write("GemmaDsId\tSource\tSourceAccession\tShortName\tName\tDescription\ttaxon\tManufacturer\n"); /* * Print out their names etc. */ int i = 0; for (ExpressionExperiment vo : vos) { vo = expressionExperimentService.thawLite(vo); log.info("Processing: " + vo.getShortName()); String acc = ""; String source = ""; if (vo.getAccession() != null && vo.getAccession().getAccession() != null) { acc = vo.getAccession().getAccession(); source = vo.getAccession().getExternalDatabase().getName(); } Long gemmaId = vo.getId(); String shortName = vo.getShortName(); String name = vo.getName(); String description = vo.getDescription(); description = StringUtils.replaceChars(description, '\t', ' '); description = StringUtils.replaceChars(description, '\n', ' '); description = StringUtils.replaceChars(description, '\r', ' '); Taxon taxon = expressionExperimentService.getTaxon(vo); if (taxon == null) continue; Collection<ArrayDesign> ads = expressionExperimentService.getArrayDesignsUsed(vo); StringBuffer manufacturers = new StringBuffer(); // TODO could cache the arrayDesigns to make faster, thawing ad is time consuming for (ArrayDesign ad : ads) { ad = arrayDesignService.thawLite(ad); if (ad.getDesignProvider() == null) { log.debug("Array Design: " + ad.getShortName() + " has no design provoider assoicated with it. Skipping"); continue; } manufacturers.append(ad.getDesignProvider().getName() + ","); } writer.write(String.format("%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", gemmaId, source, acc, shortName, name, description, taxon.getCommonName(), StringUtils.chomp(manufacturers.toString(), ","))); if (limit > 0 && ++i > limit) break; } writer.close(); }