Java Code Examples for org.apache.commons.lang.StringUtils#endsWith()

The following examples show how to use org.apache.commons.lang.StringUtils#endsWith() . 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
/**
 * Calls a script which must be located in the configurations/scripts folder.
 *
 * @param scriptName the name of the script (if the name does not end with
 *            the .script file extension it is added)
 *
 * @return the return value of the script
 * @throws ScriptExecutionException if an error occurs during the execution
 */
public static Object callScript(String scriptName) throws ScriptExecutionException {
    ModelRepository repo = ScriptServiceUtil.getModelRepository();
    if (repo != null) {
        String scriptNameWithExt = scriptName;
        if (!StringUtils.endsWith(scriptName, Script.SCRIPT_FILEEXT)) {
            scriptNameWithExt = scriptName + "." + Script.SCRIPT_FILEEXT;
        }
        XExpression expr = (XExpression) repo.getModel(scriptNameWithExt);
        if (expr != null) {
            ScriptEngine scriptEngine = ScriptServiceUtil.getScriptEngine();
            if (scriptEngine != null) {
                Script script = scriptEngine.newScriptFromXExpression(expr);
                return script.execute();
            } else {
                throw new ScriptExecutionException("Script engine is not available.");
            }
        } else {
            throw new ScriptExecutionException("Script '" + scriptName + "' cannot be found.");
        }
    } else {
        throw new ScriptExecutionException("Model repository is not available.");
    }
}
 
Example 2
/**
 * Tries as best as possible to guess the repository HTML url to use with {@link GithubWeb}.
 *
 * @param owner the owner.
 * @param repo  the repository.
 * @return the HTML url of the repository or {@code null} if we could not determine the answer.
 */
@CheckForNull
public final String repositoryUrl(String owner, String repo) {
    if (repositoryUrl != null) {
        if (repoOwner.equals(owner) && repository.equals(repo)) {
            return repositoryUrl.toExternalForm();
        }
        // hack!
        return repositoryUrl.toExternalForm().replace(repoOwner + "/" + repository, owner + "/" + repo);
    }
    if (StringUtils.isBlank(apiUri) || GitHubServerConfig.GITHUB_URL.equals(apiUri)) {
        return "https://github.com/" + owner + "/" + repo;
    }
    if (StringUtils.endsWith(StringUtils.removeEnd(apiUri, "/"), "/"+API_V3)) {
        return StringUtils.removeEnd(StringUtils.removeEnd(apiUri, "/"), API_V3) + owner + "/" + repo;
    }
    return null;
}
 
Example 3
Source Project: ymate-platform-v2   File: WebUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param url           URL地址
 * @param needStartWith 是否以'/'开始
 * @param needEndWith   是否以'/'结束
 * @return 返回修正后的URL地址
 */
public static String fixURL(String url, boolean needStartWith, boolean needEndWith) {
    url = StringUtils.trimToNull(url);
    if (url != null) {
        if (needStartWith && !StringUtils.startsWith(url, "/")) {
            url = '/' + url;
        } else if (!needStartWith && StringUtils.startsWith(url, "/")) {
            url = StringUtils.substringAfter(url, "/");
        }
        if (needEndWith && !StringUtils.endsWith(url, "/")) {
            url = url + '/';
        } else if (!needEndWith && StringUtils.endsWith(url, "/")) {
            url = StringUtils.substringBeforeLast(url, "/");
        }
        return url;
    }
    return "";
}
 
Example 4
Source Project: APM   File: Deny.java    License: Apache License 2.0 5 votes vote down vote up
private String recalculateGlob(String glob) {
  String preparedGlob = "";
  if (!StringUtils.isBlank(glob)) {
    preparedGlob = glob;
    if (StringUtils.endsWith(glob, "*")) {
      preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*'));
    }
  }
  return preparedGlob;
}
 
Example 5
Source Project: canal-1.1.3   File: BinlogDownloadQueue.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isLastFile(String fileName) {
    String needCompareName = lastDownload;
    if (StringUtils.isNotEmpty(needCompareName) && StringUtils.endsWith(needCompareName, "tar")) {
        needCompareName = needCompareName.substring(0, needCompareName.indexOf("."));
    }
    return (needCompareName == null || fileName.equalsIgnoreCase(needCompareName)) && binlogList.isEmpty();
}
 
Example 6
private InputStream getTSAKeystoreStream() throws IOException, IntegrationModuleException {
    InputStream stream = null;
    String tSAKeyStoreDir = propertyHandler.getProperty(KEYSTORE_DIR);
    String tSAKeyStoreFile = propertyHandler.getProperty(TSA_KEYSTORE_FILE);

    String keyStoreFilePath = "";
    if (StringUtils.endsWith(tSAKeyStoreDir, "/")) {
        keyStoreFilePath = tSAKeyStoreDir + tSAKeyStoreFile;
    } else {
        keyStoreFilePath = tSAKeyStoreDir + "/" + tSAKeyStoreFile;
    }
    stream = IOUtils.getResourceAsStream(keyStoreFilePath);
    return stream;
}
 
Example 7
private String createCorrectModuleName(String newName) {
    if (StringUtils.endsWith(newName,".hs")){
        return StringUtils.removeEnd(newName,".hs");
    } else {
        return newName;
    }
}
 
Example 8
Source Project: canal   File: BinlogDownloadQueue.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isLastFile(String fileName) {
    String needCompareName = lastDownload;
    if (StringUtils.isNotEmpty(needCompareName) && StringUtils.endsWith(needCompareName, "tar")) {
        needCompareName = needCompareName.substring(0, needCompareName.indexOf("."));
    }
    return (needCompareName == null || fileName.equalsIgnoreCase(needCompareName)) && binlogList.isEmpty();
}
 
Example 9
Source Project: azure-devops-intellij   File: UrlHelper.java    License: MIT License 5 votes vote down vote up
public static boolean isVSO(final URI uri) {
    if (uri != null && uri.getHost() != null) {
        final String host = uri.getHost().toLowerCase();
        if (StringUtils.endsWith(host, HOST_VSO) ||
                StringUtils.endsWith(host, HOST_TFS_ALL_IN) ||
                UrlHelper.isOrganizationHost(host)) {
            return true;
        }
    }
    return false;
}
 
Example 10
private InputStream getTSAKeystoreStream() throws IOException, IntegrationModuleException {
    InputStream stream = null;
    String tSAKeyStoreDir = propertyHandler.getProperty(KEYSTORE_DIR);
    String tSAKeyStoreFile = propertyHandler.getProperty(TSA_KEYSTORE_FILE);

    String keyStoreFilePath = "";
    if (StringUtils.endsWith(tSAKeyStoreDir, "/")) {
        keyStoreFilePath = tSAKeyStoreDir + tSAKeyStoreFile;
    } else {
        keyStoreFilePath = tSAKeyStoreDir + "/" + tSAKeyStoreFile;
    }
    stream = IOUtils.getResourceAsStream(keyStoreFilePath);
    return stream;
}
 
Example 11
private static String validateSettings(FlutterCreateAdditionalSettings settings) {
  final String description = settings.getDescription();
  if (description != null && description.contains(": ")) {
    return "Invalid package description: '" + description + "' - cannot contain the sequence ': '.";
  }
  final String org = settings.getOrg();
  if (org == null) {
    return null;
  }
  if (StringUtils.endsWith(org, ".")) {
    return "Invalid organization name: '" + org + "' - cannot end in '.'.";
  }
  // Invalid package names will cause issues down the line.
  return AndroidUtils.validateAndroidPackageName(org);
}
 
Example 12
/**
 * 连接路径字符串
 *
 * @param parentDir   路径常量字符串
 * @param packageName 包名
 * @return 连接后的路径
 */
private String joinPath(String parentDir, String packageName) {
    if (StringUtils.isEmpty(parentDir)) {
        parentDir = System.getProperty(ConstVal.JAVA_TMPDIR);
    }
    if (!StringUtils.endsWith(parentDir, File.separator)) {
        parentDir += File.separator;
    }
    packageName = packageName.replaceAll("\\.", "\\" + File.separator);
    return parentDir + packageName;
}
 
Example 13
Source Project: rice   File: Action.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * Setter for {@link #getActionScript()}.
 *
 * @param actionScript the actionScript to set
 */
public void setActionScript(String actionScript) {
    if (StringUtils.isNotBlank(actionScript) && !StringUtils.endsWith(actionScript, ";")) {
        actionScript = actionScript + ";";
    }

    this.actionScript = actionScript;
}
 
Example 14
private void addLogMessageFilter(Query query, String value, boolean negate) {
  value = value.trim();
  if (StringUtils.startsWith(value, "\"") && StringUtils.endsWith(value,"\"")) {
    value = String.format("\"%s\"", SolrUtil.escapeQueryChars(StringUtils.substring(value, 1, -1)));
    addFilterQuery(query, new Criteria(LOG_MESSAGE).expression(value), negate);
  }
  else if (isNotBlank(value)){
    addFilterQuery(query, new Criteria(LOG_MESSAGE).expression(SolrUtil.escapeQueryChars(value)), negate);
  }
}
 
Example 15
public InterceptorRuleMeta(IWebMvc owner, Class<? extends IInterceptorRule> targetClass, Method targetMethod) {
    InterceptorRule _ruleAnno = targetMethod.getAnnotation(InterceptorRule.class);
    if (_ruleAnno != null && StringUtils.trimToNull(_ruleAnno.value()) != null) {
        String _mapping = _ruleAnno.value();
        if (!StringUtils.startsWith(_mapping, "/")) {
            _mapping += "/";
        }
        //
        _ruleAnno = targetClass.getAnnotation(InterceptorRule.class);
        if (_ruleAnno != null) {
            mapping = StringUtils.trimToEmpty(_ruleAnno.value());
            if (StringUtils.endsWith(mapping, "/")) {
                mapping = StringUtils.substringBeforeLast(mapping, "/");
            }
        }
        mapping += _mapping;
        //
        if (!StringUtils.startsWith(mapping, "/")) {
            mapping += "/";
        }
        if (StringUtils.endsWith(mapping, "/*")) {
            matchAll = true;
            mapping = StringUtils.substringBeforeLast(mapping, "/*");
        }
        //
        beforeIntercepts = InterceptAnnoHelper.getBeforeIntercepts(targetClass, targetMethod);
        contextParams = InterceptAnnoHelper.getContextParams(owner.getOwner(), targetClass, targetMethod);
        //
        this.responseCache = targetMethod.getAnnotation(ResponseCache.class);
        if (this.responseCache == null) {
            this.responseCache = targetClass.getAnnotation(ResponseCache.class);
        }
    }
}
 
Example 16
/**
 * Gain table table.
 *
 * @param connection the connection
 * @param tableName  the table name
 * @param cfTable    the cf table
 * @return the table
 * @throws SQLException the sql exception
 */
public Table gainTable(Connection connection, String tableName, CfTable cfTable)
        throws SQLException {
    //支持分表,逻辑表
    String physicalName = cfTable == null ? tableName : cfTable.getPhysicalName();
    //物理表
    String logicName = tableName;
    for (String splitTableSuffix : ConfigUtil.getConfig().getSplitTableSuffixs()) {
        if (StringUtils.endsWithIgnoreCase(tableName, splitTableSuffix)) {
            logicName = StringUtils.replace(logicName, splitTableSuffix, "");
            break;
        }
    }
    //自定义字段类型
    List<CfColumn> cfColumns = cfTable == null ? null : cfTable.getColumns();
    //生成table
    Table table = new Table();
    table.setSqlName(logicName);
    for (String pre : ConfigUtil.getConfig().getTablePrefixs()) {
        if (!StringUtils.endsWith(pre, "_")) {
            pre = pre + "_";
        }

        if (StringUtils.startsWith(logicName, StringUtils.upperCase(pre))) {
            table.setJavaName(CamelCaseUtils.toCapitalizeCamelCase(StringUtils.substring(
                    logicName, pre.length())));
            break;/* 取第一个匹配的 */
        }
    }
    if (StringUtils.isBlank(table.getJavaName())) {
        table.setJavaName(CamelCaseUtils.toCapitalizeCamelCase(logicName));
    }
    table.setPhysicalName(physicalName);
    table.setRemark(logicName);
    //填充字段
    fillColumns(connection, physicalName, table, cfColumns);
    return table;
}
 
Example 17
private String createCorrectFileName(String newName) {
    if (StringUtils.endsWith(newName,".hs")){
        return newName;
    } else {
        return newName + ".hs";
    }
}
 
Example 18
/**
 * Used internally by parseExpression to evalute if the current stack is a property
 * name (ie, will be a control on the form)
 *
 * @param stack
 * @param controlNames
 */
public static void evaluateCurrentStack(String stack, List<String> controlNames) {
    if (StringUtils.isNotBlank(stack)) {
        if (!(stack.equals("==")
                || stack.equals("!=")
                || stack.equals(">")
                || stack.equals("<")
                || stack.equals(">=")
                || stack.equals("<=")
                || stack.equalsIgnoreCase("ne")
                || stack.equalsIgnoreCase("eq")
                || stack.equalsIgnoreCase("gt")
                || stack.equalsIgnoreCase("lt")
                || stack.equalsIgnoreCase("lte")
                || stack.equalsIgnoreCase("gte")
                || stack.equalsIgnoreCase("matches")
                || stack.equalsIgnoreCase("null")
                || stack.equalsIgnoreCase("false")
                || stack.equalsIgnoreCase("true")
                || stack.equalsIgnoreCase("and")
                || stack.equalsIgnoreCase("or")
                || stack.contains("#empty")
                || stack.equals("!")
                || stack.contains("#emptyList")
                || stack.contains("#listContains")
                || stack.startsWith("'")
                || stack.endsWith("'"))) {

            boolean isNumber = false;
            if ((StringUtils.isNumeric(stack.substring(0, 1)) || stack.substring(0, 1).equals("-"))) {
                try {
                    Double.parseDouble(stack);
                    isNumber = true;
                } catch (NumberFormatException e) {
                    isNumber = false;
                }
            }

            if (!(isNumber)) {
                //correct argument of a custom function ending in comma
                if (StringUtils.endsWith(stack, ",")) {
                    stack = StringUtils.removeEnd(stack, ",").trim();
                }

                if (!controlNames.contains(stack)) {
                    controlNames.add(stack);
                }
            }
        }
    }
}
 
Example 19
Source Project: azure-devops-intellij   File: WorkspaceHelper.java    License: MIT License 4 votes vote down vote up
/**
 * This method returns true if the serverPath ends with /*
 */
public static boolean isOneLevelMapping(final String serverPath) {
    return StringUtils.endsWith(serverPath, ONE_LEVEL_MAPPING_SUFFIX);
}
 
Example 20
Source Project: atlas   File: AtlasTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isArrayType(String typeName) {
    return StringUtils.startsWith(typeName, ATLAS_TYPE_ARRAY_PREFIX)
        && StringUtils.endsWith(typeName, ATLAS_TYPE_ARRAY_SUFFIX);
}