2 * Copyright 2016 ZTE, Inc. and others.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.openo.msb.wrapper.util;
\r
18 import java.util.regex.Pattern;
\r
20 public class RegExpTestUtil {
\r
24 public static boolean hostRegExpTest(String host){
\r
26 String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
\r
27 +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
\r
28 +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
\r
29 +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)"
\r
31 return Pattern.matches(hostReg, host);
\r
35 public static boolean ipRegExpTest(String ip){
\r
37 String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
\r
38 +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
\r
39 +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
\r
40 +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
\r
41 return Pattern.matches(hostReg, ip);
\r
45 public static boolean portRegExpTest(String port){
\r
47 String hostReg = "^\\d{1,5}$";
\r
48 return Pattern.matches(hostReg, port);
\r
52 public static boolean versionRegExpTest(String version){
\r
54 String versionReg = "^v\\d+(\\.\\d+)?$";
\r
55 return Pattern.matches(versionReg, version);
\r
59 public static boolean urlRegExpTest(String url){
\r
60 if(url.equals("/")) return true;
\r
62 String urlReg = "^\\/.*((?!\\/).)$";
\r
63 return Pattern.matches(urlReg, url);
\r
67 public static boolean apiRouteUrlRegExpTest(String url){
\r
69 String urlReg = "^\\/"+RouteUtil.API_ROOT_PATH+"\\/.*$";
\r
70 return Pattern.matches(urlReg, url);
\r
74 public static boolean iuiRouteUrlRegExpTest(String url){
\r
76 String urlReg = "^\\/"+RouteUtil.IUI_ROOT_PATH+"\\/.*$";
\r
77 return Pattern.matches(urlReg, url);
\r
84 public static void main(String[] args) {
\r
85 System.out.println(urlRegExpTest("/api "));
\r
86 // System.out.println("api".startsWith("/"));
\r