List of usage examples for java.text Normalizer normalize
public static String normalize(CharSequence src, Form form)
From source file:org.kuali.ole.docstore.model.bagit.BagExtractor.java
/** * @param bagFile//from w w w. j a v a 2 s . co m * @param outputDir * @throws IOException */ public static void extractBag(File bagFile, File outputDir) throws IOException { byte[] buffer = new byte[BUFFER_SIZE]; ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(bagFile))); ZipEntry next; LOG.info("extractBag bagFile.getAbsolutePath " + bagFile.getAbsolutePath()); LOG.info("extractBag outputDir.getAbsolutePath " + outputDir.getAbsolutePath()); while ((next = zis.getNextEntry()) != null) { LOG.info("next.getName " + next.getName()); System.out.println("next.getName " + next.getName()); //String name = next.getName().replaceFirst("[^/]*/", ""); String name = next.getName().replace('\\', '/').replaceFirst("[^/]*/", ""); //System.out.println("replace nameunix "+nameunixreplace.replace('\\','/').replaceFirst("[^/]*/", "")); // String name = next.getName(); LOG.info("name " + name); LOG.info("normalize " + Normalizer.normalize(name.substring(DATA_DIR.length()), FILENAME_NORMALIZATION_FORM)); LOG.info("substring " + name.substring(DATA_DIR.length())); LOG.info("DATA_DIR " + DATA_DIR); if (name.startsWith(DATA_DIR)) { LOG.info("in if name.startsWith(DATA_DIR)"); File localFile = new File(outputDir, Normalizer.normalize(name.substring(DATA_DIR.length()), FILENAME_NORMALIZATION_FORM)); if (next.isDirectory()) { LOG.info("in if next.isDirectory"); if (!localFile.exists() && !localFile.mkdir()) { throw new IOException("error creating local directories in output directory"); } } else { LOG.info("in else next.isDirectory"); File parent = localFile.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { throw new IOException("error creating local directories in output directory"); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(localFile)); int bytesRead; while ((bytesRead = zis.read(buffer, 0, BUFFER_SIZE)) != -1) { bos.write(buffer, 0, bytesRead); } bos.close(); } } } zis.close(); }
From source file:org.sonar.fortify.crawler.Main.java
private static String slugifyForTags(String s) { return Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "") .replaceAll("[^\\w+]", "-").replaceAll("\\s+", "-").replaceAll("_", "-").replaceAll("[-]+", "-") .replaceAll("^-", "").replaceAll("-$", "").toLowerCase(Locale.ENGLISH); }
From source file:de.thischwa.pmcms.tool.file.FileTool.java
/** * Replaces the german special chars and spaces in 'filename'. * //from w w w . j a v a2s. c o m * @param filename * @return normalized file name TODO Restrict special chars, replace unknown with something like that: -sp- */ public static String normalizeFileName(final String filename) { StringBuilder sb = new StringBuilder(); String tmp = filename.toLowerCase(); tmp = Normalizer.normalize(tmp, Normalizer.Form.NFC); for (char c : tmp.toCharArray()) { String replaceStr = specialCharReplacement.get(Integer.valueOf(c)); if (replaceStr != null) sb.append(replaceStr); else if (Constants.ALLOWED_CHARS_FOR_FILES.contains(c + "")) sb.append(c); } return sb.toString(); }
From source file:org.exoplatform.wcm.webui.search.UISearchResult.java
public void processRender(WebuiRequestContext context) throws Exception { PortletRequestContext porletRequestContext = (PortletRequestContext) context; PortletPreferences portletPreferences = porletRequestContext.getRequest().getPreferences(); if (resultType == null || resultType.trim().length() == 0) { resultType = "Document"; }//from w w w.j a v a 2 s . c o m PortalRequestContext portalRequestContext = Util.getPortalRequestContext(); String portal = portalRequestContext.getRequestParameter("portal"); String keyword = portalRequestContext.getRequestParameter("keyword"); if ((portal != null) && (keyword != null) && (keyword.length() > 0)) { UISearchPageLayout uiSearchPageContainer = getAncestorOfType(UISearchPageLayout.class); UISearchForm searchForm = uiSearchPageContainer.getChild(UISearchForm.class); // searchForm.getUIFormSelectBox(UISearchForm.PORTALS_SELECTOR).setSelectedValues(new // String[] {portal}); searchForm.getUIStringInput(UISearchForm.KEYWORD_INPUT).setValue(keyword); if (searchForm.getUIFormSelectBox(UISearchForm.PORTALS_SELECTOR).getValue() != null) { portal = searchForm.getUIFormSelectBox(UISearchForm.PORTALS_SELECTOR).getValue(); } if (searchForm.getUIStringInput(UISearchForm.KEYWORD_INPUT).getValue() != null) { keyword = searchForm.getUIStringInput(UISearchForm.KEYWORD_INPUT).getValue(); } setKeyword(keyword); keyword = Normalizer.normalize(keyword, Normalizer.Form.NFD) .replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); SiteSearchService siteSearchService = getApplicationComponent(SiteSearchService.class); QueryCriteria queryCriteria = new QueryCriteria(); UIFormRadioBoxInput searchOption = searchForm.getUIFormRadioBoxInput(UISearchForm.SEARCH_OPTION); boolean isSearchDocument = (searchOption.getValue().equals(UISearchForm.DOCUMENT_CHECKING)); boolean isWebPage = (searchOption.getValue().equals(UISearchForm.PAGE_CHECKING)); List<String> documentNodeTypes = new ArrayList<String>(); if (isSearchDocument) { TemplateService templateService = WCMCoreUtils.getService(TemplateService.class); documentNodeTypes = templateService.getAllDocumentNodeTypes(); portal = Util.getPortalRequestContext().getPortalOwner(); resultType = "Document"; } else { documentNodeTypes.add("gtn:language"); documentNodeTypes.add("exo:pageMetadata"); queryCriteria.setFulltextSearchProperty( new String[] { "exo:metaKeywords", "exo:metaDescription", "gtn:name" }); resultType = "Page"; } String pageMode = portletPreferences.getValue(UIWCMSearchPortlet.PAGE_MODE, SiteSearchService.PAGE_MODE_NONE); queryCriteria.setContentTypes(documentNodeTypes.toArray(new String[documentNodeTypes.size()])); queryCriteria.setSiteName(portal); queryCriteria.setKeyword( org.exoplatform.services.cms.impl.Utils.escapeIllegalCharacterInQuery(keyword).toLowerCase()); queryCriteria.setSearchWebpage(isWebPage); queryCriteria.setSearchDocument(isSearchDocument); queryCriteria.setSearchWebContent(isSearchDocument); queryCriteria.setPageMode(pageMode); queryCriteria.setLiveMode(WCMComposer.MODE_LIVE.equals(Utils.getCurrentMode())); queryCriteria.setSortBy(this.getSortField()); queryCriteria.setOrderBy(this.getOrderType()); int itemsPerPage = Integer .parseInt(portletPreferences.getValue(UIWCMSearchPortlet.ITEMS_PER_PAGE, null)); try { AbstractPageList<ResultNode> pageList = null; if (isWebPage) { pageList = siteSearchService.searchPageContents(WCMCoreUtils.getSystemSessionProvider(), queryCriteria, itemsPerPage, false); } else { pageList = siteSearchService.searchSiteContents(WCMCoreUtils.getUserSessionProvider(), queryCriteria, itemsPerPage, false); } setSearchTime(pageList.getQueryTime() / 1000); setSuggestion(pageList.getSpellSuggestion()); if (pageList.getAvailable() <= 0) { String suggestion = pageList.getSpellSuggestion(); setSuggestionURL(suggestion); searchForm.setSubmitAction(suggestion); } setPageList(pageList); } catch (Exception e) { UIApplication uiApp = getAncestorOfType(UIApplication.class); uiApp.addMessage(new ApplicationMessage(UISearchForm.MESSAGE_NOT_SUPPORT_KEYWORD, null, ApplicationMessage.WARNING)); } } super.processRender(context); }
From source file:com.cloudbees.hudson.plugins.folder.ChildNameGeneratorAltTest.java
public static String encode(String s) { // We force every name to NFD to ensure that the test works irrespective of what the filesystem does return Normalizer.normalize(s, Normalizer.Form.NFD); }
From source file:com.cloudbees.hudson.plugins.folder.ChildNameGeneratorAltTest.java
public static String mangle(String s) { // We force every name to NFD to ensure that the test works irrespective of what the filesystem does s = Normalizer.normalize(s, Normalizer.Form.NFD); String hash = Util.getDigestOf(s); String base = Normalizer.normalize(s, Normalizer.Form.NFD).toLowerCase(Locale.ENGLISH); StringBuilder buf = new StringBuilder(32); for (char c : base.toCharArray()) { if (buf.length() >= 8) break; if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9')) { buf.append(Character.toLowerCase(c)); } else {//from w w w . j ava 2 s. c om buf.append('_'); } } buf.append('-'); buf.append(hash.substring(0, 23)); return buf.toString(); }
From source file:com.cloudbees.hudson.plugins.folder.ChildNameGeneratorRecTest.java
public static String mangle(String s) { String hash = Util.getDigestOf(s); String base = Normalizer.normalize(s, Normalizer.Form.NFD).toLowerCase(Locale.ENGLISH); StringBuilder buf = new StringBuilder(32); for (char c : base.toCharArray()) { if (buf.length() >= 8) break; if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9')) { buf.append(Character.toLowerCase(c)); } else {/*from ww w . j a v a 2 s .co m*/ buf.append('_'); } } buf.append('-'); buf.append(hash.substring(0, 23)); return buf.toString(); }
From source file:org.redpill.alfresco.pdfapilot.worker.PdfaPilotWorker.java
private String getBasename(NodeRef node) { if (node == null || !_nodeService.exists(node)) { return "PPCTW_" + GUID.generate(); }/*from w w w .j a va 2 s .co m*/ try { String filename = (String) _nodeService.getProperty(node, ContentModel.PROP_NAME); String basename = FilenameUtils.getBaseName(filename); // TODO: Investigate if this is really needed // callas currently has a bug that makes it crash if the whole filepath is // longer than 260 characters basename = StringUtils.substring(basename, 0, 100); // 0x2013 is the long hyphen, not allowed here... char c = 0x2013; if (StringUtils.contains(basename, c)) { if (LOG.isTraceEnabled()) { LOG.trace("Long hyphen replaced with short one"); } basename = StringUtils.replaceChars(basename, c, '-'); } filename = basename; if (LOG.isTraceEnabled()) { LOG.trace("Filename before normalization"); for (char character : filename.toCharArray()) { LOG.trace(character + " : " + (int) character); } } filename = Normalizer.normalize(filename, Form.NFKC); if (LOG.isTraceEnabled()) { LOG.trace("Filename after normalization"); for (char character : filename.toCharArray()) { LOG.trace(character + " : " + (int) character); } } // pad the string with _ until it's at lest 3 characters long if (basename.length() < 3) { basename = StringUtils.rightPad(basename, 3, "_"); } return basename; } catch (final Exception ex) { throw new RuntimeException(ex); } }
From source file:be.wolkmaan.klimtoren.security.digest.StandardStringDigester.java
@Override public String digest(final String message) { if (message == null) { return null; }//from w ww . ja va 2 s . c o m // Check initialization if (!isInitialized()) { initialize(); } try { // Normalize Unicode message to NFC form String normalizedMessage; if (!this.unicodeNormalizationIgnored) { normalizedMessage = Normalizer.normalize(message, Normalizer.Form.NFC); } else { normalizedMessage = message; } // The input String is converted into bytes using MESSAGE_CHARSET // as a fixed charset to avoid problems with different platforms // having different default charsets (see MESSAGE_CHARSET doc). final byte[] messageBytes = normalizedMessage.getBytes(MESSAGE_CHARSET); // The StandardByteDigester does its job. byte[] digest = this.byteDigester.digest(messageBytes); // We build the result variable final StringBuffer result = new StringBuffer(); if (this.prefix != null) { // Prefix is added result.append(this.prefix); } // We encode the result in BASE64 or HEXADECIMAL so that we obtain // the safest result String possible. if (this.stringOutputTypeBase64) { digest = this.base64.encode(digest); result.append(new String(digest, DIGEST_CHARSET)); } else { result.append(CommonUtils.toHexadecimal(digest)); } if (this.suffix != null) { // Suffix is added result.append(this.suffix); } return result.toString(); } catch (EncryptionInitializationException | EncryptionOperationNotPossibleException e) { throw e; } catch (UnsupportedEncodingException e) { // If digest fails, it is more secure not to return any information // about the cause in nested exceptions. Simply fail. throw new EncryptionOperationNotPossibleException(); } }
From source file:fr.gouv.culture.thesaurus.util.TextUtils.java
/** * Supprime les accents//www. ja v a 2 s . c o m * @param strIn * @return */ public final static String removeAccent(String strIn) { return Normalizer.normalize(strIn, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); }