List of usage examples for org.apache.commons.lang StringUtils containsIgnoreCase
public static boolean containsIgnoreCase(String str, String searchStr)
Checks if String contains a search String irrespective of case, handling null
.
From source file:org.openhab.action.pushsafer.internal.Pushsafer.java
@ActionDoc(text = "Send a notification to your iOS, Android or Win10 device. Private or Alias Key and message are required. All other can be null. Check the Pushsafer.com API for more information: https://www.pushsafer.com/en/pushapi", returns = "<code>true</code>, if successful and <code>false</code> otherwise.") public static boolean pushsafer(@ParamDoc(name = "apiKey", text = "Your Private or Alias Key.") String apiKey, @ParamDoc(name = "message", text = "Your message.") String message, @ParamDoc(name = "title", text = "Your message's title.") String title, @ParamDoc(name = "device", text = "Your device id or device group id to send the message to that device(s), leave empty to send the message to all of your registered devices.") String device, @ParamDoc(name = "icon", text = "A icon to show with your message.") String icon, @ParamDoc(name = "vibration", text = "How often the device should vibrate (1-3 or leave empty).") String vibration, @ParamDoc(name = "sound", text = "The id of one of the sounds to override the default sound.") String sound) { StringBuilder data = new StringBuilder(); try {/* w w w .j a va 2 s .c o m*/ // Private or Alias Key if (!StringUtils.isEmpty(apiKey)) { addEncodedParameter(data, MESSAGE_KEY_API_KEY, apiKey); } else { logger.error("Private or Alias key not specified."); return false; } // Message if (!StringUtils.isEmpty(message)) { if ((message.length() + title.length()) <= API_MAX_MESSAGE_LENGTH) { addEncodedParameter(data, MESSAGE_KEY_MESSAGE, message); } else { logger.error("Together, the event message and title total more than {} characters.", API_MAX_MESSAGE_LENGTH); return false; } } else { logger.error("The event message is missing."); return false; } // Device if (!StringUtils.isEmpty(device)) { addEncodedParameter(data, MESSAGE_KEY_DEVICE, device); } // Title if (!StringUtils.isEmpty(title)) { addEncodedParameter(data, MESSAGE_KEY_TITLE, title); } // Icon if (!StringUtils.isEmpty(icon)) { addEncodedParameter(data, MESSAGE_KEY_ICON, icon); } // Vibration if (!StringUtils.isEmpty(vibration)) { addEncodedParameter(data, MESSAGE_KEY_VIBRATION, vibration); } // Sound if (!StringUtils.isEmpty(sound)) { addEncodedParameter(data, MESSAGE_KEY_SOUND, sound); } String content = data.toString(); logger.debug("Executing post with the following content: {}", content); String response = HttpUtil.executeUrl("POST", API_URL, IOUtils.toInputStream(content), CONTENT_TYPE, timeout); logger.debug("Raw response: {}", response); try { if (StringUtils.isEmpty(response)) { logger.error( "Received an empty response from our Pushsafer API call. This can mean either we are having trouble connecting to the Pushsafer API or the Pushsafer API is actively enforcing rate limits with a connection time-out."); return false; } if (StringUtils.containsIgnoreCase(response, API_RETURN_STATUS_SUCCESS)) { return true; } else { logger.error("Received error message from Pushsafer: {}", response); return false; } } catch (Exception e) { logger.warn("Can't parse response from Pushsafer: {}", response); return false; } } catch (Exception e) { logger.error("An error occurred while notifying your mobile device: {}", e); return false; } }
From source file:org.openhab.binding.kodi.internal.discovery.KodiDiscoveryParticipant.java
@Override public ThingUID getThingUID(RemoteDevice device) { ThingUID result = null;/*from www .j a va 2 s .c o m*/ if (isAutoDiscoveryEnabled) { String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer(); if (StringUtils.containsIgnoreCase(manufacturer, MANUFACTURER)) { logger.debug("Manufacturer matched: search: {}, device value: {}.", MANUFACTURER, device.getDetails().getManufacturerDetails().getManufacturer()); if (StringUtils.containsIgnoreCase(device.getType().getType(), UPNP_DEVICE_TYPE)) { logger.debug("Device type matched: search: {}, device value: {}.", UPNP_DEVICE_TYPE, device.getType().getType()); ThingTypeUID thingTypeUID = THING_TYPE_KODI; result = new ThingUID(thingTypeUID, device.getIdentity().getUdn().getIdentifierString()); } } } return result; }
From source file:org.openhab.binding.onkyo.internal.discovery.OnkyoDiscoveryParticipant.java
@Override public ThingUID getThingUID(RemoteDevice device) { ThingUID result = null;//from ww w.j a v a2s.c o m if (isAutoDiscoveryEnabled) { if (StringUtils.containsIgnoreCase(device.getDetails().getManufacturerDetails().getManufacturer(), MANUFACTURER)) { logger.debug("Manufacturer matched: search: {}, device value: {}.", MANUFACTURER, device.getDetails().getManufacturerDetails().getManufacturer()); if (StringUtils.containsIgnoreCase(device.getType().getType(), UPNP_DEVICE_TYPE)) { logger.debug("Device type matched: search: {}, device value: {}.", UPNP_DEVICE_TYPE, device.getType().getType()); String deviceModel = device.getDetails().getModelDetails() != null ? device.getDetails().getModelDetails().getModelName() : null; logger.debug("Device model: {}.", deviceModel); ThingTypeUID thingTypeUID = findThingType(deviceModel); result = new ThingUID(thingTypeUID, device.getIdentity().getUdn().getIdentifierString()); } } } return result; }
From source file:org.openhab.binding.pioneeravr.internal.discovery.PioneerAvrDiscoveryParticipant.java
@Override public ThingUID getThingUID(RemoteDevice device) { ThingUID result = null;/*from www . java2 s . com*/ if (isAutoDiscoveryEnabled) { if (StringUtils.containsIgnoreCase(device.getDetails().getManufacturerDetails().getManufacturer(), PioneerAvrBindingConstants.MANUFACTURER)) { logger.debug("Manufacturer matched: search: {}, device value: {}.", PioneerAvrBindingConstants.MANUFACTURER, device.getDetails().getManufacturerDetails().getManufacturer()); if (StringUtils.containsIgnoreCase(device.getType().getType(), PioneerAvrBindingConstants.UPNP_DEVICE_TYPE)) { logger.debug("Device type matched: search: {}, device value: {}.", PioneerAvrBindingConstants.UPNP_DEVICE_TYPE, device.getType().getType()); String deviceModel = device.getDetails().getModelDetails() != null ? device.getDetails().getModelDetails().getModelName() : null; ThingTypeUID thingTypeUID = PioneerAvrBindingConstants.IP_AVR_THING_TYPE; if (!isSupportedDeviceModel(deviceModel)) { logger.debug("Device model {} not supported. Odd behaviors may happen.", deviceModel); thingTypeUID = PioneerAvrBindingConstants.IP_AVR_UNSUPPORTED_THING_TYPE; } result = new ThingUID(thingTypeUID, device.getIdentity().getUdn().getIdentifierString()); } } } return result; }
From source file:org.openmrs.logic.datasource.PersonDataSource.java
/** * @see org.openmrs.logic.datasource.LogicDataSource#read(LogicContext, Cohort, LogicCriteria) * @should get gender/*from w ww . j a va 2s. c o m*/ * @should get gender equals value * @should get birthdate * @should get birthdate_estimated * @should get dead * @should get death_date * @should get cause_of_death * @should get first name * @should get middle name * @should get family name * @should get family name2 */ public Map<Integer, Result> read(LogicContext context, Cohort who, LogicCriteria criteria) { Map<Integer, Result> resultMap = new HashMap<Integer, Result>(); // calculate List<Person> personList = getLogicPersonDAO().getPersons(who.getMemberIds(), criteria); String token = criteria.getRootToken(); // put in the result map for (Person person : personList) { if (token.equalsIgnoreCase("gender")) resultMap.put(person.getPersonId(), new Result(person.getGender())); else if (token.equalsIgnoreCase("birthdate")) resultMap.put(person.getPersonId(), new Result(person.getBirthdate())); else if (token.equalsIgnoreCase("birthdate estimated")) resultMap.put(person.getPersonId(), new Result(person.getBirthdateEstimated())); else if (token.equalsIgnoreCase("death date")) resultMap.put(person.getPersonId(), new Result(person.getDeathDate())); else if (token.equalsIgnoreCase("cause of death")) { Result deathResult; if (person.isDead()) deathResult = new Result(person.getDeathDate(), person.getCauseOfDeath(), person); else deathResult = Result.emptyResult(); resultMap.put(person.getPersonId(), deathResult); } else if (token.equalsIgnoreCase("dead")) { resultMap.put(person.getPersonId(), new Result(person.isDead())); } else if (StringUtils.containsIgnoreCase(token, "name")) { PersonName personName = person.getPersonName(); String valueText = StringUtils.EMPTY; if (StringUtils.equalsIgnoreCase(token, "given name")) valueText = personName.getGivenName(); else if (StringUtils.equalsIgnoreCase(token, "middle name")) valueText = personName.getMiddleName(); else if (StringUtils.equalsIgnoreCase(token, "family name")) valueText = personName.getFamilyName(); else if (StringUtils.equalsIgnoreCase(token, "family name2")) valueText = personName.getFamilyName2(); resultMap.put(person.getPersonId(), new Result(new Date(), valueText, personName)); } // TODO more keys to be added } LogicUtil.applyAggregators(resultMap, criteria, who); return resultMap; }
From source file:org.openmrs.web.dwr.PersonListItem.java
/** *Helper method to check if all the search names(separated by spaces) are contained in the person's full name. //from ww w .j a v a 2s .c o m *@param fullName the fullName upon which the search names are to be compared *@param searchNames Array<String> of searched names *@should return true when all searched names are found in full name *@should return false if even one of the searched names are not found in full name */ private boolean containsAll(String fullName, String[] searchNames) { for (String name : searchNames) { if (StringUtils.containsIgnoreCase(fullName, name)) { continue; } return false; } return true; }
From source file:org.opens.tgol.validator.PageAuditSetUpFormValidator.java
/** * Check whether the Urls filled-in by the user are correct. * 1- They have to be all on the same domain. * 2- When the contract has on option of type DOMAIN, they have to match * to the value of the option//from ww w . j av a2 s .com * * @param pageAuditSetUpCommand * @param errors */ private void validateUrl(AuditSetUpCommand pageAuditSetUpCommand, Errors errors) { boolean onContractUrl = false; String contractUrl = getContractDataService() .getUrlFromContractOption(getContractDataService().read(pageAuditSetUpCommand.getContractId())); boolean emptyUrl = true; String domainOfFirstUrlEncountered = ""; Set<Integer> urlWithProblemIndexSet = new HashSet<Integer>(); // We parse all the URL filled-in by the user and extract the ones that // don't match with the domain of the first encountered URL. int index = 0; for (String url : pageAuditSetUpCommand.getUrlList()) { if (url != null && !url.isEmpty()) { emptyUrl = false; // first we sanitize the url and extract the domain url = url.trim(); url = extractDomainFromUrl(url); // we store the url if it's the first one. if (domainOfFirstUrlEncountered.isEmpty()) { domainOfFirstUrlEncountered = url; // if the domain of this url is different from the one of the // first encountered domain, we store its index. } else if (!url.equalsIgnoreCase(domainOfFirstUrlEncountered)) { urlWithProblemIndexSet.add(index); } if (!onContractUrl && (StringUtils.containsIgnoreCase(contractUrl, url) || contractUrl.isEmpty())) { onContractUrl = true; } } index++; } if (emptyUrl) { // if no URL is filled-in LOGGER.debug("emptyUrl"); errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY); } else if (!onContractUrl) { // if the URL is not allowed (not on the contract for authenticated users) LOGGER.debug("notOnContract"); errors.rejectValue(GENERAL_ERROR_MSG_KEY, NOT_ON_CONTRACT_MSG_BUNDLE_KEY); } else if (!urlWithProblemIndexSet.isEmpty()) { // if some URLs are not on the right domain LOGGER.debug("notOnSameDomain"); errors.rejectValue(GENERAL_ERROR_MSG_KEY, URL_ON_DIFFERENT_DOMAIN_MSG_BUNDLE_KEY); for (Integer urlIndex : urlWithProblemIndexSet) { String[] arg = { domainOfFirstUrlEncountered }; errors.rejectValue(ID_INPUT_PREFIX + "[" + urlIndex + "]", NOT_ON_SAME_DOMAIN_MSG_BUNDLE_KEY, arg, "{0}"); } } }
From source file:org.osaf.cosmo.dav.acl.report.PrincipalPropertySearchReport.java
private boolean matchText(String test, String match) { if (log.isDebugEnabled()) log.debug("Matching " + test + " against " + match); return StringUtils.containsIgnoreCase(test, match); }
From source file:org.polymap.core.catalog.model.ServiceTypeFolder.java
public String getTitle() { String typeName = type.getSimpleName(); if (StringUtils.contains(typeName, "Post")) { return "PostGIS"; } else if (StringUtils.contains(typeName, "Shp")) { return "Shapefile"; } else if (StringUtils.contains(typeName, "WMS")) { return "WMS"; } else if (StringUtils.contains(typeName, "WFS")) { return "WFS"; } else if (StringUtils.contains(typeName, "Oracle")) { return "Oracle"; } else if (StringUtils.contains(typeName, "MySQL")) { return "MySQL"; } else if (StringUtils.containsIgnoreCase(typeName, "GeoTiff")) { return "GeoTIFF"; } else if (StringUtils.containsIgnoreCase(typeName, "DXF")) { return "DXF"; } else {/*from w w w . java 2 s. c om*/ try { IService service = (IService) services.get(0); String result = service.getInfo(null).getShortTitle(); if (result != null) { return result; } else { throw new Exception("trying last resort..."); } } catch (Exception e) { String result = StringUtils.remove(typeName, "Impl"); result = StringUtils.remove(result, "Service"); return result; } } }
From source file:org.processbase.ui.bpm.admin.AdminCaseList.java
@Override public int load(int startPosition, int maxResults) { try {// w w w. j a v a 2 s.co m table.removeAllItems(); Set<InstanceState> statesFilters = new HashSet<InstanceState>(); if (showFinished == null || !((Boolean) showFinished.getValue())) { statesFilters.add(InstanceState.STARTED); } // Filter words Set<String> filterWords = new HashSet<String>(); if (additionalFilter != null && additionalFilter.getValue() != null && StringUtils.isNotBlank(additionalFilter.getValue() + "")) { String[] words = StringUtils.splitByWholeSeparator(additionalFilter.getValue() + "", " "); for (int i = 0; i < words.length; i++) { filterWords.add(words[i]); } } BPMModule bpmModule = ProcessbaseApplication.getCurrent().getBpmModule(); List<LightProcessInstance> results = new ArrayList<LightProcessInstance>(); results.addAll(bpmModule.getLightProcessInstances()); // Filter process instances List<LightProcessInstance> filtered = new ArrayList<LightProcessInstance>(); for (LightProcessInstance pi : results) { if (statesFilters.size() > 0 && !statesFilters.contains(pi.getInstanceState())) { continue; } if (filterWords.size() > 0) { String name = pi.getUUID().toString().split("--")[0] + " #" + pi.getNb(); boolean contains = true; for (String w : filterWords) { if (!StringUtils.containsIgnoreCase(name, w)) { contains = false; break; } } if (!contains) { continue; } } filtered.add(pi); } // Let sort list Collections.sort(filtered, new Comparator<LightProcessInstance>() { public int compare(LightProcessInstance o1, LightProcessInstance o2) { return o2.getStartedDate().compareTo(o1.getStartedDate()); } }); int from = startPosition < filtered.size() ? startPosition : filtered.size(); int to = (startPosition + maxResults) < filtered.size() ? (startPosition + maxResults) : filtered.size(); List<LightProcessInstance> page = filtered.subList(from, to); for (LightProcessInstance pi : page) { Item woItem = table.addItem(pi); String pdUUID = pi.getProcessDefinitionUUID().toString(); TableLinkButton teb = new TableLinkButton(pdUUID.split("--")[0] + " #" + pi.getNb(), null, null, pi, this, Constants.ACTION_OPEN); woItem.getItemProperty("name").setValue(teb); woItem.getItemProperty("initiator").setValue(pi.getStartedBy()); woItem.getItemProperty("startedDate").setValue(pi.getStartedDate()); woItem.getItemProperty("version").setValue(pdUUID.split("--")[1]); // Find all tasks List<LightTaskInstance> tasks = new ArrayList<LightTaskInstance>(); try { tasks.addAll(bpmModule.getLightTasks(pi.getProcessInstanceUUID())); } catch (Exception e) { e.printStackTrace(); } // Sort tasks Collections.sort(tasks, new Comparator<LightTaskInstance>() { public int compare(LightTaskInstance o2, LightTaskInstance o1) { return o1.getLastUpdateDate().compareTo(o2.getLastUpdateDate()); } }); if (!tasks.isEmpty()) { woItem.getItemProperty("lastUpdate").setValue(tasks.get(0).getLastUpdateDate()); } else { woItem.getItemProperty("lastUpdate").setValue(pi.getLastUpdate()); } woItem.getItemProperty("state").setValue(getText(pi.getInstanceState().toString())); } table.setSortContainerPropertyId("lastUpdate"); table.setSortAscending(false); table.sort(); return page.size(); } catch (Exception ex) { ex.printStackTrace(); } return 0; }