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.apache.archiva.web.rss.RssFeedServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String repoId = null;/*from ww w.j av a2 s . c o m*/ String groupId = null; String artifactId = null; String url = StringUtils.removeEnd(req.getRequestURL().toString(), "/"); if (StringUtils.countMatches(StringUtils.substringAfter(url, "feeds/"), "/") > 0) { artifactId = StringUtils.substringAfterLast(url, "/"); groupId = StringUtils.substringBeforeLast(StringUtils.substringAfter(url, "feeds/"), "/"); groupId = StringUtils.replaceChars(groupId, '/', '.'); } else if (StringUtils.countMatches(StringUtils.substringAfter(url, "feeds/"), "/") == 0) { // we receive feeds?babla=ded which is not correct if (StringUtils.countMatches(url, "feeds?") > 0) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request url."); return; } repoId = StringUtils.substringAfterLast(url, "/"); } else { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request url."); return; } RssFeedProcessor processor = null; try { Map<String, String> map = new HashMap<>(); SyndFeed feed = null; if (isAllowed(req, repoId, groupId, artifactId)) { if (repoId != null) { // new artifacts in repo feed request processor = newArtifactsprocessor; map.put(RssFeedProcessor.KEY_REPO_ID, repoId); } else if ((groupId != null) && (artifactId != null)) { // TODO: this only works for guest - we could pass in the list of repos // new versions of artifact feed request processor = newVersionsprocessor; map.put(RssFeedProcessor.KEY_GROUP_ID, groupId); map.put(RssFeedProcessor.KEY_ARTIFACT_ID, artifactId); } } else { res.sendError(HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED); return; } RepositorySession repositorySession = repositorySessionFactory.createSession(); try { feed = processor.process(map, repositorySession.getRepository()); } finally { repositorySession.close(); } if (feed == null) { res.sendError(HttpServletResponse.SC_NO_CONTENT, "No information available."); return; } res.setContentType(MIME_TYPE); if (repoId != null) { feed.setLink(req.getRequestURL().toString()); } else if ((groupId != null) && (artifactId != null)) { feed.setLink(req.getRequestURL().toString()); } SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, res.getWriter()); } catch (UserNotFoundException unfe) { log.debug(COULD_NOT_AUTHENTICATE_USER, unfe); res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER); } catch (AccountLockedException acce) { res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER); } catch (AuthenticationException authe) { log.debug(COULD_NOT_AUTHENTICATE_USER, authe); res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER); } catch (FeedException ex) { log.debug(COULD_NOT_GENERATE_FEED_ERROR, ex); res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR); } catch (MustChangePasswordException e) { res.sendError(HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER); } catch (UnauthorizedException e) { log.debug(e.getMessage()); if (repoId != null) { res.setHeader("WWW-Authenticate", "Basic realm=\"Repository Archiva Managed " + repoId + " Repository"); } else { res.setHeader("WWW-Authenticate", "Basic realm=\"Artifact " + groupId + ":" + artifactId); } res.sendError(HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED); } }
From source file:org.apache.cassandra.cql3.subquery.SubQueryProcessor.java
public SubQuery getSlipttedQueries(String queryString, int level) { SubQuery sq = new SubQuery(); int subQueryStartIndex = 0; int subQueryEndIndex = 0; String tempQueryString = queryString; String childQuery = ""; if (level == 1) sq.setLast(true);/* ww w . j a v a 2 s .c o m*/ int length = (StringUtils.countMatches(tempQueryString, "SELECT")) + (StringUtils.countMatches(tempQueryString, "select")); if (length > 1) { boolean isContainSubQuery = true; while (isContainSubQuery) { // All child subqueries will be created inside this loop subQueryStartIndex = findStartIndex(subQueryStartIndex, tempQueryString); subQueryEndIndex = findEndIndex(subQueryStartIndex, subQueryEndIndex, tempQueryString); childQuery = tempQueryString.substring(subQueryStartIndex, subQueryEndIndex - 1).trim(); sq.getSubQuery().add(getSlipttedQueries(childQuery, 0)); tempQueryString = replaceString(tempQueryString, subQueryStartIndex, subQueryEndIndex - 1); length = (StringUtils.countMatches(tempQueryString, "SELECT")) + (StringUtils.countMatches(tempQueryString, "select")); if (length == 1) isContainSubQuery = false; } sq.setQuery(tempQueryString); } else { sq.setQuery(queryString); } return sq; }
From source file:org.apache.cassandra.cql3.subquery.SubQueryProcessor.java
public int setMarkerString(SubQuery sq) { int totalMarkerCont = 0; String queryString = sq.getQuery(); totalMarkerCont = StringUtils.countMatches(queryString, "?"); queryString = queryString.replaceAll("#", "?"); sq.setQueryWithMarker(queryString);//from w w w . j ava 2 s. c o m List<SubQuery> subQueryList = sq.getSubQuery(); for (SubQuery subQuery : subQueryList) { totalMarkerCont = totalMarkerCont + setMarkerString(subQuery); } return totalMarkerCont; }
From source file:org.apache.cayenne.modeler.util.DbAttributePathComboBoxEditor.java
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { this.model = (ObjAttributeTableModel) table.getModel(); this.row = row; treeModel = createTreeModelForComboBox(row); if (treeModel == null) { return new JLabel("You should select table for this ObjectEntity"); }/* w w w .ja v a2s . co m*/ initializeCombo(model, row, table); String dbAttributePath = ((JTextComponent) (comboBoxPathChooser).getEditor().getEditorComponent()) .getText(); previousEmbeddedLevel = StringUtils.countMatches(dbAttributePath, "."); return comboBoxPathChooser; }
From source file:org.apache.cayenne.modeler.util.DbAttributePathComboBoxEditor.java
@Override protected void enterPressed(JTable table) { String dbAttributePath = ((JTextComponent) comboBoxPathChooser.getEditor().getEditorComponent()).getText(); Object currentNode = getCurrentNode(dbAttributePath); String[] pathStrings = dbAttributePath.split(Pattern.quote(".")); String lastStringInPath = pathStrings[pathStrings.length - 1]; if (ModelerUtil.getObjectName(currentNode).equals(lastStringInPath) && currentNode instanceof DbAttribute) { // in this case choose is made.. we save data if (table.getCellEditor() != null) { table.getCellEditor().stopCellEditing(); if (dbAttributePath.equals(savePath)) { return; }// w ww. j a v a 2 s . co m model.setUpdatedValueAt(dbAttributePath, row, DB_ATTRIBUTE_PATH_COLUMN); model.getAttribute(row).getValue().setDbAttributePath(dbAttributePath); } } else if (ModelerUtil.getObjectName(currentNode).equals(lastStringInPath) && currentNode instanceof DbRelationship) { // in this case we add dot to pathString (if it is missing) and show variants for currentNode if (dbAttributePath.charAt(dbAttributePath.length() - 1) != '.') { dbAttributePath = dbAttributePath + '.'; previousEmbeddedLevel = StringUtils.countMatches(dbAttributePath, "."); ((JTextComponent) (comboBoxPathChooser).getEditor().getEditorComponent()).setText(dbAttributePath); } List<String> currentNodeChildren = new ArrayList<>(); currentNodeChildren.addAll(getChildren(getCurrentNode(dbAttributePath), dbAttributePath)); comboBoxPathChooser.setModel(new DefaultComboBoxModel(currentNodeChildren.toArray())); comboBoxPathChooser.setSelectedItem(dbAttributePath); comboBoxPathChooser.showPopup(); comboBoxPathChooser.setPopupVisible(true); } }
From source file:org.apache.cayenne.modeler.util.PathChooserComboBoxCellEditor.java
protected void parsePathString(char lastEnteredCharacter) { JTextComponent editorComponent = (JTextComponent) (comboBoxPathChooser).getEditor().getEditorComponent(); String pathString = editorComponent.getText(); if (pathString != null && pathString.isEmpty()) { setComboModelAccordingToPath(""); previousEmbeddedLevel = 0;/*from w w w . j a va 2s. c om*/ return; } if (lastEnteredCharacter == '.') { processDotEntered(); previousEmbeddedLevel = StringUtils.countMatches(pathString, "."); return; } int currentEmbeddedLevel = StringUtils.countMatches(pathString, "."); if (previousEmbeddedLevel != currentEmbeddedLevel) { previousEmbeddedLevel = currentEmbeddedLevel; String[] pathStrings = pathString.split(Pattern.quote(".")); String lastStringInPath = pathStrings[pathStrings.length - 1]; String saveDbAttributePath = pathString; pathString = pathString.replaceAll(lastStringInPath + "$", ""); List<String> currentNodeChildren = new ArrayList<>(); currentNodeChildren.addAll(getChildren(getCurrentNode(pathString), pathString)); comboBoxPathChooser.setModel(new DefaultComboBoxModel<>(currentNodeChildren.toArray(new String[0]))); comboBoxPathChooser.setSelectedItem(saveDbAttributePath); } }
From source file:org.apache.cocoon.util.NetUtils.java
/** * Relativize an absolute resource on a given absolute path. * * @param path The absolute path//from w w w . ja v a 2 s .c o m * @param absoluteResource The absolute resource * @return the resource relative to the given path */ public static String relativize(String path, String absoluteResource) { if (StringUtils.isEmpty(path)) { return absoluteResource; } if (path.charAt(path.length() - 1) != '/') { path += "/"; } if (absoluteResource.startsWith(path)) { // resource is direct descentant return absoluteResource.substring(path.length()); } else { // resource is not direct descendant int index = StringUtils.indexOfDifference(path, absoluteResource); if (index > 0 && path.charAt(index - 1) != '/') { index = path.substring(0, index).lastIndexOf('/'); index++; } String pathDiff = path.substring(index); String resource = absoluteResource.substring(index); int levels = StringUtils.countMatches(pathDiff, "/"); StringBuffer b = new StringBuffer(levels * 3 + resource.length()); for (int i = 0; i < levels; i++) { b.append("../"); } b.append(resource); return b.toString(); } }
From source file:org.apache.cxf.jaxrs.ext.search.jpa.AbstractJPATypedQueryVisitor.java
public CriteriaQuery<T1> getCriteriaQueryWithoutContext(String orderBy, String order) { if (!criteriaFinalized) { if (!orderBy.isEmpty() && !order.isEmpty()) { if (orderBy.indexOf("-") > 1) { int occurance = StringUtils.countMatches(orderBy, "-"); if (occurance == 1) { String[] ar = orderBy.split("-"); if (order.equalsIgnoreCase("asc")) { cq.orderBy(builder.asc(root.get(ar[0]).get(ar[1]))); } else { cq.orderBy(builder.desc(root.get(ar[0]).get(ar[1]))); }//from ww w . jav a 2 s .com } else if (occurance == 2) { String[] ar = orderBy.split("-"); if (order.equalsIgnoreCase("asc")) { cq.orderBy(builder.asc(root.get(ar[0]).get(ar[1]).get(ar[2]))); } else { cq.orderBy(builder.desc(root.get(ar[0]).get(ar[1]).get(ar[2]))); } } } else { if (order.equalsIgnoreCase("asc")) { cq.orderBy(builder.asc(root.get(orderBy))); } else { cq.orderBy(builder.desc(root.get(orderBy))); } } criteriaFinalized = true; } } return cq; }
From source file:org.apache.cxf.jaxrs.ext.search.jpa.AbstractJPATypedQueryVisitor.java
public CriteriaQuery<T1> getCriteriaQuery(String orderBy, String order) { if (!criteriaFinalized) { List<Predicate> predsList = predStack.pop(); if (!orderBy.isEmpty() && !order.isEmpty()) { if (orderBy.indexOf("-") > 1) { int occurance = StringUtils.countMatches(orderBy, "-"); if (occurance == 1) { String[] ar = orderBy.split("-"); if (order.equalsIgnoreCase("asc")) { cq.orderBy(builder.asc(root.get(ar[0]).get(ar[1]))); } else { cq.orderBy(builder.desc(root.get(ar[0]).get(ar[1]))); }// w w w . java 2s . c o m } else if (occurance == 2) { String[] ar = orderBy.split("-"); if (order.equalsIgnoreCase("asc")) { cq.orderBy(builder.asc(root.get(ar[0]).get(ar[1]).get(ar[2]))); } else { cq.orderBy(builder.desc(root.get(ar[0]).get(ar[1]).get(ar[2]))); } } } else { if (order.equalsIgnoreCase("asc")) { cq.orderBy(builder.asc(root.get(orderBy))); } else { cq.orderBy(builder.desc(root.get(orderBy))); } } cq.where(predsList.toArray(new Predicate[predsList.size()])); criteriaFinalized = true; } } return cq; }
From source file:org.apache.directory.studio.test.integration.ui.BrowserTest.java
/** * Test for DIRSTUDIO-463./* w w w. ja va 2s .c om*/ * * When expanding an entry in the browser only one search request * should be send to the server * * @throws Exception */ @Test public void testOnlyOneSearchRequestWhenExpandingEntry() throws Exception { browserViewBot.selectEntry("DIT", "Root DSE", "ou=system"); // get number of search requests before expanding the entry String text = searchLogsViewBot.getSearchLogsText(); int countMatchesBefore = StringUtils.countMatches(text, "#!SEARCH REQUEST"); // expand browserViewBot.expandEntry("DIT", "Root DSE", "ou=system"); browserViewBot.waitForEntry("DIT", "Root DSE", "ou=system", "ou=users"); // get number of search requests after expanding the entry text = searchLogsViewBot.getSearchLogsText(); int countMatchesAfter = StringUtils.countMatches(text, "#!SEARCH REQUEST"); assertEquals("Expected exactly 1 search request", 1, countMatchesAfter - countMatchesBefore); assertEquals("No modification expected", "", modificationLogsViewBot.getModificationLogsText()); }