List of usage examples for org.apache.commons.lang StringUtils substringsBetween
public static String[] substringsBetween(String str, String open, String close)
Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.
From source file:feedsplugin.FeedsPlugin.java
private void addFeedKeywords(final SyndFeed feed) { final Iterator<?> iterator = feed.getEntries().iterator(); while (iterator.hasNext()) { final SyndEntry entry = (SyndEntry) iterator.next(); String feedTitle = entry.getTitle(); // index title or parts for (String[] delimiter : TITLE_DELIMITERS) { String titlePart = StringUtils.substringBetween(feedTitle, delimiter[0], delimiter[1]); if (titlePart != null && !titlePart.isEmpty()) { feedTitle = titlePart;// w ww . j a v a2 s . co m break; } } addFeedKey(feedTitle, entry, feed); // index description parts SyndContent cont = entry.getDescription(); String desc = null; if (cont != null) { desc = cont.getValue(); } if (desc != null) { for (String[] delimiter : TITLE_DELIMITERS) { if (desc.contains(delimiter[0])) { String[] descParts = StringUtils.substringsBetween(desc, delimiter[0], delimiter[1]); if (descParts != null) { for (String descPart : descParts) { if (!descPart.isEmpty()) { addFeedKey(descPart, entry, feed); } } break; } } } } } }
From source file:de.awtools.basic.AWTools.java
/** * Ersetzt die ${...} Platzhalter in einem String. Die Ersetzung werden * in einer Map gelagert. Die Schluessel repraesentieren die Platzhalter * im String. Die Ersetzungen sind die Werte der Schluessel in der * <code>placeholders</code> Map. * * @param string Der zu pruefende String. * @param placeholders Die Ersetzungen.//from ww w .j a v a2 s. c om * @return Der ueberarbeitete String. */ public static String replacePlaceholder(final String string, final Map<String, String> placeholders) { String result = string; String[] keys = StringUtils.substringsBetween(string, "${", "}"); if (keys != null) { for (String key : keys) { String value = placeholders.get(key); if (value != null) { String sb = "${" + key + "}"; result = StringUtils.replace(result, sb.toString(), value); } } } return result; }
From source file:com.gs.tools.doc.extractor.core.html.HTMLDocumentExtractor.java
private long downloadCss(final File rootDir, final String rootLocation, final String pageContent) throws Exception { long fileCount = 0; String[] cssLinks = StringUtils.substringsBetween(pageContent, "<link", ">"); if (null != cssLinks && cssLinks.length > 0) { for (String link : cssLinks) { String rel = StringUtils.substringBetween(link, "rel=\"", "\""); if (rel.equalsIgnoreCase("stylesheet")) { String css = StringUtils.substringBetween(link, "href=\"", "\""); File cssFile = new File(rootDir, css); File cssFolder = new File(rootDir.getAbsolutePath()); String cssLocation = rootLocation; if (css.contains("/")) { String path = css.substring(0, css.lastIndexOf("/")); cssLocation += "/" + path; String name = css.substring(css.lastIndexOf("/") + 1); cssFolder = new File(rootDir, path); if (!cssFolder.exists()) { cssFolder.mkdirs(); }/* w ww . ja va2s . c om*/ cssFile = new File(cssFolder, name); } if (!sourceUrlCache.contains(rootLocation + "/" + css)) { sourceUrlCache.add(rootLocation + "/" + css); byte[] cssContentByte = downloadManager.readContentFromGET(rootLocation + "/" + css); if (null != cssContentByte && cssContentByte.length > 0) { logger.info("Save to: " + cssFile.getAbsolutePath()); writeTo(cssContentByte, new BufferedOutputStream(new FileOutputStream(cssFile))); fileCount++; logger.info("File count: " + fileCount); String cssContent = new String(cssContentByte, Charset.forName("UTF-8")); fileCount += processCSSLinks(cssFolder, cssLocation, cssContent); } } } } } return fileCount; }
From source file:com.gs.tools.doc.extractor.core.html.HTMLDocumentExtractor.java
private long processCSSLinks(final File rootDir, final String rootLocation, final String cssContent) throws Exception { long fileCount = 0; String[] urlLinks = StringUtils.substringsBetween(cssContent, "url(\"", "\")"); if (null != urlLinks && urlLinks.length > 0) { for (String link : urlLinks) { // if(link.contains("..")){ // link = link.replaceAll("../", "/"); // } String cssLocation = rootLocation; File targetFolder = new File(rootDir.getAbsolutePath()); File targetFile = new File(rootDir, link); if (link.contains("/")) { String path = link.substring(0, link.lastIndexOf("/")); cssLocation += "/" + path; String name = link.substring(link.lastIndexOf("/") + 1); targetFolder = new File(rootDir, path); if (!targetFolder.exists()) { targetFolder.mkdirs(); }// w w w. j a va2 s.c o m targetFile = new File(targetFolder, name); } if (!sourceUrlCache.contains(rootLocation + "/" + link)) { sourceUrlCache.add(rootLocation + "/" + link); byte[] targetContent = downloadManager.readContentFromGET(rootLocation + "/" + link); if (null != targetContent && targetContent.length > 0) { logger.info("Save to: " + targetFile.getAbsolutePath()); writeTo(targetContent, new BufferedOutputStream(new FileOutputStream(targetFile))); fileCount++; logger.info("File count: " + fileCount); if (link.toLowerCase().endsWith(".css")) { fileCount += processCSSLinks(targetFolder, cssLocation, new String(targetContent, ENCODING_UTF_8)); } } } } } return fileCount; }
From source file:com.intuit.tank.harness.functions.JexlStringFunctions.java
private String[] internalSubstringsBetween(String subject, String open, String close) { String[] ret = null;//from w w w .j a va2 s.c o m if (subject != null && open == null && close != null) { ret = new String[] { StringUtils.substringBefore(subject, close) }; } else if (subject != null && open != null && close == null) { ret = new String[] { StringUtils.substringAfterLast(subject, open) }; } else { ret = StringUtils.substringsBetween(subject, open, close); } return ret != null ? ret : new String[0]; }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.RecommendationTab.java
private void insertTextBlock(Composite composite, String text) { if (text != null && !text.isEmpty()) { String[] links = StringUtils.substringsBetween(text, Constants.OPEN_TAG_LINK, Constants.CLOSE_TAG_LINK); if (links != null && links.length > 0) { String[] textBlocks = StringUtils.substringsBetween(text, Constants.CLOSE_TAG_LINK, Constants.OPEN_TAG_LINK); String textBlockFirst = StringUtils.substringBefore(text, Constants.OPEN_TAG_LINK); String textBlockLast = StringUtils.substringAfterLast(text, Constants.CLOSE_TAG_LINK); createStyledTextBlock(composite, parseMustache(textBlockFirst)); for (int i = 0; i < links.length; i++) { int indexOfDelimiter = links[i].indexOf(Constants.LINK_DELIM); String formattedLink = "<a href=\"" + links[i].substring(0, indexOfDelimiter) + "\">" + links[i].substring(indexOfDelimiter + Constants.LINK_DELIM.length()) + "</a>"; createLink(composite, formattedLink); if (textBlocks != null && textBlocks.length > 0 && i < links.length - 1) { createStyledTextBlock(composite, parseMustache(textBlocks[i])); }// www. ja va 2s . c o m } createStyledTextBlock(composite, parseMustache(textBlockLast)); } else { createStyledTextBlock(composite, parseMustache(text)); } } }
From source file:info.magnolia.cms.beans.config.PropertiesInitializer.java
private static String[] getNamesBetweenPlaceholders(String propertiesFilesString, String contextNamePlaceHolder) { final String[] names = StringUtils.substringsBetween(propertiesFilesString, PLACEHOLDER_PREFIX + contextNamePlaceHolder, PLACEHOLDER_SUFFIX); return StringUtils.stripAll(names); }
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String getPatronParametrizado(String string) { String patron = StringUtils.trimToEmpty(string); String[] subs = StringUtils.substringsBetween(patron, "{", "}"); if (subs != null) { int i = 0; for (String sub : subs) { patron = patron.replace("{" + sub + "}", "{" + i++ + "}"); }/*from w w w . j av a2 s . co m*/ } return patron; }
From source file:com.egt.ejb.toolkit.ToolKitUtils.java
public static String[] getParametros(String string) { // Bitacora.trace(ToolKitUtils.class, "getParametros", string); String trimToEmpty = StringUtils.trimToEmpty(string); String[] substringsBetween = StringUtils.substringsBetween(trimToEmpty, "{", "}"); String[] substringsToEmpty = substringsBetween == null ? new String[] {} : substringsBetween; // Bitacora.trace(substringsToEmpty.toString()); return substringsToEmpty; }
From source file:adalid.commons.util.StrUtils.java
public static String getPatronParametrizado(String string) { String patron = StringUtils.trimToEmpty(string); String[] subs = StringUtils.substringsBetween(patron, "{", "}"); int i = 0;/*w ww . j ava 2s. c o m*/ for (String sub : subs) { patron = patron.replace("{" + sub + "}", "{" + i++ + "}"); } return patron; }