##### Coverage Report - com.ctrip.framework.apollo.common.utils.InputValidator

Classes in this File | Line Coverage | Branch Coverage | Complexity
InputValidator |
60% | 6/10
0% | 0/6
| 2.5;2.5

1 |  |
     package com.ctrip.framework.apollo.common.utils;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.core.utils.StringUtils;
4 |  |
5 |  |
     import java.util.regex.Matcher;
6 |  |
     import java.util.regex.Pattern;
7 |  |
8 |  |
     /**
9 |  |
      * @author Jason Song(song_s@ctrip.com)
10 |  |
      */
11 | 0 |
     public class InputValidator {
12 |  |
       public static final String INVALID_CLUSTER_NAMESPACE_MESSAGE = "只允许输入数字，字母和符号 - _ .";
13 |  |
       public static final String INVALID_NAMESPACE_NAMESPACE_MESSAGE = "不允许以.json, .yml, .yaml, .xml, .properties结尾";
14 |  |
       public static final String CLUSTER_NAMESPACE_VALIDATOR = "[0-9a-zA-z_.-]+";
15 |  |
       public static final String APP_NAMESPACE_VALIDATOR = "[a-zA-z0-9._-]+(?<!\\.(json|yml|yaml|xml|properties))$";
16 | 1 |
       private static final Pattern CLUSTER_NAMESPACE_PATTERN =
17 | 1 |
           Pattern.compile(CLUSTER_NAMESPACE_VALIDATOR);
18 | 2 |
       private static final Pattern APP_NAMESPACE_PATTERN =
19 | 1 |
           Pattern.compile(APP_NAMESPACE_VALIDATOR);
20 |  |
21 |  |
22 |  |
       public static boolean isValidClusterNamespace(String input) {
23 | 3 |
         Matcher matcher = CLUSTER_NAMESPACE_PATTERN.matcher(input);
24 | 3 |
         return matcher.matches();
25 |  |
       }
26 |  |
27 |  |
       public static boolean isValidAppNamespace(String name){
28 | 0 |
         if (StringUtils.isEmpty(name)){
29 | 0 |
           return false;
30 |  |
         }
31 | 0 |
         return CLUSTER_NAMESPACE_PATTERN.matcher(name.toLowerCase()).matches() && APP_NAMESPACE_PATTERN.matcher(name).matches();
32 |  |
       }
33 |  |
     }