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:org.royaldev.royalcommands.rcommands.pluginmanager.SCmdFindTag.java
@Override public boolean runCommand(final CommandSender cs, Command cmd, String label, String[] eargs, CommandArguments ca) {// ww w .j a v a2 s. co m if (eargs.length < 1) { cs.sendMessage(MessageColor.NEGATIVE + "Please specify a search term!"); return true; } int page = 1; if (eargs.length > 1) { try { page = Integer.parseInt(eargs[eargs.length - 1]); } catch (NumberFormatException ignored) { page = 1; } } final String search; try { search = URLEncoder.encode(StringUtils.join(eargs, " "), "UTF-8"); } catch (UnsupportedEncodingException e) { cs.sendMessage(MessageColor.NEGATIVE + "Tell the developer enc1."); return true; } final URL u; try { u = new URL("http://dev.bukkit.org/search/?scope=projects&search=" + search + "&page=" + page); } catch (MalformedURLException e) { cs.sendMessage(MessageColor.NEGATIVE + "Malformed search term!"); return true; } final BufferedReader br; try { br = new BufferedReader(new InputStreamReader(u.openStream())); } catch (IOException e) { cs.sendMessage(MessageColor.NEGATIVE + "Internal input/output error. Please try again."); return true; } final Runnable r = new Runnable() { @Override public void run() { String inputLine; StringBuilder content = new StringBuilder(); try { while ((inputLine = br.readLine()) != null) content.append(inputLine); } catch (IOException e) { cs.sendMessage(MessageColor.NEGATIVE + "Internal input/output error. Please try again."); return; } cs.sendMessage(MessageColor.POSITIVE + "Project name" + MessageColor.NEUTRAL + " - tag"); for (int i = 0; i < 20; i++) { final String project = StringUtils.substringBetween(content.toString(), " row-joined-to-next\">", "</tr>"); final String base = StringUtils.substringBetween(project, "<td class=\"col-search-entry\">", "</td>"); if (base == null) { if (i == 0) cs.sendMessage(MessageColor.NEGATIVE + "No results found."); return; } final Pattern p = Pattern .compile("<h2><a href=\"/bukkit-plugins/([\\W\\w]+)/\">([\\w\\W]+)</a></h2>"); final Matcher m = p.matcher(base); if (!m.find()) { if (i == 0) cs.sendMessage(MessageColor.NEGATIVE + "No results found."); return; } final String name = m.group(2).replaceAll("</?\\w+>", ""); final String tag = m.group(1); final int beglen = StringUtils.substringBefore(content.toString(), base).length(); content = new StringBuilder(content.substring(beglen + project.length())); cs.sendMessage(MessageColor.POSITIVE + name + MessageColor.NEUTRAL + " - " + tag); } } }; this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, r); return true; }
From source file:org.sakaiproject.iclicker.logic.IClickerLogic.java
/** * @param response the http response object * @param start the start delimiter of the content * @param end the end delimiter of the content * @param emptyIndicator [OPTIONAL] if set and is contained in the body then returns empty result * @return the body of the response between the start and end strings if there is one * @throws IllegalStateException if the webservices fail or the response is invalid *///from www . j a va2 s . co m private String getXMLAndCheckResponse(HttpResponse response, String start, String end, String emptyIndicator) { if (response.getResponseCode() >= 400) { String msg = "i>clicker Webservices failure: bad response code (" + response.responseCode + "), message: " + response.responseMessage; log.error(msg); throw new IllegalStateException(msg); } String xml; String body = response.getResponseBody(); if (body != null) { body = body.trim(); if (emptyIndicator != null && StringUtils.contains(body, emptyIndicator)) { xml = ""; } else { String result = StringUtils.substringBetween(body, start, end); if (result == null) { String msg = "i>clicker Webservices failure: (" + response.responseCode + "), message:" + response.responseMessage + " : body=" + body; log.error(msg); throw new IllegalStateException(msg); } xml = StringEscapeUtils.unescapeXml(result); if (xml.startsWith("<RetStatus")) { String msg = "i>clicker Webservices failure: (" + response.responseCode + "), message:" + response.responseMessage + " : xml=" + xml; log.error(msg); throw new IllegalStateException(msg); } } } else { String msg = "i>clicker Webservices failure: no response body from server: (" + response.responseCode + "), message:" + response.responseMessage; log.error(msg); throw new IllegalStateException(msg); } return xml; }
From source file:org.sakaiproject.samigo.impl.SamigoObserver.java
private Map<String, Object> stringToHashMap(String hashMapString) { Map<String, Object> map = new HashMap<String, Object>(); hashMapString = StringUtils.substringBetween(hashMapString, "{", "}"); //remove curly brackets String[] keyValuePairs = hashMapString.split(","); //split the string to create key-value pairs for (String pair : keyValuePairs) //iterate over the pairs {/*from w w w . j av a 2 s. c o m*/ String[] entry = pair.split("="); //split the pairs to get key and value String key = StringUtils.trim(entry[0]); if (entry.length == 2) { if (key.equals("assessmentGradingID") || key.equals("publishedAssessmentID")) { map.put(key, Long.valueOf(StringUtils.trim(entry[1]))); } else { map.put(key, String.valueOf(StringUtils.trim(entry[1]))); //add them to the hashmap and trim whitespaces } } else { map.put(key, ""); } } return map; }
From source file:org.seedstack.seed.security.internal.authorization.ConfigurationRoleMapping.java
/** * Finds the scope in a string that corresponds to a role with {wildcard}.<br> * For example, if wildcardAuth is toto.{SCOPE} and auth is toto.foo then * scope is foo./*from ww w. j a v a 2 s. co m*/ * * @param wildcard the wildcard to search for * @param wildcardAuth auth with {wildcard} * @param auth auth that corresponds * @return the scope. */ private String findScope(String wildcard, String wildcardAuth, String auth) { String scope; String before = StringUtils.substringBefore(wildcardAuth, wildcard); String after = StringUtils.substringAfter(wildcardAuth, wildcard); if (StringUtils.startsWith(wildcardAuth, wildcard)) { scope = StringUtils.substringBefore(auth, after); } else if (StringUtils.endsWith(wildcardAuth, wildcard)) { scope = StringUtils.substringAfter(auth, before); } else { scope = StringUtils.substringBetween(auth, before, after); } return scope; }
From source file:org.sipfoundry.sipxconfig.admin.monitoring.MRTGConfig.java
private String parseTargetId(String line) { return StringUtils.substringBetween(line, OPEN_BRACKET, CLOSE_BRACKET); }
From source file:org.sipfoundry.sipxconfig.common.SipUri.java
/** * Attempts to extract address-spec portion from URI * * This is rather a brute force implementation tailored to extracting URI to be used for * voicemail click-to-call. Rather than doing full fledged parsing it just gets the portion of * the string between and checks if it looks like SIP URI. * * @return address-spec or null if we cannot extract it *//*from w w w .ja v a 2 s .com*/ public static String extractAddressSpec(String uri) { String candidate = StringUtils.substringBetween(uri, "<", ">"); if (matches(candidate)) { return candidate; } if (matches(uri)) { return uri; } return null; }
From source file:org.sipfoundry.sipxconfig.login.LoginEvent.java
String extractTokenValue(String line, String token) { String separator = ","; if (StringUtils.substringBetween(line, token, separator) == null) { return StringUtils.substringAfterLast(line, token); }// ww w.j a va2 s . c om return StringUtils.substringBetween(line, token, separator); }
From source file:org.sipfoundry.voicemail.MailboxServlet.java
private void listMessages(List<VmMessage> messages, String folder, PrintWriter pw) { String author = null;// w w w . java 2 s .c om String fromUri = null; for (VmMessage message : messages) { MessageDescriptor descriptor = message.getDescriptor(); String uri = descriptor.getFromUri(); author = SipUriUtil.extractUserName(uri.replace('+', ' ')); fromUri = StringUtils.substringBetween(uri, "<", ">"); pw.format( "<message id=\"%s\" heard=\"%s\" urgent=\"%s\" folder=\"%s\" duration=\"%s\" received=\"%s\" author=\"%s\" username=\"%s\" format=\"%s\"/>\n", message.getMessageId(), !message.isUnHeard(), message.isUrgent(), folder, descriptor.getDurationSecsLong(), descriptor.getTimeStampDate().getTime(), author, message.getUserName(), descriptor.getAudioFormat()); } }
From source file:org.sipfoundry.voicemail.MailboxServlet.java
private void listFullMessage(VmMessage message, String folder, PrintWriter pw) { MessageDescriptor descriptor = message.getDescriptor(); String uri = descriptor.getFromUri(); String author = SipUriUtil.extractUserName(uri.replace('+', ' ')); String fromUri = StringUtils.substringBetween(uri, "<", ">"); pw.format(// www .j a v a 2s . c o m "<message id=\"%s\" heard=\"%s\" urgent=\"%s\" folder=\"%s\" duration=\"%s\" received=\"%s\" fromUri=\"%s\" author=\"%s\" subject=\"%s\" username=\"%s\" format=\"%s\"/>\n", message.getMessageId(), !message.isUnHeard(), message.isUrgent(), folder, descriptor.getDurationSecsLong(), descriptor.getTimeStampDate().getTime(), fromUri, StringEscapeUtils.escapeHtml(author), descriptor.getSubject(), message.getUserName(), descriptor.getAudioFormat()); }
From source file:org.sonar.api.batch.maven.MavenPlugin.java
private static int getIndex(String key) { //parsing index-syntax (e.g. item[1]) if (key.matches(".*?\\[\\d+\\]")) { return Integer.parseInt(StringUtils.substringBetween(key, "[", "]")); }/*from w ww . j a va2 s . c o m*/ // for down-compatibility of api we fallback to default 0 return 0; }