下面列出了org.apache.commons.lang3.StringUtils#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static JsonElement extract(JsonElement jsonElement, String name) {
if ((null != jsonElement) && jsonElement.isJsonObject() && StringUtils.isNotEmpty(name)) {
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (StringUtils.contains(name, ".")) {
String prefix = StringUtils.substringBefore(name, ".");
String surfix = StringUtils.substringAfter(name, ".");
if (jsonObject.has(prefix)) {
return extract(jsonObject.get(prefix), surfix);
}
} else {
if (jsonObject.has(name)) {
return jsonObject.get(name);
}
}
}
return null;
}
/**
* Object types should not start with '_' because it is in conflict with the API.
* Some API resources have a path which also starts with '_' like {@code /v1/_me}.
* @param obj an object
*/
protected static void checkAndFixType(ParaObject obj) {
if (obj != null) {
if (StringUtils.startsWith(obj.getType(), SPECIAL_PREFIX)) {
obj.setType(obj.getType().replaceAll("^[" + SPECIAL_PREFIX + "]*", ""));
}
if (StringUtils.contains(obj.getType(), "#")) {
// ElasticSearch doesn't allow # in type mappings
obj.setType(obj.getType().replaceAll("#", ""));
}
if (StringUtils.contains(obj.getType(), "/")) {
// type must not contain "/"
obj.setType(obj.getType().replaceAll("/", ""));
}
if (obj.getType().isEmpty()) {
obj.setType(Utils.type(Sysprop.class));
}
}
}
static long parseDuration(String info) {
String[] lines = StringUtils.split(info, "\n");
for (String line : lines) {
if (StringUtils.isNotEmpty(line)) {
String[] columns = StringUtils.split(line, ",");
if (StringUtils.contains(columns[0], "audio")) {
for (int j = 1, columnsLength = columns.length; j < columnsLength; j++) {
String column = columns[j];
int k;
if ((k = column.indexOf(" sec")) != -1) {
String substring = column.substring(1, k);
return (long) (Double.parseDouble(substring) * 1000);
}
}
}
}
}
return 0;
}
/**
* @return Returns the prefTimeZones.
*/
public List<SelectItem> getPrefTimeZones()
{
if (prefTimeZones.size() == 0)
{
String[] timeZoneArray = TimeZone.getAvailableIDs();
Arrays.sort(timeZoneArray);
for (int i = 0; i < timeZoneArray.length; i++) {
String tzt = timeZoneArray[i];
if (StringUtils.contains(tzt, '/') && !StringUtils.startsWith(tzt, "SystemV") && !StringUtils.startsWith(tzt, "Etc/GMT")) {
String id = tzt;
String name = tzt;
if (StringUtils.contains(tzt, '_')) {
name = StringUtils.replace(tzt, "_", " ");
}
prefTimeZones.add(new SelectItem(id, name));
}
}
}
return prefTimeZones;
}
/**
* 获取用户信息
*
* @param openId
* @return
*/
@Override
public WeixinUserInfo getUserInfo(String openId) {
String url = WEIXIN_URL_GET_USER_INFO + openId;
String result = getRestTemplate().getForObject(url, String.class);
if(StringUtils.contains(result, "errcode")) {
return null;
}
WeixinUserInfo userInfo = null;
try{
userInfo = objectMapper.readValue(result,WeixinUserInfo.class);
System.out.println(userInfo);
}catch (Exception e){
e.printStackTrace();
}
return userInfo;
}
public static String getContainerStatus(String name) {
DockerClient dockerClient = getDockerClient();
List<Container> list = dockerClient.listContainersCmd().withShowAll(true).exec();
for (Container container : list) {
if (StringUtils.isEmpty(name) || StringUtils.contains(container.getNames()[0], name)) {
closeDockerClient(dockerClient);
return container.getStatus();
}
}
closeDockerClient(dockerClient);
return null;
}
/** 在请求被处理之前调用 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
// 检查每个到来的请求对应的session域中是否有登录标识
String token = (String) request.getSession().getAttribute("token");
User user = CacheUtil.getUser(token);
if (null == user) {
response.sendRedirect("/login");
return false;
}
String uri = request.getRequestURI();
// System.out.println(uri);
switch (user.getRoleId()) {
case Role.ADMIN:
if (StringUtils.contains(uri, USER.substring(0, USER.length() -2))) {
response.sendRedirect("/index");
return false;
}
break;
case Role.MEMBER:
if (!StringUtils.equals(uri, INDEX)) {
response.sendRedirect("/index");
return false;
}
break;
}
return true;
}
@Override
public HarEntryPredicate<String> getHarEntryPredicate() {
return content -> {
Optional<String> result = Optional.empty();
if (!StringUtils.contains(content, text)) {
result = Optional.of(
String.format(
"Expected to find string in content. Search string: '%s', content: '%s'",
text, content
));
}
return result;
};
}
private static void checkRegisterServer(Properties pro) {
if (StringUtils.equals("false", pro.getProperty("register.server.enabled"))) {
String registerServerUrl = pro.getProperty("register.server.url");
if (StringUtils.isBlank(registerServerUrl)) {
throw new RuntimeException("register.server.url不能为空");
}
if (StringUtils.contains(registerServerUrl, "必须修改") || !StringUtils.startsWith(registerServerUrl, "http")) {
throw new RuntimeException("register.server.url格式不正确,正确格式[http://ip:port/xxx]");
}
}
}
@Override
public void offsetReset(Object... args) {
List<TopicPartition> topicPartitions = (List<TopicPartition>) args[0];
List<TopicPartition> topicPartition2Begin = new ArrayList<>();
List<TopicPartition> topicPartition2End = new ArrayList<>();
HashMap<String, String> topicAndOffset = new HashMap<>();
String topicOffsets = dsInfo.getDataTopicOffset();
if (StringUtils.equals(topicOffsets, "none")) return;
String[] topicsArr = StringUtils.split(topicOffsets, ",");
for (String topic : topicsArr) {
topicAndOffset.put(StringUtils.split(topic, "->")[0], StringUtils.split(topic, "->")[1]);
}
for (TopicPartition tp : topicPartitions) {
String topicName = tp.topic();
if (StringUtils.contains(topicOffsets, topicName)) {
String topicInfo = topicAndOffset.get(topicName);
if (StringUtils.equals(topicInfo, "none")) {
break;
} else if (StringUtils.equals(topicInfo, "begin")) {
topicPartition2Begin.add(tp);
consumer.seekToBeginning(topicPartition2Begin);
topicPartition2Begin.clear();
logger.info(String.format("TopicName : %s, Offset changed to begin!", tp.topic()));
} else if (StringUtils.equals(topicInfo, "end")) {
topicPartition2End.add(tp);
consumer.seekToEnd(topicPartition2End);
topicPartition2End.clear();
logger.info(String.format("TopicName : %s, Offset changed to end!", tp.topic()));
} else {
long nOffset = Long.parseLong(topicInfo);
consumer.seek(tp, nOffset);
logger.info(String.format("TopicName : %s, Offset changed as: %d", tp.topic(), consumer.position(tp)));
}
}
}
}
private static boolean containsNewline(final String expression) {
return StringUtils.contains(expression, "\\n") || StringUtils.contains(expression, "\\r");
}
public ConsoleOutMatcherJunit5 contains(final String str) {
if (!StringUtils.contains(actual, str)) {
failWithMessage("Expected console to contain [<%s>] but was <%s>.", str, actual);
}
return this;
}
@Override
public boolean matches(final String page, final String parameters) {
return NAME.equals(page) && StringUtils.contains(parameters, CommitteePageMode.DECISIONTYPEDAILYSUMMARY.toString());
}
@Override
public boolean matches(final String page, final String parameters) {
return NAME.equals(page) && StringUtils.contains(parameters, PageMode.CHARTS.toString())
&& parameters.contains(ChartIndicators.DECISIONACTIVITYBYTYPE.toString());
}
@Override
public boolean matches(final String page, final String parameters) {
return NAME.equals(page) && StringUtils.contains(parameters,PageMode.PAGEVISITHISTORY.toString());
}
@SuppressWarnings("unchecked")
@Override
public void onClick(Entity item, String columnId) {
Table.Column column = table.getColumn(columnId);
MetaProperty metaProperty;
String value;
if (DynamicAttributesUtils.isDynamicAttribute(columnId)) {
metaProperty = dynamicAttributesTools.getMetaPropertyPath(item.getMetaClass(), columnId).getMetaProperty();
value = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, item.getValueEx(columnId));
} else {
value = item.getValueEx(columnId);
}
if (column.getMaxTextLength() != null) {
boolean isMultiLineCell = StringUtils.contains(value, "\n");
if (value == null || (value.length() <= column.getMaxTextLength() + MAX_TEXT_LENGTH_GAP
&& !isMultiLineCell)) {
// todo artamonov if we click with CTRL and Table is multiselect then we lose previous selected items
if (!table.getSelected().contains(item)) {
table.setSelected(item);
}
// do not show popup view
return;
}
}
VerticalLayout layout = new VerticalLayout();
layout.setMargin(false);
layout.setSpacing(false);
layout.setWidthUndefined();
layout.setStyleName("c-table-view-textcut");
CubaTextArea textArea = new CubaTextArea();
textArea.setValue(Strings.nullToEmpty(value));
textArea.setReadOnly(true);
CubaResizableTextAreaWrapper content = new CubaResizableTextAreaWrapper(textArea);
content.setResizableDirection(ResizeDirection.BOTH);
// todo implement injection for ThemeConstains in components
ThemeConstants theme = App.getInstance().getThemeConstants();
if (theme != null) {
content.setWidth(theme.get("cuba.web.Table.abbreviatedPopupWidth"));
content.setHeight(theme.get("cuba.web.Table.abbreviatedPopupHeight"));
} else {
content.setWidth("320px");
content.setHeight("200px");
}
layout.addComponent(content);
table.withUnwrapped(CubaEnhancedTable.class, enhancedTable -> {
enhancedTable.showCustomPopup(layout);
enhancedTable.setCustomPopupAutoClose(false);
});
}
@Override
public boolean matches(final String page, final String parameters) {
return NAME.equals(page) && StringUtils.contains(parameters, DocumentPageMode.DOCUMENTDATA.toString());
}
@Override
public boolean matches(final String page, final String parameters) {
return NAME.equals(page)
&& StringUtils.contains(parameters, ApplicationPageMode.LOGIN.toString());
}
private String getAccountIdFromARN(String arn) {
return StringUtils.contains(arn, ":") ? arn.split(":")[4] : "";
}
/**
* 判断是否为含附件的请求
*/
public static boolean isMultipartRequest(HttpServletRequest request){
return StringUtils.contains(request.getContentType(), "multipart");
}