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:net.theblackchamber.crypto.implementations.SecureProperties.java
/** * Utility method which will determine if a requested property needs to be * encrypted. If property key ends in -unencrypted and the encryption * provider is configured this method will return the encrypted property * value. If the key does not include -unencrypted then the property value * will be returned./*from w w w . j a v a 2s .c om*/ * * @param key * @param property * @throws RuntimeCryptoException * If not encryption provider is configured. * @return */ private String attemptEncryption(String key, String property) { if (StringUtils.endsWithIgnoreCase(key, UNENCRYPTED_SUFFIX)) { if (encryptionProvider == null) throw new RuntimeCryptoException("No encryption provider configured"); return encryptionProvider.encrypt(property); } else { return property; } }
From source file:nz.net.orcon.kanban.tools.ComplexDateConverter.java
protected boolean containsDays(String formula) { return StringUtils.endsWithIgnoreCase(formula, DAYS); }
From source file:org.asqatasun.rules.elementchecker.text.TextEndsWithChecker.java
/** * /*from ww w .j ava 2 s .c o m*/ * @param element * @param elementText * @return failed whether the text belongs to a blacklist, need_more_info * instead */ private TestSolution checkTextElementEndsWithExtension(Element element, String elementText) { // the test is made through the getter to force the initialisation if (element == null || elementText == null || CollectionUtils.isEmpty(getExtensions())) { return TestSolution.NOT_APPLICABLE; } for (String extension : extensions) { if (StringUtils.endsWithIgnoreCase(elementText, extension)) { addSourceCodeRemark(getFailureSolution(), element, textEndsWithMessageCode); return getFailureSolution(); } } if (!getSuccessSolution().equals(TestSolution.PASSED) && !getSuccessSolution().equals(TestSolution.NOT_APPLICABLE)) { addSourceCodeRemark(getSuccessSolution(), element, textNotEndsWithMessageCode); } return getSuccessSolution(); }
From source file:org.auraframework.http.AuraResourceServlet.java
private boolean isAppRequest(HttpServletRequest request) { String type = request.getParameter(AuraResourceRewriteFilter.TYPE_PARAM); if (StringUtils.endsWithIgnoreCase(type, "app")) { return true; }//from w ww . jav a 2s. co m return false; }
From source file:org.auraframework.impl.clientlibrary.ClientLibraryDefImpl.java
/** * Client library must have name, type, and parent descriptor. * * @throws QuickFixException quick fix/* w ww .j a va 2 s . c o m*/ */ @Override public void validateDefinition() throws QuickFixException { if (StringUtils.isBlank(this.name) && StringUtils.isBlank(this.url)) { throw new InvalidDefinitionException("Must have either a name or url", getLocation()); } if (this.type == null) { throw new InvalidDefinitionException("Missing required type", getLocation()); } if (this.parentDescriptor == null) { throw new InvalidDefinitionException("No parent for ClientLibraryDef", getLocation()); } if (StringUtils.isNotBlank(this.url)) { if (StringUtils.startsWithIgnoreCase(this.url, DefDescriptor.CSS_PREFIX + "://") || StringUtils.startsWithIgnoreCase(this.url, DefDescriptor.JAVASCRIPT_PREFIX + "://")) { if (!StringUtils.startsWithIgnoreCase(this.url, this.type.toString())) { throw new InvalidDefinitionException("ResourceDef type must match library type", getLocation()); } DefDescriptor<ResourceDef> resourceDesc = DefDescriptorImpl.getInstance(this.url, ResourceDef.class); if (!resourceDesc.exists()) { throw new InvalidDefinitionException("No resource named " + this.url + " found", getLocation()); } } else { // must have the same file extension as type if (!StringUtils.endsWithIgnoreCase(this.url, "." + this.type.toString())) { throw new InvalidDefinitionException("Url file extension must match type", getLocation()); } } } }
From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryHelper.java
public boolean createSiteCloneRemoteGitRepo(String siteId, String sandboxBranch, String remoteName, String remoteUrl, String remoteBranch, boolean singleBranch, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) throws InvalidRemoteRepositoryException, InvalidRemoteRepositoryCredentialsException, RemoteRepositoryNotFoundException, ServiceException { boolean toRet = true; // prepare a new folder for the cloned repository Path siteSandboxPath = buildRepoPath(SANDBOX, siteId); File localPath = siteSandboxPath.toFile(); localPath.delete();/*from www . j av a2 s .c o m*/ logger.debug("Add user credentials if provided"); // then clone logger.debug("Cloning from " + remoteUrl + " to " + localPath); CloneCommand cloneCommand = Git.cloneRepository(); Git cloneResult = null; try { final Path tempKey = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); switch (authenticationType) { case RemoteRepository.AuthenticationType.NONE: logger.debug("No authentication"); break; case RemoteRepository.AuthenticationType.BASIC: logger.debug("Basic authentication"); cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider(remoteUsername, remotePassword)); break; case RemoteRepository.AuthenticationType.TOKEN: logger.debug("Token based authentication"); cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider(remoteToken, StringUtils.EMPTY)); break; case RemoteRepository.AuthenticationType.PRIVATE_KEY: logger.debug("Private key authentication"); tempKey.toFile().deleteOnExit(); cloneCommand.setTransportConfigCallback(new TransportConfigCallback() { @Override public void configure(Transport transport) { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(getSshSessionFactory(remotePrivateKey, tempKey)); } }); break; default: throw new ServiceException("Unsupported authentication type " + authenticationType); } if (StringUtils.isNotEmpty(remoteBranch)) { cloneCommand.setBranch(remoteBranch); } cloneResult = cloneCommand.setURI(remoteUrl).setDirectory(localPath).setRemote(remoteName) .setCloneAllBranches(!singleBranch).call(); Files.deleteIfExists(tempKey); Repository sandboxRepo = checkIfCloneWasOk(cloneResult, remoteName, remoteUrl); sandboxRepo = optimizeRepository(sandboxRepo); sandboxes.put(siteId, sandboxRepo); } catch (InvalidRemoteException e) { logger.error("Invalid remote repository: " + remoteName + " (" + remoteUrl + ")", e); throw new InvalidRemoteRepositoryException( "Invalid remote repository: " + remoteName + " (" + remoteUrl + ")"); } catch (TransportException e) { if (StringUtils.endsWithIgnoreCase(e.getMessage(), "not authorized")) { logger.error("Bad credentials or read only repository: " + remoteName + " (" + remoteUrl + ")", e); throw new InvalidRemoteRepositoryCredentialsException("Bad credentials or read only repository: " + remoteName + " (" + remoteUrl + ") for username " + remoteUsername, e); } else { logger.error("Remote repository not found: " + remoteName + " (" + remoteUrl + ")", e); throw new RemoteRepositoryNotFoundException( "Remote repository not found: " + remoteName + " (" + remoteUrl + ")"); } } catch (GitAPIException | IOException e) { logger.error("Error while creating repository for site with path" + siteSandboxPath.toString(), e); toRet = false; } finally { if (cloneResult != null) { cloneResult.close(); } } return toRet; }
From source file:org.cryptomator.ui.MainApplication.java
void handleCommandLineArg(final MainController ctrl, String arg) { Path file = FileSystems.getDefault().getPath(arg); if (!Files.exists(file)) { try {/* w w w . j av a 2 s . co m*/ if (!Files.isDirectory(Files.createDirectories(file))) { return; } } catch (IOException e) { return; } // directory created. } else if (Files.isRegularFile(file)) { if (StringUtils.endsWithIgnoreCase(file.getFileName().toString(), Aes256Cryptor.MASTERKEY_FILE_EXT)) { file = file.getParent(); } else { // is a file, but not a masterkey file return; } } Path f = file; Platform.runLater(() -> { ctrl.addDirectory(f); ctrl.toFront(); }); }
From source file:org.eclipse.php.internal.core.ast.util.Util.java
/** * Returns true iff str.toLowerCase().endsWith(end.toLowerCase()) * implementation is not creating extra strings. * //from www. j ava 2 s . co m * @deprecated use org.apache.commons.lang3.StringUtils.endsWithIgnoreCase() */ public final static boolean endsWithIgnoreCase(String str, String end) { return StringUtils.endsWithIgnoreCase(str, end); }
From source file:org.gbif.ipt.action.manage.SourceAction.java
public String add() throws IOException { boolean replace = false; // Are we going to overwrite any source file? File ftest = (File) session.get(Constants.SESSION_FILE); if (ftest != null) { file = ftest;/* w w w . j av a 2 s . c om*/ fileFileName = (String) session.get(Constants.SESSION_FILE_NAME); fileContentType = (String) session.get(Constants.SESSION_FILE_CONTENT_TYPE); replace = true; } // new one if (file != null) { // uploaded a new file. Is it compressed? if (StringUtils.endsWithIgnoreCase(fileContentType, "zip") // application/zip || StringUtils.endsWithIgnoreCase(fileContentType, "gzip") || StringUtils.endsWithIgnoreCase(fileContentType, "compressed")) { // application/x-gzip try { File tmpDir = dataDir.tmpDir(); List<File> files = CompressionUtil.decompressFile(tmpDir, file); addActionMessage(getText("manage.source.compressed.files", new String[] { String.valueOf(files.size()) })); // validate if at least one file already exists to ask confirmation if (!replace) { for (File f : files) { if (resource.getSource(f.getName()) != null) { // Since FileUploadInterceptor removes the file once this action is executed, // the file need to be copied in the same directory. copyFileToOverwrite(); return INPUT; } } } // import each file. The last file will become the id parameter, // so the new page opens with that source for (File f : files) { addDataFile(f, f.getName()); } // manually remove any previous file in session and in temporal directory path removeSessionFile(); } catch (IOException e) { LOG.error(e); addActionError(getText("manage.source.filesystem.error", new String[] { e.getMessage() })); return ERROR; } catch (UnsupportedCompressionType e) { addActionError(getText("manage.source.unsupported.compression.format")); return ERROR; } catch (InvalidFilenameException e) { addActionError(getText("manage.source.invalidFileName")); return ERROR; } } else { // validate if file already exists to ask confirmation if (!replace && resource.getSource(fileFileName) != null) { // Since FileUploadInterceptor removes the file once this action is executed, // the file need to be copied in the same directory. copyFileToOverwrite(); return INPUT; } try { // treat as is - hopefully a simple text or excel file addDataFile(file, fileFileName); } catch (InvalidFilenameException e) { addActionError(getText("manage.source.invalidFileName")); return ERROR; } // manually remove any previous file in session and in temporal directory path removeSessionFile(); } } return SUCCESS; }
From source file:org.kuali.coeus.common.questionnaire.impl.answer.QuestionnaireAnswerServiceImpl.java
protected boolean isAnswerMatched(String condition, String parentAnswer, String conditionValue) { boolean valid = false; if (ConditionType.CONTAINS_TEXT.getCondition().equals(condition)) { valid = StringUtils.containsIgnoreCase(parentAnswer, conditionValue); } else if (ConditionType.BEGINS_WITH_TEXT.getCondition().equals(condition)) { valid = (StringUtils.startsWithIgnoreCase(parentAnswer, conditionValue)); } else if (ConditionType.ENDS_WITH_TEXT.getCondition().equals(condition)) { valid = (StringUtils.endsWithIgnoreCase(parentAnswer, conditionValue)); } else if (ConditionType.MATCH_TEXT.getCondition().equals(condition)) { valid = parentAnswer.equalsIgnoreCase(conditionValue); } else if (Integer.parseInt(condition) >= 5 && Integer.parseInt(condition) <= 10) { valid = (ConditionType.LESS_THAN_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) < Integer.parseInt(conditionValue))) || (ConditionType.LESS_THAN_OR_EQUALS_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) <= Integer.parseInt(conditionValue))) || (ConditionType.EQUALS_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) == Integer.parseInt(conditionValue))) || (ConditionType.NOT_EQUAL_TO_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) != Integer.parseInt(conditionValue))) || (ConditionType.GREATER_THAN_OR_EQUALS_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) >= Integer.parseInt(conditionValue))) || (ConditionType.GREATER_THAN_NUMBER.getCondition().equals(condition) && (Integer.parseInt(parentAnswer) > Integer.parseInt(conditionValue))); } else if (Integer.parseInt(condition) == 11 || Integer.parseInt(condition) == 12) { final DateFormat dateFormat = new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT_PATTERN); try {//from w w w . ja v a 2s . c o m Date date1 = new Date(dateFormat.parse(parentAnswer).getTime()); Date date2 = new Date(dateFormat.parse(conditionValue).getTime()); valid = (ConditionType.BEFORE_DATE.getCondition().equals(condition) && (date1.before(date2))) || (ConditionType.AFTER_DATE.getCondition().equals(condition) && (date1.after(date2))); } catch (Exception e) { } } return valid; }