List of usage examples for org.apache.commons.lang3 StringUtils stripAccents
public static String stripAccents(final String input)
Removes diacritics (~= accents) from a string.
From source file:org.dspace.authority.orcid.Orcid.java
@Override public List<AuthorityValue> queryAuthorities(String text, int max) { log.info("queryAuthorities - text " + text); String family_name = null;/* ww w.ja va2 s . c o m*/ String given_names = null; int pos = 0; if (!text.isEmpty()) { if (text.contains(",")) { pos = text.indexOf(","); } else if (text.contains(" ")) pos = text.indexOf(" "); else pos = text.length(); log.info("pos:" + pos); // Verifica ORCID String[] orcid_parts = text.split("-", 4); boolean orcid = true; for (int i = 0; i < orcid_parts.length; i++) { if (orcid_parts[i].length() != 4) orcid = false; } if (orcid) { try { text = URLEncoder.encode("orcid:" + text, "UTF-8"); } catch (Exception e) { log.info("URLEncoder exception"); } } else { if (pos > -1) { family_name = text.substring(0, pos); log.info("family_name:" + family_name); if (pos + 1 < text.length()) { given_names = text.substring(pos + 1); log.info("given-names:" + given_names); } } try { text = "(family-name:" + URLEncoder.encode(family_name.trim(), "UTF-8").replaceAll("\\+", "%20"); if (given_names != null) text = text + "+AND+given-names:" + URLEncoder.encode(given_names.trim(), "UTF-8").replaceAll("\\+", "%20") + ")"; else { log.info("Given names is null"); text = text + ")"; } log.info("Text apos 1o given names:" + text); text = text + "+OR+(family-name:" + URLEncoder .encode(StringUtils.stripAccents(family_name), "UTF-8").replaceAll("\\+", "%20"); if (given_names != null) text = text + "+AND+given-names:" + URLEncoder .encode(StringUtils.stripAccents(given_names), "UTF-8").replaceAll("\\+", "%20") + ")"; else text = text + ")"; } catch (Exception e) { log.info("URLEncoder exception"); } } log.info("queryAuthorities - newtext " + text); } List<Bio> bios = queryBio_a(text, 0, max); List<AuthorityValue> authorities = new ArrayList<AuthorityValue>(); for (Bio bio : bios) { authorities.add(OrcidAuthorityValue.create(bio)); } return authorities; }
From source file:org.efaps.esjp.common.file.FileUtil_Base.java
/** * Method to get a file with given name and ending. * * @param _name name for the file//from ww w . ja va 2 s.com * @return file * @throws EFapsException on error */ public File getFile(final String _name) throws EFapsException { File ret = null; try { File tmpfld = AppConfigHandler.get().getTempFolder(); if (tmpfld == null) { final File temp = File.createTempFile("eFaps", ".tmp"); tmpfld = temp.getParentFile(); temp.delete(); } final File storeFolder = new File(tmpfld, FileUtil_Base.TMPFOLDERNAME); final NumberFormat formater = NumberFormat.getInstance(); formater.setMinimumIntegerDigits(8); formater.setGroupingUsed(false); final File userFolder = new File(storeFolder, formater.format(Context.getThreadContext().getPersonId())); if (!userFolder.exists()) { userFolder.mkdirs(); } final String name = StringUtils.stripAccents(_name); ret = new File(userFolder, name.replaceAll("[^a-zA-Z0-9.-]", "_")); } catch (final IOException e) { throw new EFapsException(FileUtil_Base.class, "IOException", e); } return ret; }
From source file:org.esupportail.pay.services.UrlIdService.java
public String generateUrlId4PayEvt(String title) { String urlId = title.replaceAll("[^\\p{L}\\p{Nd}]+", ""); urlId = StringUtils.stripAccents(urlId); try {/*w w w . j a v a 2 s. co m*/ urlId = URLEncoder.encode(urlId, "UTF-8"); } catch (UnsupportedEncodingException e) { log.warn("UnsupportedEncodingException encoding " + urlId, e); } int i = 1; while (!PayEvt.findPayEvtsByUrlIdEquals(urlId).getResultList().isEmpty()) { urlId = urlId + i++; } return urlId; }
From source file:org.esupportail.pay.services.UrlIdService.java
public String generateUrlId4PayEvtMontant(PayEvt payboxEvt, String title) { String urlId = title.replaceAll("[^\\p{L}\\p{Nd}]+", ""); urlId = StringUtils.stripAccents(urlId); try {/*from w w w . j a va 2s . com*/ urlId = URLEncoder.encode(urlId, "UTF-8"); } catch (UnsupportedEncodingException e) { log.warn("UnsupportedEncodingException encoding " + urlId, e); } int i = 1; while (!PayEvtMontant.findPayEvtMontantsByEvtAndUrlIdEquals(payboxEvt, urlId).getResultList().isEmpty()) { urlId = urlId + i++; } return urlId; }
From source file:org.jraf.irondad.handler.pixgame.PixGameHandler.java
private void guess(Connection connection, HandlerContext handlerContext, String channel, String fromNickname, String guess) throws IOException { mGuessCount++;/*from w w w.ja va2s . com*/ if (!StringUtils.stripAccents(mSearchTerms.toLowerCase(Locale.FRANCE)) .equals(StringUtils.stripAccents(guess.toLowerCase(Locale.FRANCE)))) { // Lost connection.send(Command.PRIVMSG, channel, fromNickname + ": WRONG."); if (mGuessCount >= mSearchResultCount) { connection.send(Command.PRIVMSG, channel, "Well there are no more results. You lose, after " + mGuessCount + " guesses! The secret search was \"" + mSearchTerms + "\"... FAIL."); resetGame(); return; } switch (mGuessCount) { case GUESSES_FIRST_HINT: int nbWords = mSearchTerms.split("\\s+").length; connection.send(Command.PRIVMSG, channel, "Ok since you guys suck, here's an hint: the search has " + nbWords + " word" + (nbWords == 1 ? "." : "s.")); break; case GUESSES_SECOND_HINT: connection.send(Command.PRIVMSG, channel, "Ok since you guys suck, here's another hint: the search looks like this: \"" + getSecondHint() + "\"."); break; case GUESSES_THIRD_HINT: connection.send(Command.PRIVMSG, channel, "Ok I'll give you one last hint: the search looks like this: \"" + getThirdHint() + "\"."); break; case GUESSES_MAX: connection.send(Command.PRIVMSG, channel, "Ok you guys suck too much. You lose, after " + mGuessCount + " guesses! The secret search was \"" + mSearchTerms + "\"... FAIL."); resetGame(); return; } if (mGuessCount % RESULT_SIZE == 0) { // Fetch a new results page queryGoogle(handlerContext, connection, mSearchTerms); } connection.send(Command.PRIVMSG, channel, hideUrl(mSearchResults.get(mGuessCount % RESULT_SIZE).getLink())); } else { // Won connection.send(Command.PRIVMSG, channel, fromNickname + ": YES! The secret search was \"" + mSearchTerms + "\". It was found in " + mGuessCount + " guesses. Congrats!"); resetGame(); } }
From source file:org.korecky.nlp.library.BasicTextProcessing.java
/** * Normalize text//from w w w. j ava 2s. c om * * @param input: Input string * @param removeAccents: Remove accents form the input text * @return Output string */ public String normalizeText(String input, boolean removeAccents) { // Convert text to lowercase String output = input.toLowerCase(); // Remove accents if (removeAccents) { output = StringUtils.stripAccents(output); } return output; }
From source file:org.mayocat.shop.catalog.store.memory.MemoryProductStore.java
private static final Predicate<Product> withTitleLike(final String title) { return new Predicate<Product>() { public boolean apply(@Nullable Product input) { return StringUtils.stripAccents(input.getTitle()).toLowerCase() .indexOf(StringUtils.stripAccents(title).toLowerCase()) >= 0; }/*from www .j a va 2 s . c o m*/ }; }
From source file:org.talend.dataquality.semantic.index.DictionarySearcher.java
/** * This method transforms a string according to a validation mode * * @param stringToTransform/*from www. j a v a 2 s. co m*/ * @param validationMode * @return the transformed string */ private String transformSringByValidationMode(String stringToTransform, ValidationMode validationMode) { if (ValidationMode.EXACT_IGNORE_CASE_AND_ACCENT.equals(validationMode)) return StringUtils.stripAccents(stringToTransform.toLowerCase()); return stringToTransform; }
From source file:org.xwiki.officeimporter.internal.converter.OfficeConverterFileStorage.java
/** * Creates a new {@link OfficeConverterFileStorage} instance for tracking file system storage for a convert * operation./* w w w. j a va2s. co m*/ * * @param parentDir parent directory under which temporary storage is to be allocated. * @param inputFileName main input file which will be fed into office server. * @param outputFileName main output file into which result of the office conversion will be written into. * @throws IOException if an error occurs while creating temporary directory structure. */ public OfficeConverterFileStorage(File parentDir, String inputFileName, String outputFileName) throws IOException { boolean success = false; // Realize the temporary directory hierarchy. this.rootDir = new File(parentDir, UUID.randomUUID().toString()); if (this.rootDir.mkdir()) { this.inputDir = new File(this.rootDir, "input"); this.outputDir = new File(this.rootDir, "output"); if (this.inputDir.mkdir() && this.outputDir.mkdir()) { this.inputFile = new File(this.inputDir, StringUtils.stripAccents(inputFileName)); this.outputFile = new File(this.outputDir, StringUtils.stripAccents(outputFileName)); success = true; } } // Cleanup & signal if an error is encountered. if (!success) { cleanUp(); throw new IOException("Could not create temporary directory hierarchy."); } }
From source file:org.yamj.core.tools.MetadataTools.java
public static String cleanIdentifier(final String identifier) { String result = identifier;//w w w. j a v a2 s .c o m if (IDENT_TRANSLITERATE) { result = TRANSLITERATOR.transliterate(result); } if (IDENT_CLEAN) { // format to ss result = result.replaceAll("", "ss"); // remove all accents from letters result = StringUtils.stripAccents(result); // capitalize first letter result = WordUtils.capitalize(result, CLEAN_DELIMITERS); // remove punctuation and symbols result = result.replaceAll("[\\p{Po}|\\p{S}]", ""); // just leave characters and digits result = CLEAN_STRING_PATTERN.matcher(result).replaceAll(" ").trim(); // remove double whitespaces result = result.replaceAll("^ +| +$|( ){2,}", "$1"); } return result; }