protected static String prepareLabel(String label) { if (label == null) return null; // convert bad characters ('-', ' ', '.') to '_' label = label.toLowerCase(); label = SearchReplace.replace(label, INTERACTION_SEPARATOR, "_"); label = SearchReplace.replace(label, " ", "_"); label = SearchReplace.replace(label, ".", "_"); return label; }
/** * Perform a search replace on a text. * Takes into account special caracters. * * @param text the text to work on - must not be null. * @param patternStr the string to look for - must not be null. * @param replacement the replacement string - must not be null. * @return the modified String */ public static String replace ( String text, String patternStr, String replacement ) { if ( text == null ) throw new IllegalArgumentException( "The text you want to modify must not be null!" ); if ( patternStr == null ) throw new IllegalArgumentException( "The pattern you want to replace must not be null!" ); if ( replacement == null ) throw new IllegalArgumentException( "The replacement string must not be null!" ); String escapedPatternStr = escapeRE( patternStr ); // Compile regular expression Pattern pattern = Pattern.compile (escapedPatternStr); // Replace all occurrences of pattern in input Matcher matcher = pattern.matcher (text); String result = matcher.replaceAll (replacement); return result; } }
private static String generateCitexploreUrl( String pubmedId ) { return SearchReplace.replace( CITEXPLORE_URL, PUBMED_ID_FLAG, pubmedId ); }
/** * Perform a search replace on a text. * Takes into account special caracters. * * @param text the text to work on - must not be null. * @param patternStr the string to look for - must not be null. * @param replacement the replacement string - must not be null. * @return the modified String */ public static String replace ( String text, String patternStr, String replacement ) { if ( text == null ) throw new IllegalArgumentException( "The text you want to modify must not be null!" ); if ( patternStr == null ) throw new IllegalArgumentException( "The pattern you want to replace must not be null!" ); if ( replacement == null ) throw new IllegalArgumentException( "The replacement string must not be null!" ); String escapedPatternStr = escapeRE( patternStr ); // Compile regular expression Pattern pattern = Pattern.compile (escapedPatternStr); // Replace all occurrences of pattern in input Matcher matcher = pattern.matcher (text); String result = matcher.replaceAll (replacement); return result; } }
private GoHandler getGoResponse( String goId ) throws IOException, SAXException { String query = SearchReplace.replace( EGO_QUERY, GOID_FLAG, goId ); URL url = new URL( myURL + query ); URLConnection servletConnection = url.openConnection(); // Turn off caching servletConnection.setUseCaches( false ); // Wrting to the server. servletConnection.setDoOutput( true ); // The reader to read response from the server. GoHandler goHandler = null; InputStream inputStream = null; try { inputStream = servletConnection.getInputStream(); goHandler = getGoResponse( inputStream ); } finally { if( inputStream != null ) { try { inputStream.close(); } catch( IOException ioe ) { } } } return goHandler; } // getGoResponse
String proteinID) { String tremblEntry = SearchReplace.replace( TREMBL_TEMPLATE, PROTEIN_SEQUENCE_LENGTH, "" + protein.getSequence().length() ); tremblEntry = SearchReplace.replace( tremblEntry, PROTEIN_ID, proteinID ); tremblEntry = SearchReplace.replace( tremblEntry, ORGANISM_NAME, organismName ); tremblEntry = SearchReplace.replace( tremblEntry, TREMBL_RELEASE_DATE, tremblReleaseDate ); tremblEntry = SearchReplace.replace( tremblEntry, TREMBL_RELEASE_NUMBER, tremblReleaseNumber ); tremblEntry = SearchReplace.replace( tremblEntry, PROTEIN_FULLNAME, protein.getFullName() ); tremblEntry = SearchReplace.replace( tremblEntry, NCBI_TAXID, protein.getBioSource().getTaxId() ); tremblEntry = SearchReplace.replace( tremblEntry, R_LINE_REFERENCE_POSITION, referencePosition ); tremblEntry = SearchReplace.replace( tremblEntry, R_LINE_PUBMED, pubmedId ); tremblEntry = SearchReplace.replace( tremblEntry, R_LINE_TISSUE, referenceTissue ); tremblEntry = SearchReplace.replace( tremblEntry, R_LINE_REFERENCE_AUTHOR, referenceAuthor ); tremblEntry = SearchReplace.replace( tremblEntry, R_LINE_REFERENCE_TITLE, referenceTitle ); tremblEntry = SearchReplace.replace( tremblEntry, R_LINE_REFERENCE_LINE, referenceLine ); tremblEntry = SearchReplace.replace( tremblEntry, PROTEIN_AC, protein.getAc() ); tremblEntry = SearchReplace.replace( tremblEntry, PROTEIN_CREATION_DATE, time.toUpperCase() ); tremblEntry = SearchReplace.replace( tremblEntry, PROTEIN_CRC64, Crc64.getCrc64( protein.getSequence() ) ); String formatedSequence = formatSequence( protein.getSequence() ); tremblEntry = SearchReplace.replace( tremblEntry, PROTEIN_SEQUENCE, formatedSequence );
val = v.getText(); val = SearchReplace.replace(val, "\\\\", "\\\\\\\\"); val = SearchReplace.replace(val, ":", "\\\\:"); val = SearchReplace.replace(val, ")", "\\\\)"); val = SearchReplace.replace(val, "(", "\\\\("); val = SearchReplace.replace(val, "+", "\\\\+"); val = SearchReplace.replace(val, "-", "\\\\-"); val = SearchReplace.replace(val, "!", "\\\\!"); val = SearchReplace.replace(val, "&&", "\\\\&&"); val = SearchReplace.replace(val, "||", "\\\\||");
val = v.getText(); val = SearchReplace.replace( val, "\\\\", "\\\\\\\\" ); val = SearchReplace.replace( val, ":", "\\\\:" ); val = SearchReplace.replace( val, ")", "\\\\)" ); val = SearchReplace.replace( val, "(", "\\\\(" ); val = SearchReplace.replace( val, "+", "\\\\+" ); val = SearchReplace.replace( val, "-", "\\\\-" ); val = SearchReplace.replace( val, "!", "\\\\!" ); val = SearchReplace.replace( val, "&&", "\\\\&&" ); val = SearchReplace.replace( val, "||", "\\\\||" );