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:com.manydesigns.portofino.model.database.DatabaseLogic.java
static String checkFirstLetter(String letter) { letter = StringUtils.replaceChars(letter, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"); if (letter.equals("_") || letter.equals("$") || StringUtils.isAlpha(letter)) { return letter; } else if (StringUtils.isNumeric(letter)) { return "_" + letter; } else {/*from w w w .java 2 s .c om*/ return "_"; } }
From source file:net.di2e.ddf.argo.probe.responder.ProbeHandler.java
private String getUniqueServiceId(ServiceInfo serviceInfo, String siteName) { return StringUtils.replaceChars(siteName + "-" + serviceInfo.getServiceType(), ' ', '-'); }
From source file:com.manydesigns.portofino.model.database.DatabaseLogic.java
static String checkOtherLetters(String letter) { letter = StringUtils.replaceChars(letter, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz"); if (letter.equals("_") || letter.equals("$") || StringUtils.isAlphanumeric(letter)) { return letter; } else {// w w w . j a va 2 s.c om return "_"; } }
From source file:com.ecyrd.jspwiki.search.LuceneSearchProvider.java
/** * Indexes page using the given IndexWriter. * * @param page WikiPage/* ww w. j ava2 s . c o m*/ * @param text Page text to index * @param writer The Lucene IndexWriter to use for indexing * @return the created index Document * @throws IOException If there's an indexing problem */ protected Document luceneIndexPage(WikiPage page, String text, IndexWriter writer) throws IOException { if (log.isDebugEnabled()) log.debug("Indexing " + page.getName() + "..."); // make a new, empty document Document doc = new Document(); if (text == null) return doc; // Raw name is the keyword we'll use to refer to this document for updates. Field field = new Field(LUCENE_ID, page.getName(), Field.Store.YES, Field.Index.UN_TOKENIZED); doc.add(field); // Body text. It is stored in the doc for search contexts. field = new Field(LUCENE_PAGE_CONTENTS, text, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add(field); // Allow searching by page name. Both beautified and raw String unTokenizedTitle = StringUtils.replaceChars(page.getName(), MarkupParser.PUNCTUATION_CHARS_ALLOWED, c_punctuationSpaces); field = new Field(LUCENE_PAGE_NAME, TextUtil.beautifyString(page.getName()) + " " + unTokenizedTitle, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add(field); // Allow searching by authorname if (page.getAuthor() != null) { field = new Field(LUCENE_AUTHOR, page.getAuthor(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add(field); } // Now add the names of the attachments of this page try { Collection attachments = m_engine.getAttachmentManager().listAttachments(page); String attachmentNames = ""; for (Iterator it = attachments.iterator(); it.hasNext();) { Attachment att = (Attachment) it.next(); attachmentNames += att.getName() + ";"; } field = new Field(LUCENE_ATTACHMENTS, attachmentNames, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO); doc.add(field); } catch (ProviderException e) { // Unable to read attachments log.error("Failed to get attachments for page", e); } writer.addDocument(doc); return doc; }
From source file:com.npower.dm.model.TestGenerateModelXMLByWurfl.java
/** * @param maps//w ww .ja v a2 s.c om * @param outputBaseDir * @throws DMException * @throws Exception */ private void outputModelsXML(Map<String, Set<String>> maps, Map<String, String> brandNames, String outputBaseDir) throws DMException, Exception { // Generate XML ManagementBeanFactory factory = AllTests.getManagementBeanFactory(); ModelBean bean = factory.createModelBean(); int total = 0; int total4New = 0; int total4Exists = 0; try { for (String manufacturerExtID : maps.keySet()) { String folderName = manufacturerExtID.trim().toLowerCase(); folderName = StringUtils.replaceChars(folderName, '-', '_'); folderName = StringUtils.replaceChars(folderName, ' ', '_'); File outputDir = new File(outputBaseDir, "models/" + folderName); if (!outputDir.exists()) { outputDir.mkdirs(); File iconDir = new File(outputDir, "icons"); if (!iconDir.exists()) { iconDir.mkdirs(); } } File outputFile = new File(outputDir, "models.2nd.xml"); BufferedWriter out = new BufferedWriter(new FileWriter(outputFile)); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.write("<Setup>\n"); out.write("<!-- Models: " + brandNames.get(manufacturerExtID.trim().toLowerCase()) + " -->\n"); out.write("<Models>\n"); out.write("\n"); for (String modelExtID : maps.get(manufacturerExtID)) { total++; Manufacturer manufacturer = bean.getManufacturerByExternalID(manufacturerExtID); Model model = bean.getModelByManufacturerModelID(manufacturer, modelExtID); if (model != null) { // Exists total4Exists++; System.err.println(manufacturerExtID + " " + modelExtID + " exists!"); } else { total4New++; out.write(this.writeXML(manufacturerExtID, modelExtID, folderName)); out.write("\n"); } } out.write("\n"); out.write("</Models>\n"); out.write("</Setup>\n"); out.close(); } } catch (Exception e) { throw e; } finally { factory.release(); } System.out.println("*********************************************************************"); System.out.println(" Total : " + total); System.out.println(" Total (Exists): " + total4Exists); System.out.println(" Total (New) : " + total4New); System.out.println("*********************************************************************"); }
From source file:com.ecyrd.jspwiki.attachment.AttachmentManager.java
/** * Validates the filename and makes sure it is legal. It trims and splits * and replaces bad characters./*from ww w .ja va2 s. c o m*/ * * @param filename * @return A validated name with annoying characters replaced. * @throws WikiException If the filename is not legal (e.g. empty) */ static String validateFileName(String filename) throws WikiException { if (filename == null || filename.trim().length() == 0) { log.error("Empty file name given."); // the caller should catch the exception and use the exception text as an i18n key throw new WikiException("attach.empty.file"); } // // Should help with IE 5.22 on OSX // filename = filename.trim(); // If file name ends with .jsp or .jspf, the user is being naughty! if (filename.toLowerCase().endsWith(".jsp") || filename.toLowerCase().endsWith(".jspf")) { log.info("Attempt to upload a file with a .jsp/.jspf extension. In certain cases this" + " can trigger unwanted security side effects, so we're preventing it."); // // the caller should catch the exception and use the exception text as an i18n key throw new WikiException("attach.unwanted.file"); } // // Some browser send the full path info with the filename, so we need // to remove it here by simply splitting along slashes and then taking the path. // String[] splitpath = filename.split("[/\\\\]"); filename = splitpath[splitpath.length - 1]; // // Remove any characters that might be a problem. Most // importantly - characters that might stop processing // of the URL. // filename = StringUtils.replaceChars(filename, "#?\"'", "____"); return filename; }
From source file:eu.europeana.uim.sugarcrmclient.plugin.SugarCRMServiceImpl.java
@Override public Collection<?> updateCollectionFromRecord(SugarCrmRecord record, Provider provider) throws StorageEngineException { StorageEngine<?> engine = registry.getStorageEngine(); String mnemonicCode = record.getItemValue(EuropeanaRetrievableField.NAME).split("_")[0]; String fulname = record.getItemValue(EuropeanaRetrievableField.NAME); StringUtils.replaceChars(fulname, "_", " "); StringUtils.replace(fulname, mnemonicCode, ""); String collectionName = fulname; String collectionID = record.getItemValue(EuropeanaRetrievableField.NAME); String countryCode = record.getItemValue(EuropeanaRetrievableField.COUNTRY).toLowerCase(); String harvestUrl = record.getItemValue(EuropeanaUpdatableField.HARVEST_URL); String set = record.getItemValue(EuropeanaUpdatableField.SETSPEC); String sugarCRMID = record.getItemValue(EuropeanaRetrievableField.ID); String collectionDescription = record.getItemValue(EuropeanaRetrievableField.DESCRIPTION); String ingestionDate = record.getItemValue(EuropeanaRetrievableField.EXPECTED_INGESTION_DATE); String collectionStatus = record.getItemValue(EuropeanaUpdatableField.STATUS); String metadataformat = record.getItemValue(EuropeanaUpdatableField.METADATA_FORMAT); String metadatanamespace = record.getItemValue(EuropeanaUpdatableField.METADATA_NAMESPACE); String metadataschema = record.getItemValue(EuropeanaUpdatableField.METADATA_SCHEMA); String Z3950ADDRESS = record.getItemValue(EuropeanaUpdatableField.Z3950ADDRESS); String Z3950PORT = record.getItemValue(EuropeanaUpdatableField.Z3950PORT); String Z3950DATABASE = record.getItemValue(EuropeanaUpdatableField.Z3950DATABASE); String FTP_Z3950_USER = record.getItemValue(EuropeanaUpdatableField.FTP_Z3950_USER); String FTP_Z3950_PASSWORD = record.getItemValue(EuropeanaUpdatableField.FTP_Z3950_PASSWORD); String Z3950RECORD_SYNTAX = record.getItemValue(EuropeanaUpdatableField.Z3950RECORD_SYNTAX); String Z3950CHARSET = record.getItemValue(EuropeanaUpdatableField.Z3950CHARSET); String Z3950METHOD = record.getItemValue(EuropeanaUpdatableField.Z3950METHOD); String Z3950FILEPATH = record.getItemValue(EuropeanaUpdatableField.Z3950FILEPATH); String Z3950MAXIMUMID = record.getItemValue(EuropeanaUpdatableField.Z3950MAXIMUMID); String Z3950EARLIEST_TIMESTAMP = record.getItemValue(EuropeanaUpdatableField.Z3950EARLIEST_TIMESTAMP); String FTPPATH = record.getItemValue(EuropeanaUpdatableField.FTPPATH); String FTP_HTTP_ISOFORMAT = record.getItemValue(EuropeanaUpdatableField.FTP_HTTP_ISOFORMAT); String FTPSERVER = record.getItemValue(EuropeanaUpdatableField.FTPSERVER); String RECORD_XPATH = record.getItemValue(EuropeanaUpdatableField.RECORDXPATH); String HTTPURL = record.getItemValue(EuropeanaUpdatableField.HTTPURL); String FOLDER = record.getItemValue(EuropeanaUpdatableField.FOLDER); String HARVESTING_TYPE = record.getItemValue(EuropeanaRetrievableField.HARVESTING_TYPE); String DATE_ENTERED = record.getItemValue(EuropeanaRetrievableField.DATE_ENTERED); String CREATED_BY_USER = record.getItemValue(EuropeanaRetrievableField.CREATED_BY_USER); String DELETED = record.getItemValue(EuropeanaUpdatableField.DELETED); String ACRONYM = record.getItemValue(EuropeanaRetrievableField.ACRONYM); String ENABLED = record.getItemValue(EuropeanaUpdatableField.ENABLED); String PREVIEWS_IN_PORTAL = record.getItemValue(EuropeanaRetrievableField.PREVIEWS_ONLY_IN_PORTAL); Collection currcollection = engine.findCollection(mnemonicCode); if (currcollection == null) { currcollection = engine.createCollection(provider); }/*from ww w .ja v a2s. c om*/ currcollection.setLanguage(countryCode); currcollection.setMnemonic(mnemonicCode); currcollection.setName(collectionName); currcollection.setOaiBaseUrl(harvestUrl); currcollection.setOaiMetadataPrefix(metadataformat); currcollection.setOaiSet(set); currcollection.putValue(ControlledVocabularyProxy.METADATA_FORMAT, metadataformat); currcollection.putValue(ControlledVocabularyProxy.STATUS, collectionStatus); currcollection.putValue(ControlledVocabularyProxy.NAME, collectionID); currcollection.putValue(ControlledVocabularyProxy.SUGARCRMID, sugarCRMID); currcollection.putValue(ControlledVocabularyProxy.DESCRIPTION, collectionDescription); currcollection.putValue(ControlledVocabularyProxy.EXPECTED_INGESTION_DATE, ingestionDate); currcollection.putValue(ControlledVocabularyProxy.DATE_ENTERED, DATE_ENTERED); currcollection.putValue(ControlledVocabularyProxy.METADATA_NAMESPACE, metadatanamespace); currcollection.putValue(ControlledVocabularyProxy.METADATA_SCHEMA, metadataschema); currcollection.putValue(ControlledVocabularyProxy.Z3950ADDRESS, Z3950ADDRESS); currcollection.putValue(ControlledVocabularyProxy.Z3950PORT, Z3950PORT); currcollection.putValue(ControlledVocabularyProxy.Z3950DATABASE, Z3950DATABASE); currcollection.putValue(ControlledVocabularyProxy.FTP_Z3950_USER, FTP_Z3950_USER); currcollection.putValue(ControlledVocabularyProxy.FTP_Z3950_PASSWORD, FTP_Z3950_PASSWORD); currcollection.putValue(ControlledVocabularyProxy.Z3950RECORD_SYNTAX, Z3950RECORD_SYNTAX); currcollection.putValue(ControlledVocabularyProxy.Z3950CHARSET, Z3950CHARSET); currcollection.putValue(ControlledVocabularyProxy.Z3950METHOD, Z3950METHOD); currcollection.putValue(ControlledVocabularyProxy.Z3950FILEPATH, Z3950FILEPATH); currcollection.putValue(ControlledVocabularyProxy.Z3950MAXIMUMID, Z3950MAXIMUMID); currcollection.putValue(ControlledVocabularyProxy.Z3950EARLIEST_TIMESTAMP, Z3950EARLIEST_TIMESTAMP); currcollection.putValue(ControlledVocabularyProxy.FTPPATH, FTPPATH); currcollection.putValue(ControlledVocabularyProxy.FTP_HTTP_ISOFORMAT, FTP_HTTP_ISOFORMAT); currcollection.putValue(ControlledVocabularyProxy.FTPSERVER, FTPSERVER); currcollection.putValue(ControlledVocabularyProxy.RECORDXPATH, RECORD_XPATH); currcollection.putValue(ControlledVocabularyProxy.HTTPURL, HTTPURL); currcollection.putValue(ControlledVocabularyProxy.FOLDER, FOLDER); currcollection.putValue(ControlledVocabularyProxy.HARVESTING_TYPE, HARVESTING_TYPE); currcollection.putValue(ControlledVocabularyProxy.CREATED_BY_USER, CREATED_BY_USER); currcollection.putValue(ControlledVocabularyProxy.DELETED, DELETED); currcollection.putValue(ControlledVocabularyProxy.ACRONYM, ACRONYM); currcollection.putValue(ControlledVocabularyProxy.ENABLED, ENABLED); currcollection.putValue(ControlledVocabularyProxy.PREVIEWS_ONLY_IN_PORTAL, PREVIEWS_IN_PORTAL); engine.updateCollection(currcollection); engine.checkpoint(); return currcollection; }
From source file:edu.ku.brc.specify.toycode.mexconabio.AnalysisBase.java
/** * @param refRow/* ww w .j a v a2s.c o m*/ * @param compareRow * @return */ public int score(final Object[] refRow, final Object[] compareRow) { //Calendar cal = Calendar.getInstance(); if (maxScore == 0) { calcMaxScore(); } //String refCatNum = (String)refRow[CATNUM_INX]; String refCollectorNum = (String) refRow[COLNUM_INX]; String refGenus = (String) refRow[GENUS_INX]; String refSpecies = (String) refRow[SPECIES_INX]; String refSubSpecies = (String) refRow[SUBSPECIES_INX]; String refCollector = (String) refRow[COLLECTOR_INX]; String refLocality = (String) refRow[LOCALITY_INX]; //String refLatitude = (String)refRow[LATITUDE_INX]; //String refLongitude = (String)refRow[LONGITUDE_INX]; String refYear = (String) refRow[YEAR_INX]; String refMon = (String) refRow[MON_INX]; String refDay = (String) refRow[DAY_INX]; String refCountry = (String) refRow[COUNTRY_INX]; String refState = (String) refRow[STATE_INX]; //String catNum = (String)compareRow[CATNUM_INX]; String collectorNum = (String) compareRow[COLNUM_INX]; String genus = (String) compareRow[GENUS_INX]; String species = (String) compareRow[SPECIES_INX]; String subSpecies = (String) compareRow[SUBSPECIES_INX]; String collector = (String) compareRow[COLLECTOR_INX]; String locality = (String) compareRow[LOCALITY_INX]; //String latitude = (String)compareRow[LATITUDE_INX]; //String longitude = (String)compareRow[LONGITUDE_INX]; String year = (String) compareRow[YEAR_INX]; String mon = (String) compareRow[MON_INX]; String day = (String) compareRow[DAY_INX]; String country = (String) compareRow[COUNTRY_INX]; String state = (String) compareRow[STATE_INX]; if (country != null && country.toLowerCase().equals("mexico")) { country = "Mxico"; } /* String refCollector = null; switch (numFieldForName) { case 1 : refLastNameF = getStr(gRS, inx++); refCollector = refLastNameF; break; case 2 : refLastNameF = getStr(gRS, inx++); refFirstName = getStr(gRS, inx++); refCollector = String.format("%s %s", (StringUtils.isNotEmpty(refLastNameF) ? refLastNameF : ""), (StringUtils.isNotEmpty(refFirstName) ? refFirstName : "")).trim(); break; case 3 : refLastNameF = getStr(gRS, inx++); refLastNameM = getStr(gRS, inx++); refFirstName = getStr(gRS, inx++); refCollector = String.format("%s %s %s", (StringUtils.isNotEmpty(refLastNameF) ? refLastNameF : ""), (StringUtils.isNotEmpty(refLastNameM) ? refLastNameM : ""), (StringUtils.isNotEmpty(refFirstName) ? refFirstName : "")).trim(); break; } */ if (refCountry != null && refCountry.toLowerCase().equals("mexico")) { refCountry = "Mxico"; } if (StringUtils.isNotEmpty(refCollector)) { refCollector = StringUtils.replaceChars(refCollector, ',', ' '); } if (StringUtils.isNotEmpty(collector)) { collector = StringUtils.replaceChars(collector, ',', ' '); } int score = 0; score += compareDate(year, mon, day, refYear, refMon, refDay); String refCollectorStr = refCollector != null ? refCollector.toLowerCase() : ""; String collectorStr = collector != null ? collector.toLowerCase() : ""; String refLocStr = refLocality != null ? refLocality.toLowerCase() : ""; String locStr = locality != null ? locality.toLowerCase() : ""; double ratingLoc = longStringCompare(refLocStr, locStr, false, true); double ratingColtr = longStringCompare(refCollectorStr, collectorStr, false, true); if (ratingLoc > 50.0) { score += 10; tdColorCodes[LOCALITY_INX] = BGR; } else if (ratingLoc > 30.0) { score += 6; tdColorCodes[LOCALITY_INX] = GR; } else if (ratingLoc > 0.0) { score += 3; tdColorCodes[LOCALITY_INX] = YW; } if (ratingColtr > 50.0) { score += 10; tdColorCodes[COLLECTOR_INX] = BGR; } else if (ratingColtr > 30.0) { score += 6; tdColorCodes[COLLECTOR_INX] = GR; } else if (ratingColtr > 0.0) { score += 3; tdColorCodes[COLLECTOR_INX] = YW; } boolean genusMatches = false; if (refGenus != null && genus != null) { if (refGenus.equals(genus)) { score += 15; genusMatches = true; tdColorCodes[GENUS_INX] = GR; } else if (StringUtils.getLevenshteinDistance(genus, refGenus) < 3) { score += 7; tdColorCodes[GENUS_INX] = YW; } } boolean speciesMatches = false; if (refSpecies != null && species != null) { if (refSpecies.equals(species)) { score += 20; speciesMatches = true; if (genusMatches) { tdColorCodes[GENUS_INX] = BGR; tdColorCodes[SPECIES_INX] = BGR; } else { tdColorCodes[SPECIES_INX] = GR; } } else if (StringUtils.getLevenshteinDistance(species, refSpecies) < 3) { score += 10; tdColorCodes[SPECIES_INX] = YW; } } if (refSubSpecies != null && subSpecies != null) { if (refSubSpecies.equals(subSpecies)) { score += 20; if (genusMatches && speciesMatches) { tdColorCodes[GENUS_INX] = BGR; tdColorCodes[SPECIES_INX] = BGR; tdColorCodes[SUBSPECIES_INX] = BGR; } else if (speciesMatches) { tdColorCodes[SPECIES_INX] = BGR; tdColorCodes[SUBSPECIES_INX] = BGR; } else { tdColorCodes[SUBSPECIES_INX] = GR; } } else if (StringUtils.getLevenshteinDistance(subSpecies, refSubSpecies) < 3) { score += 10; tdColorCodes[SUBSPECIES_INX] = YW; } } if (refCountry != null && country != null) { refCountry = refCountry.toLowerCase(); country = country.toLowerCase(); if (refCountry.equals(country)) { score += 10; tdColorCodes[COUNTRY_INX] = BGR; } else if (StringUtils.getLevenshteinDistance(country, refCountry) < 3) { score += 5; tdColorCodes[COUNTRY_INX] = YW; } } if (refState != null && state != null) { refState = refState.toLowerCase(); state = state.toLowerCase(); if (refState.equals(state)) { score += 10; tdColorCodes[STATE_INX] = BGR; } else if (StringUtils.getLevenshteinDistance(state, refState) < 3) { score += 5; tdColorCodes[STATE_INX] = YW; } } /*if (refGenus != null && species != null && refGenus.equals(species)) { cCls[3] = DF; cCls[2] = DF; score += 10; } if (refSpecies != null && genus != null && refSpecies.equals(genus)) { cCls[2] = DF; cCls[3] = DF; score += 15; }*/ if (collectorNum != null && refCollectorNum != null && collectorNum.equals(refCollectorNum)) { score += 10; tdColorCodes[COLNUM_INX] = BGR; } return score; }
From source file:adalid.commons.util.StrUtils.java
/** * replaces all characters with diacritical marks in a string with their corresponding letter. * * @param string/*from ww w.ja v a 2 s .c om*/ * @return a string without diacritical marks */ public static String diacriticless(String string) { final String with = "????"; final String sans = "AAAAAACEEEEIIIINOOOOOUUUUYaaaaaaceeeeiiiinooooouuuuyy"; String dless = string == null ? null : StringUtils.replaceChars(StringUtils.trimToEmpty(string), with, sans); return dless; }
From source file:edu.ku.brc.specify.toycode.mexconabio.AnalysisBase.java
/** * @param str/* ww w. j a v a 2 s .co m*/ * @param usePeriods * @return */ protected String cleanString(final String str, final boolean usePeriods, final boolean replaceWithSpaces) { String s = StringUtils.remove(str, ':'); if (!usePeriods) { if (replaceWithSpaces) { s = StringUtils.replaceChars(s, '.', ' '); } else { s = StringUtils.remove(s, '.'); } } s = StringUtils.remove(s, '-'); s = StringUtils.remove(s, ','); return s; }