List of usage examples for org.springframework.util StringUtils trimAllWhitespace
public static String trimAllWhitespace(String str)
From source file:com.streamreduce.util.SecurityUtil.java
public static String createNodeableFUID(String str, Long created) { str = StringUtils.trimAllWhitespace(str); str = str.toLowerCase();/*from w w w . jav a 2 s . c o m*/ // remove all non alphanumeric str = str.replaceAll("[^a-zA-Z0-9]", ""); str = str + "_" + created; return str; }
From source file:eu.trentorise.smartcampus.permissionprovider.common.Utils.java
/** * Correct values of the specified comma-separated string: remove redundant spaces * @param in//w w w. j a v a 2s. c o m * @return */ public static String normalizeValues(String in) { return StringUtils.trimAllWhitespace(in); }
From source file:org.zalando.github.spring.pagination.StringToLinkRelation.java
@Override public LinkRelation apply(String input) { Iterable<String> splittResult = splitter.split(input); String link = Iterables.get(splittResult, 0); link = StringUtils.trimAllWhitespace(link); link = StringUtils.trimLeadingCharacter(link, '<'); link = StringUtils.trimTrailingCharacter(link, '>'); String relation = Iterables.get(splittResult, 1); relation = StringUtils.trimAllWhitespace(relation); return new LinkRelation(link, relation); }
From source file:org.zalando.stups.stupsback.admin.domain.ApplicationHandler.java
protected String buildUsername(Application application) { return StringUtils.trimAllWhitespace(application.getName()).toLowerCase(); }
From source file:de.dlopes.stocks.facilitator.services.impl.FinanznachrichtenOrderbuchExtractorImpl.java
@Override public List<String> getFinanceData(String url, FinanceDataType dataType) { List<String> list = new ArrayList<String>(); try {/* ww w. ja va 2 s .c o m*/ Document doc = null; if (url.startsWith("file://")) { File input = new File(url.replaceFirst("file://", "")); doc = Jsoup.parse(input, "UTF-8"); } else { URL input = new URL(url); doc = Jsoup.parse(input, 30000); } Elements elements = doc.body().select("span[id^=productid] > span"); for (Element e : elements) { String text = e.text(); // Guard: move on when the text is empty if (StringUtils.isEmpty(text)) { continue; } text = StringUtils.trimAllWhitespace(text); // Guard: move on when the text does not contain the ISIN or WKN if (!text.startsWith(dataType.name() + ":")) { continue; } text = text.replace(dataType.name() + ":", ""); list.add(text); } } catch (IOException e) { e.printStackTrace(); } return list; }
From source file:de.dlopes.stocks.facilitator.services.impl.FinanzenNetIndexHTMLExtractorImpl.java
@Override public List<String> getFinanceData(String url, FinanceDataType dataType) { List<String> list = new ArrayList<String>(); try {//from www .jav a 2s. co m Document doc = null; if (url.startsWith("file://")) { File input = new File(url.replaceFirst("file://", "")); doc = Jsoup.parse(input, "UTF-8"); } else { URL input = new URL(url); doc = Jsoup.parse(input, 30000); } //String index = doc.body().select("div#mainWrapper > div.main h1 > a").text(); Elements elements = doc.body().select("#fragIndexBarView > table tr"); for (Element e : elements) { String text = e.select("td > div").text(); // Guard: move on when the text is empty if (StringUtils.isEmpty(text)) { continue; } text = StringUtils.trimAllWhitespace(text); list.add(text); } } catch (IOException e) { e.printStackTrace(); } return list; }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.legacy.impl.LegacySystemRepositoryImpl.java
@Override public String[] getLegacyCategoriesForCatDocRef(String pCatdocref) { logger.debug(".getLegacyCategoriesForCatDocRef> processing catDocRef: {}", pCatdocref); String catdocref = pCatdocref.replaceAll("\\<.*?>", " "); catdocref = catdocref.replace("/", " "); if (StringUtils.isEmpty(StringUtils.trimAllWhitespace(catdocref))) { logger.error(".getLegacyCategoriesForCatDocRef : once cleaned, the parameter is an empty string", pCatdocref);//from w w w . j a va2s. c om return null; } ResponseEntity<LegacySearchResponse> entityResponse = submitSearchRequest(legacySystemSearchExactUrl, catdocref, 1); if (isLegacySystemResponseValid(entityResponse)) { return null; } return getLegacyCategoriesFromResponse(entityResponse); }
From source file:de.dlopes.stocks.facilitator.services.impl.StockInfoServiceImpl.java
@Override public void addStocks(AddStocksForm addStocksForm) { List<String> yahooSymbols = null; String url = addStocksForm.getUrl(); if (StringUtils.isEmpty(url)) { String yhooSymString = addStocksForm.getListOfYahooSymbols(); yhooSymString = yhooSymString.replace("\n", ","); yhooSymString = yhooSymString.replace("\r", ","); yhooSymString = yhooSymString.replace(",,", ","); yhooSymString = StringUtils.trimAllWhitespace(yhooSymString); yahooSymbols = Arrays.asList(StringUtils.delimitedListToStringArray(yhooSymString, ",")); } else {//from ww w . j av a 2 s. co m /* // get the ISINs FinanzenNetIndexHTMLExtractorImpl fn_isin_extr = new FinanzenNetIndexHTMLExtractorImpl(); List<String> isins = fn_isin_extr.getFinanceData(url); // TODO: remove ISINs which already exist in the DB from list log.info("ISINs extracted!"); // guard: abort when there is nothing to add if (isins.size() < 1) { throw new RuntimeException("no ISINs found!."); // TODO: propagate error message to UI } log.info("ISINs found!"); // receive the mapping Map<String,String> symbols2isins = null; try { symbols2isins = YahooFinanceDataCollectorImpl.getSymbols4ISINs(isins); } catch (SFApplicationException sfae) { throw new RuntimeException("Yahoo Symbols could not be loaded", sfae); } log.info("Yahoo symbols loaded!"); // when there was no mapping was found for one or more ISIN, the we // have to propagate this as a warning message if (symbols2isins.size() < isins.size()) { // remove all ISINs that returned a valid mapping and see what stays in the list for (String s : symbols2isins.keySet()) { String isin = symbols2isins.get(s); isins.remove(isin); } // TODO: propagate a message to the UI } log.info("Yahoo symbols cleaned up!"); // guard: do not proceed when we don't have new symbols to add if (symbols2isins.size() < 1) { throw new RuntimeException("no YAHOO symbols found!."); // TODO: propagate error message to UI } log.info("still have Yahoo symbols to load!"); */ FinanceDataExtractor finDataExtr = cs.getFinanceDataExtractor(); yahooSymbols = finDataExtr.getFinanceData(url); } // guard: abort when there is nothing to add if (yahooSymbols == null || yahooSymbols.isEmpty()) { throw new RuntimeException("no Yahoo Symbols found!."); // TODO: propagate error message to UI } // load stock details from yahoo finance api Map<String, Stock> stocks = null; try { stocks = YahooFinanceDataCollectorImpl.requestStocks(yahooSymbols); } catch (SFApplicationException sfae) { throw new RuntimeException("Stock details could not be loaded", sfae); } log.info("Stock info requested from Yahoo!"); for (String symbol : stocks.keySet()) { Stock stock = stocks.get(symbol); // TODO: refactor FinanznachrichtenOrderbuchExtractorImpl foei = new FinanznachrichtenOrderbuchExtractorImpl(); List<String> isins = foei.getFinanceData( FinanznachrichtenOrderbuchExtractorImpl.PREFIX + symbol.split("\\.")[0] + ".htm"); String isin = null; if (isins != null && isins.size() > 0) { isin = isins.get(0); } log.debug("creating StockInfo record for ISIN '" + isin + "'"); StockInfo si = new StockInfo(isin); Stock2StockInfoConverter.applyUpdates(stock, si); log.debug("yahoo data applied to StockInfo record for ISIN '" + isin + "'"); siRepo.save(si); log.debug("StockInfo record for ISIN '" + isin + "' saved"); } siRepo.flush(); log.info("Stock info committed to database!"); }
From source file:cz.muni.fi.mir.similarity.SimilarityFormConverter.java
/** * Method used for traveling inside XML tree. We recursively call this * method on each node. Last node, that has some text has 1 child <b>text * node</b>, thats why we stop there, and append its contents into * StringBuilder class./*w ww .j av a2 s .com*/ * * @param node to be examined * @param sb into which is output text appended */ private void distanceTravel(Node node, StringBuilder sb) { if (node == null) { return; } NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { //last node has 1 child ~> text value if (currentNode.getChildNodes().getLength() == 1) { sb.append(StringUtils.trimAllWhitespace(currentNode.getTextContent())); } else { // there is something more so we continue in greater depth distanceTravel(currentNode, sb); } } } }
From source file:org.jboss.spring.factory.NamedXmlBeanFactory.java
private void initializeNames(Resource resource) { try {/* w w w .j ava 2s.c om*/ XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new NamespaceContext() { @Override public String getNamespaceURI(String prefix) { return "http://www.springframework.org/schema/beans"; } @Override public String getPrefix(String namespaceURI) { return "beans"; } @Override public Iterator getPrefixes(String namespaceURI) { return Collections.singleton("beans").iterator(); } }); String expression = "/beans:beans/beans:description"; InputSource inputSource = new InputSource(resource.getInputStream()); String description = xPath.evaluate(expression, inputSource); if (description != null) { Matcher bfm = Pattern.compile(Constants.BEAN_FACTORY_ELEMENT).matcher(description); if (bfm.find()) { this.name = bfm.group(1); } Matcher pbfm = Pattern.compile(Constants.PARENT_BEAN_FACTORY_ELEMENT).matcher(description); if (pbfm.find()) { String parentName = pbfm.group(1); try { this.setParentBeanFactory((BeanFactory) Util.lookup(parentName, BeanFactory.class)); } catch (Exception e) { throw new BeanDefinitionStoreException( "Failure during parent bean factory JNDI lookup: " + parentName, e); } } Matcher inst = Pattern.compile(Constants.INSTANTIATION_ELEMENT).matcher(description); if (inst.find()) { instantiate = Boolean.parseBoolean(inst.group(1)); } } if (this.name == null || "".equals(StringUtils.trimAllWhitespace(this.name))) { this.name = this.defaultName; } } catch (Exception e) { throw new RuntimeException(e); } }