List of usage examples for org.apache.commons.lang StringUtils countMatches
public static int countMatches(String str, String sub)
Counts how many times the substring appears in the larger String.
From source file:org.medici.bia.controller.search.SimpleSearchController.java
/** * This controller act as a dispatcher for result view. * /*w w w .j a va2s . co m*/ * @param command * @param result * @return */ @RequestMapping(method = { RequestMethod.POST }) public ModelAndView processSubmit(@ModelAttribute("command") SimpleSearchCommand command, BindingResult result) { Map<String, Object> model = new HashMap<String, Object>(0); try { command.setText(URIUtil.decode(command.getText(), "UTF-8")); } catch (URIException e) { } if (StringUtils.countMatches(command.getText(), "\"") % 2 != 0) { StringBuffer tempString = new StringBuffer(command.getText()); tempString.setCharAt(tempString.lastIndexOf("\""), ' '); command.setText(tempString.toString()); } model.put("yourSearch", command.getText()); // RR: we consider single quote equivalent to double quotes model.put("textSearch", command.getText().replace("'", "%22").replace("\"", "%22")); // This number is used to generate an unique id for new search UUID uuid = UUID.randomUUID(); command.setSearchUUID(uuid.toString()); model.put("searchUUID", uuid.toString()); // Add outputFields; List<String> outputFields = getOutputFields(command.getSimpleSearchPerimeter()); model.put("outputFields", outputFields); return new ModelAndView("search/SimpleSearchResult", model); }
From source file:org.metamorfosis.template.directive.AppendFileSectionLogic.java
public String process(String position, String ocurrenceCountStr, String ocurrence) { // 1. interpretar el ocurrenceCount: [first , last, number] -> a numero int ocurrenceCount = ocurrenceCountParser(originalStr, ocurrenceCountStr, ocurrence); // 1.1 Validar el ocurrenceCount int matchesInFile = StringUtils.countMatches(originalStr, ocurrence); if (ocurrenceCount > matchesInFile) { throw new DirectiveException( "<@AppendFileSection .../> " + "El nmero de ocurrencia solicitada '" + ocurrenceCount + "' " + "supera el numero de ocurrencias en el archivo original '" + matchesInFile + "'"); }/* www. j a v a2s.co m*/ // 2. Obtener la posicion de la ocurrencia dentro del archivo original int initIndex = StringUtils.ordinalIndexOf(originalStr, ocurrence, ocurrenceCount); int lastIndex = initIndex + ocurrence.length(); // 3. Interpretar la posicion StringBuilder originalSb = new StringBuilder(originalStr); if ("before".equalsIgnoreCase(position)) { originalSb.insert(initIndex, matchOutputStr); } else if ("after".equalsIgnoreCase(position)) { originalSb.insert(lastIndex, matchOutputStr); } return originalSb.toString(); }
From source file:org.metamorfosis.template.directive.AppendFileSectionLogic.java
private int ocurrenceCountParser(String originalFileText, String ocurrenceCountStr, String ocurrence) { int ocurrenceInt = 0; try {/*from ww w .j a v a 2s . com*/ ocurrenceInt = Integer.parseInt(ocurrenceCountStr); } catch (NumberFormatException ex) { if ("first".equals(ocurrenceCountStr)) { ocurrenceInt = 1; } else if ("last".equals(ocurrenceCountStr)) { ocurrenceInt = StringUtils.countMatches(originalFileText, ocurrence); } } if (ocurrenceInt == 0) { throw new DirectiveException("Error en la directiva <@AppendFileSection, " + "ocurrenceCount solo permite [first | last | number]"); } return ocurrenceInt; }
From source file:org.ms123.common.data.SessionContextImpl.java
public Map executeFilter(Map filterDesc, Map<String, Object> fparams, Map<String, Object> options) { List<String> missingParamList = new ArrayList(); if (getBoolean(options, CHECK_PARAMS, false)) { getMissingFilterParameter((Map) filterDesc.get("filter"), missingParamList, fparams); if (missingParamList.size() > 0) { Map ret = new HashMap(); ret.put("missingParamList", missingParamList); return ret; }/*ww w . j av a2s .c o m*/ } String entityName = (String) filterDesc.get("modulename"); m_js.prettyPrint(true); debug("executeFilter:" + m_js.deepSerialize(filterDesc)); List<String> aliasList = new ArrayList(); List<String> fieldList = new ArrayList(); List<Map> fieldsArray = (List) filterDesc.get("fields"); if (fieldsArray == null) { List<Map> rfields = getReportFields(entityName); for (Map f : rfields) { fieldList.add((String) entityName + "." + f.get("name")); aliasList.add((String) f.get("name")); } } else { for (Map f : fieldsArray) { if ((Boolean) f.get("display")) { fieldList.add((String) f.get("path") + "." + (String) f.get("id")); aliasList.add((String) f.get("mapping")); } } } String orderby = null; //Needs a better solution for (String field : fieldList) { if (StringUtils.countMatches(field, "$") == 0) { orderby = field; break; } } debug("orderby:" + orderby); debug("fieldList:" + fieldList); List moduleList = new ArrayList(); String clazzName = m_inflector.getClassName(entityName); moduleList.add(clazzName); Map<String, Object> params = new HashMap(options); params.put("fields", m_js.serialize(moduleList)); Map filter = (Map) filterDesc.get("filter"); filter = addExclusionFilter(filter, (List) filterDesc.get("exclusion")); debug("FilterWith:" + m_js.deepSerialize(filter)); params.put("filter", filter); params.put("orderby", orderby); params.put("filterParams", fparams); if (params.get("pageSize") == null) { params.put("pageSize", "0"); } Map<String, Object> ret = m_dataLayer.query(this, params, m_sdesc, entityName); List<Map> rows = (List) ret.get("rows"); List<Map> retList = new ArrayList(); boolean isAdmin = m_permissionService.hasAdminRole(); if (!isAdmin || !getBoolean(options, GET_OBJECT, false)) { for (Map row : rows) { Object obj = row.get(clazzName); retList.add(SojoFilterInterceptor.filterFields(obj, this, fieldList, aliasList)); } } boolean withMeta = getBoolean(options, "withMeta", false); if (withMeta) { Map meta = new HashMap(); meta.put("params", getFilterParameter(filterDesc)); meta.put("fields", Utils.prepareFields(fieldList, aliasList)); meta.put("aliases", aliasList); ret.put("meta", meta); } ret.put("rows", retList); return ret; }
From source file:org.ms123.common.docbook.BaseBuilder.java
private Object[] insertLineNumbers(String lines, String lineNumber, int hit) { int lnr = -1; if (lineNumber != null) { lnr = Integer.parseInt(lineNumber); }//w w w .j a va 2 s .c o m BufferedReader br = new BufferedReader(new StringReader(lines)); StringBuilder sb = new StringBuilder(); int totalScriptStart = 0; int matchedAt = -1; try { int count = 1; String line = br.readLine(); while (line != null) { if (hit == -1 && matchedAt == -1) { totalScriptStart += StringUtils.countMatches(line, "<%"); } if (matchedAt == -1 && ((lnr != -1 && lnr == (count + (totalScriptStart - 1))) || hit == count)) { sb.append("+ "); matchedAt = count; } else { sb.append(" "); } sb.append(count++); sb.append(" "); sb.append(line); sb.append("\n"); line = br.readLine(); } } catch (Exception e) { e.printStackTrace(); } finally { try { br.close(); } catch (Exception e) { } } Object[] ret = new Object[2]; ret[0] = matchedAt; ret[1] = sb.toString(); return ret; }
From source file:org.mule.devkit.generation.javadoc.JavaDocAnnotationVerifier.java
protected boolean exampleDoesNotExist(Method method) throws AnnotationVerificationException { if (!method.hasJavaDocTag("sample.xml")) { throw new AnnotationVerificationException(method, "Method " + method.getSimpleName().toString() + " does not contain an example using {@sample.xml} tag."); }/*from www . j a va 2s . c om*/ boolean found = false; String sample = method.getJavaDocTagContent("sample.xml"); String[] split = sample.split(" "); if (split.length != 2) { throw new AnnotationVerificationException(method, "Check @sample.xml javadoc tag because is not well formed for method: " + method.getSimpleName()); } String pathToExamplesFile = split[0]; String exampleName = split[1]; String sourcePath = method.parent().getPathToSourceFile(); int packageCount = StringUtils.countMatches(method.parent().getQualifiedName().toString(), ".") + 1; while (packageCount > 0) { sourcePath = sourcePath.substring(0, sourcePath.lastIndexOf("/")); packageCount--; } try { File docFile = new File(sourcePath, pathToExamplesFile); String examplesFileContent = IOUtils.toString(new FileInputStream(docFile)); if (examplesFileContent.contains("BEGIN_INCLUDE(" + exampleName + ")")) { found = true; } } catch (IOException e) { // do nothing } return !found; }
From source file:org.mule.devkit.generation.mule.studio.MuleStudioIconsGenerator.java
private void copyFile(String fileName, String folder, DevKitTypeElement typeElement) throws GenerationException { String sourcePath = context.getSourceUtils().getPath(typeElement.getInnerTypeElement()); int packageCount = StringUtils.countMatches(typeElement.getQualifiedName().toString(), ".") + 1; while (packageCount > 0) { sourcePath = sourcePath.substring(0, sourcePath.lastIndexOf("/")); packageCount--;/*from w w w. j a v a2s . c om*/ } OutputStream outputStream = null; try { outputStream = createFile(folder, fileName); File fileToCopy = new File(sourcePath, fileName); if (!fileToCopy.exists()) { throw new GenerationException( "The following icon file does not exist: " + fileToCopy.getAbsolutePath()); } IOUtils.copy(new FileInputStream(fileToCopy), outputStream); } catch (IOException e) { throw new GenerationException("Error copying icons to output folder: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:org.mule.devkit.generation.studio.MuleStudioIconsGenerator.java
private void copyFile(String fileName, String folder, Type type) throws GenerationException { String sourcePath = type.getPathToSourceFile(); int packageCount = StringUtils.countMatches(type.getQualifiedName().toString(), ".") + 1; while (packageCount > 0) { sourcePath = sourcePath.substring(0, sourcePath.lastIndexOf("/")); packageCount--;//from w w w . j a v a 2s. c o m } OutputStream outputStream = null; try { outputStream = createFile(folder, fileName); File fileToCopy = new File(sourcePath, fileName); if (!fileToCopy.exists()) { throw new GenerationException( "The following icon file does not exist: " + fileToCopy.getAbsolutePath()); } IOUtils.copy(new FileInputStream(fileToCopy), outputStream); } catch (IOException e) { throw new GenerationException("Error copying icons to output folder: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:org.mule.devkit.validation.JavaDocValidator.java
protected boolean exampleDoesNotExist(GeneratorContext context, ExecutableElement method) throws ValidationException { if (!context.getJavaDocUtils().hasTag("sample.xml", method)) { throw new ValidationException(method, "Method " + method.getSimpleName().toString() + " does not contain an example using {@sample.xml} tag."); }//from w w w . j a v a2 s . co m boolean found = false; String sample = context.getJavaDocUtils().getTagContent("sample.xml", method); String[] split = sample.split(" "); if (split.length != 2) { throw new ValidationException(method, "Check @sample.xml javadoc tag because is not well formed for method: " + method.getSimpleName()); } String pathToExamplesFile = split[0]; String exampleName = split[1]; TypeElement typeElement = (TypeElement) method.getEnclosingElement(); String sourcePath = context.getSourceUtils().getPath(typeElement); int packageCount = StringUtils.countMatches(typeElement.getQualifiedName().toString(), ".") + 1; while (packageCount > 0) { sourcePath = sourcePath.substring(0, sourcePath.lastIndexOf("/")); packageCount--; } try { File docFile = new File(sourcePath, pathToExamplesFile); String examplesFileContent = IOUtils.toString(new FileInputStream(docFile)); if (examplesFileContent.contains("BEGIN_INCLUDE(" + exampleName + ")")) { found = true; } } catch (IOException e) { // do nothing } return !found; }
From source file:org.nuxeo.ecm.platform.smart.query.IncrementalSmartQuery.java
/** * Returns true if there are strictly more open parenthesis in the existing query part than closed ones. */// w w w .ja v a 2 s .c o m public boolean getShowCloseParenthesis() { if (existingQueryPart != null) { int numberOpened = StringUtils.countMatches(existingQueryPart, "("); int numberClosed = StringUtils.countMatches(existingQueryPart, ")"); if (numberOpened > numberClosed) { return true; } } return false; }