com.baifendian.swordfish.common.utils.VerifyUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.baifendian.swordfish.common.utils.VerifyUtil.java

Source

/*
 * Copyright (C) 2017 Baifendian Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *           http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.baifendian.swordfish.common.utils;

import com.baifendian.swordfish.common.config.BaseConfig;
import com.baifendian.swordfish.common.consts.Constants;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

/**
 * 
 */
public class VerifyUtil {

    /**
     * ?
     *
     * @param str
     * @param pattern
     * @return
     */
    public static boolean regexMatches(String str, Pattern pattern) {
        if (StringUtils.isEmpty(str)) {
            return false;
        }

        return pattern.matcher(str).matches();
    }

    /**
     * ??
     *
     * @param str
     * @return
     */
    public static boolean matcheProjectName(String str) {
        return regexMatches(str, Constants.REGEX_PROJECT_NAME);
    }

    /**
     * ????
     *
     * @param str
     * @return
     */
    public static boolean matcheUserName(String str) {
        return regexMatches(str, Constants.REGEX_USER_NAME);
    }

    /**
     * ??
     *
     * @param str
     * @return
     */
    public static boolean matchEmail(String str) {
        return regexMatches(str, Constants.REGEX_MAIL_NAME) && str.length() <= 64;
    }

    /**
     * ?????
     *
     * @param str
     * @return
     */
    public static boolean matcheResName(String str) {
        return regexMatches(str, Constants.REGEX_RES_NAME);
    }

    /**
     * ??????
     *
     * @param str
     * @return
     */
    public static boolean matcheDatasourceName(String str) {
        return regexMatches(str, Constants.REGEX_DATASOURCE_NAME);
    }

    /**
     * ????
     *
     * @param str
     * @return
     */
    public static boolean matchWorkflowName(String str) {
        return regexMatches(str, Constants.REGEX_WORKFLOW_NAME);
    }

    /**
     * ??
     *
     * @param str
     * @return
     */
    public static boolean matchProxyUser(String str) {
        return BaseConfig.isProhibitUser(str);
    }
}