List of usage examples for org.apache.commons.lang3 StringUtils contains
public static boolean contains(final CharSequence seq, final CharSequence searchSeq)
Checks if CharSequence contains a search CharSequence, handling null .
From source file:info.magnolia.ui.workbench.search.SearchJcrContainerTest.java
protected void assertContains(final String searchString, final String string) { if (!StringUtils.contains(string, searchString)) { Assert.fail(String.format("[%s] was expected to be contained into [%s]", searchString, string)); }// ww w .j av a 2s . c o m }
From source file:com.glaf.core.config.DBConfiguration.java
public static String getDatabaseType(String url) { String dbType = null;/* www. ja va 2 s . c om*/ if (StringUtils.contains(url, "jdbc:mysql:")) { dbType = "mysql"; } else if (StringUtils.contains(url, "jdbc:postgresql:")) { dbType = "postgresql"; } else if (StringUtils.contains(url, "jdbc:h2:")) { dbType = "h2"; } else if (StringUtils.contains(url, "jdbc:jtds:sqlserver:")) { dbType = "sqlserver"; } else if (StringUtils.contains(url, "jdbc:sqlserver:")) { dbType = "sqlserver"; } else if (StringUtils.contains(url, "jdbc:oracle:")) { dbType = "oracle"; } else if (StringUtils.contains(url, "jdbc:db2:")) { dbType = "db2"; } else if (StringUtils.contains(url, "jdbc:sqlite:")) { dbType = "sqlite"; } return dbType; }
From source file:cgeo.geocaching.connector.gc.GCParser.java
private static SearchResult parseSearch(final String url, final String pageContent, final boolean showCaptcha, final RecaptchaReceiver recaptchaReceiver) { if (StringUtils.isBlank(pageContent)) { Log.e("GCParser.parseSearch: No page given"); return null; }// ww w. jav a2s . c om final List<String> cids = new ArrayList<String>(); String page = pageContent; final SearchResult searchResult = new SearchResult(); searchResult.setUrl(url); searchResult.viewstates = GCLogin.getViewstates(page); // recaptcha if (showCaptcha) { final String recaptchaJsParam = TextUtils.getMatch(page, GCConstants.PATTERN_SEARCH_RECAPTCHA, false, null); if (recaptchaJsParam != null) { recaptchaReceiver.setKey(recaptchaJsParam.trim()); recaptchaReceiver.fetchChallenge(); } if (recaptchaReceiver != null && StringUtils.isNotBlank(recaptchaReceiver.getChallenge())) { recaptchaReceiver.notifyNeed(); } } if (!page.contains("SearchResultsTable")) { // there are no results. aborting here avoids a wrong error log in the next parsing step return searchResult; } int startPos = page.indexOf("<div id=\"ctl00_ContentBody_ResultsPanel\""); if (startPos == -1) { Log.e("GCParser.parseSearch: ID \"ctl00_ContentBody_dlResults\" not found on page"); return null; } page = page.substring(startPos); // cut on <table startPos = page.indexOf('>'); final int endPos = page.indexOf("ctl00_ContentBody_UnitTxt"); if (startPos == -1 || endPos == -1) { Log.e("GCParser.parseSearch: ID \"ctl00_ContentBody_UnitTxt\" not found on page"); return null; } page = page.substring(startPos + 1, endPos - startPos + 1); // cut between <table> and </table> final String[] rows = page.split("<tr class="); final int rows_count = rows.length; int excludedCaches = 0; final ArrayList<Geocache> caches = new ArrayList<Geocache>(); for (int z = 1; z < rows_count; z++) { final Geocache cache = new Geocache(); final String row = rows[z]; // check for cache type presence if (!row.contains("images/wpttypes")) { continue; } try { final MatcherWrapper matcherGuidAndDisabled = new MatcherWrapper( GCConstants.PATTERN_SEARCH_GUIDANDDISABLED, row); while (matcherGuidAndDisabled.find()) { if (matcherGuidAndDisabled.groupCount() > 0) { //cache.setGuid(matcherGuidAndDisabled.group(1)); if (matcherGuidAndDisabled.group(2) != null) { cache.setName(Html.fromHtml(matcherGuidAndDisabled.group(2).trim()).toString()); } if (matcherGuidAndDisabled.group(3) != null) { cache.setLocation(Html.fromHtml(matcherGuidAndDisabled.group(3).trim()).toString()); } final String attr = matcherGuidAndDisabled.group(1); if (attr != null) { cache.setDisabled(attr.contains("Strike")); cache.setArchived(attr.contains("OldWarning")); } } } } catch (final RuntimeException e) { // failed to parse GUID and/or Disabled Log.w("GCParser.parseSearch: Failed to parse GUID and/or Disabled data"); } if (Settings.isExcludeDisabledCaches() && (cache.isDisabled() || cache.isArchived())) { // skip disabled and archived caches excludedCaches++; continue; } cache.setGeocode( TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_GEOCODE, true, 1, cache.getGeocode(), true)); // cache type cache.setType(CacheType .getByPattern(TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_TYPE, true, 1, null, true))); // cache direction - image if (Settings.getLoadDirImg()) { final String direction = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION_DISTANCE, false, 1, null, false); if (direction != null) { cache.setDirectionImg(direction); } } // cache distance - estimated distance for basic members final String distance = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_DIRECTION_DISTANCE, false, 2, null, false); if (distance != null) { cache.setDistance(DistanceParser.parseDistance(distance, !Settings.isUseImperialUnits())); } // difficulty/terrain final MatcherWrapper matcherDT = new MatcherWrapper(GCConstants.PATTERN_SEARCH_DIFFICULTY_TERRAIN, row); if (matcherDT.find()) { final Float difficulty = parseStars(matcherDT.group(1)); if (difficulty != null) { cache.setDifficulty(difficulty); } final Float terrain = parseStars(matcherDT.group(3)); if (terrain != null) { cache.setTerrain(terrain); } } // size final String container = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_CONTAINER, false, 1, null, false); cache.setSize(CacheSize.getById(container)); // date hidden, makes sorting event caches easier final String dateHidden = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_HIDDEN_DATE, false, 1, null, false); if (StringUtils.isNotBlank(dateHidden)) { try { Date date = GCLogin.parseGcCustomDate(dateHidden); if (date != null) { cache.setHidden(date); } } catch (ParseException e) { Log.e("Error parsing event date from search"); } } // cache inventory final MatcherWrapper matcherTbs = new MatcherWrapper(GCConstants.PATTERN_SEARCH_TRACKABLES, row); String inventoryPre = null; while (matcherTbs.find()) { if (matcherTbs.groupCount() > 0) { try { cache.setInventoryItems(Integer.parseInt(matcherTbs.group(1))); } catch (final NumberFormatException e) { Log.e("Error parsing trackables count", e); } inventoryPre = matcherTbs.group(2); } } if (StringUtils.isNotBlank(inventoryPre)) { final MatcherWrapper matcherTbsInside = new MatcherWrapper( GCConstants.PATTERN_SEARCH_TRACKABLESINSIDE, inventoryPre); while (matcherTbsInside.find()) { if (matcherTbsInside.groupCount() == 2 && matcherTbsInside.group(2) != null && !matcherTbsInside.group(2).equalsIgnoreCase("premium member only cache") && cache.getInventoryItems() <= 0) { cache.setInventoryItems(1); } } } // premium cache cache.setPremiumMembersOnly(row.contains("/images/icons/16/premium_only.png")); // found it cache.setFound(row.contains("/images/icons/16/found.png") || row.contains("uxUserLogDate\" class=\"Success\"")); // id String result = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_ID, null); if (null != result) { cache.setCacheId(result); cids.add(cache.getCacheId()); } // favorite count try { result = getNumberString( TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_FAVORITE, false, 1, null, true)); if (null != result) { cache.setFavoritePoints(Integer.parseInt(result)); } } catch (final NumberFormatException e) { Log.w("GCParser.parseSearch: Failed to parse favorite count"); } caches.add(cache); } searchResult.addAndPutInCache(caches); // total caches found try { final String result = TextUtils.getMatch(page, GCConstants.PATTERN_SEARCH_TOTALCOUNT, false, 1, null, true); if (null != result) { searchResult.setTotalCountGC(Integer.parseInt(result) - excludedCaches); } } catch (final NumberFormatException e) { Log.w("GCParser.parseSearch: Failed to parse cache count"); } String recaptchaText = null; if (recaptchaReceiver != null && StringUtils.isNotBlank(recaptchaReceiver.getChallenge())) { recaptchaReceiver.waitForUser(); recaptchaText = recaptchaReceiver.getText(); } if (!cids.isEmpty() && (Settings.isGCPremiumMember() || showCaptcha) && ((recaptchaReceiver == null || StringUtils.isBlank(recaptchaReceiver.getChallenge())) || StringUtils.isNotBlank(recaptchaText))) { Log.i("Trying to get .loc for " + cids.size() + " caches"); try { // get coordinates for parsed caches final Parameters params = new Parameters("__EVENTTARGET", "", "__EVENTARGUMENT", ""); GCLogin.putViewstates(params, searchResult.viewstates); for (final String cid : cids) { params.put("CID", cid); } if (StringUtils.isNotBlank(recaptchaText) && recaptchaReceiver != null) { params.put("recaptcha_challenge_field", recaptchaReceiver.getChallenge()); params.put("recaptcha_response_field", recaptchaText); } params.put("ctl00$ContentBody$uxDownloadLoc", "Download Waypoints"); final String coordinates = Network.getResponseData( Network.postRequest("http://www.geocaching.com/seek/nearest.aspx", params), false); if (StringUtils.contains(coordinates, "You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) { Log.i("User has not agreed to the license agreement. Can\'t download .loc file."); searchResult.setError(StatusCode.UNAPPROVED_LICENSE); return searchResult; } LocParser.parseLoc(searchResult, coordinates); } catch (final RuntimeException e) { Log.e("GCParser.parseSearch.CIDs", e); } } // get direction images if (Settings.getLoadDirImg()) { final Set<Geocache> cachesReloaded = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); for (final Geocache cache : cachesReloaded) { if (cache.getCoords() == null && StringUtils.isNotEmpty(cache.getDirectionImg())) { DirectionImage.getDrawable(cache.getDirectionImg()); } } } return searchResult; }
From source file:net.eledge.android.europeana.gui.activity.SearchActivity.java
private void handleIntent(Intent intent) { String query = null;// ww w .j a v a2s .co m String[] qf = null; if (intent != null) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY)); } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) parcelables[0]; Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload())); query = uri.getQueryParameter("query"); qf = StringArrayUtils.toArray(uri.getQueryParameters("qf")); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { query = intent.getDataString(); if (!TextUtils.isEmpty(query)) { if (StringUtils.contains(query, "europeana.eu/")) { Uri uri = Uri.parse(query); query = uri.getQueryParameter("query"); qf = StringArrayUtils.toArray(uri.getQueryParameters("qf")); } } } else { // no search action recognized? end this activity... closeSearchActivity(); } if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) { runningSearch = query; if (StringArrayUtils.isNotBlank(qf)) { searchController.newSearch(this, query, qf); } else { searchController.newSearch(this, query); } getSupportActionBar().setTitle(searchController.getSearchTitle(this)); } } }
From source file:com.sixt.service.framework.registry.consul.RegistrationManager.java
private String getLastComponent(String fullName) { if (!StringUtils.contains(fullName, ".")) { return fullName; }/*from w w w. j ava2 s. c o m*/ int index = fullName.lastIndexOf('.'); return fullName.substring(index + 1); }
From source file:com.oncore.calorders.core.utils.FormatHelper.java
/** * The <code>retrievePageName</code> method will examine a valid URL and * return just the page name portion./*from w w w .java 2 s .c o m*/ * * @author OnCore Consulting LLC * * @param url a fully qualified URL * * @return the page name from the URL */ public static String retrievePageName(String url) { Logger.debug(LOG, "retrievePageName for " + url); @SuppressWarnings("UnusedAssignment") String[] values = null; String value = url; if (StringUtils.isNotBlank(url) && StringUtils.contains(url, "/")) { values = url.split("/"); value = values[values.length - 1]; } if (StringUtils.contains(value, "?faces-redirect")) { values = value.split("/?faces"); value = values[0]; value = value.substring(0, value.length() - 1); } if (StringUtils.contains(value, ".xhtml")) { values = value.split("\\."); value = values[0]; } Logger.debug(LOG, "retrievePageName value is " + value); return value; }
From source file:com.github.binlee1990.spider.movie.spider.MovieCrawler.java
private List<Album> createOrGetAlbumList(Document doc) { List<Album> albumList = Lists.newArrayList(); Elements albumElements = doc.select(".panel .fm-little li:has(a) a"); if (CollectionUtils.isNotEmpty(albumElements)) { albumElements.forEach(albumElement -> { String href = albumElement.attr("href").toString(); if (StringUtils.isNotBlank(href) && StringUtils.contains(href, "collection")) { String albumName = StringUtils.trimToEmpty(albumElement.text()); if (StringUtils.isNotBlank(albumName)) { Album album = createOrQueryAlbum(albumName); if (null != album) { albumList.add(album); }//from w ww .j a va 2 s. com } } }); } return albumList; }
From source file:com.utdallas.s3lab.smvhunter.monkey.MonkeyMe.java
/** * Uninstall app//from ww w . j a v a2 s . c o m * @param packageName * @param device * @throws IOException */ private void uninstallApk(String packageName, IDevice device) throws IOException { //uninstall the app String result = execCommand(String.format("%s %s %s", getDeviceString(device), " uninstall ", packageName)); if (StringUtils.contains(result, "Failure")) { logger.error(String.format("%s uninstall failed for apk %s", device.getSerialNumber(), packageName)); } if (logDebug) logger.debug(String.format("%s uninstall success for apk %s", device.getSerialNumber(), packageName)); }
From source file:in.mycp.workers.IpAddressWorker.java
@Async public void disassociateAddress(final Infra infra, final AddressInfoP addressInfoP) { String threadName = Thread.currentThread().getName(); try {// w ww. j a v a 2 s.co m logger.debug("threadName " + threadName + " started for disassociateAddress"); Jec2 ec2 = getNewJce2(infra); try { ec2.disassociateAddress(addressInfoP.getPublicIp()); } catch (Exception e) { logger.error(e);//e.printStackTrace(); if (e.getMessage().indexOf("Permission denied while") > -1) { throw new Exception("Permission denied."); } else if (e.getMessage().indexOf("Number of retries exceeded") > -1) { throw new Exception("No Connectivity to Cloud"); } } String instanceIdOrig = addressInfoP.getInstanceId(); if (StringUtils.contains(instanceIdOrig, " ")) { instanceIdOrig = StringUtils.substringBefore(instanceIdOrig, " "); } InstanceP orig_compute = null; try { orig_compute = InstanceP.findInstancePsByInstanceIdEquals(instanceIdOrig).getSingleResult(); } catch (Exception e) { logger.error(e);//e.printStackTrace(); } AddressInfoP addressInfoP4PublicIp = null; try { addressInfoP4PublicIp = AddressInfoP.findAddressInfoPsByPublicIpEquals(addressInfoP.getPublicIp()) .getSingleResult(); } catch (Exception e) { logger.error(e);//e.printStackTrace(); } String newIp = ""; boolean match = false; int START_SLEEP_TIME = 5000; int waitformaxcap = START_SLEEP_TIME * 10; long now = 0; outer: while (!match) { if (now > waitformaxcap) { throw new Exception("Got bored, Quitting."); } now = now + START_SLEEP_TIME; try { List<String> params = new ArrayList<String>(); List<ReservationDescription> instances = ec2.describeInstances(params); for (ReservationDescription res : instances) { if (res.getInstances() != null) { HashSet<InstanceP> instancesP = new HashSet<InstanceP>(); for (Instance inst : res.getInstances()) { logger.info(inst.getInstanceId() + " " + orig_compute.getInstanceId() + " " + inst.getDnsName() + " " + addressInfoP.getPublicIp()); if (inst.getInstanceId().equals(orig_compute.getInstanceId()) && !inst.getDnsName().equals(addressInfoP.getPublicIp())) { newIp = inst.getDnsName(); match = true; break outer; } } //for (Instance inst : res.getInstances()) { } //if (res.getInstances() != null) { } //for (ReservationDescription res : instances) { logger.info("Ipaddress " + addressInfoP.getPublicIp() + " getting disassociated; sleeping " + START_SLEEP_TIME + "ms"); Thread.sleep(START_SLEEP_TIME); } catch (Exception e) { logger.error(e);//e.printStackTrace(); //addressInfoLocal=null; } } AddressInfoP addressInfoP4NewPublicIp = null; try { addressInfoP4NewPublicIp = AddressInfoP.findAddressInfoPsByPublicIpEquals(newIp).getSingleResult(); } catch (Exception e) { logger.error(e);//e.printStackTrace(); } if (match == true) { try { orig_compute.setDnsName(newIp); orig_compute.merge(); } catch (Exception e) { logger.error(e);//e.printStackTrace(); } try { addressInfoP4PublicIp.setAssociated(false); addressInfoP4PublicIp.setInstanceId("available"); addressInfoP4PublicIp.setStatus(Commons.ipaddress_STATUS.available + ""); addressInfoP4PublicIp.merge(); } catch (Exception e) { logger.error(e);//e.printStackTrace(); } try { addressInfoP4NewPublicIp.setAssociated(false); addressInfoP4NewPublicIp.setInstanceId(orig_compute.getInstanceId()); addressInfoP4PublicIp.setStatus(Commons.ipaddress_STATUS.available + ""); addressInfoP4NewPublicIp.merge(); } catch (Exception e) { logger.error(e);//e.printStackTrace(); } } } catch (Exception e) { logger.error(e);//e.printStackTrace(); try { AddressInfoP a = AddressInfoP.findAddressInfoP(addressInfoP.getId()); a.setStatus(Commons.ipaddress_STATUS.failed + ""); a = a.merge(); setAssetEndTime(a.getAsset()); } catch (Exception e2) { // TODO: handle exception } } }
From source file:com.dgtlrepublic.anitomyj.Parser.java
/** Validate Elements. */ private void validateElements() { if (!empty(kElementAnimeType) && !empty(kElementEpisodeTitle)) { String episodeTitle = get(kElementEpisodeTitle); for (int i = 0; i < elements.size();) { Element el = elements.get(i); if (el.getCategory() == kElementAnimeType) { if (StringUtils.contains(episodeTitle, el.getValue())) { if (episodeTitle.length() == el.getValue().length()) { elements.removeIf(element -> element.getCategory() == kElementEpisodeTitle); // invalid episode title } else { String keyword = KeywordManager.normalzie(el.getValue()); if (KeywordManager.getInstance().contains(kElementAnimeType, keyword)) { i = erase(el); // invalid anime type continue; }/*from w ww. java 2 s . c om*/ } } } ++i; } } }