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

The following examples show how to use org.apache.commons.lang3.StringUtils#startsWithAny() . 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: GradleReportLineParser.java    From synopsys-detect with Apache License 2.0 6 votes vote down vote up
private int parseTreeLevel(final String line) {
    if (StringUtils.startsWithAny(line, TREE_LEVEL_TERMINALS)) {
        return 0;
    }

    String modifiedLine = DetectableStringUtils.removeEvery(line, TREE_LEVEL_TERMINALS);

    if (!modifiedLine.startsWith("|") && modifiedLine.startsWith(" ")) {
        modifiedLine = "|" + modifiedLine;
    }
    modifiedLine = modifiedLine.replace("     ", "    |");
    modifiedLine = modifiedLine.replace("||", "|");
    if (modifiedLine.endsWith("|")) {
        modifiedLine = modifiedLine.substring(0, modifiedLine.length() - 5);
    }
    final int matches = StringUtils.countMatches(modifiedLine, "|");

    return matches;
}
 
Example 2
Source File: BlurImageController.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping(value = "/blur", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> blur(@RequestParam("source") String sourceUrl) {
    if (!StringUtils.startsWithAny(sourceUrl, ALLOWED_PREFIX)) {
        return ResponseEntity.badRequest().build();
    }

    String hash = DigestUtils.sha1Hex(sourceUrl);

    try {
        ImageInfo info = readCached(hash);
        if (info == null) {
            info = renderImage(sourceUrl);
            saveCached(hash, info);
        }
        return ResponseEntity.ok()
                .contentLength(info.contentLength)
                .contentType(MediaType.IMAGE_JPEG)
                .body(new InputStreamResource(info.inputStream));
    } catch (IOException e) {
        // fall down
    }
    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
 
Example 3
Source File: LanguageProcessingHelper.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean skip(Item o) {
	if ((StringUtils.length(o.getValue()) > 1) && (!StringUtils.startsWithAny(o.getValue(), SKIP_START_WITH))
			&& (!StringUtils.endsWithAny(o.getValue(), SKIP_END_WITH))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "b"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "c"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "d"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "e"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "f"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "h"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "k"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "o"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "p"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "q"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "r"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "u"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "w")) && (!label_skip_m(o))) {
		return false;
	}
	return true;
}
 
Example 4
Source File: LanguageProcessingHelper.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean skip(Item o) {
	if ((StringUtils.length(o.getValue()) > 1) && (!StringUtils.startsWithAny(o.getValue(), SKIP_START_WITH))
			&& (!StringUtils.endsWithAny(o.getValue(), SKIP_END_WITH))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "b"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "c"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "d"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "e"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "f"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "h"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "k"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "o"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "p"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "q"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "r"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "u"))
			&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "w")) && (!label_skip_m(o))) {
		return false;
	}
	return true;
}
 
Example 5
Source File: MsgHandler.java    From fw-cloud-framework with MIT License 6 votes vote down vote up
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
		WxMpService weixinService, WxSessionManager sessionManager) {

	if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
		// TODO 可以选择将消息保存到本地
	}

	// 当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
	try {
		if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
				&& weixinService.getKefuService().kfOnlineList().getKfOnlineList().size() > 0) { return WxMpXmlOutMessage
				.TRANSFER_CUSTOMER_SERVICE().fromUser(wxMessage.getToUser()).toUser(
						wxMessage.getFromUser()).build(); }
	} catch (WxErrorException e) {
		e.printStackTrace();
	}

	// TODO 组装回复消息
	String content = "收到信息内容:" + JsonUtils.toJson(wxMessage);

	return new TextBuilder().build(content, wxMessage, weixinService);

}
 
Example 6
Source File: PythonAbstractConnexionServerCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public String toModelImport(String name) {
    String modelImport;
    if (StringUtils.startsWithAny(name, "import", "from")) {
        modelImport = name;
    } else {
        modelImport = "from ";
        if (!"".equals(modelPackage())) {
            modelImport += modelPackage() + ".";
        }
        modelImport += toModelFilename(name) + " import " + name;
    }
    return modelImport;
}
 
Example 7
Source File: DataBaseAdvisor.java    From app-engine with Apache License 2.0 5 votes vote down vote up
@Before("execution(* com.appengine..*Dao.*(..))")
public void beforMethod(JoinPoint joinPoint) {
    String methodName = joinPoint.getSignature().getName();
    RequestContext rc = ThreadLocalContext.getRequestContext();

    if (StringUtils.startsWithAny(methodName, writeMethodPrefixs)) {
        rc.setShouldReadMasterDB(true);
    } else if (StringUtils.startsWithAny(methodName, queryMethodPrefixs)) {
        rc.setShouldReadMasterDB(false);
    } else {
        log.warn("cannot found handle db method for methodName is: " + methodName);
        rc.setShouldReadMasterDB(true);
    }
}
 
Example 8
Source File: MantaSession.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
protected boolean isUserWritable(final MantaObject object) {
    final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());
    return StringUtils.startsWithAny(
        object.getPath(),
        account.getAccountPublicRoot().getAbsolute(),
        account.getAccountPrivateRoot().getAbsolute());
}
 
Example 9
Source File: MsgHandler.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                Map<String, Object> context, WxMpService weixinService,
                                WxSessionManager sessionManager) {

    if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
        //TODO 可以选择将消息保存到本地
    }

    //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
    try {
        if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
            && weixinService.getKefuService().kfOnlineList()
            .getKfOnlineList().size() > 0) {
            return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
                .fromUser(wxMessage.getToUser())
                .toUser(wxMessage.getFromUser()).build();
        }
    } catch (WxErrorException e) {
        e.printStackTrace();
    }

    //TODO 组装回复消息
    String content = "收到信息内容:" + JsonUtils.toJson(wxMessage);

    return new TextBuilder().build(content, wxMessage, weixinService);

}
 
Example 10
Source File: SimpleRSSPreferencesValidator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected boolean isValidScheme(String url) {
	
	//check if url starts with one of the schemes
	if(StringUtils.startsWithAny(url, schemes)) {
		return true;
	} 
	return false;
	
}
 
Example 11
Source File: JsonUtil.java    From codeway_service with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 判断是否json串
 * @param jsonStr JSON字符串
 * @return java对象
 */
public static synchronized boolean isJson(String jsonStr) {
	try {
		return StringUtils.startsWithAny(jsonStr, "{", "[");
	} catch (Exception e) {
           LogBack.error(JACKSON_ERROR, e.getMessage());
		return false;
	}
}
 
Example 12
Source File: PythonClientCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public String toModelImport(String name) {
    String modelImport;
    if (StringUtils.startsWithAny(name, "import", "from")) {
        modelImport = name;
    } else {
        modelImport = "from ";
        if (!"".equals(modelPackage())) {
            modelImport += modelPackage() + ".";
        }
        modelImport += toModelFilename(name) + " import " + name;
    }
    return modelImport;
}
 
Example 13
Source File: PythonClientCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public String toModelImport(String name) {
    String modelImport;
    if (StringUtils.startsWithAny(name,"import", "from")) {
        modelImport = name;
    } else {
        modelImport = "from ";
        if (!"".equals(modelPackage())) {
            modelImport += modelPackage() + ".";
        }
        modelImport += toModelFilename(name)+ " import " + name;
    }
    return modelImport;
}
 
Example 14
Source File: FlaskConnexionCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public String toModelImport(String name) {
    String modelImport;
    if (StringUtils.startsWithAny(name,"import", "from")) {
        modelImport = name;
    } else {
        modelImport = "from ";
        if (!"".equals(modelPackage())) {
            modelImport += modelPackage() + ".";
        }
        modelImport += toModelFilename(name)+ " import " + name;
    }
    return modelImport;
}
 
Example 15
Source File: SimpleRSSPreferencesValidator.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
protected boolean isValidScheme(String url) {
	
	//check if url starts with one of the schemes
	if(StringUtils.startsWithAny(url, schemes)) {
		return true;
	} 
	return false;
	
}
 
Example 16
Source File: MsgHandler.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                Map<String, Object> context, WxMpService weixinService,
                                WxSessionManager sessionManager) {

    if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
        //TODO 可以选择将消息保存到本地
    }

    //当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
    try {
        if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
            && weixinService.getKefuService().kfOnlineList()
            .getKfOnlineList().size() > 0) {
            return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
                .fromUser(wxMessage.getToUser())
                .toUser(wxMessage.getFromUser()).build();
        }
    } catch (WxErrorException e) {
        e.printStackTrace();
    }

    //TODO 组装回复消息
    String content = "yshop收到信息内容:" + wxMessage.getContent();

    return new TextBuilder().build(content, wxMessage, weixinService);

}
 
Example 17
Source File: StringStartsWith.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void string_starts_with_any_apache_commons() {

	boolean startsWithHttpProtocol = StringUtils
			.startsWithAny("http://www.leveluplunch.com", new String[] {
					"http", "https" });

	assertTrue(startsWithHttpProtocol);
}
 
Example 18
Source File: MantaSession.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
protected boolean isWorldReadable(final MantaObject object) {
    final MantaAccountHomeInfo accountHomeInfo = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());
    return StringUtils.startsWithAny(
        object.getPath(),
        accountHomeInfo.getAccountPublicRoot().getAbsolute());
}
 
Example 19
Source File: QueryOpinionService.java    From ghidra with Apache License 2.0 4 votes vote down vote up
static boolean secondaryAttributeMatches(String eFlagsDecimalString, String attribute) {

		// eFlagDecimalString is the elf e_flags value, as a decimal string
		// sa is the secondary attribute string from the opinion file,
		// and it must start with "0x" or "0b"
		if (attribute == null) {
			return false;
		}

		if (!StringUtils.startsWithAny(attribute.toLowerCase(), "0x", "0b")) {
			return false;
		}

		int eFlagsInt = Integer.parseInt(eFlagsDecimalString);
		String eFlagsBinaryString = Integer.toBinaryString(eFlagsInt);
		if (eFlagsBinaryString == null) {
			return false;
		}

		eFlagsBinaryString = StringUtils.leftPad(eFlagsBinaryString, 32, "0");
		String eFlagsHexString = Integer.toHexString(eFlagsInt);
		eFlagsHexString = StringUtils.leftPad(eFlagsHexString, 8, "0");

		// Remove '_' and whitespace from the attribute string
		String cleaned = attribute.replace("_", "").replaceAll("\\s+", "").trim();
		String prefix = cleaned.substring(0, 2);
		String value = cleaned.substring(2);
		if (prefix.toLowerCase().startsWith("0x")) {

			// It's a hex string
			value = StringUtils.leftPad(value, 8, "0");
			return value.equals(eFlagsHexString);
		}

		// It's a binary string
		value = StringUtils.leftPad(value, 32, "0");
		for (int i = 0; i < 32; i++) {
			char c = value.charAt(i);
			if (c == '.') { // wildcard
				continue;
			}

			if (eFlagsBinaryString.charAt(i) != c) {
				return false;
			}
		}

		return true;
	}
 
Example 20
Source File: StackTraceProviderJdk8.java    From more-lambdas-java with Artistic License 2.0 2 votes vote down vote up
/**
 * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 * at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 * at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 * at java.lang.reflect.Method.invoke(Method.java:498)
 */
private boolean isReflection(String stackClassName) {
    return StringUtils.startsWithAny(stackClassName, REFLECTION_PREFIXES);
}