List of usage examples for org.apache.commons.lang3 StringUtils substringBetween
public static String substringBetween(final String str, final String open, final String close)
Gets the String that is nested in between two Strings.
From source file:com.gargoylesoftware.htmlunit.util.WebClientUtils.java
/** * Attaches a visual (GUI) debugger to the specified client. * @param client the client to which the visual debugger is to be attached * @see <a href="http://www.mozilla.org/rhino/debugger.html">Mozilla Rhino Debugger Documentation</a> *///from www. ja v a2 s. c o m public static void attachVisualDebugger(final WebClient client) { final ScopeProvider sp = null; final HtmlUnitContextFactory cf = client.getJavaScriptEngine().getContextFactory(); final Main main = Main.mainEmbedded(cf, sp, "HtmlUnit JavaScript Debugger"); main.getDebugFrame().setExtendedState(Frame.MAXIMIZED_BOTH); final SourceProvider sourceProvider = new SourceProvider() { @Override public String getSource(final DebuggableScript script) { String sourceName = script.getSourceName(); if (sourceName.endsWith("(eval)") || sourceName.endsWith("(Function)")) { return null; // script is result of eval call. Rhino already knows the source and we don't } if (sourceName.startsWith("script in ")) { sourceName = StringUtils.substringBetween(sourceName, "script in ", " from"); for (final WebWindow ww : client.getWebWindows()) { final WebResponse wr = ww.getEnclosedPage().getWebResponse(); if (sourceName.equals(wr.getWebRequest().getUrl().toString())) { return wr.getContentAsString(); } } } return null; } }; main.setSourceProvider(sourceProvider); }
From source file:com.willwinder.universalgcodesender.connection.TCPConnection.java
@Override public void setUri(String uri) { try {/*from ww w . j ava 2s. c o m*/ host = StringUtils.substringBetween(uri, ConnectionDriver.TCP.getProtocol(), ":"); port = Integer.valueOf(StringUtils.substringAfterLast(uri, ":")); } catch (Exception e) { throw new ConnectionException("Couldn't parse connection string " + uri, e); } if (StringUtils.isEmpty(host)) { throw new ConnectionException("Empty host in connection string."); } if ((port < 1) || (port > 65535)) { throw new ConnectionException("Please ensure port is a port number between 1 and 65535."); } }
From source file:com.cognifide.qa.bb.aem.core.sidepanel.internal.ComponentTreeLocatorHelper.java
private static int calculateElementNumber(String element) { int toReturn = 0; String elementNumber = StringUtils.substringBetween(element, "[", "]"); if (null != elementNumber) { try {//ww w. j av a 2 s . c o m toReturn = Integer.parseInt(elementNumber); } catch (NumberFormatException e) { LOG.error("Error in component settings", e); } } return toReturn; }
From source file:com.nestof.paraweather.utils.LocationConverter.java
/** * Returns the Decimal Degrees that corresponds to the DMS values entered. * Requires values in Degrees, Minutes, Seconds, and Direction * * @return String//from w w w .jav a 2 s.co m */ public String toDecimalDegrees(String location) { degrees = StringUtils.substringBefore(location, "").trim(); minutes = StringUtils.substringBetween(location, "", "'").trim(); seconds = StringUtils.substringBetween(location, "'", "\"").trim(); direction = StringUtils.substringAfter(location, "\"").trim(); String returnString = null; Double dblDegree; Double dblMinutes; Double dblSeconds; Double decDegrees; String CompassDirection; dblDegree = Double.parseDouble(getDegrees()); dblMinutes = Double.parseDouble(getMinutes()); dblSeconds = Double.parseDouble(getSeconds()); CompassDirection = getDirection(); decDegrees = dblDegree + (dblMinutes / 60) + (dblSeconds / 3600); if (CompassDirection.equalsIgnoreCase("S")) decDegrees = decDegrees * -1; if (CompassDirection.equalsIgnoreCase("W")) decDegrees = decDegrees * -1; returnString = decDegrees.toString() + direction; return returnString; }
From source file:cc.recommenders.names.CoReFieldName.java
@Override public String getFieldName() { final String fieldName = StringUtils.substringBetween(identifier, ".", ";"); return fieldName; }
From source file:com.thinkbiganalytics.metadata.jobrepo.nifi.provenance.NifiBulletinExceptionExtractor.java
/** * Extracts the identifier for the flow file from a bulletin message * * @param message The bulleting message/*from w ww .j av a 2 s. c om*/ * @return A UUID as string */ public String getFlowFileUUIDFromBulletinMessage(String message) { return StringUtils.substringBetween(message, "StandardFlowFileRecord[uuid=", ","); }
From source file:com.erudika.para.rest.RestUtils.java
/** * Extracts the access key from a request. It can be a header or a parameter. * @param request a request/* w w w. jav a 2 s . c om*/ * @return the access key */ public static String extractAccessKey(HttpServletRequest request) { if (request == null) { return ""; } String auth = request.getHeader(HttpHeaders.AUTHORIZATION); if (StringUtils.isBlank(auth)) { auth = request.getParameter("X-Amz-Credential"); if (StringUtils.isBlank(auth)) { return ""; } else { return StringUtils.substringBefore(auth, "/"); } } else { String credential = StringUtils.substringBetween(auth, "Credential=", ","); return StringUtils.substringBefore(credential, "/"); } }
From source file:com.gargoylesoftware.htmlunit.html.IEConditionalCommentExpressionEvaluator.java
/** * Evaluates the condition./* w w w.jav a 2s .c o m*/ * @param condition the condition like "lt IE 7" * @param browserVersion the browser version. Note that currently it can only be an IE browser. * @return the evaluation result */ public static boolean evaluate(String condition, final BrowserVersion browserVersion) { condition = condition.trim(); if ("IE".equals(condition)) { return true; } else if ("true".equals(condition)) { return true; } else if ("false".equals(condition)) { return false; } else if (condition.contains("&")) { return evaluate(StringUtils.substringBefore(condition, "&"), browserVersion) && evaluate(StringUtils.substringAfter(condition, "&"), browserVersion); } else if (condition.contains("|")) { return evaluate(StringUtils.substringBefore(condition, "|"), browserVersion) || evaluate(StringUtils.substringAfter(condition, "|"), browserVersion); } else if (condition.startsWith("!")) { return !evaluate(condition.substring(1), browserVersion); } else if (condition.startsWith("IE")) { final String currentVersion = Float.toString(browserVersion.getBrowserVersionNumeric()); return currentVersion.startsWith(condition.substring(2).trim()); } else if (condition.startsWith("lte IE")) { return browserVersion.getBrowserVersionNumeric() <= parseVersion(condition.substring(6)); } else if (condition.startsWith("lt IE")) { return browserVersion.getBrowserVersionNumeric() < parseVersion(condition.substring(5)); } else if (condition.startsWith("gt IE")) { return browserVersion.getBrowserVersionNumeric() > parseVersion(condition.substring(5)); } else if (condition.startsWith("gte IE")) { return browserVersion.getBrowserVersionNumeric() >= parseVersion(condition.substring(6)); } else if (condition.startsWith("lt")) { return true; } else if (condition.startsWith("gt")) { return false; } else if (condition.startsWith("(")) { // in fact not fully correct if () can be nested return evaluate(StringUtils.substringBetween(condition, "(", ")"), browserVersion); } else { return false; } }
From source file:com.jayway.restassured.path.json.JsonPathObjectDeserializationTest.java
@Test public void json_path_supports_custom_deserializer() { // Given//from www .j ava 2s.c o m final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false); final JsonPath jsonPath = new JsonPath(GREETING) .using(new JsonPathConfig().defaultObjectDeserializer(new JsonPathObjectDeserializer() { public <T> T deserialize(ObjectDeserializationContext ctx) { customDeserializerUsed.set(true); final String json = ctx.getDataToDeserialize().asString(); final Greeting greeting = new Greeting(); greeting.setFirstName(StringUtils.substringBetween(json, "\"firstName\":\"", "\"")); greeting.setLastName(StringUtils.substringBetween(json, "\"lastName\":\"", "\"")); return (T) greeting; } })); // When final Greeting greeting = jsonPath.getObject("", Greeting.class); // Then assertThat(greeting.getFirstName(), equalTo("John")); assertThat(greeting.getLastName(), equalTo("Doe")); assertThat(customDeserializerUsed.get(), is(true)); }
From source file:alliance.docs.DocumentationTest.java
@Test public void testBrokenAnchorsPresent() throws IOException, URISyntaxException { List<Path> docs = Files.list(getPath()).filter(f -> f.toString().endsWith(HTML_DIRECTORY)) .collect(Collectors.toList()); Set<String> links = new HashSet<>(); Set<String> anchors = new HashSet<>(); for (Path path : docs) { Document doc = Jsoup.parse(path.toFile(), "UTF-8", EMPTY_STRING); String thisDoc = StringUtils.substringAfterLast(path.toString(), File.separator); Elements elements = doc.body().getAllElements(); for (Element element : elements) { if (!element.toString().contains(":") && StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE) != null) { links.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE)); }/*from ww w. j av a2s . c om*/ anchors.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), ID, CLOSE)); } } links.removeAll(anchors); assertThat("Anchors missing section reference: " + links.toString(), links.isEmpty()); }