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:org.goko.controller.grbl.v08.GrblCommunicator.java
private String parseCoordinateSystem(String strOrigin, Tuple6b targetPoint) throws GkException { String identifier = StringUtils.substringBetween(strOrigin, "[", ":"); String valuesGroup = StringUtils.substringBetween(strOrigin, ":", "]"); String[] values = StringUtils.split(valuesGroup, ","); Unit<Length> unit = grbl.getConfiguration().getReportUnit(); if (values == null || values.length < 3) { throw new GkFunctionalException("Received incomplete offset report " + strOrigin + ". Ignoring..."); }//from w w w .j a va 2s .co m BigDecimal x = new BigDecimal(values[0]); BigDecimal y = new BigDecimal(values[1]); BigDecimal z = new BigDecimal(values[2]); targetPoint.setX(Length.valueOf(x, unit)); targetPoint.setY(Length.valueOf(y, unit)); targetPoint.setZ(Length.valueOf(z, unit)); return identifier; }
From source file:org.goko.controller.grbl.v08.GrblControllerService.java
protected void handleConfigurationReading(String cofigurationMessage) throws GkException { String identifier = StringUtils.substringBefore(cofigurationMessage, "=").trim(); String value = StringUtils.substringBetween(cofigurationMessage, "=", "(").trim(); configuration.setValue(identifier, value); LOG.info("Updating setting '" + identifier + "' with value '" + value + "'"); }
From source file:org.goko.controller.grbl.v09.GrblCommunicator.java
/** * Handling of incoming data/*from w w w. jav a 2s .co m*/ * @param data the received data * @throws GkException GkException */ protected void handleIncomingData(String data) throws GkException { String trimmedData = StringUtils.trim(data); if (StringUtils.isNotEmpty(trimmedData)) { /* Received OK response */ if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) { grbl.handleOkResponse(); /* Received error */ } else if (StringUtils.startsWith(trimmedData, "error:")) { grbl.handleError(trimmedData); /* Received status report */ } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) { grbl.handleStatusReport(parseStatusReport(trimmedData)); /* Received Grbl header */ } else if (StringUtils.startsWith(trimmedData, "Grbl")) { handleHeader(trimmedData); grbl.initialiseConnectedState(); // refreshStatus(); /* Received a configuration confirmation */ } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) { grbl.handleConfigurationReading(trimmedData); /* Received a probe result */ } else if (StringUtils.defaultString(trimmedData).matches("\\$[PRB*]")) { //[PRB:0.000,0.000,0.000:0] ProbeResult probeResult = parseProbeResult(StringUtils.defaultString(trimmedData)); grbl.handleProbeResult(probeResult); /* Received a work position report */ } else if (StringUtils.defaultString(trimmedData).matches("\\[G5.*\\]")) { Tuple6b targetPoint = new Tuple6b().setNull(); String offsetName = parseCoordinateSystem(trimmedData, targetPoint); grbl.setOffsetCoordinate(offsetName, targetPoint); /* Received an offset position report */ } else if (StringUtils.defaultString(trimmedData).matches("\\[(G92|G28|G30).*\\]")) { // Tuple6b targetPoint = new Tuple6b().setNull(); // String coordinateSystemName = parseCoordinateSystem(trimmedData, targetPoint); // grbl.setOffsetCoordinate(coordinateSystemName, targetPoint); // TODO Handle G92 /* Parser state report */ } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) { grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]")); /* Unkown format received */ } else { LOG.error("Ignoring received data " + trimmedData); grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData, GrblControllerService.SERVICE_ID); } } }
From source file:org.goko.grbl.controller.GrblCommunicator.java
/** * Handling of incoming data//from w w w .j ava2 s .c o m * @param data the received data * @throws GkException GkException */ protected void handleIncomingData(String data) throws GkException { String trimmedData = StringUtils.trim(data); if (StringUtils.isNotEmpty(trimmedData)) { /* Received OK response */ if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) { grbl.handleOkResponse(); /* Received error */ } else if (StringUtils.startsWith(trimmedData, "error:")) { grbl.handleError(trimmedData); /* Received status report */ } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) { grbl.handleStatusReport(parseStatusReport(trimmedData)); /* Received Grbl header */ } else if (StringUtils.startsWith(trimmedData, "Grbl")) { handleHeader(trimmedData); grbl.initialiseConnectedState(); // refreshStatus(); /* Received a configuration confirmation */ } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) { grbl.handleConfigurationReading(trimmedData); /* Received an offset position report */ } else if (StringUtils.defaultString(trimmedData).matches("\\[(G5|G28|G30|G92).*\\]")) { Tuple6b targetPoint = new Tuple6b().setNull(); String offsetName = parseCoordinateSystem(trimmedData, targetPoint); grbl.setOffsetCoordinate(offsetName, targetPoint); /* Parser state report */ } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) { grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]")); /* Unkown format received */ } else { LOG.error("Ignoring received data " + trimmedData); grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData, GrblControllerService.SERVICE_ID); } } }
From source file:org.goko.grbl.controller.GrblCommunicator.java
private String parseCoordinateSystem(String strOrigin, Tuple6b targetPoint) throws GkException { String identifier = StringUtils.substringBetween(strOrigin, "[", ":"); String valuesGroup = StringUtils.substringBetween(strOrigin, ":", "]"); String[] values = StringUtils.split(valuesGroup, ","); Unit<Length> unit = grbl.getConfiguration().getReportUnit(); if (values == null || values.length < 3) { throw new GkFunctionalException("Received incomplete offset report " + strOrigin + ". Ignoring..."); }//from w ww . ja v a 2s. co m BigDecimal x = new BigDecimal(values[0]); BigDecimal y = new BigDecimal(values[1]); BigDecimal z = new BigDecimal(values[2]); targetPoint.setX(NumberQuantity.of(x, unit)); targetPoint.setY(NumberQuantity.of(y, unit)); targetPoint.setZ(NumberQuantity.of(z, unit)); return identifier; }
From source file:org.karndo.piracy.Scraper.java
/** * /*w w w . j av a 2 s . com*/ * @param url * @param io * @return */ public LinkedList<PiracyEvent> parse_piracy_data(String url, InputOutput io) throws IOException { //use the private method in this class to get the data String data = get_piracy_data(url); System.out.println(data); //strip everything before "icons" String temp = StringUtils.strip(data, "head.ready(function() {fabrikMap45 = new FbGoogleMapViz('table_map', {\"icons\":["); temp = "\"" + temp; //after stripping the first section, the data can be split using the //'curly brackets' String[] events = StringUtils.split(temp, "{"); LinkedList<PiracyEvent> events_list = new LinkedList<PiracyEvent>(); //some parameters for holding data from the event strings PiracyEvent event1 = null; double longitude = 0.0; double latitude = 0.0; String attack_id = ""; String vessel_type = ""; String status = ""; Date date = null; for (String str : events) { try { //Strip out the latitude and longitude String lat1 = StringUtils.strip(StringUtils.substringBetween(str, "\"0\":", ","), "\""); String long1 = StringUtils.strip(StringUtils.substringBetween(str, "\"1\":", ","), "\""); //parse the values into doubles latitude = Double.parseDouble(lat1); longitude = Double.parseDouble(long1); //strip out the attack id. attack_id = StringUtils.strip(StringUtils.substringBetween(str, "\"2\":", "<br \\/>"), "\"Attack ID:"); //strip out the date String date_str = StringUtils.strip(StringUtils.substringBetween(str, "Date:", "<br"), "Date:"); // TODO change this to a GMT time-format date = DateUtils.parseDate(StringUtils.trim(date_str), "yyyy-MM-dd"); //strip out the Vessel type vessel_type = StringUtils.strip(StringUtils.substringBetween(str, "Vessel:", "<br \\/>"), "Vessel:"); //strip out the status status = StringUtils.strip(StringUtils.substringBetween(str, "Status:", "<br \\/>"), "Status:"); //create a piracy event event1 = new PiracyEvent(latitude, longitude, attack_id, date, StringUtils.trim(status), StringUtils.trim(vessel_type)); events_list.add(event1); //print to the supplied InputOutput from the main window io.getOut().println(event1); } catch (ParseException ex) { System.err.println("A parse exception occurred parsing the date"); System.err.println(ex.getMessage()); } finally { } } return events_list; }
From source file:org.kawanfw.sql.api.client.RemoteDriverUtil.java
/** * Create a Proxy instance from a Proxy.toString() representation * Example: HTTP @ www.kawansoft.com/195.154.226.82:8080 * @param proxyToString the proxy in Proxy.toString() format * @return the build proxy/* w ww.j av a 2 s . com*/ */ public static Proxy buildProxy(String proxyToString) { if (proxyToString == null) { throw new NullPointerException("ip is null!"); } if (!proxyToString.contains(" @ ")) { throw new IllegalArgumentException("Malformed Proxy.toString() format: @ separator is missing."); } // Get the type String type = StringUtils.substringBefore(proxyToString, " @ "); if (type == null) { throw new IllegalArgumentException("Malformed Proxy.toString() format: no Type"); } type = type.trim(); debug("Proxy.Type.DIRECT: " + Proxy.Type.DIRECT.toString()); if (!type.equals(Proxy.Type.DIRECT.toString()) && !type.equals(Proxy.Type.HTTP.toString()) && !type.equals(Proxy.Type.SOCKS.toString())) { throw new IllegalArgumentException( "Malformed Proxy.toString() format: Type does not contain DIRECT / HTTP / SOCKS: " + type + ":"); } String hostname = null; String portStr = null; int port = 0; if (proxyToString.contains("@ /")) { // Case 1 : HTTP @ /195.154.226.82:8080 // no hostname IP only hostname = StringUtils.substringBetween(proxyToString, "/", ":"); } else { // Case 2 : HTTP @ localhost/127.0.0.1:8080 // hostname followed by ip or /subaddress hostname = StringUtils.substringBetween(proxyToString, " @ ", "/"); String ip = StringUtils.substringBetween(proxyToString, "/", ":"); // if ip string is in IP format, dont take in account the ip after / // If not, following / is the hostname if (validateIpFormat(ip)) { hostname = StringUtils.substringBetween(proxyToString, " @ ", "/"); } else { hostname = StringUtils.substringBetween(proxyToString, " @ ", ":"); } } portStr = StringUtils.substringAfter(proxyToString, ":"); if (StringUtils.isNumeric(portStr)) { port = Integer.parseInt(portStr); } else { throw new IllegalArgumentException( "Malformed Proxy.toString() format: does not contain numeric port: " + proxyToString); } Proxy proxy = new Proxy(Type.valueOf(type), new InetSocketAddress(hostname, port)); return proxy; }
From source file:org.kawanfw.sql.transport.SavepointHttp.java
/** * Builds a Savepoint from a String/*from w w w . j a v a2 s.c o m*/ * * @param savepointStrthe * String containing a SavepointHttp.toString() * @return a SavepointHttp */ public static Savepoint buildFromString(String savepointStr) { if (savepointStr == null) { throw new IllegalArgumentException("Savepoint can not be null!"); } if (!savepointStr.contains("[id=") || !savepointStr.contains(", name") || !savepointStr.endsWith("]")) { throw new IllegalArgumentException( "Savepoint String is not conform to pattern [id=theId, name=theName]: " + savepointStr); } String idStr = StringUtils.substringBetween(savepointStr, "[id=", ", name="); if (idStr == null) { throw new IllegalArgumentException("id as String can not be null!"); } idStr = idStr.trim(); int id = Integer.parseInt(idStr); String name = StringUtils.substringBetween(savepointStr, ", name=", "]"); if (name == null) { throw new IllegalArgumentException("name can not be null!"); } name = name.trim(); SavepointHttp savepointHttp = new SavepointHttp(id, name); return savepointHttp; }
From source file:org.kuali.coeus.common.budget.impl.struts.BudgetExpensesAction.java
private int getImagePropertyValue(HttpServletRequest request, String open, String close) { int selectedLine = -1; String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); if (StringUtils.isNotBlank(parameterName)) { String lineNumber = StringUtils.substringBetween(parameterName, open, close); if (StringUtils.isEmpty(lineNumber)) { return selectedLine; }/*from w ww .j av a 2 s . co m*/ selectedLine = Integer.parseInt(lineNumber); } return selectedLine; }
From source file:org.kuali.coeus.common.budget.impl.struts.BudgetExpensesAction.java
protected String getSelectedBudgetCategoryType(HttpServletRequest request) { String selectedCategoryTypeCode = ""; String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); if (StringUtils.isNotBlank(parameterName)) { selectedCategoryTypeCode = StringUtils.substringBetween(parameterName, ".budgetCategoryTypeCode", "."); }/*from ww w . j a va2 s . c o m*/ return selectedCategoryTypeCode; }