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

The following examples show how to use org.apache.commons.lang3.StringUtils#startsWithAny() . These examples are extracted from open source projects. 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
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 Project: fw-cloud-framework   File: MsgHandler.java    License: 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 3
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
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
@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 6
/**
 * 判断是否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 7
@Test
public void string_starts_with_any_apache_commons() {

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

	assertTrue(startsWithHttpProtocol);
}
 
Example 8
Source Project: yshopmall   File: MsgHandler.java    License: 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 9
@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 10
@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 11
@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 12
@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
@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
@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 15
Source Project: sdb-mall   File: MsgHandler.java    License: 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 16
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 17
Source Project: app-engine   File: DataBaseAdvisor.java    License: 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 18
Source Project: ghidra   File: QueryOpinionService.java    License: 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 19
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 20
/**
 * 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);
}