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:learningresourcefinder.web.Slugify.java
public static String slugify(String input) { String ret = StringUtils.trim(input); if (StringUtils.isBlank(input)) { return ""; }/* w w w .j av a 2 s.c om*/ ret = Jsoup.parse(ret).text(); // In case the string contains some html, such as <em>. ret = normalize(ret); ret = removeSmallWords(ret); ret = removeDuplicateWhiteSpaces(ret); ret = StringUtils.stripAccents(ret); // It seems to be bad practice to have accents in slugs: --> e return ret.replace(" ", "-").toLowerCase(); }
From source file:apps.provisioning.util.Utils.java
/** * Replaces special characters to e-mail valid characters. * * @param username User name to be formatted. * @return Formatted text/*from w ww . ja v a 2s .c om*/ */ public static String replaceSpecialChars(String username) { if (username == null) { return null; } username = username.toLowerCase(); // Replaces characters with accents for the same characters without accents. username = StringUtils.stripAccents(username); // Filters e-mail valid characters username = username.replaceAll(REGEXP_SPECIAL_CHARS, ""); // The maximum Google Apps username length is 60 characters if (username.length() > USERNAME_MAX_LENGTH) { username = username.substring(0, USERNAME_MAX_LENGTH); } return username; }
From source file:info.novatec.testit.livingdoc.util.NameUtils.java
/** * Tries to convert <code>string</code> to a Java class name by following a * few simple steps:/*w w w.j a v a 2 s . c o m*/ * <p> * <p> * <ul> * <li>First of all, <code>string</code> gets <i>camel cased</i>, the usual * Java class naming convention. * <li>Secondly, any whitespace, by virtue of * <code>Character.isWhitespace()</code> is removed from the camel cased * <code>string</code>. * <li>Third, all accented characters (diacritis) are replaced by their * non-accented equivalent (ex: \u00e9 -> e)</li> * <li>Fourth, all non java identifier characters are removed</li> * </ul> * <p> * The only exception to executing these two steps is when * <code>string</code> represents a fully-qualified class name. To check if * <code>string</code> represents a fully-qualified class name, a simple * validation of the existence of the '.' character is made on * <code>string</code>. * * @param s The String that may represent a Java class name * @return The input string converted by following the documented steps */ public static String toClassName(String s) { if (StringUtils.isEmpty(s) || s.contains(".")) { return s; } return removeNonJavaIdentifierCharacters( StringUtils.stripAccents(StringUtils.deleteWhitespace(WordUtils.capitalizeFully(s)))); }
From source file:fr.univrouen.poste.services.WordParser.java
public void modifyWord(InputStream docx, Map<String, String> textMap, OutputStream out) { try {//from w w w .ja v a 2s . c om XWPFDocument doc = new XWPFDocument(OPCPackage.open(docx)); // tentative avec les noms {{}} for (XWPFParagraph p : doc.getParagraphs()) { for (CTBookmark bookmark : p.getCTP().getBookmarkStartList()) { log.trace(bookmark.getName()); for (String key : textMap.keySet()) { String cleanKey = StringUtils.stripAccents(key); cleanKey = cleanKey.replaceAll(" ", "_"); cleanKey = cleanKey.replaceAll("\\W", ""); if (bookmark.getName().equalsIgnoreCase(cleanKey)) { Node nextNode = bookmark.getDomNode().getNextSibling(); while (nextNode != null && nextNode.getNodeName() != null && !(nextNode.getNodeName().contains("bookmarkEnd"))) { p.getCTP().getDomNode().removeChild(nextNode); nextNode = bookmark.getDomNode().getNextSibling(); } XWPFRun run = p.createRun(); run.setText(textMap.get(key)); p.getCTP().getDomNode().insertBefore(run.getCTR().getDomNode(), nextNode); } } } } doc.write(out); } catch (Exception e) { log.error("Pb durant la modification du document word", e); } }
From source file:br.com.itfox.beans.Product.java
public String getNameReplaceAll(boolean extension) { if (name != null) { try {/*from w w w . j av a 2s. c o m*/ name = StringUtils.stripAccents(name); } catch (Exception ex) { ex.printStackTrace(); } } if (name != null && extension) { return name.replaceAll(" ", "_").replaceAll("/", "_").replaceAll(",", "_").replaceAll("'", "") .toLowerCase() + ".png"; } else if (name != null && extension == false) { return name.replaceAll(" ", "_").replaceAll("/", "_").replaceAll(",", "_").replaceAll("'", "") .toLowerCase(); } else { return ""; } }
From source file:mesclasses.util.EleveFileUtil.java
public static String sanitize(String str) { return StringUtils.stripAccents(str).replaceAll("[^\\w.-]", "_"); }
From source file:alfio.manager.EventNameManager.java
/** * Generates and returns a short name based on the given display name.<br> * The generated short name will be returned only if it was not already used.<br> * The input parameter will be clean from "evil" characters such as punctuation and accents * * 1) if the {@code displayName} is a one-word name, then no further calculation will be done and it will be returned as it is, to lower case * 2) the {@code displayName} will be split by word and transformed to lower case. If the total length is less than 15, then it will be joined using "-" and returned * 3) the first letter of each word will be taken, excluding numbers * 4) a random code will be returned/* www .j av a2 s . com*/ * * @param displayName * @return */ public String generateShortName(String displayName) { Validate.isTrue(StringUtils.isNotBlank(displayName)); String cleanDisplayName = StringUtils.stripAccents(StringUtils.normalizeSpace(displayName)) .toLowerCase(Locale.ENGLISH).replaceAll(FIND_EVIL_CHARACTERS, "-"); if (!StringUtils.containsWhitespace(cleanDisplayName) && isUnique(cleanDisplayName)) { return cleanDisplayName; } Optional<String> dashedName = getDashedName(cleanDisplayName); if (dashedName.isPresent()) { return dashedName.get(); } Optional<String> croppedName = getCroppedName(cleanDisplayName); if (croppedName.isPresent()) { return croppedName.get(); } return generateRandomName(); }
From source file:com.google.gitiles.doc.TocFormatter.java
private static String idFromTitle(String title) { StringBuilder b = new StringBuilder(title.length()); for (char c : StringUtils.stripAccents(title).toCharArray()) { if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) { b.append(c);//from w w w . j a v a 2s . c o m } else if (c == ' ') { if (b.length() > 0 && b.charAt(b.length() - 1) != '-' && b.charAt(b.length() - 1) != '_') { b.append('-'); } } else if (b.length() > 0 && b.charAt(b.length() - 1) != '-' && b.charAt(b.length() - 1) != '_') { b.append('_'); } } while (b.length() > 0) { char c = b.charAt(b.length() - 1); if (c == '-' || c == '_') { b.setLength(b.length() - 1); continue; } break; } return b.toString(); }
From source file:es.alrocar.poiproxy.proxy.LocalFilter.java
/** * Performs a contains operation between the {@link LocalFilter#value} * property and the attribute parameter/*from www . ja va 2 s . c o m*/ * * @param attribute * @return True if passes the filter */ public boolean apply(String attribute) { if (attribute == null || value == null) { return true; } String attNoAccents = StringUtils.stripAccents(attribute); String valueNoAccents = StringUtils.stripAccents(value); return StringUtils.containsIgnoreCase(attNoAccents, valueNoAccents); }
From source file:info.novatec.testit.livingdoc.util.NameUtils.java
public static String toJavaIdentifierForm(String name) { return removeNonJavaIdentifierCharacters(StringUtils.stripAccents(toLowerCamelCase(name))); }