List of usage examples for org.apache.commons.lang3 StringUtils endsWithIgnoreCase
public static boolean endsWithIgnoreCase(final CharSequence str, final CharSequence suffix)
Case insensitive check if a CharSequence ends with a specified suffix.
null s are handled without exceptions.
From source file:com.nridge.connector.ws.con_ws.task.TaskConnectorWS.java
/** * If this task is scheduled to be executed (e.g. its run/test * name matches the command line arguments), then this method * is guaranteed to be executed prior to the thread being * started./* w ww. j av a 2 s.co m*/ * * @param anAppMgr Application manager instance. * * @throws com.nridge.core.base.std.NSException Application specific exception. */ @Override public void init(AppMgr anAppMgr) throws NSException { mAppMgr = anAppMgr; Logger appLogger = mAppMgr.getLogger(this, "init"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); mIsAlive = new AtomicBoolean(false); // Write our configuration properties for troubleshooting purposes. mAppMgr.writeCfgProperties(appLogger); // Assign our between crawl sleep time. mSleepTimeInMinutes = 15; String sleepTimeString = mAppMgr.getString(Constants.CFG_PROPERTY_PREFIX + ".run_sleep_between"); if (StringUtils.endsWithIgnoreCase(sleepTimeString, "m")) { String minuteString = StringUtils.stripEnd(sleepTimeString, "m"); if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) mSleepTimeInMinutes = Integer.parseInt(minuteString); } else if ((StringUtils.isNotEmpty(sleepTimeString)) && (StringUtils.isNumeric(sleepTimeString))) mSleepTimeInMinutes = Integer.parseInt(sleepTimeString); // The extract queue holds documents that have been extracted from the content source. int extractQueueSize = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".extract.queue_length", Connector.QUEUE_LENGTH_DEFAULT); BlockingQueue extractQueue = new ArrayBlockingQueue(extractQueueSize); mAppMgr.addProperty(Connector.QUEUE_EXTRACT_NAME, extractQueue); // The transform queue holds documents that have been transformed after extraction. int transformQueueSize = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".transform.queue_length", Connector.QUEUE_LENGTH_DEFAULT); BlockingQueue transformQueue = new ArrayBlockingQueue(transformQueueSize); mAppMgr.addProperty(Connector.QUEUE_TRANSFORM_NAME, transformQueue); // The publish queue holds documents that have been published to the search index. int publishQueueSize = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".publish.queue_length", Connector.QUEUE_LENGTH_DEFAULT); BlockingQueue publishQueue = new ArrayBlockingQueue(publishQueueSize); mAppMgr.addProperty(Connector.QUEUE_PUBLISH_NAME, publishQueue); // Load our schema definition from the data source folder. DataBag schemaBag; String schemaPathFileName = String.format("%s%c%s", mAppMgr.getString(mAppMgr.APP_PROPERTY_DS_PATH), File.separatorChar, Constants.SCHEMA_FILE_NAME); DataBagXML dataBagXML = new DataBagXML(); try { dataBagXML.load(schemaPathFileName); schemaBag = dataBagXML.getBag(); } catch (Exception e) { String msgStr = String.format("%s: %s", schemaPathFileName, e.getMessage()); appLogger.error(msgStr); appLogger.warn("Using internal document schema as alternative - data source schema ignored."); schemaBag = schemaBag(); } mAppMgr.addProperty(Connector.PROPERTY_SCHEMA_NAME, schemaBag); // Create our mail manager instance. MailManager mailManager = new MailManager(mAppMgr, Constants.CFG_PROPERTY_PREFIX + ".mail"); mAppMgr.addProperty(Connector.PROPERTY_MAIL_NAME, mailManager); // Create/Load service time tracking file. mServiceTimer = new ServiceTimer(mAppMgr); mServiceTimer.setPropertyPrefix(Constants.CFG_PROPERTY_PREFIX); String stPathFileName = mServiceTimer.createServicePathFileName(); File stFile = new File(stPathFileName); if (stFile.exists()) mServiceTimer.load(); // Is there an explicit list of phases to execute? String propertyName = Constants.CFG_PROPERTY_PREFIX + ".phase_list"; String phaseProperty = mAppMgr.getString(propertyName); if (StringUtils.isNotEmpty(phaseProperty)) { if (mAppMgr.isPropertyMultiValue(propertyName)) mPhases = mAppMgr.getStringArray(propertyName); else { mPhases = new String[1]; mPhases[0] = phaseProperty; } } // Load and assign our crawl follow and ignore instances. CrawlFollow crawlFollow = new CrawlFollow(mAppMgr); crawlFollow.setCfgPropertyPrefix(Constants.CFG_PROPERTY_PREFIX + ".extract"); try { crawlFollow.load(); } catch (NSException | IOException e) { String msgStr = String.format("Crawl Follow: %s", e.getMessage()); appLogger.error(msgStr); } mAppMgr.addProperty(Constants.PROPERTY_CRAWL_FOLLOW, crawlFollow); CrawlIgnore crawlIgnore = new CrawlIgnore(mAppMgr); crawlIgnore.setCfgPropertyPrefix(Constants.CFG_PROPERTY_PREFIX + ".extract"); try { crawlIgnore.load(); } catch (NSException | IOException e) { String msgStr = String.format("Crawl Ignore: %s", e.getMessage()); appLogger.error(msgStr); } mAppMgr.addProperty(Constants.PROPERTY_CRAWL_IGNORE, crawlIgnore); // Clear out crawl queue from previous service sessions. CrawlQueue crawlQueue = new CrawlQueue(mAppMgr); crawlQueue.reset(); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); mIsAlive.set(true); }
From source file:com.nridge.connector.fs.con_fs.task.TaskConnectorFS.java
/** * If this task is scheduled to be executed (e.g. its run/test * name matches the command line arguments), then this method * is guaranteed to be executed prior to the thread being * started.// w ww. ja va 2 s . co m * * @param anAppMgr Application manager instance. * * @throws com.nridge.core.base.std.NSException Application specific exception. */ @Override public void init(AppMgr anAppMgr) throws NSException { mAppMgr = anAppMgr; Logger appLogger = mAppMgr.getLogger(this, "init"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); mIsAlive = new AtomicBoolean(false); // Write our configuration properties for troubleshooting purposes. mAppMgr.writeCfgProperties(appLogger); // Assign our between crawl sleep time. mSleepTimeInMinutes = 15; String sleepTimeString = mAppMgr.getString(Constants.CFG_PROPERTY_PREFIX + ".run_sleep_between"); if (StringUtils.endsWithIgnoreCase(sleepTimeString, "m")) { String minuteString = StringUtils.stripEnd(sleepTimeString, "m"); if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) mSleepTimeInMinutes = Integer.parseInt(minuteString); } else if ((StringUtils.isNotEmpty(sleepTimeString)) && (StringUtils.isNumeric(sleepTimeString))) mSleepTimeInMinutes = Integer.parseInt(sleepTimeString); // The extract queue holds documents that have been extracted from the content source. int extractQueueSize = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".extract.queue_length", Connector.QUEUE_LENGTH_DEFAULT); BlockingQueue extractQueue = new ArrayBlockingQueue(extractQueueSize); mAppMgr.addProperty(Connector.QUEUE_EXTRACT_NAME, extractQueue); // The transform queue holds documents that have been transformed after extraction. int transformQueueSize = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".transform.queue_length", Connector.QUEUE_LENGTH_DEFAULT); BlockingQueue transformQueue = new ArrayBlockingQueue(transformQueueSize); mAppMgr.addProperty(Connector.QUEUE_TRANSFORM_NAME, transformQueue); // The publish queue holds documents that have been published to the search index. int publishQueueSize = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".publish.queue_length", Connector.QUEUE_LENGTH_DEFAULT); BlockingQueue publishQueue = new ArrayBlockingQueue(publishQueueSize); mAppMgr.addProperty(Connector.QUEUE_PUBLISH_NAME, publishQueue); // Load our schema definition from the data source folder. DataBag schemaBag; String schemaPathFileName = String.format("%s%c%s", mAppMgr.getString(mAppMgr.APP_PROPERTY_DS_PATH), File.separatorChar, Constants.SCHEMA_FILE_NAME); DataBagXML dataBagXML = new DataBagXML(); try { dataBagXML.load(schemaPathFileName); schemaBag = dataBagXML.getBag(); } catch (Exception e) { String msgStr = String.format("%s: %s", schemaPathFileName, e.getMessage()); appLogger.error(msgStr); appLogger.warn("Using internal document schema as alternative - data source schema ignored."); schemaBag = schemaBag(); } mAppMgr.addProperty(Connector.PROPERTY_SCHEMA_NAME, schemaBag); // Create our mail manager instance. MailManager mailManager = new MailManager(mAppMgr, Constants.CFG_PROPERTY_PREFIX + ".mail"); mAppMgr.addProperty(Connector.PROPERTY_MAIL_NAME, mailManager); // Create/Load service time tracking file. mServiceTimer = new ServiceTimer(mAppMgr); mServiceTimer.setPropertyPrefix(Constants.CFG_PROPERTY_PREFIX); String stPathFileName = mServiceTimer.createServicePathFileName(); File stFile = new File(stPathFileName); if (stFile.exists()) mServiceTimer.load(); // Is there an explicit list of phases to execute? String propertyName = Constants.CFG_PROPERTY_PREFIX + ".phase_list"; String phaseProperty = mAppMgr.getString(propertyName); if (StringUtils.isNotEmpty(phaseProperty)) { if (mAppMgr.isPropertyMultiValue(propertyName)) mPhases = mAppMgr.getStringArray(propertyName); else { mPhases = new String[1]; mPhases[0] = phaseProperty; } } // Clear out crawl queue from previous service sessions. CrawlQueue crawlQueue = new CrawlQueue(mAppMgr); crawlQueue.reset(); // Create Restlet server instance. int portNumber = mAppMgr.getInt(Constants.CFG_PROPERTY_PREFIX + ".restlet.port_number", Constants.APPLICATION_PORT_NUMBER_DEFAULT); RestletApplication restletApplication = new RestletApplication(mAppMgr); appLogger.info("Starting Restlet Server."); mServer = new Server(Protocol.HTTP, portNumber, restletApplication); try { mServer.start(); } catch (Exception e) { appLogger.error("Restlet Server (start): " + e.getMessage(), e); throw new NSException(e.getMessage()); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); mIsAlive.set(true); }
From source file:com.qcadoo.mes.workPlans.WorkPlansServiceImpl.java
private boolean checkAttachmentExtension(final String attachementPathValue) { if (StringUtils.isBlank(attachementPathValue)) { return true; }// www . ja v a 2 s .c om // TODO DEV_TEAM after upgrade Apache's commons-lang this loop // may be replaced with StringUtils.endsWithAny(attachementPathValue.toLowerCase(), WorkPlansConstants.FILE_EXTENSIONS) for (String allowedFileExtension : WorkPlansConstants.FILE_EXTENSIONS) { if (StringUtils.endsWithIgnoreCase(attachementPathValue, '.' + allowedFileExtension)) { return true; } } return false; }
From source file:architecture.ee.web.attachment.DefaultAttachmentManager.java
protected File getThumbnailFromCacheIfExist(Attachment attach, int width, int height) throws IOException { log.debug("thumbnail generation " + width + "x" + height); File dir = getAttachmentCacheDir(); File file = new File(dir, toThumbnailFilename(attach, width, height)); File originalFile = getAttachmentFromCacheIfExist(attach); log.debug("source: " + originalFile.getAbsoluteFile() + ", " + originalFile.length()); log.debug("thumbnail:" + file.getAbsoluteFile()); if (file.exists() && file.length() > 0) { attach.setThumbnailSize((int) file.length()); return file; }/*from ww w. j a v a2 s . c o m*/ if (StringUtils.endsWithIgnoreCase(attach.getContentType(), "pdf")) { PDDocument document = PDDocument.load(originalFile); List<PDPage> pages = document.getDocumentCatalog().getAllPages(); PDPage page = pages.get(0); BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 72); ImageIO.write(Thumbnails.of(image).size(width, height).asBufferedImage(), "png", file); attach.setThumbnailSize((int) file.length()); return file; } else if (StringUtils.startsWithIgnoreCase(attach.getContentType(), "image")) { BufferedImage originalImage = ImageIO.read(originalFile); if (originalImage.getHeight() < height || originalImage.getWidth() < width) { attach.setThumbnailSize(0); return originalFile; } BufferedImage thumbnail = Thumbnails.of(originalImage).size(width, height).asBufferedImage(); ImageIO.write(thumbnail, "png", file); attach.setThumbnailSize((int) file.length()); return file; } return null; }
From source file:forge.gui.ImportSourceAnalyzer.java
private void analyzeGauntletDataDir(final File root) { analyzeDir(root, new Analyzer() { @Override/*from w w w. ja v a2 s .c o m*/ void onFile(final File file) { // find *.dat files, but exclude LOCKED_* final String filename = file.getName(); if (StringUtils.endsWithIgnoreCase(filename, ".dat") && !filename.startsWith("LOCKED_")) { final File targetFile = new File(ForgeConstants.GAUNTLET_DIR.userPrefLoc, lcaseExt(filename)); if (!file.equals(targetFile)) { cb.addOp(OpType.GAUNTLET_DATA, file, targetFile); } } } }); }
From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java
private static OpType mapOpType(String opType) { try {// www . j a v a2 s .co m return OpType.valueOf(opType.toUpperCase()); } catch (IllegalArgumentException exc) { if (opType.equalsIgnoreCase("END") || opType.equalsIgnoreCase("FINISH") // NON-NLS || opType.equalsIgnoreCase("DISCONNECT") || opType.equalsIgnoreCase("COMMIT") // NON-NLS || opType.equalsIgnoreCase("BACK")) { // NON-NLS return OpType.STOP; } if (opType.equalsIgnoreCase("CONNECT") || opType.equalsIgnoreCase("BEGIN")) { // NON-NLS return OpType.START; } if (opType.equalsIgnoreCase("CALLBACK") || opType.equalsIgnoreCase("GET")) { // NON-NLS return OpType.RECEIVE; } if (opType.equalsIgnoreCase("PUT")) { // NON-NLS return OpType.SEND; } if (StringUtils.endsWithIgnoreCase(opType, "OPEN")) { // NON-NLS return OpType.OPEN; } if (StringUtils.endsWithIgnoreCase(opType, "CLOSE")) { // NON-NLS return OpType.CLOSE; } } return OpType.OTHER; }
From source file:forge.gui.ImportSourceAnalyzer.java
private void analyzeLayoutsDir(final File root) { analyzeDir(root, new Analyzer() { @Override/*w w w . java 2 s .c o m*/ void onFile(final File file) { // find *_preferred.xml files final String filename = file.getName(); if (StringUtils.endsWithIgnoreCase(filename, "_preferred.xml")) { final File targetFile = new File(ForgeConstants.USER_PREFS_DIR, file.getName().toLowerCase(Locale.ENGLISH).replace("_preferred", "")); cb.addOp(OpType.PREFERENCE_FILE, file, targetFile); } } }); }
From source file:com.moviejukebox.plugin.ImdbPlugin.java
/** * Scan IMDB HTML page for the specified movie *//*from www .j av a2 s . c o m*/ private boolean updateImdbMediaInfo(Movie movie) { String imdbID = movie.getId(IMDB_PLUGIN_ID); if (!imdbID.startsWith("tt")) { imdbID = "tt" + imdbID; // Correct the ID if it's wrong movie.setId(IMDB_PLUGIN_ID, imdbID); } String xml = ImdbPlugin.this.getImdbUrl(movie); // Add the combined tag to the end of the request if required if (fullInfo) { xml += "combined"; } xml = getImdbData(xml); if (!Movie.TYPE_TVSHOW.equals(movie.getMovieType()) && (xml.contains("\"tv-extra\"") || xml.contains("\"tv-series-series\""))) { movie.setMovieType(Movie.TYPE_TVSHOW); return Boolean.FALSE; } // We can work out if this is the new site by looking for " - IMDb" at the end of the title String title = HTMLTools.extractTag(xml, "<title>"); if (!Movie.TYPE_TVSHOW.equals(movie.getMovieType()) && title.contains("(TV Series")) { movie.setMovieType(Movie.TYPE_TVSHOW); return Boolean.FALSE; } // Correct the title if "imdb" found if (StringUtils.endsWithIgnoreCase(title, " - imdb")) { title = title.substring(0, title.length() - 7); } else if (StringUtils.startsWithIgnoreCase(title, "imdb - ")) { title = title.substring(7); } // Remove the (VG) or (V) tags from the title title = title.replaceAll(" \\([VG|V]\\)$", ""); //String yearPattern = "(?i).\\((?:TV.|VIDEO.)?(\\d{4})(?:/[^\\)]+)?\\)"; String yearPattern = "(?i).\\((?:TV.|VIDEO.)?(\\d{4})"; Pattern pattern = Pattern.compile(yearPattern, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(title); if (matcher.find()) { // If we've found a year, set it in the movie if (OverrideTools.checkOverwriteYear(movie, IMDB_PLUGIN_ID)) { movie.setYear(matcher.group(1), IMDB_PLUGIN_ID); } // Remove the year from the title title = title.substring(0, title.indexOf(matcher.group(0))); } if (OverrideTools.checkOverwriteTitle(movie, IMDB_PLUGIN_ID)) { movie.setTitle(title, IMDB_PLUGIN_ID); } if (OverrideTools.checkOverwriteOriginalTitle(movie, IMDB_PLUGIN_ID)) { String originalTitle = title; if (xml.contains("<span class=\"title-extra\">")) { originalTitle = HTMLTools.extractTag(xml, "<span class=\"title-extra\">", "</span>"); if (originalTitle.contains("(original title)")) { originalTitle = originalTitle.replace(" <i>(original title)</i>", ""); } else { originalTitle = title; } } movie.setOriginalTitle(originalTitle, IMDB_PLUGIN_ID); } // Update the movie information updateInfo(movie, xml); // update common values updateInfoCommon(movie, xml); if (scrapeAwards) { updateAwards(movie); // Issue 1901: Awards } if (scrapeBusiness) { updateBusiness(movie); // Issue 2012: Financial information about movie } if (scrapeTrivia) { updateTrivia(movie); // Issue 2013: Add trivia } // TODO: Move this check out of here, it doesn't belong. if (downloadFanart && isNotValidString(movie.getFanartURL())) { movie.setFanartURL(getFanartURL(movie)); if (isValidString(movie.getFanartURL())) { movie.setFanartFilename(movie.getBaseName() + fanartToken + "." + fanartExtension); } } // always true return Boolean.TRUE; }
From source file:com.hybris.mobile.activity.AbstractProductDetailActivity.java
@Override public void onReceiveResult(RESTLoaderResponse restLoaderResponse, WebserviceMethodEnums webserviceEnumMethod) { if (restLoaderResponse.getCode() == RESTLoaderResponse.SUCCESS) { String jsonResult = restLoaderResponse.getData(); switch (webserviceEnumMethod) { case METHOD_ADD_PRODUCT_TO_CART: ProductStockLevelStatus productStockLevelStatus = JsonUtils.fromJson(jsonResult, ProductStockLevelStatus.class); String errMsgToShow = null; if (StringUtils.equals(productStockLevelStatus.getStatusCode(), "success")) { // Repopulate the product String[] options = { InternalConstants.PRODUCT_OPTION_PROMOTIONS }; populateProduct(mProduct.getCode(), options); MenuUtil.setCartEmpty(false); } else { showLoadingDialog(false); errMsgToShow = getString(R.string.productDetails_couldNotAddToCart); if (StringUtils.endsWithIgnoreCase(productStockLevelStatus.getStatusCode(), "noStock")) { errMsgToShow += " (" + getString(R.string.stock_details_out_of_stock) + ")"; } else { errMsgToShow += " (" + productStockLevelStatus.getStatusCode() + ")"; }/*ww w.ja v a 2 s .c o m*/ Toast.makeText(getApplicationContext(), errMsgToShow, Toast.LENGTH_SHORT).show(); invalidateOptionsMenu(); } break; case METHOD_GET_PRODUCT_WITH_CODE: showLoadingDialog(false); Product product = JsonUtils.fromJson(jsonResult, Product.class); product.populate(); if (mProduct == null) { mProduct = product; } else { mProduct.addDetails(product); } updateUI(); default: break; } } else if (restLoaderResponse.getCode() == RESTLoaderResponse.ERROR) { switch (webserviceEnumMethod) { case METHOD_GET_PRODUCT_WITH_CODE: showLoadingDialog(false); Toast.makeText(getApplicationContext(), R.string.error_product_not_found, Toast.LENGTH_LONG).show(); break; default: break; } } }
From source file:forge.gui.ImportSourceAnalyzer.java
private void analyzeCardPicsSetDir(final File root) { if (null == cardFileNamesBySet) { cardFileNamesBySet = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (final CardEdition ce : FModel.getMagicDb().getEditions()) { final Map<String, String> cardFileNames = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); final Predicate<PaperCard> filter = IPaperCard.Predicates.printedInSet(ce.getCode()); addSetCards(cardFileNames, FModel.getMagicDb().getCommonCards().getAllCards(), filter); addSetCards(cardFileNames, FModel.getMagicDb().getVariantCards().getAllCards(), filter); cardFileNamesBySet.put(ce.getCode2(), cardFileNames); }//from w w w . ja v a2 s . c o m // planar cards now don't have the ".full" part in their filenames nameUpdates = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); final Predicate<PaperCard> predPlanes = new Predicate<PaperCard>() { @Override public boolean apply(final PaperCard arg0) { return arg0.getRules().getType().isPlane() || arg0.getRules().getType().isPhenomenon(); } }; for (final PaperCard c : Iterables.filter(FModel.getMagicDb().getVariantCards().getAllCards(), predPlanes)) { String baseName = ImageUtil.getImageKey(c, false, true); nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg"); if (ImageUtil.hasBackFacePicture(c)) { baseName = ImageUtil.getImageKey(c, true, true); nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg"); } } } final CardEdition.Collection editions = FModel.getMagicDb().getEditions(); final String editionCode = root.getName(); final CardEdition edition = editions.get(editionCode); if (null == edition) { // not a valid set name, skip numFilesAnalyzed += countFiles(root); return; } final String editionCode2 = edition.getCode2(); final Map<String, String> validFilenames = cardFileNamesBySet.get(editionCode2); analyzeListedDir(root, ForgeConstants.CACHE_CARD_PICS_DIR, new ListedAnalyzer() { @Override public String map(String filename) { filename = editionCode2 + "/" + filename; if (nameUpdates.containsKey(filename)) { filename = nameUpdates.get(filename); } if (validFilenames.containsKey(filename)) { return validFilenames.get(filename); } else if (StringUtils.endsWithIgnoreCase(filename, ".jpg") || StringUtils.endsWithIgnoreCase(filename, ".png")) { return filename; } return null; } @Override public OpType getOpType(final String filename) { return validFilenames.containsKey(filename) ? OpType.SET_CARD_PIC : OpType.POSSIBLE_SET_CARD_PIC; } }); }