Java Code Examples for org.apache.commons.lang3.StringUtils#replacePattern()
The following examples show how to use
org.apache.commons.lang3.StringUtils#replacePattern() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: RDFUnit File: LOVEndpoint.java License: Apache License 2.0 | 6 votes |
/** * Will try to get a responsive content location by adding suffixes based on the given SerializationFormats * @param currentUrl - the base url onto which to concatenate the suffixes * @param formats - the list of SerializationFormats to try out * @param redirects - list of established redirects which led to this point * @return - the optional content location */ private Optional<String> getContentVersions(String currentUrl, Collection<SerializationFormat> formats, ArrayList<String> redirects){ Optional<SerializationFormat> test = formats.stream().filter(x -> currentUrl.trim().endsWith(x.getExtension())).findFirst(); if(currentUrl != null && ! test.isPresent()){ for(SerializationFormat format : formats) { String tryOwl = StringUtils.replacePattern(currentUrl, "#$", ""); tryOwl = StringUtils.replacePattern(tryOwl, "/$", ""); tryOwl = StringUtils.replacePattern(tryOwl, "\\.html$", ""); tryOwl = StringUtils.replacePattern(tryOwl, "\\.htm$", ""); Optional<String> res = getContentLocation(tryOwl + "." + format.getExtension(), format, redirects); if (res.isPresent()) { return res; } res = getContentLocation(tryOwl + "/ontology." + format.getExtension(), format, redirects); if (res.isPresent()) { return res; } res = getContentLocation(tryOwl + "/schema." + format.getExtension(), format, redirects); if (res.isPresent()) { return res; } } } return Optional.empty(); }
Example 2
Source Project: bisq-core File: BSFormatter.java License: GNU Affero General Public License v3.0 | 5 votes |
public static String formatDurationAsWords(long durationMillis, boolean showSeconds) { String format = ""; String second = Res.get("time.second"); String minute = Res.get("time.minute"); String hour = Res.get("time.hour").toLowerCase(); String day = Res.get("time.day").toLowerCase(); String days = Res.get("time.days"); String hours = Res.get("time.hours"); String minutes = Res.get("time.minutes"); String seconds = Res.get("time.seconds"); if (durationMillis >= DateUtils.MILLIS_PER_DAY) { format = "d\' " + days + ", \'"; } if (showSeconds) { format += "H\' " + hours + ", \'m\' " + minutes + ", \'s\' " + seconds + "\'"; } else format += "H\' " + hours + ", \'m\' " + minutes + "\'"; String duration = durationMillis > 0 ? DurationFormatUtils.formatDuration(durationMillis, format) : ""; duration = StringUtils.replacePattern(duration, "^1 " + seconds + "|\\b1 " + seconds, "1 " + second); duration = StringUtils.replacePattern(duration, "^1 " + minutes + "|\\b1 " + minutes, "1 " + minute); duration = StringUtils.replacePattern(duration, "^1 " + hours + "|\\b1 " + hours, "1 " + hour); duration = StringUtils.replacePattern(duration, "^1 " + days + "|\\b1 " + days, "1 " + day); return duration.trim(); }
Example 3
Source Project: Java-for-Data-Science File: App.java License: MIT License | 5 votes |
public static String findReplaceApacheCommons(String text, String toFind, String replaceWith){ out.println(text); text = StringUtils.replacePattern(text, "\\W\\s", " "); out.println(text); //out.println(StringUtils.replace(text, " me ", "X")); return StringUtils.replace(text, " me ", "X"); }
Example 4
Source Project: bisq File: FormattingUtils.java License: GNU Affero General Public License v3.0 | 5 votes |
public static String formatDurationAsWords(long durationMillis, boolean showSeconds, boolean showZeroValues) { String format = ""; String second = Res.get("time.second"); String minute = Res.get("time.minute"); String hour = Res.get("time.hour").toLowerCase(); String day = Res.get("time.day").toLowerCase(); String days = Res.get("time.days"); String hours = Res.get("time.hours"); String minutes = Res.get("time.minutes"); String seconds = Res.get("time.seconds"); if (durationMillis >= DateUtils.MILLIS_PER_DAY) { format = "d\' " + days + ", \'"; } if (showSeconds) { format += "H\' " + hours + ", \'m\' " + minutes + ", \'s\' " + seconds + "\'"; } else { format += "H\' " + hours + ", \'m\' " + minutes + "\'"; } String duration = durationMillis > 0 ? DurationFormatUtils.formatDuration(durationMillis, format) : ""; duration = StringUtils.replacePattern(duration, "^1 " + seconds + "|\\b1 " + seconds, "1 " + second); duration = StringUtils.replacePattern(duration, "^1 " + minutes + "|\\b1 " + minutes, "1 " + minute); duration = StringUtils.replacePattern(duration, "^1 " + hours + "|\\b1 " + hours, "1 " + hour); duration = StringUtils.replacePattern(duration, "^1 " + days + "|\\b1 " + days, "1 " + day); if (!showZeroValues) { duration = duration.replace(", 0 seconds", ""); duration = duration.replace(", 0 minutes", ""); duration = duration.replace(", 0 hours", ""); duration = StringUtils.replacePattern(duration, "^0 days, ", ""); duration = StringUtils.replacePattern(duration, "^0 hours, ", ""); duration = StringUtils.replacePattern(duration, "^0 minutes, ", ""); duration = StringUtils.replacePattern(duration, "^0 seconds, ", ""); } return duration.trim(); }
Example 5
Source Project: windup File: FileMapping.java License: Eclipse Public License 1.0 | 5 votes |
private FileMapping(Pattern pattern) { this.pattern = pattern; String normalizedPattern = StringUtils.replacePattern(pattern.pattern(), "\\s", "_"); normalizedPattern = StringUtils.substring(normalizedPattern, 0, 10); this.id = this.getClass().getSimpleName()+ "_" + normalizedPattern + "_" + RandomStringUtils.randomAlphanumeric(2); }
Example 6
Source Project: vscrawler File: ReplacePattern.java License: Apache License 2.0 | 4 votes |
@Override protected String handle(String input, String second, String third) { return StringUtils.replacePattern(input, second, third); }
Example 7
Source Project: livingdoc-confluence File: ConfluenceLivingDocServiceImpl.java License: GNU General Public License v3.0 | 4 votes |
private String getRenderedSpecification(Page page, boolean implementedVersion, boolean includeStyle) { try { String baseUrl = ldUtil.getBaseUrl(); StringBuffer basicRenderedPage = new StringBuffer("<html>\n"); basicRenderedPage.append("<head>\n<title>").append(page.getTitle()).append("</title>\n"); basicRenderedPage.append("<meta http-equiv=\"content-type\" content=\"text/html;charset=").append( ldUtil.getEncoding()).append("\"/>\n"); basicRenderedPage.append("<meta name=\"title\" content=\"").append(page.getTitle()).append("\"/>\n"); basicRenderedPage.append("<meta name=\"external-link\" content=\"").append(baseUrl).append(page.getUrlPath()) .append("\"/>\n"); if (includeStyle) { basicRenderedPage.append(styleSheetExtractor.renderStyleSheet(page.getSpace())); basicRenderedPage.append("<base href=\"").append(baseUrl).append("\"/>\n"); } basicRenderedPage.append("</head>\n<body>\n"); if (includeStyle) { basicRenderedPage.append("<div id=\"Content\" style=\"text-align:left; padding: 5px;\">\n"); } String content = ldUtil.getPageContent(page, implementedVersion); if (content == null) { throw new LivingDocServerException(); } // To prevent loops caused by these macro rendering content = content.replaceAll("livingdoc-manage", "livingdoc-manage-not-rendered"); content = content.replaceAll("livingdoc-hierarchy", "livingdoc-hierarchy-not-rendered"); content = content.replaceAll("livingdoc-children", "livingdoc-children-not-rendered"); content = content.replaceAll("livingdoc-labels", "livingdoc-labels-not-rendered"); content = content.replaceAll("livingdoc-group", "livingdoc-group-not-rendered"); content = content.replaceAll("livingdoc-historic", "livingdoc-historic-not-rendered"); content = content.replaceAll(LivingDocPage.MACRO_KEY, "livingdoc-page-not-rendered"); content = StringUtils.replacePattern(content, "<ac:structured-macro ac:macro-id=\"(.{5,50}?)\" ac:name=\"jira\"(.*?)</ac:structured-macro>", "<span>Jira macro removed</span>"); // This macro breaks the labels/children macro with Javascript error // "treeRequests not defined" content = content.replaceAll("\\{pagetree", "{pagetree-not-rendered"); basicRenderedPage.append(ldUtil.getViewRenderer().render(content, new DefaultConversionContext(page.toPageContext()))); if (includeStyle) { basicRenderedPage.append("\n</div>"); } basicRenderedPage.append("\n</body>\n</html>"); HtmlEntityEscapeUtil.unEscapeHtmlEntities(basicRenderedPage); return basicRenderedPage.toString(); } catch (LivingDocServerException e) { return e.getId().equals(LivingDocConfluenceManager.NEVER_IMPLEMENTED) ? warning(e.getId()) : error(e.getId()); } }