List of usage examples for org.apache.commons.lang3 StringUtils endsWithAny
public static boolean endsWithAny(final CharSequence string, final CharSequence... searchStrings)
Check if a CharSequence ends with any of an array of specified strings.
StringUtils.endsWithAny(null, null) = false StringUtils.endsWithAny(null, new String[] {"abc"}) = false StringUtils.endsWithAny("abcxyz", null) = false StringUtils.endsWithAny("abcxyz", new String[] {""}) = true StringUtils.endsWithAny("abcxyz", new String[] {"xyz"}) = true StringUtils.endsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
From source file:kenh.expl.functions.EndsWithAny.java
public boolean process(String str, String[] searchStrings) { return StringUtils.endsWithAny(str, searchStrings); }
From source file:mrcg.utils.Utils.java
public static String pluralize(String s) { if (s.length() == 0) return s; char c = Character.toLowerCase(s.charAt(s.length() - 1)); if (c == 'y') { if (StringUtils.endsWithAny(s.toLowerCase(), "day")) { return s + "s"; } else {/* www . j a va2s . co m*/ return s.substring(0, s.length() - 1) + "ies"; } } else if (c == 's') { return s + "es"; } else { return s + "s"; } }
From source file:com.moviejukebox.scanner.WatchedScanner.java
/** * Calculate the watched state of a movie based on the files * {filename}.watched & {filename}.unwatched * * Always assumes that the file is unwatched if nothing is found. * /*from www . j a v a2s . c o m*/ * Also TraktTV watched check can be done. * * @param jukebox * @param movie * @return */ public static boolean checkWatched(Jukebox jukebox, Movie movie) { if (WATCH_FILES && !warned && (LOCATION == WatchedWithLocation.CUSTOM)) { LOG.warn("Custom file location not supported for watched scanner"); warned = Boolean.TRUE; } TrackedShow trackedShow = null; TrackedMovie trackedMovie = null; boolean watchTraktTV = WATCH_TRAKTTV; if (watchTraktTV) { if (movie.isTVShow()) { if (TraktTV.getInstance().isPreloadWatchedShows()) { // get matching show trackedShow = getMatchingShow(movie); } else { // disable watching if preLoading failed watchTraktTV = false; } } else if (!movie.isExtra()) { if (TraktTV.getInstance().isPreloadWatchedMovies()) { // get matching movie trackedMovie = getMatchingMovie(movie); } else { // disable watching if preLoading failed watchTraktTV = false; } } else { // disable watching for extras watchTraktTV = false; } } // assume no changes boolean returnStatus = Boolean.FALSE; // check if media file watched has changed boolean movieFileWatchChanged = Boolean.FALSE; // the number of watched files found int fileWatchedCount = 0; File foundFile = null; boolean movieWatchedFile = Boolean.TRUE; for (MovieFile mf : movie.getFiles()) { // Check that the file pointer is valid if (mf.getFile() == null) { continue; } if (MovieJukebox.isJukeboxPreserve() && !mf.getFile().exists()) { fileWatchedCount++; } else { boolean fileWatched = Boolean.FALSE; long fileWatchedDate = mf.getWatchedDate(); // check for watched/unwatched files on file system if (WATCH_FILES) { String filename; // BluRay stores the file differently to DVD and single files, so we need to process the path a little if (movie.isBluray()) { filename = new File(FileTools.getParentFolder(mf.getFile())).getName(); } else { filename = mf.getFile().getName(); } if (WITH_EXTENSION == WatchedWithExtension.EXTENSION || WITH_EXTENSION == WatchedWithExtension.BOTH || movie.isBluray()) { if (LOCATION == WatchedWithLocation.WITHJUKEBOX) { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.TRUE); } else { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.FALSE); } } if (foundFile == null && (WITH_EXTENSION == WatchedWithExtension.NOEXTENSION || WITH_EXTENSION == WatchedWithExtension.BOTH) && !movie.isBluray()) { // Remove the extension from the filename filename = FilenameUtils.removeExtension(filename); // Check again without the extension if (LOCATION == WatchedWithLocation.WITHJUKEBOX) { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.TRUE); } else { foundFile = FileTools.findFilenameInCache(filename, EXTENSIONS, jukebox, Boolean.FALSE); } } if (foundFile != null) { fileWatchedCount++; fileWatchedDate = new DateTime(foundFile.lastModified()).withMillisOfSecond(0).getMillis(); fileWatched = StringUtils.endsWithAny(foundFile.getName().toLowerCase(), EXTENSIONS.toArray(new String[0])); } } // check for watched status from Trakt.TV if (watchTraktTV) { // always increase file counter fileWatchedCount++; long traktWatchedDate = 0; if (movie.isTVShow()) { // get watched date for episode traktWatchedDate = watchedDate(trackedShow, movie, mf); } else { // get watched date for movie traktWatchedDate = watchedDate(trackedMovie, movie); } // watched date only set if movie/episode has been watched if (traktWatchedDate > 0) { fileWatched = Boolean.TRUE; fileWatchedDate = Math.max(traktWatchedDate, fileWatchedDate); } } else if (WATCH_TRAKTTV || movie.isExtra()) { // the file watch status has not changed if watching is disabled // due to preLoad error or if movie is an extra fileWatched = mf.isWatched(); } if (mf.setWatched(fileWatched, fileWatchedDate)) { movieFileWatchChanged = Boolean.TRUE; } } // as soon as there is an unwatched file, the whole movie becomes unwatched movieWatchedFile = movieWatchedFile && mf.isWatched(); } if (movieFileWatchChanged) { // set dirty flag if movie file watched status has changed movie.setDirty(DirtyFlag.WATCHED, Boolean.TRUE); } // change the watched status if: // - we found at least 1 file and watched file has change // - no files are found and the movie is watched if ((fileWatchedCount > 0 && movie.isWatchedFile() != movieWatchedFile) || (fileWatchedCount == 0 && movie.isWatchedFile())) { movie.setWatchedFile(movieWatchedFile); movie.setDirty(DirtyFlag.WATCHED, Boolean.TRUE); // Issue 1949 - Force the artwork to be overwritten (those that can have icons on them) movie.setDirty(DirtyFlag.POSTER, Boolean.TRUE); movie.setDirty(DirtyFlag.BANNER, Boolean.TRUE); returnStatus = Boolean.TRUE; } // build the final return status returnStatus |= movieFileWatchChanged; if (returnStatus) { LOG.debug("The video has one or more files that have changed status."); } return returnStatus; }
From source file:com.zkai.xxbs.shiro.Servlets.java
/** * URI???/*from w w w .j a va 2s . c o m*/ * @throws Exception */ public static boolean isStaticFile(String uri) { if (staticFiles == null) { try { throw new Exception( "app.properties??web.staticFile??\n#???\n" + "web.staticFile=.css,.js,.png,.jpg,.gif,.jpeg,.bmp,.ico,.swf,.psd,.htc,.crx,.xpi,.exe,.ipa,.apk"); } catch (Exception e) { e.printStackTrace(); } } if (StringUtils.endsWithAny(uri, staticFiles) && !StringUtils.endsWithAny(uri, urlSuffix) && !StringUtils.endsWithAny(uri, ".jsp") && !StringUtils.endsWithAny(uri, ".java")) { return true; } return false; }
From source file:de.aschoerk.javaconv.RustDumpVisitor.java
private String removePlusAndSuffix(String value, CharSequence... searchStrings) { if (value.startsWith("+")) { value = value.substring(1);// w w w . ja va2 s. c o m } if (value.startsWith(".")) { value = "0" + value; } if (StringUtils.endsWithAny(value, searchStrings)) { value = value.substring(0, value.length() - 1); } if (value.endsWith(".")) { value = value + "0"; } value = value.replace("d.", "."); return value; }
From source file:architecture.ee.web.community.spring.controller.DisplayController.java
protected String getFreemarkerView(String view, String defaultView) { String viewToUse = StringUtils.defaultString(view, defaultView); if (StringUtils.endsWithAny(viewToUse, "ftl")) { viewToUse = StringUtils.removeEndIgnoreCase(viewToUse, ".ftl"); }//w w w .j a va2s. co m return viewToUse; }
From source file:de.micromata.genome.gwiki.controls.GWikiWeditServiceActionBean.java
private void fillImageLinks(String querystring, JsonArray array) { String pageType = ""; String queryexpr = SearchUtils.createLinkExpression(querystring, true, pageType); SearchQuery query = new SearchQuery(queryexpr, wikiContext.getWikiWeb()); query.setMaxCount(1000);/*from w w w .j a v a 2 s . c o m*/ QueryResult qr = filter(query); for (SearchResult sr : qr.getResults()) { String pageid = sr.getPageId(); if (StringUtils.endsWithAny(pageid, new String[] { ".png", ".jpeg", ".PNG", ".JPEG", ".JPG", ".jpg" }) == false) { continue; } String title = wikiContext.getTranslatedProp(sr.getElementInfo().getTitle()); array.add(JsonBuilder.map("key", sr.getPageId(), "url", sr.getPageId(), "label", title, "title", title, "onInsert", "gwedit_ac_insert_imagelink")); } }
From source file:com.moviejukebox.plugin.FilmwebPlugin.java
@Override public boolean scanNFO(String nfo, Movie movie) { // Always scan for IMDb id, look for ttXXXXXX super.scanNFO(nfo, movie); // ID already present if (StringTools.isValidString(movie.getId(FILMWEB_PLUGIN_ID))) { return Boolean.TRUE; }//from w ww. ja v a2s. co m LOG.debug("Scanning NFO for filmweb url"); Matcher m = NFO_PATTERN.matcher(nfo); while (m.find()) { String url = m.group(); // Check to see that the URL isn't a picture if (!StringUtils.endsWithAny(url, new String[] { ".jpg", ".jpeg", ".gif", ".png", ".bmp" })) { movie.setId(FILMWEB_PLUGIN_ID, url); LOG.debug("Filmweb url found in NFO = {}", url); return Boolean.TRUE; } } LOG.debug("No filmweb url found in NFO"); return Boolean.FALSE; }
From source file:org.exist.collections.triggers.XQueryStartupTrigger.java
/** * List all xquery scripts in /db/system/autostart * * @param broker The exist-db broker/*from www .ja v a 2 s. c o m*/ * @return List of xquery scripts */ private List<String> getScriptsInStartupCollection(DBBroker broker) { // Return values List<String> paths = new ArrayList<>(); XmldbURI uri = XmldbURI.create(AUTOSTART_COLLECTION); Collection collection = null; try { collection = broker.openCollection(uri, Lock.READ_LOCK); if (collection == null) { LOG.debug(String.format("Collection '%s' not found.", AUTOSTART_COLLECTION)); createAutostartCollection(broker); } else { LOG.debug(String.format("Scanning collection '%s'.", AUTOSTART_COLLECTION)); if (isPermissionsOK(collection)) { Iterator<DocumentImpl> documents = collection.iteratorNoLock(broker); while (documents.hasNext()) { DocumentImpl document = documents.next(); String docPath = document.getURI().toString(); if (isPermissionsOK(document)) { if (StringUtils.endsWithAny(docPath, XQUERY_EXTENSIONS)) { paths.add(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + docPath); } else { LOG.error(String.format("Skipped document '%s', not an xquery script.", docPath)); } } else { LOG.error(String.format("Document %s should be owned by DBA, mode %s, mimetype %s", docPath, Permission.DEFAULT_SYSTEM_SECURITY_COLLECTION_PERM, REQUIRED_MIMETYPE)); } } } else { LOG.error(String.format("Collection %s should be owned by SYSTEM/DBA, mode %s.", AUTOSTART_COLLECTION, Permission.DEFAULT_SYSTEM_SECURITY_COLLECTION_PERM)); } } LOG.debug(String.format("Found %s xquery scripts in '%s'.", paths.size(), AUTOSTART_COLLECTION)); } catch (PermissionDeniedException ex) { LOG.error(ex.getMessage()); } finally { // Clean up resources if (collection != null) { collection.release(Lock.READ_LOCK); } } return paths; }
From source file:org.exist.mongodb.xquery.gridfs.Store.java
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from w w w. jav a 2 s .c om // Verify clientid and get client String mongodbClientId = args[0].itemAt(0).getStringValue(); MongodbClientStore.getInstance().validate(mongodbClientId); MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId); // Get parameters String dbname = args[1].itemAt(0).getStringValue(); String bucket = args[2].itemAt(0).getStringValue(); String documentName = args[3].itemAt(0).getStringValue(); String contentType = getMimeType(args[4], documentName); LOG.info(String.format("Storing document %s (%s)", documentName, contentType)); // Actual content: File object, doc() element, base64... Item content = args[5].itemAt(0); // Get database DB db = client.getDB(dbname); // Creates a GridFS instance for the specified bucket GridFS gfs = new GridFS(db, bucket); // Create file GridFSInputFile gfsFile = gfs.createFile(); // Set meta data gfsFile.setFilename(documentName); gfsFile.setContentType(contentType); StopWatch stopWatch = new StopWatch(); // Write data if (StringUtils.endsWithAny(documentName, nonCompressables)) { writeRaw(gfsFile, stopWatch, content); } else { int dataType = content.getType(); writeCompressed(gfsFile, stopWatch, content, dataType); } LOG.info(String.format("serialization time: %s", stopWatch.getTime())); // Report identifier return new StringValue(gfsFile.getId().toString()); } catch (XPathException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, ex.getMessage(), ex); } catch (MongoException ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, GridfsModule.GRFS0002, ex.getMessage()); } catch (Throwable ex) { LOG.error(ex.getMessage(), ex); throw new XPathException(this, GridfsModule.GRFS0003, ex.getMessage()); } }