List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.exoplatform.forum.webui.popup.UIPrivateMessageForm.java
private String removeCurrentUser(String s) throws Exception { if (s.equals(userName)) return ForumUtils.EMPTY_STR; if (s.contains(userName + ForumUtils.COMMA)) s = StringUtils.remove(s, userName + ForumUtils.COMMA); if (s.contains(ForumUtils.COMMA + userName)) s = StringUtils.remove(s, ForumUtils.COMMA + userName); return s;/*from www .ja va 2 s. c o m*/ }
From source file:org.exoplatform.outlook.forum.ForumUtils.java
/** * Split for forum.//from www .j a va 2 s .c om * * @param str the str * @return the string[] */ public static String[] splitForForum(String str) { if (!isEmpty(str)) { str = StringUtils.remove(str, " "); if (str.contains(COMMA)) { str = str.replaceAll(";", COMMA); return str.trim().split(COMMA); } else { str = str.replaceAll(COMMA, ";"); return str.trim().split(";"); } } else return new String[] { EMPTY_STR }; }
From source file:org.exoplatform.platform.portlet.juzu.notificationsAdmin.NotificationsAdministration.java
public static boolean isValidEmailAddresses(String addressList) { if (addressList == null || addressList.trim().length() == 0) return false; addressList = StringUtils.remove(addressList, " "); addressList = StringUtils.replace(addressList, ";", ","); try {//ww w .ja v a 2 s . c om InternetAddress[] iAdds = InternetAddress.parse(addressList, true); String emailRegex = "[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[_A-Za-z0-9-.]+\\.[A-Za-z]{2,5}"; for (int i = 0; i < iAdds.length; i++) { if (!iAdds[i].getAddress().matches(emailRegex)) return false; } } catch (AddressException e) { return false; } return true; }
From source file:org.glimpse.server.finance.RegexpQuotationFinder.java
@Override public Quotation getQuotation(String text) { Matcher valueMatcher = valuePattern.matcher(text); if (valueMatcher.find()) { String s = valueMatcher.group(1); s = StringUtils.remove(s, " "); double value = Double.parseDouble(s); Matcher unitMatcher = unitPattern.matcher(text); if (unitMatcher.find()) { String unit = unitMatcher.group(1); Matcher variationMatcher = variationPattern.matcher(text); if (variationMatcher.find()) { s = variationMatcher.group(1); s = StringUtils.remove(s, " "); double variation = Double.parseDouble(s); return new Quotation(value, unit, variation); }// w w w. jav a2 s . c om } } return null; }
From source file:org.jamwiki.parser.jflex.JFlexParser.java
/** * Convert a string of text to be parsed into a StringReader, performing any * preprocessing, such as removing linefeeds, in the process. *///from ww w . java 2 s. c o m private StringReader toStringReader(String raw) { return new StringReader(StringUtils.remove(raw, '\r')); }
From source file:org.jamwiki.parser.jflex.JFlexParserUtil.java
/** * Clean up HTML tags to make them XHTML compliant (lowercase, no * unnecessary spaces).// w ww .java 2 s. c o m */ protected static String sanitizeHtmlTag(String tag) { String result = tag.trim(); result = StringUtils.remove(result, " ").toLowerCase(); if (result.endsWith("/>")) { // spaces were stripped, so make sure tag is of the form "<br />" result = result.substring(0, result.length() - 2) + " />"; } return result; }
From source file:org.jamwiki.servlets.EditServlet.java
/** * Functionality to handle the "Save" button being clicked. *//*from w w w. j ava2 s .c om*/ private void save(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { String topicName = WikiUtil.getTopicFromRequest(request); String virtualWiki = pageInfo.getVirtualWikiName(); Topic topic = loadTopic(virtualWiki, topicName); Topic lastTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null); if (lastTopic != null && !lastTopic.getCurrentVersionId().equals(retrieveLastTopicVersionId(request, topic))) { // someone else has edited the topic more recently resolve(request, next, pageInfo); return; } String contents = request.getParameter("contents"); String sectionName = ""; if (!StringUtils.isBlank(request.getParameter("section"))) { // load section of topic int section = Integer.valueOf(request.getParameter("section")); ParserOutput parserOutput = new ParserOutput(); String[] spliceResult = ParserUtil.parseSplice(parserOutput, request.getContextPath(), request.getLocale(), virtualWiki, topicName, section, contents); contents = spliceResult[1]; sectionName = parserOutput.getSectionName(); } if (contents == null) { logger.warning("The topic " + topicName + " has no content"); throw new WikiException(new WikiMessage("edit.exception.nocontent", topicName)); } // strip line feeds contents = StringUtils.remove(contents, '\r'); String lastTopicContent = (lastTopic != null) ? StringUtils.remove(lastTopic.getTopicContent(), '\r') : ""; if (lastTopic != null && StringUtils.equals(lastTopicContent, contents)) { // topic hasn't changed. redirect to prevent user from refreshing and // re-submitting ServletUtil.redirect(next, virtualWiki, topic.getName()); return; } if (handleSpam(request, next, topicName, contents)) { this.loadEdit(request, next, pageInfo, contents, virtualWiki, topicName, false); return; } // parse for signatures and other syntax that should not be saved in raw // form WikiUser user = ServletUtil.currentWikiUser(); ParserInput parserInput = new ParserInput(); parserInput.setContext(request.getContextPath()); parserInput.setLocale(request.getLocale()); parserInput.setWikiUser(user); parserInput.setTopicName(topicName); parserInput.setUserDisplay(ServletUtil.getIpAddress(request)); parserInput.setVirtualWiki(virtualWiki); ParserOutput parserOutput = ParserUtil.parseMetadata(parserInput, contents); // parse signatures and other values that need to be updated prior to saving contents = ParserUtil.parseMinimal(parserInput, contents); topic.setTopicContent(contents); // if (!StringUtils.isBlank(parserOutput.getRedirect())) { // // set up a redirect // topic.setRedirectTo(parserOutput.getRedirect()); // topic.setTopicType(Topic.TYPE_REDIRECT); // } else if (topic.getTopicType() == Topic.TYPE_REDIRECT) { // // no longer a redirect // topic.setRedirectTo(null); // topic.setTopicType(Topic.TYPE_ARTICLE); // } int charactersChanged = StringUtils.length(contents) - StringUtils.length(lastTopicContent); TopicVersion topicVersion = new TopicVersion(user, ServletUtil.getIpAddress(request), request.getParameter("editComment"), contents, charactersChanged); if (request.getParameter("minorEdit") != null) { topicVersion.setEditType(TopicVersion.EDIT_MINOR); } WikiBase.getDataHandler().writeTopic(topic, topicVersion, parserOutput.getCategories(), parserOutput.getLinks()); // // update watchlist WikiUserDetails userDetails = ServletUtil.currentUserDetails(); if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS)) { // Watchlist watchlist = ServletUtil.currentWatchlist(request, // virtualWiki); // boolean watchTopic = (request.getParameter("watchTopic") != null); // if (watchlist.containsTopic(topicName) != watchTopic) { // WikiBase.getDataHandler().writeWatchlistEntry(watchlist, virtualWiki, // topicName, user.getUserId()); // } } // redirect to prevent user from refreshing and re-submitting String target = topic.getName(); if (!StringUtils.isBlank(sectionName)) { target += "#" + sectionName; } ServletUtil.redirect(next, virtualWiki, target); }
From source file:org.jamwiki.utils.DiffUtil.java
/** * Return a list of WikiDiff objects that can be used to create a display of * the diff content./*from ww w. j av a 2s.c o m*/ * * @param newVersion * The String that is to be compared to, ie the later version of a * topic. * @param oldVersion * The String that is to be considered as having changed, ie the * earlier version of a topic. * @return Returns a list of WikiDiff objects that correspond to the changed * text. */ public static List<WikiDiff> diff(String newVersion, String oldVersion) { List<WikiDiff> result = null; // List<WikiDiff> result = DiffUtil.retrieveFromCache(newVersion, // oldVersion); // if (result != null) { // return result; // } String version1 = newVersion; String version2 = oldVersion; if (version2 == null) { version2 = ""; } if (version1 == null) { version1 = ""; } // remove line-feeds to avoid unnecessary noise in the diff due to // cut & paste or other issues version2 = StringUtils.remove(version2, '\r'); version1 = StringUtils.remove(version1, '\r'); result = DiffUtil.process(version1, version2); // DiffUtil.addToCache(newVersion, oldVersion, result); return result; }
From source file:org.jboss.bqt.client.TestResultsSummary.java
private void addTotalPassFailGen(String scenario_name, Collection results, Date testStartTSx, Date endTSx, Date lengthTime) {// w w w. j a va2 s.c o m int queries = 0; int pass = 0; int fail = 0; int succeed = 0; double avg; double totalFullMilliSecs = 0.0; String queryset = null; total_querysets++; for (Iterator resultsItr = results.iterator(); resultsItr.hasNext();) { TestResult stat = (TestResult) resultsItr.next(); if (queryset == null) { queryset = stat.getQuerySetID(); } ++queries; switch (stat.getStatus()) { case TestResult.RESULT_STATE.TEST_EXCEPTION: ++fail; String msg = StringUtils.remove(StringUtils.remove(stat.getExceptionMsg(), '\r'), '\n'); // removeChars(stat.getExceptionMsg(), // new char[] { '\r', '\n' }); this.failed_queries.add(stat.getQuerySetID() + "." + stat.getQueryID() + "~" + msg); break; case TestResult.RESULT_STATE.TEST_SUCCESS: ++pass; ++succeed; totalFullMilliSecs += (stat.getEndTS() - stat.getBeginTS()); break; case TestResult.RESULT_STATE.TEST_EXPECTED_EXCEPTION: ++pass; break; } } avg = (succeed > 0 ? totalFullMilliSecs / succeed : -1.0); this.query_sets.add("\t" + pad(queryset, 42, ' ') + "\t" + pass + "\t" + fail + "\t" + queries + "\t" + (lengthTime.getTime() / 1000) + "\t\t" + avg); total_fail = total_fail + fail; total_pass = total_pass + pass; total_queries = total_queries + queries; }
From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java
/** * Consume an XML results File and produce a Map containing query results * as List objects, with resultNames/IDs as Keys. * <br>//www . ja va2 s. co m * @param test * @param querySetID Identifies the query set * @param resultsFile the XML file object that is to be parsed * @return the Map containig results. * @throws IOException * @exception JDOMException if there is an error consuming the message. */ public ExpectedResultsHolder parseXMLResultsFile(final QueryTest test, final String querySetID, final File resultsFile) throws IOException, JDOMException { QueryResults queryResults; ExpectedResultsHolder expectedResults = null; final SAXBuilder builder = SAXBuilderHelper.createSAXBuilder(false); final Document resultsDocument = builder.build(resultsFile); final String query = resultsDocument.getRootElement().getChildText(TagNames.Elements.QUERY); final List resultElements = resultsDocument.getRootElement().getChildren(TagNames.Elements.QUERY_RESULTS); final Iterator iter = resultElements.iterator(); while (iter.hasNext()) { final Element resultElement = (Element) iter.next(); final String resultName = resultElement.getAttributeValue(TagNames.Attributes.NAME); final String execTime = resultElement.getAttributeValue(TagNames.Attributes.EXECUTION_TIME); queryResults = consumeMsg(new QueryResults(), resultElement); if (queryResults.getFieldCount() != 0) { // // We've got a ResultSet // expectedResults = new ExpectedResultsHolder(TagNames.Elements.QUERY_RESULTS, test); // expectedResults.setQueryID( resultName ); expectedResults.setQuery(query); if (execTime != null && execTime.trim().length() > 0) expectedResults.setExecutionTime(Long.parseLong(execTime)); expectedResults.setIdentifiers(queryResults.getFieldIdents()); expectedResults.setTypes(queryResults.getTypes()); if (queryResults.getRecordCount() > 0) { expectedResults.setRows(queryResults.getRecords()); } } else { // // We've got an exception // expectedResults = new ExpectedResultsHolder(TagNames.Elements.EXCEPTION, test); expectedResults.setQuery(query); final Element exceptionElement = resultElement.getChild(TagNames.Elements.EXCEPTION); if (exceptionElement != null) { expectedResults.setExceptionClassName( exceptionElement.getChild(TagNames.Elements.CLASS).getTextTrim()); String msg = null; if (exceptionElement.getChild(TagNames.Elements.MESSAGE) != null) { msg = exceptionElement.getChild(TagNames.Elements.MESSAGE).getTextTrim(); } else if (exceptionElement.getChild(TagNames.Elements.MESSAGE_STARTSWITH) != null) { msg = exceptionElement.getChild(TagNames.Elements.MESSAGE_STARTSWITH).getTextTrim(); expectedResults.setExceptionStartsWith(true); } else if (exceptionElement.getChild(TagNames.Elements.MESSAGE_CONTAINS) != null) { msg = exceptionElement.getChild(TagNames.Elements.MESSAGE_CONTAINS).getTextTrim(); expectedResults.setExceptionContains(true); } expectedResults.setExceptionMsg(StringUtils.remove(msg, '\r')); } } } return expectedResults; }