Java Code Examples for org.apache.commons.lang3.StringUtils#equalsAny()
The following examples show how to use
org.apache.commons.lang3.StringUtils#equalsAny() .
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: PrimitiveArray.java From Prism with MIT License | 8 votes |
public static PrimitiveArray of(Document document) { if (document.size() != 2 || !(document.containsKey("key") && document.containsKey("value"))) { return null; } if (!(document.get("key") instanceof String)) { return null; } String key = document.getString("key"); if (!StringUtils.equalsAny(key, BYTE_ARRAY_ID, INT_ARRAY_ID, LONG_ARRAY_ID)) { return null; } List<Number> value = document.getList("value", Number.class); if (value == null) { return null; } return new PrimitiveArray(key, value); }
Example 2
Source File: MantaAccountHomeInfo.java From cyberduck with GNU General Public License v3.0 | 6 votes |
private Path buildNormalizedHomePath(final String rawHomePath) { final String defaultPath = StringUtils.defaultIfBlank(rawHomePath, Path.HOME); final String accountRootRegex = String.format("^/?(%s|~~?)/?", accountRoot.getAbsolute()); final String subdirectoryRawPath = defaultPath.replaceFirst(accountRootRegex, ""); if(StringUtils.isEmpty(subdirectoryRawPath)) { return accountRoot; } final String[] subdirectoryPathSegments = StringUtils.split(subdirectoryRawPath, Path.DELIMITER); Path homePath = accountRoot; for(final String pathSegment : subdirectoryPathSegments) { EnumSet<Path.Type> types = EnumSet.of(Path.Type.directory); if(homePath.getParent().equals(accountRoot) && StringUtils.equalsAny(pathSegment, HOME_PATH_PRIVATE, HOME_PATH_PUBLIC)) { types.add(Path.Type.volume); } homePath = new Path(homePath, pathSegment, types); } return homePath; }
Example 3
Source File: PrimitiveArray.java From Prism with MIT License | 6 votes |
public static PrimitiveArray of(JsonObject jsonObject) { if (jsonObject.size() != 2 || !(jsonObject.has("key") && jsonObject.has("value"))) { return null; } if (!jsonObject.get("key").isJsonPrimitive() || !jsonObject.getAsJsonPrimitive("key").isString()) { return null; } String key = jsonObject.get("key").getAsString(); if (!StringUtils.equalsAny(key, BYTE_ARRAY_ID, INT_ARRAY_ID, LONG_ARRAY_ID)) { return null; } List<Number> value = Lists.newArrayList(); JsonArray jsonArray = jsonObject.get("value").getAsJsonArray(); jsonArray.forEach(entry -> value.add(NumberUtils.createNumber(entry.getAsString()))); return new PrimitiveArray(key, value); }
Example 4
Source File: DownloadStationService.java From torrssen2 with MIT License | 5 votes |
private DownloadList setInfo(JSONObject json) throws JSONException { DownloadList down = new DownloadList(); if(json.has("id")) { boolean done = StringUtils.equalsAny(json.getString("status"), "finished", "seeding"); Long id = Long.parseLong(StringUtils.remove(json.getString("id"), "dbid_")); down.setId(id); down.setDbid(json.getString("id")); down.setDone(done); down.setName(json.getString("title")); down.setFileName(json.getString("title")); down.setUri(json.getJSONObject("additional").getJSONObject("detail").getString("uri")); down.setDownloadPath(json.getJSONObject("additional").getJSONObject("detail").getString("destination")); Optional<DownloadList> info = downloadListRepository.findById(id); if(info.isPresent()) { down.setVueItemIndex(info.get().getVueItemIndex()); } try { Long sizeDownloaded = json.getJSONObject("additional").getJSONObject("transfer").getLong("size_downloaded"); Long fileSize = json.getLong("size"); log.debug("percent-done: " + sizeDownloaded.toString() + " / " + fileSize.toString() + " = " + String.valueOf(((double)sizeDownloaded / (double)fileSize) * 100)); if(fileSize > 0L) { down.setPercentDone((int)(((double)sizeDownloaded / (double)fileSize) * 100)); } } catch (ArithmeticException ae) { log.error(ae.getMessage()); } } return down; }
Example 5
Source File: LogUtil.java From MergeProcessor with Apache License 2.0 | 5 votes |
/** * Identifies the cause of the current thread stack. * * @return the cause {@link StackTraceElement} */ private static StackTraceElement getCause() { for (final StackTraceElement element : Thread.currentThread().getStackTrace()) { if (!StringUtils.equalsAny(element.getClassName(), Thread.class.getName(), LogUtil.class.getName())) { return element; } } // Only when initialized within LogUtil return Thread.currentThread().getStackTrace()[1]; }
Example 6
Source File: InstanceMetadataUpdater.java From cloudbreak with Apache License 2.0 | 5 votes |
private void addPackageVersionsFromCommand(GatewayConfig gatewayConfig, HostOrchestrator hostOrchestrator, Map<String, Map<String, String>> packageVersionsByNameByHost) throws CloudbreakOrchestratorFailedException { List<Package> packagesWithCommand = packages.stream().filter(pkg -> StringUtils.isNotBlank(pkg.getCommand())).collect(Collectors.toList()); for (Package packageWithCommand : packagesWithCommand) { Map<String, String> versionsByHost = hostOrchestrator.runCommandOnAllHosts(gatewayConfig, packageWithCommand.getCommand()); for (Entry<String, String> entry : versionsByHost.entrySet()) { String version = parseVersion(entry.getValue(), packageWithCommand.getCommandVersionPattern()); if (!StringUtils.equalsAny(version, "false", "null", null)) { packageVersionsByNameByHost.computeIfAbsent(entry.getKey(), s -> new HashMap<>()) .put(packageWithCommand.getName(), version); } } } }
Example 7
Source File: InstanceMetadataUpdater.java From cloudbreak with Apache License 2.0 | 5 votes |
private void addPackageVersionsFromGrain(GatewayConfig gatewayConfig, HostOrchestrator hostOrchestrator, Map<String, Map<String, String>> packageVersionsByNameByHost) throws CloudbreakOrchestratorFailedException { List<Package> packagesWithGrain = packages.stream().filter(pkg -> StringUtils.isNotBlank(pkg.getGrain())).collect(Collectors.toList()); for (Package packageWithGrain : packagesWithGrain) { Map<String, JsonNode> versionsByHost = hostOrchestrator.getGrainOnAllHosts(gatewayConfig, packageWithGrain.getGrain()); for (Entry<String, JsonNode> entry : versionsByHost.entrySet()) { String entryValue = entry.getValue().textValue(); if (!StringUtils.equalsAny(entryValue, "false", "null", null)) { packageVersionsByNameByHost.computeIfAbsent(entry.getKey(), s -> new HashMap<>()) .put(packageWithGrain.getName(), entryValue); } } } }
Example 8
Source File: HasEvents.java From gocd with Apache License 2.0 | 5 votes |
default void validateEvents(String... allowedEvents) { String event = event(); if (!StringUtils.equalsAny(event, allowedEvents)) { throw die(format("Invalid event type `%s`. Allowed events are [%s].", event, join(", ", allowedEvents))); } }
Example 9
Source File: AwvsScan.java From TrackRay with GNU General Public License v3.0 | 4 votes |
private boolean monitor() { Awvs.Scan scan = awvs.scan(scanId); if (scan!=null){ List<Awvs.Vulnerabilities> vulns = awvs.vulns(sessionid, scanId); SysLog.info("深度扫描漏洞数 "+vulns.size()); if (!vulns.isEmpty()){ for (Awvs.Vulnerabilities vuln : vulns) { if (!vulnQueue.contains(vuln)){ vulnQueue.add(vuln); Awvs.Vulndetail vulndetail = awvs.vuln(scanId, sessionid, vuln.getVulnId()); vuln.setVuln(vulndetail); int type = Vulnerable.Type.UNKNOWN.getType(); String vname = vulndetail.getVtName().toLowerCase(); if (vname.contains("xss") || vname.contains("Cross site scripting")){ type = Vulnerable.Type.XSS.getType(); }else if(vname.contains("csrf")){ type = Vulnerable.Type.CSRF.getType(); }else if(vname.contains("overflow")){ type = Vulnerable.Type.OVERFLOW.getType(); }else if (vname.contains("SQL")){ type = Vulnerable.Type.SQL_INJECTION.getType(); } Vulnerable vulnerable = Vulnerable.builder() .address(vulndetail.getAffectsUrl()) .level(vulndetail.getSeverity()) .title(vulndetail.getVtName()) .detail(vulndetail.getAffectsDetail()) .type(type) .payload(vulndetail.getRequest()) .build(); //task.getResult().getItems().get(target).getVulns().add(vulnerable); addVulnerable(vulnerable); } } } if (StringUtils.equalsAny(scan.getCurrentSession().getStatus() , Awvs.State.COMPLETED , Awvs.State.ABORTED , Awvs.State.FAILED)) { vulnQueue.clear(); return true; } } return false; }
Example 10
Source File: OpenFilter.java From seed with Apache License 2.0 | 4 votes |
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { ReqData reqData; String reqDataStr; String respDataStr; String reqIp = RequestUtil.getClientIP(request); long startTime = System.currentTimeMillis(); try{ //将请求入参解析到ReqData String method = request.getParameter("method"); if(StringUtils.isNotBlank(method) && StringUtils.endsWithAny(method, "h5", "file.upload")){ reqDataStr = JadyerUtil.buildStringFromMap(request.getParameterMap()); LogUtil.getLogger().debug("收到客户端IP=[{}]的请求报文为-->{}", reqIp, reqDataStr); reqData = BeanUtil.requestToBean(request, ReqData.class); }else{ reqDataStr = IOUtils.toString(request.getInputStream(), SeedConstants.DEFAULT_CHARSET); LogUtil.getLogger().debug("收到客户端IP=[{}]的请求报文为-->[{}]", reqIp, reqDataStr); if(StringUtils.isBlank(reqDataStr)){ throw new SeedException(CodeEnum.OPEN_FORM_ILLEGAL.getCode(), "请求无数据"); } reqData = JSON.parseObject(reqDataStr, ReqData.class); method = reqData.getMethod(); } //验证请求方法名非空 if(StringUtils.isBlank(reqData.getMethod())){ throw new SeedException(CodeEnum.OPEN_UNKNOWN_METHOD.getCode(), String.format("%s-->[%s]", CodeEnum.OPEN_UNKNOWN_METHOD.getMsg(), reqData.getMethod())); } //验证时间戳 this.verifyTimestamp(reqData.getTimestamp()); //识别合作方 String appsecret = appsecretMap.get(reqData.getAppid()); LogUtil.getLogger().debug("通过appid=[{}]读取到合作方密钥{}", reqData.getAppid(), appsecret); if(appsecretMap.isEmpty() || StringUtils.isBlank(appsecret)){ throw new SeedException(CodeEnum.OPEN_UNKNOWN_APPID); } //获取协议版本 if(!StringUtils.equalsAny(reqData.getVersion(), SeedConstants.OPEN_VERSION_21, SeedConstants.OPEN_VERSION_22)){ throw new SeedException(CodeEnum.OPEN_UNKNOWN_VERSION); } //验证接口是否已授权 this.verifyGrant(reqData.getAppid(), method); //验签 //if(SeedConstants.VERSION_20.equals(reqData.getVersion())){ // this.verifySign(request.getParameterMap(), apiApplication.getAppSecret()); // filterChain.doFilter(request, response); //} //解密并处理(返回诸如html或txt内容时,就不用先得到字符串再转成字节数组输出,这会影响性能,尤其对账文件下载) RequestParameterWrapper requestWrapper = new RequestParameterWrapper(request); requestWrapper.addAllParameters(this.decrypt(reqData, appsecret)); if(StringUtils.endsWithAny(method, "h5", "agree", "download")){ filterChain.doFilter(requestWrapper, response); respDataStr = method + "..."; LogUtil.getLogger().info("返回客户端IP=[{}]的应答明文为-->[{}],Duration[{}]ms", reqIp, respDataStr, (System.currentTimeMillis()-startTime)); }else{ ResponseContentWrapper responseWrapper = new ResponseContentWrapper(response); filterChain.doFilter(requestWrapper, responseWrapper); respDataStr = responseWrapper.getContent(); LogUtil.getLogger().info("返回客户端IP=[{}]的应答明文为-->[{}]", reqIp, respDataStr); RespData respData = JSON.parseObject(respDataStr, RespData.class); if(CodeEnum.SUCCESS.getCode() == Integer.parseInt(respData.getCode())){ if(SeedConstants.OPEN_VERSION_21.equals(reqData.getVersion())){ respData.setData(StringUtils.isBlank(respData.getData()) ? "" : CodecUtil.buildAESEncrypt(respData.getData(), appsecret)); }else{ Map<String, String> dataMap = JSON.parseObject(appsecret, new TypeReference<Map<String, String>>(){}); respData.setSign(StringUtils.isBlank(respData.getData()) ? "" : CodecUtil.buildRSASignByPrivateKey(respData.getData(), dataMap.get("openPrivateKey"))); respData.setData(StringUtils.isBlank(respData.getData()) ? "" : CodecUtil.buildRSAEncryptByPublicKey(respData.getData(), dataMap.get("publicKey"))); } } String respDataJson = JSON.toJSONString(respData); LogUtil.getLogger().debug("返回客户端IP=[{}]的应答密文为-->[{}],Duration[{}]ms", reqIp, respDataJson, (System.currentTimeMillis()-startTime)); this.writeToResponse(respDataJson, response); } }catch(SeedException e){ respDataStr = JSON.toJSONString(CommResult.fail(e.getCode(), e.getMessage()), true); LogUtil.getLogger().info("返回客户端IP=[{}]的应答明文为-->[{}],Duration[{}]ms", reqIp, respDataStr, (System.currentTimeMillis()-startTime)); this.writeToResponse(respDataStr, response); } }
Example 11
Source File: MxisdStandaloneExec.java From mxisd with GNU Affero General Public License v3.0 | 4 votes |
public static void main(String[] args) { String logLevel = System.getenv("MXISD_LOG_LEVEL"); if (StringUtils.isNotBlank(logLevel)) { System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", logLevel); } try { MxisdConfig cfg = null; Iterator<String> argsIt = Arrays.asList(args).iterator(); while (argsIt.hasNext()) { String arg = argsIt.next(); if (StringUtils.equalsAny(arg, "-h", "--help", "-?", "--usage")) { System.out.println("Available arguments:" + System.lineSeparator()); System.out.println(" -h, --help Show this help message"); System.out.println(" --version Print the version then exit"); System.out.println(" -c, --config Set the configuration file location"); System.out.println(" -v Increase log level (log more info)"); System.out.println(" -vv Further increase log level"); System.out.println(" "); System.exit(0); } else if (StringUtils.equals(arg, "-v")) { System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "debug"); } else if (StringUtils.equals(arg, "-vv")) { System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "trace"); } else if (StringUtils.equalsAny(arg, "-c", "--config")) { String cfgFile = argsIt.next(); cfg = YamlConfigLoader.loadFromFile(cfgFile); } else if (StringUtils.equals("--version", arg)) { System.out.println(Mxisd.Version); System.exit(0); } else { System.err.println("Invalid argument: " + arg); System.err.println("Try '--help' for available arguments"); System.exit(1); } } if (Objects.isNull(cfg)) { cfg = YamlConfigLoader.tryLoadFromFile("mxisd.yaml").orElseGet(MxisdConfig::new); } log.info("mxisd starting"); log.info("Version: {}", Mxisd.Version); HttpMxisd mxisd = new HttpMxisd(cfg); Runtime.getRuntime().addShutdownHook(new Thread(() -> { mxisd.stop(); log.info("mxisd stopped"); })); mxisd.start(); log.info("mxisd started"); } catch (ConfigurationException e) { log.error(e.getDetailedMessage()); log.error(e.getMessage()); System.exit(2); } catch (Throwable t) { t.printStackTrace(); System.exit(1); } }