+++ /dev/null
-/**\r
-* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
-*\r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*/\r
-package org.openo.msb.wrapper.util;\r
-\r
-import java.util.regex.Pattern;\r
-\r
-public class RegExpTestUtil {\r
- \r
- \r
- \r
- public static boolean hostRegExpTest(String host){\r
- \r
- String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\." \r
- +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." \r
- +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." \r
- +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)"\r
- +":(\\d{1,5})$"; \r
- return Pattern.matches(hostReg, host); \r
- \r
- }\r
- \r
- public static boolean ipRegExpTest(String ip){\r
- \r
- String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\." \r
- +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." \r
- +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\." \r
- +"(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$"; \r
- return Pattern.matches(hostReg, ip); \r
- \r
- }\r
- \r
- public static boolean portRegExpTest(String port){\r
- \r
- String hostReg = "^\\d{1,5}$"; \r
- return Pattern.matches(hostReg, port); \r
- \r
- }\r
- \r
-public static boolean versionRegExpTest(String version){\r
- \r
- String versionReg = "^v\\d+(\\.\\d+)?$"; \r
- return Pattern.matches(versionReg, version); \r
- \r
- }\r
-\r
-public static boolean urlRegExpTest(String url){\r
- if(url.equals("/")) return true;\r
- \r
- String urlReg = "^\\/.*((?!\\/).)$"; \r
- return Pattern.matches(urlReg, url); \r
- \r
-}\r
-\r
-public static boolean apiRouteUrlRegExpTest(String url){\r
- \r
- String urlReg = "^\\/"+RouteUtil.API_ROOT_PATH+"\\/.*$"; \r
- return Pattern.matches(urlReg, url); \r
- \r
-}\r
-\r
-public static boolean iuiRouteUrlRegExpTest(String url){\r
- \r
- String urlReg = "^\\/"+RouteUtil.IUI_ROOT_PATH+"\\/.*$"; \r
- return Pattern.matches(urlReg, url); \r
- \r
-}\r
-\r
-\r
- \r
- \r
- public static void main(String[] args) {\r
- System.out.println(urlRegExpTest("/api "));\r
-// System.out.println("api".startsWith("/"));\r
- }\r
-}\r