Java Code Examples for org.apache.commons.lang3.StringUtils#endsWithIgnoreCase()

The following examples show how to use org.apache.commons.lang3.StringUtils#endsWithIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IOUtils.java    From codehelper.generator with Apache License 2.0 6 votes vote down vote up
@Nullable
    public static File matchOnlyOneFile(String directory, String subFileName){
        List<File> allSubFiles = IOUtils.getAllSubFiles(directory);
        if(!subFileName.startsWith(GenCodeResponseHelper.getPathSplitter())){
            subFileName = GenCodeResponseHelper.getPathSplitter() + subFileName;
        }
        allSubFiles = PojoUtil.avoidEmptyList(allSubFiles);
        File configFile = null;
        String targetDirPrefix = GenCodeResponseHelper.getPathSplitter() + "target" + GenCodeResponseHelper.getPathSplitter();
        for (File subFile : allSubFiles) {
            if(!StringUtils.containsIgnoreCase(subFile.getAbsolutePath(), targetDirPrefix)
                    && StringUtils.endsWithIgnoreCase(subFile.getAbsolutePath(),subFileName)){
                if(configFile == null){
                    configFile = subFile;
                }else{
                    //todo 调试的时候加上.
//                    return "NOT_ONLY";
                    throw new BizException("not only one file:" + subFileName);
                }
            }
        }
        if(configFile == null){
            return null;
        }
        return configFile;
    }
 
Example 2
Source File: RssLoadService.java    From torrssen2 with MIT License 6 votes vote down vote up
public boolean checkWatchListQuality(RssFeed rssFeed, WatchList watchList) {
    boolean checkQuality = false;

    if (StringUtils.isBlank(watchList.getQuality())) {
        watchList.setQuality("100p");
    }

    try {
        if (StringUtils.contains(watchList.getQuality(), ',')) {
            checkQuality = StringUtils.containsIgnoreCase(watchList.getQuality(), rssFeed.getRssQuality());

        } else if (StringUtils.endsWithIgnoreCase(watchList.getQuality(), "P+")) {
            checkQuality = Integer.parseInt(StringUtils.removeIgnoreCase(rssFeed.getRssQuality(), "P")) 
                >= Integer.parseInt(StringUtils.removeIgnoreCase(watchList.getQuality(), "P+"));
        } else {
            checkQuality = Integer.parseInt(StringUtils.removeIgnoreCase(rssFeed.getRssQuality(), "P")) 
                == Integer.parseInt(StringUtils.removeIgnoreCase(watchList.getQuality(), "P"));
        }
    } catch (NumberFormatException e) {
        log.error(e.getMessage());
    }

    return checkQuality;
}
 
Example 3
Source File: LoggerWrapper.java    From codehelper.generator with Apache License 2.0 6 votes vote down vote up
public static void saveAllLogs(String projectPath)  {
    try{
        String firstMatch = MapHelper.getFirstMatch(UserConfigService.userConfigMap, "printLog", "printlog", "debug");
        if(!StringUtils.endsWithIgnoreCase(firstMatch,"true") || StringUtils.isBlank(projectPath)){
            return;
        }
        logList.add("----------------------     end     -------------------------");
        if(!projectPath.endsWith(GenCodeResponseHelper.getPathSplitter())){
            projectPath = projectPath + GenCodeResponseHelper.getPathSplitter();
        }
        String path = projectPath + "codehelper.generator.log";
        File logFile = new File(path);
        List<String> allLines = Lists.newArrayList();
        if(logFile.exists()){
            List<String> oldLines = IOUtils.readLines(path);
            if(oldLines !=null && !oldLines.isEmpty()){
                allLines.addAll(oldLines);
            }
        }
        allLines.addAll(logList);
        IOUtils.writeLines(new File(path),allLines);
    }catch(Throwable ignored){

    }

}
 
Example 4
Source File: CoreConfigure.java    From jvm-sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取用户模块加载文件/目录(集合)
 *
 * @return 用户模块加载文件/目录(集合)
 */
public synchronized File[] getUserModuleLibFiles() {

    final Collection<File> foundModuleJarFiles = new LinkedHashSet<File>();
    for (final String path : getUserModuleLibPaths()) {
        final File fileOfPath = new File(path);
        if (fileOfPath.isDirectory()) {
            foundModuleJarFiles.addAll(FileUtils.listFiles(new File(path), new String[]{"jar"}, false));
        } else {
            if (StringUtils.endsWithIgnoreCase(fileOfPath.getPath(), ".jar")) {
                foundModuleJarFiles.add(fileOfPath);
            }
        }
    }

    return GET_USER_MODULE_LIB_FILES_CACHE = foundModuleJarFiles.toArray(new File[]{});
}
 
Example 5
Source File: ProductItemProcessor.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
private void defaultFileExtensions(Product product) {
	if (!StringUtils.isBlank(product.getOneUpFilename())) {
		if (!StringUtils.endsWithIgnoreCase(product.getOneUpFilename(), ".pdf")) {
			product.setOneUpFilename(product.getOneUpFilename() + ".pdf");
		}
	}
	if (!StringUtils.isBlank(product.getTwoUpFilename())) {
		if (!StringUtils.endsWithIgnoreCase(product.getTwoUpFilename(), ".pdf")) {
			product.setTwoUpFilename(product.getTwoUpFilename() + ".pdf");
		}
	}
}
 
Example 6
Source File: SwaggerHeaderFilter.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
    ServerHttpRequest request = exchange.getRequest();
    String path = request.getURI().getPath();
    if (!StringUtils.endsWithIgnoreCase(path, SwaggerProvider.API_URI)) {
        return chain.filter(exchange);
    }
    String basePath = path.substring(0, path.lastIndexOf(SwaggerProvider.API_URI));
    log.info("basePath: {}", basePath);
    ServerHttpRequest newRequest = request.mutate().header(HEADER_NAME, basePath).build();
    ServerWebExchange newExchange = exchange.mutate().request(newRequest).build();
    return chain.filter(newExchange);
}
 
Example 7
Source File: EndsWith.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean handle(String input, String searchString, boolean ignoreCase) {
    if (ignoreCase) {
        return StringUtils.endsWithIgnoreCase(input, searchString);
    } else {
        return StringUtils.endsWith(input, searchString);
    }
}
 
Example 8
Source File: ExtractTextHelper.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String extract(byte[] bytes, String name, Boolean office, Boolean pdf, Boolean txt, Boolean image) {
	if ((null != bytes) && bytes.length > 0) {
		if (office) {
			if (StringUtils.endsWithIgnoreCase(name, ".doc") || StringUtils.endsWithIgnoreCase(name, ".docx")) {
				return word(bytes);
			}
			if (StringUtils.endsWithIgnoreCase(name, ".xls") || StringUtils.endsWithIgnoreCase(name, ".xlsx")) {
				return excel(bytes);
			}
		}
		if (pdf) {
			if (StringUtils.endsWithIgnoreCase(name, ".pdf")) {
				return pdf(bytes);
			}
		}
		if (txt) {
			if (StringUtils.endsWithIgnoreCase(name, ".txt")) {
				return text(bytes);
			}
		}
		if (image) {
			if (StringUtils.endsWithIgnoreCase(name, ".jpg") || StringUtils.endsWithIgnoreCase(name, ".png")
					|| StringUtils.endsWithIgnoreCase(name, ".gif")) {
				return image(bytes);
			}
		}
	}
	return null;
}
 
Example 9
Source File: ExtractTextHelper.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String extract(byte[] bytes, String name, Boolean office, Boolean pdf, Boolean txt, Boolean image) {
	if ((null != bytes) && bytes.length > 0) {
		if (office) {
			if (StringUtils.endsWithIgnoreCase(name, ".doc") || StringUtils.endsWithIgnoreCase(name, ".docx")) {
				return word(bytes);
			}
			if (StringUtils.endsWithIgnoreCase(name, ".xls") || StringUtils.endsWithIgnoreCase(name, ".xlsx")) {
				return excel(bytes);
			}
		}
		if (pdf) {
			if (StringUtils.endsWithIgnoreCase(name, ".pdf")) {
				return pdf(bytes);
			}
		}
		if (txt) {
			if (StringUtils.endsWithIgnoreCase(name, ".txt")) {
				return text(bytes);
			}
		}
		if (image) {
			if (StringUtils.endsWithIgnoreCase(name, ".jpg") || StringUtils.endsWithIgnoreCase(name, ".png")
					|| StringUtils.endsWithIgnoreCase(name, ".gif")) {
				return image(bytes);
			}
		}
	}
	return null;
}
 
Example 10
Source File: PermissionUtils.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 权限错误消息提醒
 * 
 * @param permissionsStr 错误信息
 * @return 提示信息
 */
public static String getMsg(String permissionsStr)
{
    String permission = StringUtils.substringBetween(permissionsStr, "[", "]");
    String msg = MessageUtils.message(PERMISSION, permission);
    if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION))
    {
        msg = MessageUtils.message(CREATE_PERMISSION, permission);
    }
    else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION))
    {
        msg = MessageUtils.message(UPDATE_PERMISSION, permission);
    }
    else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION))
    {
        msg = MessageUtils.message(DELETE_PERMISSION, permission);
    }
    else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION))
    {
        msg = MessageUtils.message(EXPORT_PERMISSION, permission);
    }
    else if (StringUtils.endsWithAny(permission,
            new String[] { PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION }))
    {
        msg = MessageUtils.message(VIEW_PERMISSION, permission);
    }
    return msg;
}
 
Example 11
Source File: Applications.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public String findApplicationName(String name) throws Exception {
	for (String str : this.keySet()) {
		if (StringUtils.equalsIgnoreCase(str, name) || StringUtils.endsWithIgnoreCase(str, "." + name)) {
			return str;
		}
	}
	return null;
}
 
Example 12
Source File: CurvatureSensitivityUtils.java    From simm-lib with MIT License 5 votes vote down vote up
private static BigDecimal getNumberOfDays(String expiry) {
  if (StringUtils.endsWithIgnoreCase(expiry, TENOR_SUFFIX_YEARS)) {
    return DAYS_IN_YEAR.multiply(new BigDecimal(StringUtils.replaceIgnoreCase(expiry, TENOR_SUFFIX_YEARS, StringUtils.EMPTY)));
  } else if (StringUtils.endsWithIgnoreCase(expiry, TENOR_SUFFIX_MONTHS)) {
    return DAYS_PER_MONTH.multiply(new BigDecimal(StringUtils.replaceIgnoreCase(expiry, TENOR_SUFFIX_MONTHS, StringUtils.EMPTY)));
  } else {
    return DAYS_IN_WEEK.multiply(new BigDecimal(StringUtils.replaceIgnoreCase(expiry, TENOR_SUFFIX_WEEKS, StringUtils.EMPTY)));
  }
}
 
Example 13
Source File: PermissionUtils.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 权限错误消息提醒
 * 
 * @param permissionsStr 错误信息
 * @return
 */
public static String getMsg(String permissionsStr)
{
    String permission = StringUtils.substringBetween(permissionsStr, "[", "]");
    String msg = MessageUtils.message("no.view.permission", permission);
    if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION))
    {
        msg = MessageUtils.message("no.create.permission", permission);
    }
    else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION))
    {
        msg = MessageUtils.message("no.update.permission", permission);
    }
    else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION))
    {
        msg = MessageUtils.message("no.delete.permission", permission);
    }
    else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION))
    {
        msg = MessageUtils.message("no.export.permission", permission);
    }
    else if (StringUtils.endsWithAny(permission,
            new String[] { PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION }))
    {
        msg = MessageUtils.message("no.view.permission", permission);
    }
    return msg;
}
 
Example 14
Source File: DbUpdaterEngine.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected boolean executeGroovyScript(ScriptResource file) {
    try {
        ClassLoader classLoader = getClass().getClassLoader();
        CompilerConfiguration cc = new CompilerConfiguration();
        cc.setRecompileGroovySource(true);

        Binding bind = new Binding();
        bind.setProperty("ds", getDataSource());
        bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(),
                StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
        if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
            bind.setProperty("postUpdate", new PostUpdateScripts() {
                @Override
                public void add(Closure closure) {
                    super.add(closure);

                    log.warn("Added post update action will be ignored for data store [{}]", storeNameToString(storeName));
                }
            });
        }

        GroovyShell shell = new GroovyShell(classLoader, bind, cc);
        Script script = shell.parse(file.getContent());
        script.run();
    } catch (Exception e) {
        throw new RuntimeException(
                String.format("%sError executing Groovy script %s\n%s", ERROR, file.name, e.getMessage()), e);
    }
    return true;
}
 
Example 15
Source File: CompressionUtil.java    From entrada with GNU General Public License v3.0 5 votes vote down vote up
/**
 * wraps the inputstream with a decompressor based on a filename ending
 *
 * @param in The input stream to wrap with a decompressor
 * @param filename The filename from which we guess the correct decompressor
 * @param bufSize size of the read buffer to use, in bytes
 * @return the compressor stream wrapped around the inputstream. If no decompressor is found,
 *         returns the inputstream wrapped in a BufferedInputStream
 * @throws IOException when stream cannot be created
 */
public static InputStream getDecompressorStreamWrapper(InputStream in, int bufSize,
    String filename) throws IOException {

  if (StringUtils.endsWithIgnoreCase(filename, ".pcap")) {
    return wrap(in, bufSize);
  } else if (StringUtils.endsWithIgnoreCase(filename, ".gz")) {
    return new GzipCompressorInputStream(wrap(in, bufSize), true);
  } else if (StringUtils.endsWithIgnoreCase(filename, ".xz")) {
    return new XZInputStream(wrap(in, bufSize));
  }

  // unkown file type
  throw new ApplicationException("Could not open file with unknown extension: " + filename);
}
 
Example 16
Source File: ApacheCommonsUtils.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean endsWithIgnoreCase(String text, String expected) {
	return StringUtils.endsWithIgnoreCase(text, expected);
}
 
Example 17
Source File: RecursiveFileFinder.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public RecursiveFileFinder()
{
	pccFileFilter = (parentDir, fileName) -> StringUtils.endsWithIgnoreCase(fileName, ".pcc")
			|| new File(parentDir, fileName).isDirectory();
}
 
Example 18
Source File: HealthStateScope.java    From gocd with Apache License 2.0 4 votes vote down vote up
public boolean isSame(String scope) {
    return StringUtils.endsWithIgnoreCase(this.scope, scope);
}
 
Example 19
Source File: VSCrawlerConfigFileWatcher.java    From vscrawler with Apache License 2.0 4 votes vote down vote up
public void watchAndBindEvent() {
    if (hasStartWatch.compareAndSet(false, true)) {
        URL resource = VSCrawlerConfigFileWatcher.class.getResource(configFileName);
        String dir;
        if (resource == null) {
            URL classPathRoot = VSCrawlerConfigFileWatcher.class.getResource("/");
            if (classPathRoot != null) {
                dir = new File(classPathRoot.getPath()).getAbsolutePath();
            } else {
                dir = System.getProperty("java.class.path ");
            }
        } else {
            dir = new File(resource.getFile()).getParent();
        }
        final String file = new File(dir, configFileName).getAbsolutePath();

        loadFileAndSendEvent(file);

        if (StringUtils.endsWithIgnoreCase(dir, ".jar!") && !new File(dir).isDirectory()) {
            //目录解析到jar包下面,证明用户使用all_in_one jar的方式,此方式没有热发文件,因为jar包不是可写文件
            return;
        }
        if (StringUtils.endsWithIgnoreCase(dir, "classes!")) {
            return;
        }
        DirectoryWatcher.WatcherCallback watcherCallback = new DirectoryWatcher.WatcherCallback() {
            private long lastExecute = System.currentTimeMillis();

            @Override
            public void execute(WatchEvent.Kind<?> kind, String path) {
                if (System.currentTimeMillis() - lastExecute > 1000) {
                    lastExecute = System.currentTimeMillis();
                    if (!path.equals(file)) {
                        return;
                    }
                    loadFileAndSendEvent(file);
                }
            }

        };
        DirectoryWatcher fileWatcher = DirectoryWatcher.getDirectoryWatcher(watcherCallback,
                StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);
        fileWatcher.watchDirectory(dir);
    }
}
 
Example 20
Source File: ColorCommand.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) {
    boolean moderator = moderationService.isModerator(event.getMember());
    Member member = moderator ? reference.getMember() : event.getMember();
    if (member == null) {
        return fail(event);
    }

    String removeKeyWord = messageService.getMessage("discord.command.mod.color.remove");
    if (StringUtils.endsWithIgnoreCase(query, removeKeyWord)) {
        if (moderationService.setColor(member, null)) {
            ok(event);
        } else {
            fail(event);
        }
        return false;
    }

    Matcher matcher = COLOR_PATTERN.matcher(query);
    if (!matcher.find()) {
        String colorCommand = messageService.getMessageByLocale("discord.command.mod.color.key",
                context.getCommandLocale());
        String message = messageService.getMessage("discord.command.mod.color.help",
                context.getConfig().getPrefix(), colorCommand);
        if (moderator) {
            message += "\n" + messageService.getMessage("discord.command.mod.color.help.mod",
                    context.getConfig().getPrefix(), colorCommand);
        }
        messageService.onEmbedMessage(event.getChannel(), message);
        return false;
    }

    Member self = event.getGuild().getSelfMember();
    Role conflicting = member.getRoles().stream()
            .filter(e -> e.getColor() != null && !self.canInteract(e))
            .findAny().orElse(null);
    if (conflicting != null) {
        messageService.onError(event.getChannel(), null, "discord.command.mod.color.conflict", conflicting.getName());
        return false;
    }

    if (moderationService.setColor(member, matcher.group(1))) {
        ok(event);
    }
    return true;
}