List of usage examples for org.apache.commons.lang StringUtils substringBetween
public static String substringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings.
From source file:de.forsthaus.backend.util.IpLocator.java
/** * @return the country// ww w . jav a 2 s . c o m */ public String getCountryCode() { return StringUtils.defaultString(StringUtils.substringBetween(this.country, "(", ")")); }
From source file:mediathekplugin.Database.java
public ArrayList<MediathekProgramItem> getMediathekPrograms(final Program program) { ArrayList<MediathekProgramItem> result = new ArrayList<MediathekProgramItem>(); String channelName = unifyChannelName(program.getChannel().getName()); HashMap<Long, ArrayList<Integer>> programsMap = mChannelItems.get(channelName); // search parts in brackets like for ARD if (programsMap == null && channelName.contains("(")) { String bracketPart = StringUtils.substringBetween(channelName, "(", ")"); programsMap = mChannelItems.get(bracketPart); }/*w w w.j ava 2s . co m*/ // search for partial name, if full name is not found if (programsMap == null && channelName.contains(" ")) { String firstPart = StringUtils.substringBefore(channelName, " "); programsMap = mChannelItems.get(firstPart); } if (programsMap == null) { for (Entry<String, HashMap<Long, ArrayList<Integer>>> entry : mChannelItems.entrySet()) { if (StringUtils.startsWithIgnoreCase(channelName, entry.getKey())) { programsMap = entry.getValue(); break; } } } if (programsMap == null) { return result; } String title = program.getTitle(); ArrayList<Integer> programs = programsMap.get(getKey(title)); if (programs == null && title.endsWith(")") && title.contains("(")) { String newTitle = StringUtils.substringBeforeLast(title, "(").trim(); programs = programsMap.get(getKey(newTitle)); } if (programs == null && title.endsWith("...")) { String newTitle = title.substring(0, title.length() - 3).trim(); programs = programsMap.get(getKey(newTitle)); } if (programs == null) { return result; } try { RandomAccessFile file = new RandomAccessFile(new File(mFileName), "r"); for (Integer byteOffset : programs) { file.seek(byteOffset); String lineEncoded = file.readLine(); String line = new String(lineEncoded.getBytes(), "UTF-8"); Matcher itemMatcher = ITEM_PATTERN.matcher(line); if (itemMatcher.find()) { String itemTitle = itemMatcher.group(3).trim(); String itemUrl = itemMatcher.group(4).trim(); result.add(new MediathekProgramItem(itemTitle, itemUrl, null)); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
From source file:com.vecna.taglib.processor.JspAnnotationsProcessor.java
/** * Scan a classloader for classes under the given package. * @param pkg package name//from w w w.j a va2s . c om * @param loader classloader * @param lookInsideJars whether to consider classes inside jars or only "unpacked" class files * @return matching class names (will not attemp to actually load these classes) */ private Collection<String> scanClasspath(String pkg, ClassLoader loader, boolean lookInsideJars) { Collection<String> classes = Lists.newArrayList(); Enumeration<URL> resources; String packageDir = pkg.replace(PACKAGE_SEPARATOR, JAR_PATH_SEPARATOR) + JAR_PATH_SEPARATOR; try { resources = loader.getResources(packageDir); } catch (IOException e) { s_log.warn("couldn't scan package", e); return classes; } while (resources.hasMoreElements()) { URL resource = resources.nextElement(); String path = resource.getPath(); s_log.debug("processing path {}", path); if (path.startsWith(FILE_URL_PREFIX)) { if (lookInsideJars) { String jarFilePath = StringUtils.substringBetween(path, FILE_URL_PREFIX, NESTED_FILE_URL_SEPARATOR); try { JarFile jarFile = new JarFile(jarFilePath); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { String entryName = entries.nextElement().getName(); if (entryName.startsWith(packageDir) && entryName.endsWith(CLASS_NAME_SUFFIX)) { String potentialClassName = entryName.substring(packageDir.length(), entryName.length() - CLASS_NAME_SUFFIX.length()); if (!potentialClassName.contains(JAR_PATH_SEPARATOR)) { classes.add(pkg + PACKAGE_SEPARATOR + potentialClassName); } } } } catch (IOException e) { s_log.warn("couldn't open jar file", e); } } } else { File dir = new File(path); if (dir.exists() && dir.isDirectory()) { String[] files = dir.list(); for (String file : files) { s_log.debug("file {}", file); if (file.endsWith(CLASS_NAME_SUFFIX)) { classes.add(pkg + PACKAGE_SEPARATOR + StringUtils.removeEnd(file, CLASS_NAME_SUFFIX)); } } } } } return classes; }
From source file:com.glluch.profilesparser.ProfileHtmlReader.java
private ArrayList<ECFMap> getLevel(String allTxt, String posterior, String f) { //throws java.lang.ArrayIndexOutOfBoundsException ArrayList<ECFMap> res = new ArrayList<>(); String chunk;/* www. j a v a 2 s . c om*/ if (f != null) { chunk = StringUtils.substringBetween(allTxt, posterior, f).trim(); } else { chunk = StringUtils.substringAfter(allTxt, posterior).trim(); } String prelevels = StringUtils.substringAfter(chunk, "Proficiency Levels"); String[] levels = StringUtils.splitByWholeSeparator(prelevels, "Proficiency Level"); //System.out.println("levels:\n"+levels.toString()); int i = 0; while (i < levels.length) { if (levels[i].length() > 1) { String c3 = levels[i].substring(1, 2); HashMap<Integer, String> c0; c0 = parseCompName(posterior); String c1 = c0.get(0); String c2 = c0.get(1); //System.out.println(c1+" "+c2+", level "+c3); ECFMap em = new ECFMap(c1, c2, c3); res.add(em); //System.out.println(levels[i] + "\n-->" + levels[i].substring(1, 2)); } i++; } return res; }
From source file:com.dianping.dpsf.jmx.DpsfRequestorMonitor.java
/** * /*from ww w . j a v a 2 s . c o m*/ * @param serviceFullName http://service.dianping.com/cacheService/cacheConfigService_1.0.0 * @return http://service.dianping.com/cacheService */ private String getServiceName(String serviceFullName) { String serviceSubName = StringUtils.substringBetween(serviceFullName, PigeonConfig.getServiceNameSpace(), "/"); if (serviceSubName != null) { return PigeonConfig.getServiceNameSpace() + serviceSubName; } return null; }
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(); }//from ww w .j av a2 s.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.zb.app.biz.service.WeixinTest.java
private boolean compareFakeid(String fakeid, String openid) { PostMethod post = new PostMethod( "https://mp.weixin.qq.com/cgi-bin/singlesendpage?t=message/send&action=index&token=" + token + "&tofakeid=" + fakeid + "&lang=zh_CN"); post.setRequestHeader("Cookie", this.cookiestr); post.setRequestHeader("Host", "mp.weixin.qq.com"); post.setRequestHeader("Referer", "https://mp.weixin.qq.com/cgi-bin/contactmanage?t=user/index&token=" + token + "&lang=zh_CN&pagesize=10&pageidx=0&type=0"); post.setRequestHeader("Content-Type", "text/html;charset=UTF-8"); post.addParameter(new NameValuePair("token", token)); post.addParameter(new NameValuePair("ajax", "1")); try {//from w w w . j ava 2 s .c o m int code = httpClient.executeMethod(post); if (HttpStatus.SC_OK == code) { String str = post.getResponseBodyAsString(); String msgJson = StringUtils.substringBetween(str, "<script id=\"json-msgList\" type=\"json\">", "</script>"); JSONParser parser = new JSONParser(); try { JSONArray array = (JSONArray) parser.parse(msgJson); for (int i = 0; i < array.size(); i++) { JSONObject obj = (JSONObject) array.get(i); String content = (String) obj.get("content"); if (content.contains(openid)) { return true; } } } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:edu.ku.brc.dbsupport.MySQLDMBSUserMgr.java
@Override public List<String> getDatabaseListForUser(final String username) { String[] permsArray = new String[] { "SELECT", "DELETE", "UPDATE", "INSERT", "LOCK TABLES", }; HashSet<String> permsHash = new HashSet<String>(); Collections.addAll(permsHash, permsArray); ArrayList<String> dbNames = new ArrayList<String>(); try {/*from w w w . ja v a 2s .c o m*/ if (connection != null) { String userStr = String.format("'%s'@'%s'", username, hostName); String sql = "SHOW GRANTS"; for (Object obj : BasicSQLUtils.querySingleCol(connection, sql)) { boolean isAllDBs = false; String data = (String) obj; String dbName = null; System.out.println("->[" + data + "]"); if (StringUtils.contains(data, userStr)) { // get database name String[] toks = StringUtils.split(data, '`'); if (toks.length > 2) { dbName = toks[1]; } } else if (StringUtils.contains(data, "ON *.* TO")) { //dbNames.add(obj.toString()); isAllDBs = true; } // get permissions String permsStr = StringUtils.substringBetween(data, "GRANT ", " ON"); String[] pToks = StringUtils.split(permsStr, ','); if (pToks != null) { if (pToks.length == 1 && pToks[0].equalsIgnoreCase("ALL PRIVILEGES") && isAllDBs) { dbNames.addAll(getDatabaseList()); } else if (pToks.length >= permsHash.size()) { int cnt = 0; for (String p : pToks) { if (permsHash.contains(p.trim())) { cnt++; } } if (cnt == permsHash.size()) { if (isAllDBs) { dbNames.addAll(getDatabaseList()); break; } else if (dbName != null) { dbNames.add(dbName); } } } } } } } catch (Exception ex) { ex.printStackTrace(); } return dbNames; }
From source file:info.magnolia.templating.inheritance.DefaultInheritanceContentDecoratorTest.java
private Map<String, String> loadSessionConfigs(String resourceSuffix) throws IOException { InputStream stream = getClass() .getResourceAsStream(getClass().getSimpleName() + "_" + resourceSuffix + ".txt"); List<String> lines = IOUtils.readLines(stream); HashMap<String, String> sections = new HashMap<String, String>(); String sectionName = null;//w ww .j a va 2 s .com List<String> sectionLines = new ArrayList<String>(); for (String line : lines) { if (line.equals("")) { continue; } if (line.startsWith("#")) { continue; } if (line.startsWith("[")) { if (sectionName != null) { sections.put(sectionName, StringUtils.join(sectionLines, "\n")); } sectionName = StringUtils.substringBetween(line, "[", "]"); sectionLines.clear(); continue; } sectionLines.add(line); } if (sectionName != null) { sections.put(sectionName, StringUtils.join(sectionLines, "\n")); } return sections; }
From source file:$.MessageLogParser.java
@Nullable private String getRequestId(String line) { // 2013-05-23 20:22:36,754 [MACHINE_IS_UNDEFINED, ajp-bio-8009-exec-19, /esb/ws/account/v1, 10.10.0.95:72cab819:13ecdbd371c:-7eff, ] DEBUG String logHeader = StringUtils.substringBetween(line, "[", "]"); if (logHeader == null) { // no match - the line doesn't contain [] return null; }//from w w w .j av a 2s . c o m String[] headerParts = StringUtils.split(logHeader, ","); String requestId = StringUtils.trim(headerParts[3]); // note: if request starts from scheduled job, then there is request ID information // 2013-05-27 16:37:25,633 [MACHINE_IS_UNDEFINED, DefaultQuartzScheduler-camelContext_Worker-8, , , ] // WARN c.c.c.i.c.a.d.RepairMessageServiceDbImpl${symbol_dollar}2 - The message (msg_id = 372, correlationId = ... return StringUtils.trimToNull(requestId); }