List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.goko.controller.grbl.v08.GrblControllerService.java
/** * Log the given error on the given gcode line (line can be null) * @param errorMessage the error message * @param line the line (optionnal)/*from w ww .j av a 2 s.c o m*/ * @throws GkException GkException */ protected void logError(String errorMessage, GCodeLine line) throws GkException { String formattedErrorMessage = StringUtils.EMPTY; if (line != null) { String lineStr = gcodeService.render(line); formattedErrorMessage = "Error with command '" + lineStr + "' : " + StringUtils.substringAfter(errorMessage, "error: "); } else { formattedErrorMessage = "Grbl Error : " + StringUtils.substringAfter(errorMessage, "error: "); } LOG.error(formattedErrorMessage); getApplicativeLogService().error(formattedErrorMessage, SERVICE_ID); // If not in check mode, let's pause the execution (disabled in check mode because check mode can't handle paused state and buffer would be flooded with commands) if (!ObjectUtils.equals(GrblMachineState.CHECK, getState())) { pauseMotion(); EventBrokerUtils.send(eventAdmin, new GrblExecutionErrorTopic(), new GrblExecutionError( "Error reported durring execution", "Execution was paused after Grbl reported an error. You can resume, or stop the execution at your own risk.", formattedErrorMessage)); } }
From source file:org.goko.controller.grbl.v09.GrblControllerService.java
/** * Log the given error on the given gcode line (line can be null) * @param errorMessage the error message * @param line the line (optionnal)//w w w.j a va 2s .c o m * @throws GkException GkException */ protected void logError(String errorMessage, GCodeLine line) throws GkException { String formattedErrorMessage = StringUtils.EMPTY; if (line != null) { String lineStr = gcodeService.render(line); formattedErrorMessage = "Error with command '" + lineStr + "' : " + StringUtils.substringAfter(errorMessage, "error: "); } else { formattedErrorMessage = "Grbl " + errorMessage; } LOG.error(formattedErrorMessage); getApplicativeLogService().error(formattedErrorMessage, SERVICE_ID); // If not in check mode, let's pause the execution (disabled in check mode because check mode can't handle paused state and buffer would be flooded with commands) if (!ObjectUtils.equals(GrblMachineState.CHECK, getState())) { pauseMotion(); EventBrokerUtils.send(eventAdmin, new GrblExecutionErrorTopic(), new GrblExecutionError( "Error reported durring execution", "Execution was paused after Grbl reported an error. You can resume, or stop the execution at your own risk.", formattedErrorMessage)); } }
From source file:org.goko.grbl.controller.GrblControllerService.java
protected void handleError(String errorMessage) throws GkException { if (executionQueue != null) { GrblGCodeExecutionToken currentToken = executionQueue.getCurrentToken(); String formattedErrorMessage = StringUtils.EMPTY; if (currentToken != null && currentToken.getSentCommandCount() > 0) { // Error occured during GCode programm execution, let's give the source command GCodeCommand command = currentToken.markNextCommandAsError(); formattedErrorMessage = "Error with command '" + command.toString() + "' : " + StringUtils.substringAfter(errorMessage, "error: "); } else {/* w w w. ja v a 2 s . c om*/ formattedErrorMessage = "Grbl Error : " + StringUtils.substringAfter(errorMessage, "error: "); } LOG.error(formattedErrorMessage); getApplicativeLogService().error(formattedErrorMessage, SERVICE_ID); // If not in check mode, let's pause the execution (disabled in check mode because check mode can't handle paused state and buffer would be flooded with commands) if (!ObjectUtils.equals(GrblMachineState.CHECK, getState())) { pauseMotion(); // Map<String, String> mapArgs = new HashMap<String, String>(); // mapArgs.put(Grbl.Topic.GrblExecutionError.TITLE, "Error reported durring execution"); // mapArgs.put(Grbl.Topic.GrblExecutionError.MESSAGE, "Execution was paused after Grbl reported an error. You can resume, or stop the execution at your own risk."); // mapArgs.put(Grbl.Topic.GrblExecutionError.ERROR, formattedErrorMessage); // eventAdmin.sendEvent(new Event(Grbl.Topic.GrblExecutionError.TOPIC, mapArgs)); EventBrokerUtils.send(eventAdmin, new GrblExecutionErrorTopic(), new GrblExecutionError( "Error reported durring execution", "Execution was paused after Grbl reported an error. You can resume, or stop the execution at your own risk.", formattedErrorMessage)); // Verifier pourquoi l'erreur n'est pas affiche } } else { LOG.error("Grbl Error : " + StringUtils.substringAfter(errorMessage, "error: ")); getApplicativeLogService().error(StringUtils.substringAfter(errorMessage, "error: "), SERVICE_ID); } }
From source file:org.grible.servlets.ui.panels.GetCategories.java
private boolean isOneOfParentCategoriesForTable(int tableId, Category category) throws Exception { if (isJson()) { Table table = jDao.getTable(tableId, productId); Product product = DataManager.getInstance().getDao().getProduct(productId); String tableFilePath = StringUtils.substringAfter(table.getFile().getAbsolutePath(), product.getPath() + File.separator + category.getType().getSection().getDirName() + File.separator); return tableFilePath.startsWith(category.getPath()); }// www . j av a 2s.c o m int parentCategoryId = pDao.getTable(tableId).getCategoryId(); if (parentCategoryId == category.getId()) { return true; } else { Category currentCategory = pDao.getCategory(parentCategoryId); while (currentCategory.getParentId() > 0) { parentCategoryId = currentCategory.getParentId(); if (parentCategoryId == category.getId()) { return true; } currentCategory = pDao.getCategory(parentCategoryId); } } return false; }
From source file:org.guess.core.orm.PropertyFilter.java
/** * @param filterName ,???. /*from ww w .j a v a 2s . c o m*/ * eg. LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }
From source file:org.gvnix.addon.jpa.addon.entitylistener.JpaOrmEntityListenerMetadata.java
/** * @param metadataIdentificationString//from w w w . ja va 2s . c o m * @return if metadata is valid */ public static boolean isValid(String metadataIdentificationString) { return PhysicalTypeIdentifierNamingUtils.isValid(PROVIDES_TYPE_STRING, StringUtils.substringBefore(metadataIdentificationString, METADATA_SOURCE_DELIMITER)) && StringUtils.contains(metadataIdentificationString, METADATA_SOURCE_DELIMITER) && StringUtils.isNotBlank( StringUtils.substringAfter(metadataIdentificationString, METADATA_SOURCE_DELIMITER)); }
From source file:org.gvnix.addon.jpa.addon.entitylistener.JpaOrmEntityListenerMetadata.java
/** * @param metadataIdentificationString/* w w w. j a v a 2s. co m*/ * @return gets source metatada id */ public static final String getSorceId(String metadataIdentificationString) { return StringUtils.substringAfter(metadataIdentificationString, METADATA_SOURCE_DELIMITER); }
From source file:org.gvnix.web.json.BindingResultSerializer.java
/** * Iterate over list items errors and load it on allErrorsMessages map. * <p/>//from w w w. j a v a2 s . c o m * Delegates on {@link #loadObjectError(FieldError, String, Map)} * * @param fieldErrors * @param allErrorsMessages */ @SuppressWarnings("unchecked") private void loadListErrors(List<FieldError> fieldErrors, Map<String, Object> allErrorsMessages) { // Get prefix to unwrapping list: // "list[0].employedSince" String fieldNamePath = fieldErrors.get(0).getField(); // "list" String prefix = StringUtils.substringBefore(fieldNamePath, "["); String index; Map<String, Object> currentErrors; // Iterate over errors for (FieldError error : fieldErrors) { // get property path without list prefix // "[0].employedSince" fieldNamePath = StringUtils.substringAfter(error.getField(), prefix); // Get item's index: // "[0].employedSince" index = StringUtils.substringBefore(StringUtils.substringAfter(fieldNamePath, "["), "]"); // Remove index definition from field path // "employedSince" fieldNamePath = StringUtils.substringAfter(fieldNamePath, "."); // Check if this item already has errors registered currentErrors = (Map<String, Object>) allErrorsMessages.get(index); if (currentErrors == null) { // No errors registered: create map to contain this error currentErrors = new HashMap<String, Object>(); allErrorsMessages.put(index, currentErrors); } // Load error on item's map loadObjectError(error, fieldNamePath, currentErrors); } }
From source file:org.gvnix.web.json.BindingResultSerializer.java
/** * Loads an object field error in errors map. * <p/>// w w w . j a v a 2 s . c o m * This method identifies if referred object property is an array, an object * or a simple property to decide how to store the error message. * * @param error * @param fieldNamePath * @param objectErrors */ @SuppressWarnings("unchecked") private void loadObjectError(FieldError error, String fieldNamePath, Map<String, Object> objectErrors) { String propertyName; boolean isObject = false; boolean isList = false; // Get this property name and if is a object property if (StringUtils.contains(fieldNamePath, ".")) { isObject = true; propertyName = StringUtils.substringBefore(fieldNamePath, "."); } else { isObject = false; propertyName = fieldNamePath; } // Check if property is an array or a list isList = StringUtils.contains(propertyName, "["); // Process a list item property if (isList) { // Get property name String listPropertyName = StringUtils.substringBefore(propertyName, "["); // Get referred item index String index = StringUtils.substringBefore(StringUtils.substringAfter(propertyName, "["), "]"); // Get item path String itemPath = StringUtils.substringAfter(fieldNamePath, "."); // Get container of list property errors Map<String, Object> listErrors = (Map<String, Object>) objectErrors.get(listPropertyName); if (listErrors == null) { // property has no errors yet: create a container for it listErrors = new HashMap<String, Object>(); objectErrors.put(listPropertyName, listErrors); } // Get current item errors Map<String, Object> itemErrors = (Map<String, Object>) listErrors.get(index); if (itemErrors == null) { // item has no errors yet: create a container for it itemErrors = new HashMap<String, Object>(); listErrors.put(index, itemErrors); } // Load error in item property path loadObjectError(error, itemPath, itemErrors); } else if (isObject) { // It's not a list but it has properties in it value // Get current property errors Map<String, Object> propertyErrors = (Map<String, Object>) objectErrors.get(propertyName); if (propertyErrors == null) { // item has no errors yet: create a container for it propertyErrors = new HashMap<String, Object>(); objectErrors.put(propertyName, propertyErrors); } // Get error sub path String subFieldPath = StringUtils.substringAfter(fieldNamePath, "."); // Load error in container loadObjectError(error, subFieldPath, propertyErrors); } else { // standard property with no children value // Store error message in container objectErrors.put(propertyName, error.getDefaultMessage()); } }
From source file:org.hbird.business.groundstation.hamlib.protocol.HamlibProtocolHelper.java
public static Map<String, String> toMap(String response) { String[] lines = StringUtils.split(response, "\n"); Map<String, String> map = new HashMap<String, String>(); for (String line : lines) { if (StringUtils.isBlank(line)) { // skip the blank lines continue; }// w ww.j a va2s . c om String key; String value; if (line.startsWith(HamlibProtocolConstants.RESPONSE_END_MARKER)) { key = HamlibProtocolConstants.RESPONSE_END_MARKER; value = StringUtils.substringAfter(line, HamlibProtocolConstants.RESPONSE_END_MARKER); } else { key = StringUtils.substringBefore(line, ":"); value = StringUtils.substringAfter(line, ":"); } map.put(key.trim(), value.trim()); } return map; }