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

The following examples show how to use org.apache.commons.lang.StringUtils#endsWith() . 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: ScriptExecution.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 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
Source File: WebUtils.java    From ymate-platform-v2 with 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 3
Source File: GitHubSCMBuilder.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * 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 4
Source File: ConfigBuilder.java    From mybatis-plus-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 连接路径字符串
 *
 * @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 5
Source File: HaskellRenamePsiElementProcessor.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
private String createCorrectFileName(String newName) {
    if (StringUtils.endsWith(newName,".hs")){
        return newName;
    } else {
        return newName + ".hs";
    }
}
 
Example 6
Source File: OBTableRepository.java    From mybatis-dalgen with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: DefaultInterceptorRuleProcessor.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
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 8
Source File: AbstractOperationHolderConverter.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
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 9
Source File: Action.java    From rice with 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 10
Source File: Deny.java    From APM with 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 11
Source File: FlutterModuleBuilder.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: EncryptionUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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 13
Source File: UrlHelper.java    From azure-devops-intellij with 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 14
Source File: BinlogDownloadQueue.java    From canal with 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 15
Source File: HaskellRenamePsiElementProcessor.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
private String createCorrectModuleName(String newName) {
    if (StringUtils.endsWith(newName,".hs")){
        return StringUtils.removeEnd(newName,".hs");
    } else {
        return newName;
    }
}
 
Example 16
Source File: EncryptionUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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 17
Source File: BinlogDownloadQueue.java    From canal-1.1.3 with 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 18
Source File: AtlasTypeUtil.java    From atlas with 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);
}
 
Example 19
Source File: WorkspaceHelper.java    From azure-devops-intellij with 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 File: ExpressionUtils.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * 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);
                }
            }
        }
    }
}