List of usage examples for org.apache.commons.lang3 StringUtils containsIgnoreCase
public static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr)
Checks if CharSequence contains a search CharSequence irrespective of case, handling null .
From source file:org.squashtest.tm.web.internal.exceptionresolver.ExceptionResolverUtils.java
public static boolean clientAcceptsMIMEOrAnything(HttpServletRequest request, MimeType type) { Enumeration<String> e = request.getHeaders(RequestHeaders.ACCEPT); while (e.hasMoreElements()) { String header = e.nextElement(); if (StringUtils.containsIgnoreCase(StringUtils.trimToEmpty(header), type.requestHeaderValue()) || StringUtils.containsIgnoreCase(StringUtils.trimToEmpty(header), MimeType.ANYTHING.requestHeaderValue())) { return true; }// ww w .j a va2 s.c o m } return false; }
From source file:org.squashtest.tm.web.internal.exceptionresolver.HandlerGenericValidation.java
private boolean clientAcceptsJson(HttpServletRequest request) { Enumeration<String> e = request.getHeaders(RequestHeaders.ACCEPT); while (e.hasMoreElements()) { String header = e.nextElement(); if (StringUtils.containsIgnoreCase(StringUtils.trimToEmpty(header), MimeType.ANYTHING.requestHeaderValue()) || StringUtils.containsIgnoreCase(StringUtils.trimToEmpty(header), MimeType.APPLICATION_JSON.requestHeaderValue())) { return true; }/*from www .j a v a 2 s. c o m*/ } return false; }
From source file:org.structr.core.graph.search.PropertySearchAttribute.java
@Override public boolean includeInResult(final GraphObject entity) { T nodeValue = entity.getProperty(getKey()); Occur occur = getOccur();//www. jav a2s . c o m T searchValue = getValue(); if (occur.equals(Occur.MUST_NOT)) { if ((nodeValue != null) && compare(nodeValue, searchValue) == 0) { // don't add, do not check other results return false; } } else { if (nodeValue != null) { if (!isExactMatch) { if (nodeValue instanceof String && searchValue instanceof String) { String n = (String) nodeValue; String s = (String) searchValue; return StringUtils.containsIgnoreCase(n, s); } } if (compare(nodeValue, searchValue) != 0) { return false; } } else { if (searchValue != null && StringUtils.isNotBlank(searchValue.toString())) { return false; } } } return true; }
From source file:org.symphonyoss.simplebot.Eliza.java
private ElizaCommand getElizaCommand(String text) { if (StringUtils.containsIgnoreCase(text, "sad")) { return SAD; } else if (StringUtils.containsIgnoreCase(text, "happy birthday")) { return HAPPY_BD; } else if (StringUtils.containsIgnoreCase(text, "hungry")) { return HUNGRY; } else if (StringUtils.containsIgnoreCase(text, "fact")) { return FACT; } else {//from w w w .j a v a2 s . c o m return UNKNOWN; } }
From source file:org.symphonyoss.simplebot.LunchBoxBot.java
private LunchBotCommand getLunchBotCommand(String text) { if ((StringUtils.containsIgnoreCase(text, "menu") || StringUtils.containsIgnoreCase(text, "today's menu")) && !StringUtils.containsIgnoreCase(text, "tomorrow")) { return MENU; } else if (StringUtils.containsIgnoreCase(text, "feedback")) { return FEEDBACK; } else if (StringUtils.containsIgnoreCase(text, "tomorrow") || StringUtils.containsIgnoreCase(text, "tomorrow's menu")) { return TOMORROW; } else if (StringUtils.containsIgnoreCase(text, "format")) { return FORMAT; } else if (StringUtils.containsIgnoreCase(text, "help")) { return OPTIONS; } else {//from w w w. j a va 2s . c om return UNKNOWN; } }
From source file:org.talend.dataquality.semantic.api.LocalDictionaryCache.java
private Set<String> doSuggestValues(String categoryName, String input, int num, boolean isPrefixSearch) { String jointInput = DictionarySearcher.getJointTokens(input); String queryString = isPrefixSearch ? jointInput + "*" : "*" + jointInput + "*"; final BooleanQuery booleanQuery = new BooleanQuery(); final Query catQuery = new TermQuery(new Term(DictionarySearcher.F_WORD, categoryName)); booleanQuery.add(catQuery, BooleanClause.Occur.MUST); final Query wildcardQuery = new WildcardQuery(new Term(DictionarySearcher.F_SYNTERM, queryString)); booleanQuery.add(wildcardQuery, BooleanClause.Occur.MUST); Set<String> results = new TreeSet<String>(); try {// ww w . j a v a2 s . co m mgr.maybeRefresh(); IndexSearcher searcher = mgr.acquire(); IndexReader reader = searcher.getIndexReader(); TopDocs topDocs = searcher.search(booleanQuery, num); mgr.release(searcher); for (int i = 0; i < topDocs.scoreDocs.length; i++) { Document doc = reader.document(topDocs.scoreDocs[i].doc); IndexableField[] fields = doc.getFields(DictionarySearcher.F_RAW); for (IndexableField f : fields) { final String str = f.stringValue(); if (isPrefixSearch) { if (StringUtils.startsWithIgnoreCase(str, input) || StringUtils .startsWithIgnoreCase(DictionarySearcher.getJointTokens(str), jointInput)) { results.add(str); } } else {// infix search if (StringUtils.containsIgnoreCase(str, input) || StringUtils .containsIgnoreCase(DictionarySearcher.getJointTokens(str), jointInput)) { results.add(str); } } } } } catch (IOException e) { LOGGER.trace(e.getMessage(), e); } return results; }
From source file:org.tdar.web.functional.resource.CompleteDocumentSeleniumWebITCase.java
@Test public void testDupCreator() { gotoPage("/document/add"); setFieldByName("document.title", "My Sample Document"); setFieldByName("document.documentType", "OTHER"); setFieldByName("document.description", "A resource description"); setFieldByName("document.date", "1923"); setFieldByName("projectId", "-1"); // add a person to satisfy the confidential file requirement addPersonWithRole(new Person(LOBLAW, ROBERT, BOBLOBLAW_BLANK_COM), "authorshipProxies[0]", ResourceCreatorRole.AUTHOR); find("#authorshipRow_0_ .institutionButton").click(); addInstitutionWithRole(new Institution(UNIVERSITY_OF_TEST), "authorshipProxies[0]", ResourceCreatorRole.AUTHOR); find("#authorshipSection .addanother").click(); addInstitutionWithRole(new Institution(UNIVERSITY_OF_TEST), "authorshipProxies[1]", ResourceCreatorRole.AUTHOR); find("#authorshipRow_1_ .personButton").click(); addPersonWithRole(new Person(LOBLAW, ROBERT, BOBLOBLAW_BLANK_COM), "authorshipProxies[1]", ResourceCreatorRole.AUTHOR); addPersonWithRole(new Person(JONES, INDIANA, IJ_BLANK_COM), "creditProxies[0]", ResourceCreatorRole.CONTACT); find("#creditRow_0_ .institutionButton").click(); addInstitutionWithRole(new Institution("UC"), "creditProxies[0]", ResourceCreatorRole.CONTACT); find("#creditSection .addanother").click(); addInstitutionWithRole(new Institution("UC"), "creditProxies[1]", ResourceCreatorRole.CONTACT); find("#creditRow_1_ .personButton").click(); addPersonWithRole(new Person(JONES, INDIANA, IJ_BLANK_COM), "creditProxies[1]", ResourceCreatorRole.CONTACT); submitForm();//from w w w .j a v a 2s . co m logger.trace(getText()); assertTrue(getText().contains(JONES)); assertTrue(getText().contains(INDIANA)); assertTrue(getText().contains("UC")); assertTrue(getText().contains(LOBLAW)); assertTrue(StringUtils.containsIgnoreCase(getText(), UNIVERSITY_OF_TEST)); }
From source file:org.thelq.stackexchange.dbimport.Utils.java
public static String genTablePrefix(String containerName) { String name = containerName.trim().toLowerCase(); if (StringUtils.isBlank(name)) return ""; //Hardcoded conversions name = StringUtils.removeEnd(name, ".7z"); name = StringUtils.removeEnd(name, ".stackexchange.com"); if (StringUtils.contains(name, "stackoverflow")) name = StringUtils.replace(name, "stackoverflow", "so"); else if (StringUtils.contains(name, "serverfault")) name = StringUtils.replace(name, "serverfault", "sf"); else if (StringUtils.containsIgnoreCase(name, "superuser")) name = StringUtils.replace(name, "superuser", "su"); //Remove unnessesary extensions name = StringUtils.removeEnd(name, ".com"); //Meta handling if (StringUtils.startsWith(name, "meta")) name = StringUtils.removeStart(name, "meta") + "_m"; else if (StringUtils.startsWith(name, "meta.")) name = StringUtils.removeStart(name, "meta.") + "_m"; //Basic make valid for SQL //TODO: more validation? name = StringUtils.remove(name, " "); name = StringUtils.remove(name, "."); return name + "_"; }
From source file:org.tinymediamanager.core.entities.MediaFile.java
License:asdf
/** * Gathers the media information via the native mediainfo lib. * // ww w .j av a 2s.c o m * @param force * forces the execution, will not stop on already imported files */ public void gatherMediaInformation(boolean force) { // check for supported filetype if (!isValidMediainfoFormat()) { // okay, we have no valid MI file, be sure it will not be triggered any more if (StringUtils.isBlank(getContainerFormat())) { setContainerFormat(getExtension()); } return; } // mediainfo already gathered if (!force && !getContainerFormat().isEmpty()) { return; } // gather subtitle infos independent of MI if (getType() == MediaFileType.SUBTITLE) { gatherSubtitleInformation(); } // file size and last modified try { BasicFileAttributes attrs = Files.readAttributes(getFileAsPath(), BasicFileAttributes.class); filedate = attrs.lastModifiedTime().toMillis(); setFilesize(attrs.size()); } catch (IOException e) { if (miSnapshot == null) { // maybe we set it already (from ISO) so only display message when empty LOGGER.warn("could not get file information (size/date): " + e.getMessage()); } // do not set/return here - we might have set it already... and the next check does check for a 0-byte file // setContainerFormat(getExtension()); // return; } // do not work further on 0 byte files if (getFilesize() == 0) { LOGGER.warn("0 Byte file detected: " + this.filename); // set container format to do not trigger it again setContainerFormat(getExtension()); return; } // do not work further on subtitles/NFO files if (type == MediaFileType.SUBTITLE || type == MediaFileType.NFO) { // set container format to do not trigger it again setContainerFormat(getExtension()); return; } // get media info LOGGER.debug("start MediaInfo for " + this.getFileAsPath()); long discFilesSizes = 0L; if (isISO) { discFilesSizes = getMediaInfoSnapshotFromISO(); } else { getMediaInfoSnapshot(); } if (miSnapshot == null) { // MI could not be opened LOGGER.error("error getting MediaInfo for " + this.filename); // set container format to do not trigger it again setContainerFormat(getExtension()); closeMediaInfo(); return; } LOGGER.trace("got MI"); String height = ""; String scanType = ""; String width = ""; String videoCodec = ""; switch (type) { case VIDEO: case VIDEO_EXTRA: case SAMPLE: case TRAILER: height = getMediaInfo(StreamKind.Video, 0, "Height"); scanType = getMediaInfo(StreamKind.Video, 0, "ScanType"); width = getMediaInfo(StreamKind.Video, 0, "Width"); videoCodec = getMediaInfo(StreamKind.Video, 0, "CodecID/Hint", "Format"); // fix for Microsoft VC-1 if (StringUtils.containsIgnoreCase(videoCodec, "Microsoft")) { videoCodec = getMediaInfo(StreamKind.Video, 0, "Format"); } // ***************** // get audio streams // ***************** // int streams = getMediaInfo().streamCount(StreamKind.Audio); int streams = 0; if (streams == 0) { // fallback 1 String cnt = getMediaInfo(StreamKind.General, 0, "AudioCount"); try { streams = Integer.parseInt(cnt); } catch (Exception e) { streams = 0; } } if (streams == 0) { // fallback 2 String cnt = getMediaInfo(StreamKind.Audio, 0, "StreamCount"); try { streams = Integer.parseInt(cnt); } catch (Exception e) { streams = 0; } } audioStreams.clear(); for (int i = 0; i < streams; i++) { MediaFileAudioStream stream = new MediaFileAudioStream(); String audioCodec = getMediaInfo(StreamKind.Audio, i, "CodecID/Hint", "Format"); audioCodec = audioCodec.replaceAll("\\p{Punct}", ""); String audioAddition = getMediaInfo(StreamKind.Audio, i, "Format_Profile"); if ("dts".equalsIgnoreCase(audioCodec) && StringUtils.isNotBlank(audioAddition)) { if (audioAddition.contains("ES")) { audioCodec = "DTSHD-ES"; } if (audioAddition.contains("HRA")) { audioCodec = "DTSHD-HRA"; } if (audioAddition.contains("MA")) { audioCodec = "DTSHD-MA"; } } stream.setCodec(audioCodec); // AAC sometimes codes channels into Channel(s)_Original String channels = getMediaInfo(StreamKind.Audio, i, "Channel(s)_Original", "Channel(s)"); stream.setChannels(StringUtils.isEmpty(channels) ? "" : channels + "ch"); try { String br = getMediaInfo(StreamKind.Audio, i, "BitRate"); stream.setBitrate(Integer.parseInt(br) / 1024); } catch (Exception ignored) { } String language = getMediaInfo(StreamKind.Audio, i, "Language/String", "Language"); if (language.isEmpty()) { if (!isDiscFile()) { // video_ts parsed 'ts' as Tsonga // try to parse from filename String shortname = getBasename().toLowerCase(Locale.ROOT); stream.setLanguage(parseLanguageFromString(shortname)); } } else { stream.setLanguage(parseLanguageFromString(language)); } audioStreams.add(stream); } // ******************** // get subtitle streams // ******************** // streams = getMediaInfo().streamCount(StreamKind.Text); streams = 0; if (streams == 0) { // fallback 1 String cnt = getMediaInfo(StreamKind.General, 0, "TextCount"); try { streams = Integer.parseInt(cnt); } catch (Exception e) { streams = 0; } } if (streams == 0) { // fallback 2 String cnt = getMediaInfo(StreamKind.Text, 0, "StreamCount"); try { streams = Integer.parseInt(cnt); } catch (Exception e) { streams = 0; } } subtitles.clear(); for (int i = 0; i < streams; i++) { MediaFileSubtitle stream = new MediaFileSubtitle(); String codec = getMediaInfo(StreamKind.Text, i, "CodecID/Hint", "Format"); stream.setCodec(codec.replaceAll("\\p{Punct}", "")); String lang = getMediaInfo(StreamKind.Text, i, "Language/String", "Language"); stream.setLanguage(parseLanguageFromString(lang)); String forced = getMediaInfo(StreamKind.Text, i, "Forced"); boolean b = forced.equalsIgnoreCase("true") || forced.equalsIgnoreCase("yes"); stream.setForced(b); subtitles.add(stream); } // detect 3D video (mainly from MKV files) // sample Mediainfo output: // MultiView_Count : 2 // MultiView_Layout : Top-Bottom (left eye first) // MultiView_Layout : Side by Side (left eye first) String mvc = getMediaInfo(StreamKind.Video, 0, "MultiView_Count"); if (!StringUtils.isEmpty(mvc) && mvc.equals("2")) { video3DFormat = VIDEO_3D; String mvl = getMediaInfo(StreamKind.Video, 0, "MultiView_Layout").toLowerCase(Locale.ROOT); LOGGER.debug("3D detected :) " + mvl); if (!StringUtils.isEmpty(mvl) && mvl.contains("top") && mvl.contains("bottom")) { video3DFormat = VIDEO_3D_TAB; } if (!StringUtils.isEmpty(mvl) && mvl.contains("side")) { video3DFormat = VIDEO_3D_SBS; } } break; case AUDIO: MediaFileAudioStream stream = new MediaFileAudioStream(); String audioCodec = getMediaInfo(StreamKind.Audio, 0, "CodecID/Hint", "Format"); stream.setCodec(audioCodec.replaceAll("\\p{Punct}", "")); String channels = getMediaInfo(StreamKind.Audio, 0, "Channel(s)"); stream.setChannels(StringUtils.isEmpty(channels) ? "" : channels + "ch"); try { String br = getMediaInfo(StreamKind.Audio, 0, "BitRate"); stream.setBitrate(Integer.parseInt(br) / 1024); } catch (Exception e) { } String language = getMediaInfo(StreamKind.Audio, 0, "Language/String", "Language"); if (language.isEmpty()) { // try to parse from filename String shortname = getBasename().toLowerCase(Locale.ROOT); stream.setLanguage(parseLanguageFromString(shortname)); } else { stream.setLanguage(parseLanguageFromString(language)); } audioStreams.clear(); audioStreams.add(stream); break; case POSTER: case BANNER: case FANART: case THUMB: case EXTRAFANART: case GRAPHIC: case SEASON_POSTER: case LOGO: case CLEARLOGO: case CLEARART: case DISCART: case EXTRATHUMB: height = getMediaInfo(StreamKind.Image, 0, "Height"); // scanType = getMediaInfo(StreamKind.Image, 0, "ScanType"); // no scantype on graphics width = getMediaInfo(StreamKind.Image, 0, "Width"); videoCodec = getMediaInfo(StreamKind.Image, 0, "CodecID/Hint", "Format"); // System.out.println(height + "-" + width + "-" + videoCodec); break; case NFO: // do nothing here, but do not display default warning (since we got the filedate) break; default: LOGGER.warn("no mediainformation handling for MediaFile type " + getType() + " yet."); break; } // video codec // e.g. XviD, x264, DivX 5, MPEG-4 Visual, AVC, etc. // get first token (e.g. DivX 5 => DivX) setVideoCodec(StringUtils.isEmpty(videoCodec) ? "" : new Scanner(videoCodec).next()); // container format for all except subtitles (subtitle container format is handled another way) if (type == MediaFileType.SUBTITLE) { setContainerFormat(getExtension()); } else { String extensions = getMediaInfo(StreamKind.General, 0, "Codec/Extensions", "Format"); // get first extension setContainerFormat( StringUtils.isBlank(extensions) ? "" : new Scanner(extensions).next().toLowerCase(Locale.ROOT)); // if container format is still empty -> insert the extension if (StringUtils.isBlank(containerFormat)) { setContainerFormat(getExtension()); } } if (height.isEmpty() || scanType.isEmpty()) { setExactVideoFormat(""); } else { setExactVideoFormat(height + Character.toLowerCase(scanType.charAt(0))); } // video dimension if (!width.isEmpty()) { try { setVideoWidth(Integer.parseInt(width)); } catch (NumberFormatException e) { setVideoWidth(0); } } if (!height.isEmpty()) { try { setVideoHeight(Integer.parseInt(height)); } catch (NumberFormatException e) { setVideoHeight(0); } } switch (type) { case VIDEO: case VIDEO_EXTRA: case SAMPLE: case TRAILER: case AUDIO: // overall bitrate (OverallBitRate/String) String br = getMediaInfo(StreamKind.General, 0, "OverallBitRate"); if (!br.isEmpty()) { try { setOverallBitRate(Integer.parseInt(br) / 1024); // in kbps } catch (NumberFormatException e) { setOverallBitRate(0); } } // Duration;Play time of the stream in ms // Duration/String;Play time in format : XXx YYy only, YYy omited if zero // Duration/String1;Play time in format : HHh MMmn SSs MMMms, XX om.if.z. // Duration/String2;Play time in format : XXx YYy only, YYy omited if zero // Duration/String3;Play time in format : HH:MM:SS.MMM if (!isISO) { // ISO files get duration accumulated with snapshot String dur = getMediaInfo(StreamKind.General, 0, "Duration"); if (!dur.isEmpty()) { try { Double d = Double.parseDouble(dur); setDuration(d.intValue() / 1000); } catch (NumberFormatException e) { setDuration(0); } } } else { // do some sanity check, to see, if we have an invalid DVD structure // eg when the sum(filesize) way higher than ISO size LOGGER.trace("ISO size:" + filesize + " dataSize:" + discFilesSizes + " = diff:" + Math.abs(discFilesSizes - filesize)); if (discFilesSizes > 0 && filesize > 0) { long gig = 1024 * 1024 * 1024; if (Math.abs(discFilesSizes - filesize) > gig) { LOGGER.error("ISO file seems to have an invalid structure - ignore duration"); // we set the ISO duration to zero, // so the standard getDuration() will always get the scraped duration setDuration(0); } } } default: break; } LOGGER.trace("extracted MI"); // close mediainfo lib closeMediaInfo(); LOGGER.trace("closed MI"); }
From source file:org.wikipedia.nirvana.nirvanabot.NewPagesWithImages.java
/** * We have no power to add thumbnails of images which are non-free (fair use of images) * So we check for fair-use templates in image description before using it. * /*from ww w . ja va 2 s . com*/ * @return true if image looks like free (doesn't have a description with fair use template) * @throws IOException */ private boolean checkImageFree(NirvanaWiki wiki, String image) throws IOException { String text = null; try { text = wiki.getPageText(wiki.namespaceIdentifier(NirvanaWiki.FILE_NAMESPACE) + ":" + image); } catch (FileNotFoundException e) { log.info("Failed to get text for image (probably it's on commons): " + image); // Most likely this image comes from Commons and is free to use therefore return true; } for (String tmpl : this.fairUseImageTemplates) { if (StringUtils.containsIgnoreCase(text, "{{" + tmpl)) { return false; } } return true; }