use of org.apache.commons.lang3.StringUtils.contains in project eol-globi-data by jhpoelen.
the class CitationUtil method citationFor.
public static String citationFor(Dataset dataset) {
String defaultCitation = "<" + dataset.getArchiveURI().toString() + ">";
String citation = citationOrDefaultFor(dataset, defaultCitation);
if (!StringUtils.contains(citation, "doi.org") && !StringUtils.contains(citation, "doi:")) {
String citationTrimmed = StringUtils.trim(defaultString(citation));
String doiTrimmed = defaultString(dataset.getDOI());
if (StringUtils.isBlank(doiTrimmed)) {
citation = citationTrimmed;
} else {
citation = citationTrimmed + separatorFor(citationTrimmed) + doiTrimmed;
}
}
return StringUtils.trim(citation);
}
use of org.apache.commons.lang3.StringUtils.contains in project Awful.apk by Awful.
the class ThreadDisplayFragment method showUrlMenu.
private void showUrlMenu(final String url) {
if (url == null) {
Timber.w("Passed null URL to #showUrlMenu!");
return;
}
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager == null) {
Timber.w("showUrlMenu called but can't get FragmentManager!");
return;
}
boolean isImage = false;
boolean isGif = false;
// TODO: parsing fails on magic webdev urls like http://tpm2016.zoffix.com/#/40
// it thinks the # is the start of the ref section of the url, so the Path for that url is '/'
Uri path = Uri.parse(url);
String lastSegment = path.getLastPathSegment();
// null-safe path checking (there may be no path segments, e.g. a link to a domain name)
if (lastSegment != null) {
lastSegment = lastSegment.toLowerCase();
// using 'contains' instead of 'ends with' in case of any url suffix shenanigans, like twitter's ".jpg:large"
isImage = (StringUtils.indexOfAny(lastSegment, ".jpg", ".jpeg", ".png", ".gif") != -1 && !StringUtils.contains(lastSegment, ".gifv")) || (lastSegment.equals("attachment.php") && path.getHost().equals("forums.somethingawful.com"));
isGif = StringUtils.contains(lastSegment, ".gif") && !StringUtils.contains(lastSegment, ".gifv");
}
// TODO: 28/04/2017 remove all this when Crashlytics #717 is fixed
if (AwfulApplication.crashlyticsEnabled()) {
Crashlytics.setString("Menu for URL:", url);
Crashlytics.setInt("Thread ID", getThreadId());
Crashlytics.setInt("Page", getPageNumber());
FragmentActivity activity = getActivity();
Crashlytics.setBool("Activity exists", activity != null);
if (activity != null) {
String state = "Activity:";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
state += (activity.isDestroyed()) ? "IS_DESTROYED " : "";
}
state += (activity.isFinishing()) ? "IS_FINISHING" : "";
state += (activity.isChangingConfigurations()) ? "IS_CHANGING_CONFIGURATIONS" : "";
Crashlytics.setString("Activity state:", state);
}
Crashlytics.setBool("Thread display fragment resumed", isResumed());
Crashlytics.setBool("Thread display fragment attached", isAdded());
Crashlytics.setBool("Thread display fragment removing", isRemoving());
}
// //////////////////////////////////////////////////////////////////////
UrlContextMenu linkActions = UrlContextMenu.newInstance(url, isImage, isGif, isGif ? "Getting file size" : null);
if (isGif) {
queueRequest(new ImageSizeRequest(url, result -> {
if (linkActions == null) {
return;
}
String size = result == null ? "unknown" : Formatter.formatShortFileSize(getContext(), result);
linkActions.setSubheading(String.format("Size: %s", size));
}));
}
linkActions.setTargetFragment(ThreadDisplayFragment.this, -1);
linkActions.show(fragmentManager, "Link Actions");
}
use of org.apache.commons.lang3.StringUtils.contains in project azure-tools-for-java by Microsoft.
the class AzureSdkTreePanel method loadData.
private void loadData(final Map<String, List<AzureSdkCategoryEntity>> categoryToServiceMap, final List<? extends AzureSdkServiceEntity> services, String... filters) {
final DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.model.getRoot();
root.removeAllChildren();
final Map<String, AzureSdkServiceEntity> serviceMap = services.stream().collect(Collectors.toMap(e -> getServiceKeyByName(e.getName()), e -> e));
final List<String> categories = categoryToServiceMap.keySet().stream().filter(StringUtils::isNotBlank).sorted((s1, s2) -> StringUtils.contains(s1, "Others") ? 1 : StringUtils.contains(s2, "Others") ? -1 : s1.compareTo(s2)).collect(Collectors.toList());
for (final String category : categories) {
// no feature found for current category
if (CollectionUtils.isEmpty(categoryToServiceMap.get(category)) || categoryToServiceMap.get(category).stream().allMatch(e -> Objects.isNull(serviceMap.get(getServiceKeyByName(e.getServiceName()))) || CollectionUtils.isEmpty(serviceMap.get(getServiceKeyByName(e.getServiceName())).getContent()))) {
continue;
}
// add features for current category
final MutableTreeNode categoryNode = new DefaultMutableTreeNode(category);
final boolean categoryMatched = this.isMatchedFilters(category, filters);
categoryToServiceMap.get(category).stream().sorted(Comparator.comparing(AzureSdkCategoryEntity::getServiceName)).forEach(categoryService -> {
final AzureSdkServiceEntity service = serviceMap.get(getServiceKeyByName(categoryService.getServiceName()));
this.loadServiceData(service, categoryService, categoryNode, filters);
});
if (ArrayUtils.isEmpty(filters) || categoryMatched || categoryNode.getChildCount() > 0) {
this.model.insertNodeInto(categoryNode, root, root.getChildCount());
}
}
this.model.reload();
if (ArrayUtils.isNotEmpty(filters)) {
TreeUtil.expandAll(this.tree);
}
TreeUtil.promiseSelectFirstLeaf(this.tree);
}
use of org.apache.commons.lang3.StringUtils.contains in project DataX by alibaba.
the class SingleTableSplitUtil method checkSplitPk.
/**
* 检测splitPk的配置是否正确。
* configuration为null, 是precheck的逻辑,不需要回写PK_TYPE到configuration中
*
*/
private static Pair<Object, Object> checkSplitPk(Connection conn, String pkRangeSQL, int fetchSize, String table, String username, Configuration configuration) {
LOG.info("split pk [sql={}] is running... ", pkRangeSQL);
ResultSet rs = null;
Pair<Object, Object> minMaxPK = null;
try {
try {
rs = DBUtil.query(conn, pkRangeSQL, fetchSize);
} catch (Exception e) {
throw RdbmsException.asQueryException(DATABASE_TYPE, e, pkRangeSQL, table, username);
}
ResultSetMetaData rsMetaData = rs.getMetaData();
if (isPKTypeValid(rsMetaData)) {
if (isStringType(rsMetaData.getColumnType(1))) {
if (configuration != null) {
configuration.set(Constant.PK_TYPE, Constant.PK_TYPE_STRING);
}
while (DBUtil.asyncResultSetNext(rs)) {
minMaxPK = new ImmutablePair<Object, Object>(rs.getString(1), rs.getString(2));
}
} else if (isLongType(rsMetaData.getColumnType(1))) {
if (configuration != null) {
configuration.set(Constant.PK_TYPE, Constant.PK_TYPE_LONG);
}
while (DBUtil.asyncResultSetNext(rs)) {
minMaxPK = new ImmutablePair<Object, Object>(rs.getString(1), rs.getString(2));
// check: string shouldn't contain '.', for oracle
String minMax = rs.getString(1) + rs.getString(2);
if (StringUtils.contains(minMax, '.')) {
throw DataXException.asDataXException(DBUtilErrorCode.ILLEGAL_SPLIT_PK, "您配置的DataX切分主键(splitPk)有误. 因为您配置的切分主键(splitPk) 类型 DataX 不支持. DataX 仅支持切分主键为一个,并且类型为整数或者字符串类型. 请尝试使用其他的切分主键或者联系 DBA 进行处理.");
}
}
} else {
throw DataXException.asDataXException(DBUtilErrorCode.ILLEGAL_SPLIT_PK, "您配置的DataX切分主键(splitPk)有误. 因为您配置的切分主键(splitPk) 类型 DataX 不支持. DataX 仅支持切分主键为一个,并且类型为整数或者字符串类型. 请尝试使用其他的切分主键或者联系 DBA 进行处理.");
}
} else {
throw DataXException.asDataXException(DBUtilErrorCode.ILLEGAL_SPLIT_PK, "您配置的DataX切分主键(splitPk)有误. 因为您配置的切分主键(splitPk) 类型 DataX 不支持. DataX 仅支持切分主键为一个,并且类型为整数或者字符串类型. 请尝试使用其他的切分主键或者联系 DBA 进行处理.");
}
} catch (DataXException e) {
throw e;
} catch (Exception e) {
throw DataXException.asDataXException(DBUtilErrorCode.ILLEGAL_SPLIT_PK, "DataX尝试切分表发生错误. 请检查您的配置并作出修改.", e);
} finally {
DBUtil.closeDBResources(rs, null, null);
}
return minMaxPK;
}
use of org.apache.commons.lang3.StringUtils.contains in project syncope by apache.
the class SyncopeEnduserApplication method init.
@Override
protected void init() {
super.init();
// read enduser.properties
Properties props = PropertyUtils.read(getClass(), ENDUSER_PROPERTIES, "enduser.directory").getLeft();
domain = props.getProperty("domain", SyncopeConstants.MASTER_DOMAIN);
adminUser = props.getProperty("adminUser");
Args.notNull(adminUser, "<adminUser>");
anonymousUser = props.getProperty("anonymousUser");
Args.notNull(anonymousUser, "<anonymousUser>");
anonymousKey = props.getProperty("anonymousKey");
Args.notNull(anonymousKey, "<anonymousKey>");
captchaEnabled = Boolean.parseBoolean(props.getProperty("captcha"));
Args.notNull(captchaEnabled, "<captcha>");
xsrfEnabled = Boolean.parseBoolean(props.getProperty("xsrf"));
Args.notNull(xsrfEnabled, "<xsrf>");
String scheme = props.getProperty("scheme");
Args.notNull(scheme, "<scheme>");
String host = props.getProperty("host");
Args.notNull(host, "<host>");
String port = props.getProperty("port");
Args.notNull(port, "<port>");
String rootPath = props.getProperty("rootPath");
Args.notNull(rootPath, "<rootPath>");
String useGZIPCompression = props.getProperty("useGZIPCompression");
Args.notNull(useGZIPCompression, "<useGZIPCompression>");
maxUploadFileSizeMB = props.getProperty("maxUploadFileSizeMB") == null ? null : Integer.valueOf(props.getProperty("maxUploadFileSizeMB"));
clientFactory = new SyncopeClientFactoryBean().setAddress(scheme + "://" + host + ":" + port + "/" + rootPath).setContentType(SyncopeClientFactoryBean.ContentType.JSON).setUseCompression(BooleanUtils.toBoolean(useGZIPCompression));
// read customForm.json
try (InputStream is = getClass().getResourceAsStream("/" + CUSTOM_FORM_FILE)) {
customForm = MAPPER.readValue(is, new TypeReference<HashMap<String, CustomAttributesInfo>>() {
});
File enduserDir = new File(props.getProperty("enduser.directory"));
boolean existsEnduserDir = enduserDir.exists() && enduserDir.canRead() && enduserDir.isDirectory();
if (existsEnduserDir) {
File customFormFile = FileUtils.getFile(enduserDir, CUSTOM_FORM_FILE);
if (customFormFile.exists() && customFormFile.canRead() && customFormFile.isFile()) {
customForm = MAPPER.readValue(FileUtils.openInputStream(customFormFile), new TypeReference<HashMap<String, CustomAttributesInfo>>() {
});
}
}
FileAlterationObserver observer = existsEnduserDir ? new FileAlterationObserver(enduserDir, pathname -> StringUtils.contains(pathname.getPath(), CUSTOM_FORM_FILE)) : new FileAlterationObserver(getClass().getResource("/" + CUSTOM_FORM_FILE).getFile(), pathname -> StringUtils.contains(pathname.getPath(), CUSTOM_FORM_FILE));
FileAlterationMonitor monitor = new FileAlterationMonitor(5000);
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
@Override
public void onFileChange(final File file) {
try {
LOG.trace("{} has changed. Reloading form customization configuration.", CUSTOM_FORM_FILE);
customForm = MAPPER.readValue(FileUtils.openInputStream(file), new TypeReference<HashMap<String, CustomAttributesInfo>>() {
});
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
@Override
public void onFileCreate(final File file) {
try {
LOG.trace("{} has been created. Loading form customization configuration.", CUSTOM_FORM_FILE);
customForm = MAPPER.readValue(FileUtils.openInputStream(file), new TypeReference<HashMap<String, CustomAttributesInfo>>() {
});
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
@Override
public void onFileDelete(final File file) {
LOG.trace("{} has been deleted. Resetting form customization configuration.", CUSTOM_FORM_FILE);
customForm = null;
}
};
observer.addListener(listener);
monitor.addObserver(observer);
monitor.start();
} catch (Exception e) {
throw new WicketRuntimeException("Could not read " + CUSTOM_FORM_FILE, e);
}
// mount resources
ClassPathScanImplementationLookup classPathScanImplementationLookup = (ClassPathScanImplementationLookup) getServletContext().getAttribute(EnduserInitializer.CLASSPATH_LOOKUP);
for (final Class<? extends AbstractResource> resource : classPathScanImplementationLookup.getResources()) {
Resource annotation = resource.getAnnotation(Resource.class);
if (annotation == null) {
LOG.debug("No @Resource annotation found on {}, ignoring", resource.getName());
} else {
try {
final AbstractResource instance = resource.newInstance();
mountResource(annotation.path(), new ResourceReference(annotation.key()) {
private static final long serialVersionUID = -128426276529456602L;
@Override
public IResource getResource() {
return instance;
}
});
} catch (Exception e) {
LOG.error("Could not instantiate {}", resource.getName(), e);
}
}
}
// mount captcha resource only if captcha is enabled
if (captchaEnabled) {
mountResource("/api/captcha", new ResourceReference("captcha") {
private static final long serialVersionUID = -128426276529456602L;
@Override
public IResource getResource() {
return new CaptchaResource();
}
});
}
}
Aggregations