List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:de.micromata.tpsb.doc.parser.JavaDocUtil.java
public static String getScenarioSuiteFileContent(String projectRoot, TestStepInfo stepInfo, AnnotationInfo annotation) {//from ww w . java 2s . c o m StringBuilder sb = new StringBuilder(); String fileName = (String) annotation.getParams().get("filePattern"); if (fileName == null) { return null; } fileName = TypeUtils.unqoteString(fileName); String dirPart = StringUtils.substringBefore(fileName, "${0}"); String suffixPart = StringUtils.substringAfter(fileName, "${0}"); File dir = lookupFileOrDir(projectRoot, dirPart); if (dir == null || dir.isDirectory() == false) { return sb.toString(); } File[] files = dir.listFiles(); if (files == null || files.length == 0) { return sb.toString(); } for (File f : files) { if (f.getName().endsWith(suffixPart) == false) { continue; } try { String content = FileUtils.readFileToString(f); AnnotationInfo scenarioAnot = TpsbEnvUtils.getAnnotation(stepInfo.getTestBuilderMethod(), "TpsbScenarioFile"); content = renderScenarioFile(f, scenarioAnot, content); sb.append( "\n\n===================================================================================\n")// .append("<h3>Testscenario: ").append(StringUtils.substringBefore(f.getName(), suffixPart)) .append("</h3>\n\n")// .append(content); } catch (IOException ex) { log.warn("Scanrio file can't be read: " + f.getAbsolutePath() + "; " + ex.getMessage(), ex); } } return sb.toString(); }
From source file:de.crowdcode.kissmda.core.jdt.JdtHelper.java
/** * Get JDT ParameterizedType for the given type name. * //from ww w. j av a 2s . co m * @param ast * JDT AST tree * @param typeName * input type name * @return JDT ParameterizedType */ @SuppressWarnings("unchecked") public ParameterizedType getAstParameterizedType(AST ast, String typeName) { // Get the component type and parameters <Type, Type, ...> String componentTypeName = StringUtils.substringBefore(typeName, "<"); Type componentType = getAstSimpleType(ast, componentTypeName); ParameterizedType parameterizedType = ast.newParameterizedType(componentType); String paramTypeNames = StringUtils.substringAfter(typeName, "<"); paramTypeNames = StringUtils.removeEnd(paramTypeNames, ">"); // Result: String, Integer, List<Boolean>, de.test.Company String[] parametersAsString = StringUtils.split(paramTypeNames, ","); for (int index = 0; index < parametersAsString.length; index++) { String paramTypeName = parametersAsString[index]; paramTypeName = StringUtils.remove(paramTypeName, ","); paramTypeName = StringUtils.trim(paramTypeName); Type paramType = getChosenType(ast, paramTypeName, paramTypeName, ""); // Add the type arguments parameterizedType.typeArguments().add(paramType); } return parameterizedType; }
From source file:com.neatresults.mgnltweaks.json.JsonBuilder.java
/** * Includes only specified properties. Use together with excludeAll(). *///from w ww .ja v a2 s . c om public JsonBuilder add(String... string) { Arrays.asList(string).stream().filter(it -> it.contains("['") && it.contains("']")) .map(it -> it.split("\\['")).forEach(subpropertyArray -> addToSubPropertyMap(subpropertyArray[0], StringUtils.substringBefore(subpropertyArray[1], "']"))); List<String> list = new ArrayList<>(); Arrays.asList(string).stream().filter(it -> !it.contains("['")).forEach(list::add); this.butInclude.addAll(list); return this; }
From source file:com.opensymphony.xwork2.util.finder.UrlSet.java
private List<URL> getUrls(ClassLoaderInterface classLoader, Set<String> protocols) throws IOException { if (protocols == null) { return getUrls(classLoader); }//from www. j ava2s . co m List<URL> list = new ArrayList<URL>(); //find jars ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF")); for (URL url : urls) { if (protocols.contains(url.getProtocol())) { String externalForm = url.toExternalForm(); //build a URL pointing to the jar, instead of the META-INF dir url = new URL(StringUtils.substringBefore(externalForm, "META-INF")); list.add(url); } else if (LOG.isDebugEnabled()) LOG.debug("Ignoring URL [#0] because it is not a valid protocol", url.toExternalForm()); } return list; }
From source file:me.utils.excel.ImportExcelme.java
/** * ??//from w w w.j av a2 s . c o m * @param cls */ public <E> List<E> getDataList(Class<E> cls, List<Zbx> zbxList) throws Exception { String title = (String) getMergedRegionValue(sheet, 0, 1);//? String tbDw = StringUtils.substringAfter((String) getMergedRegionValue(sheet, 1, 0), "");// Date tbDate = DateUtils .parseDate((StringUtils.substringAfter((String) getMergedRegionValue(sheet, 1, 4), ":")));//5? // Date tbDate = DateUtil.getJavaDate(Double.valueOf(StringUtils.substringAfter((String)getMergedRegionValue(sheet, 1, 4), ":"))) ;//5? Map<String, String> map = Maps.newHashMap(); for (Zbx zbx : zbxList) { map.put(zbx.getPropertyText(), zbx.getPropertyName()); } List<String> propertyNames = Lists.newArrayList(); for (int i = 0; i < this.getLastCellNum(); i++) {//?header ? Row row = this.getRow(this.getHeaderRowNum()); Object val = this.getCellValue(row, i); String propertyName = map.get(val); if (StringUtils.isEmpty(propertyName)) { throw new BusinessException("" + val + "?"); } propertyNames.add(propertyName); } //log.debug("Import column count:"+annotationList.size()); // Get excel data List<E> dataList = Lists.newArrayList(); for (int i = this.getDataRowNum(); i <= this.getLastDataRowNum(); i++) { E e = (E) cls.newInstance(); int column = 0; Row row = this.getRow(i); StringBuilder sb = new StringBuilder(); for (String propertyName : propertyNames) { Object val = this.getCellValue(row, column++);//string if (val != null) { // Get param type and type cast Class<?> valType = Reflections.getAccessibleField(e, propertyName).getType(); check(e, propertyName, val, i, column); //log.debug("Import value type: ["+i+","+column+"] " + valType); try { if (valType == String.class) { String s = String.valueOf(val.toString()); if (StringUtils.endsWith(s, ".0")) { val = StringUtils.substringBefore(s, ".0"); } else { val = String.valueOf(val.toString()); } } else if (valType == Integer.class) { val = Double.valueOf(val.toString()).intValue(); } else if (valType == Long.class) { val = Double.valueOf(val.toString()).longValue(); } else if (valType == Double.class) { val = Double.valueOf(val.toString()); } else if (valType == Float.class) { val = Float.valueOf(val.toString()); } else if (valType == Date.class) { // val = DateUtil.getJavaDate((Double)val); val = DateUtils.parseDate(val.toString()); } else {//? wjmany-to-one etc. } } catch (Exception ex) { log.info("Get cell value [" + i + "," + column + "] error: " + ex.toString()); val = null; } // set entity value Reflections.invokeSetter(e, propertyName, val); } sb.append(val + ", "); } Reflections.invokeSetter(e, "title", title); Reflections.invokeSetter(e, "tbDw", tbDw); Reflections.invokeSetter(e, "tbDate", tbDate); dataList.add(e); log.debug("Read success: [" + i + "] " + sb.toString()); } return dataList; }
From source file:com.intuit.wasabi.api.pagination.filters.PaginationFilter.java
/** * Tests an object's properties according the current filter. * * @param object the object to test// w ww.j av a2 s . c om * @param enumType the possible properties * @param <V> the enum's type * @return true or false depending on the test result. For details see this class' documentation * {@link PaginationFilter}. */ public final <V extends Enum<V> & PaginationFilterProperty> boolean test(T object, Class<V> enumType) { if (StringUtils.isBlank(filter)) { return true; } else if (filter.contains(SEPARATOR)) { if (StringUtils.containsNone(StringUtils.substringBefore(filter, SEPARATOR), DELIMITER)) { return testFields(object, enumType); } return testFields(object, enumType) && testFulltext(object, enumType); } return testFulltext(object, enumType); }
From source file:com.adobe.acs.commons.data.Spreadsheet.java
/** * Look for type hints in the name of a column to extract a usable type. Also look for array hints as well. <br> * Possible formats: //from w w w . jav a2 s . co m * <ul> * <li>column-name - A column named "column-name" </li> * <li>col@int - An integer column named "col" </li> * <li>col2@int[] - An integer array colum named "col2", assumes standard delimiter (,) </li> * <li>col3@string[] or col3@[] - A String array named "col3", assumes standard delimiter (,)</li> * <li>col4@string[||] - A string array where values are using a custom delimiter (||)</li> * </ul> * * @param name * @return */ private Class detectTypeFromName(String name) { boolean isArray = false; Class detectedClass = String.class; if (name.contains("@")) { String typeStr = StringUtils.substringAfter(name, "@"); if (name.endsWith("]")) { String colName = convertHeaderName(name); isArray = true; String delimiter = StringUtils.substringBetween(name, "[", "]"); typeStr = StringUtils.substringBefore("[", delimiter); if (!StringUtils.isEmpty(delimiter)) { delimiters.put(colName, delimiter); } } detectedClass = getClassFromName(typeStr); } if (isArray) { return getArrayType(detectedClass); } else { return detectedClass; } }
From source file:com.gargoylesoftware.htmlunit.html.XmlSerializer.java
private String getSuffix(final WebResponse response) { // first try to take the one from the requested file final String url = response.getWebRequest().getUrl().toString(); final String fileName = StringUtils.substringAfterLast(StringUtils.substringBefore(url, "?"), "/"); // if there is a suffix with 2-4 letters, the take it final String suffix = StringUtils.substringAfterLast(fileName, "."); if (suffix.length() > 1 && suffix.length() < 5) { return suffix; }/* w w w. java 2 s. c om*/ // use content type return MimeType.getFileExtension(response.getContentType()); }
From source file:kenh.expl.impl.ExpLParser.java
/** * Get the value in brace.//from www.ja v a2 s.co m * $ - it will be a variable in environment. * # - will be a function * other - use sub parser * * @param variable the string in brace. * @return Return string or non-string object. Return empty string instead of null. * @throws UnsupportedExpressionException */ private Object getVariableValue(String variable) throws UnsupportedExpressionException { if (variable == null) { UnsupportedExpressionException e = new UnsupportedExpressionException("Variable is null."); throw e; } logger.trace("Var: " + variable); if (variable.startsWith("$")) { // $ - it will be a variable in environment. if (variable.indexOf('{') != -1) { Object obj = this.parseExpress(variable); if (obj instanceof String) { variable = (String) obj; } else { UnsupportedExpressionException ex = new UnsupportedExpressionException( "Unable to get variable"); ex.push(variable); throw ex; } } String name = variable.substring(1); int index = name.indexOf('.'); if (index == -1) { return this.getEnvironment().getVariable(name); } else { // use BeanUtils String str = name.substring(index + 1); name = name.substring(0, index); Object obj = null; if ((obj = this.getEnvironment().getVariable(name)) != null) { try { return BeanUtils.getProperty(obj, str); } catch (Exception e) { return ""; } } else { return ""; } } } else if (variable.startsWith("#")) { // # - will be a function int left = StringUtils.countMatches(variable, "("); int right = StringUtils.countMatches(variable, ")"); if (left != right) { UnsupportedExpressionException ex = new UnsupportedExpressionException( "'(' and ')' does not match."); ex.push(variable); throw ex; } String funcName = StringUtils.substringBefore(variable, "("); String funcAfter = StringUtils.substringAfterLast(variable, ")"); if (StringUtils.isNotBlank(funcAfter)) { UnsupportedExpressionException e = new UnsupportedExpressionException("Function parse error."); e.push(variable); throw e; } if (funcNamePattern.matcher(funcName).matches()) { Object result = executeFunction(variable); logger.debug(variable + " -> " + ((result == null) ? "<null>" : result.toString())); if (result == null) return ""; return result; } else { UnsupportedExpressionException e = new UnsupportedExpressionException("Function name parse error."); e.push(variable); throw e; } } else { if (variable.indexOf('{') != -1) { Object obj = this.parseExpress(variable); if (obj instanceof String) { variable = (String) obj; } else { UnsupportedExpressionException ex = new UnsupportedExpressionException( "Unable to get variable"); ex.push(variable); throw ex; } } // use sub parser try { return subParser.parse(variable); } catch (UnsupportedExpressionException e) { e.push(variable); throw e; } catch (Exception e) { UnsupportedExpressionException ex = new UnsupportedExpressionException(e); ex.push(variable); throw ex; } } }
From source file:de.micromata.tpsb.doc.ParserContext.java
private String removeGenerics(String type) { // Generics enthalten? if (StringUtils.indexOf(type, "<") > 0) { type = StringUtils.substringBefore(type, "<"); }/* ww w. j av a 2s . c o m*/ return type; }