]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/DataValidation.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / DataValidation.java
diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/DataValidation.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/DataValidation.java
deleted file mode 100644 (file)
index d36f258..0000000
+++ /dev/null
@@ -1,712 +0,0 @@
-/** @file\r
\r
- The file is used to provides all kinds of Data Validation interface \r
\r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution.  The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- **/\r
-\r
-package org.tianocore.frameworkwizard.common;\r
-\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-\r
-/**\r
- The class is used to provides all kinds of data validation interface\r
-\r
- <p>All provided interfaces are in static mode</p>\r
\r
- **/\r
-public class DataValidation {\r
-\r
-    /**\r
-     Reserved for test\r
-     \r
-     @param args\r
-     \r
-     **/\r
-    public static void main(String[] args) {\r
-\r
-    }\r
-\r
-    //\r
-    // The below is used to check common data types\r
-    //\r
-\r
-    /**\r
-     Check if the imput data is int\r
-     \r
-     @param strInt The input string which needs validation\r
-     \r
-     @retval true - The input is Int\r
-     @retval false - The input is not Int\r
-     \r
-     **/\r
-    public static boolean isInt(String strInt) {\r
-        return isMatch("^-?[0-9]\\d*$", strInt);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is int and it is in the valid scope\r
-     The scope is provided by String\r
-     \r
-     @param strNumber The input string which needs validation\r
-     @param BeginNumber The left boundary of the scope\r
-     @param EndNumber The right boundary of the scope\r
-     \r
-     @retval true - The input is Int and in the scope;\r
-     @retval false - The input is not Int or not in the scope\r
-     \r
-     **/\r
-    public static boolean isInt(String strNumber, int BeginNumber, int EndNumber) {\r
-        //\r
-        //Check if the input data is int first\r
-        //\r
-        if (!isInt(strNumber)) {\r
-            return false;\r
-        }\r
-        //\r
-        //And then check if the data is between the scope\r
-        //\r
-        Integer intTemp = new Integer(strNumber);\r
-        if ((intTemp.intValue() < BeginNumber) || (intTemp.intValue() > EndNumber)) {\r
-            return false;\r
-        }\r
-        return true;\r
-    }\r
-\r
-    /**\r
-     Check if the input data is int and it is in the valid scope\r
-     The scope is provided by String\r
-     \r
-     @param strNumber The input string which needs validation\r
-     @param strBeginNumber The left boundary of the scope\r
-     @param strEndNumber The right boundary of the scope\r
-     \r
-     @retval true - The input is Int and in the scope;\r
-     @retval false - The input is not Int or not in the scope\r
-     \r
-     **/\r
-    public static boolean isInt(String strNumber, String strBeginNumber, String strEndNumber) {\r
-        //\r
-        //Check if all input data are int\r
-        //\r
-        if (!isInt(strNumber)) {\r
-            return false;\r
-        }\r
-        if (!isInt(strBeginNumber)) {\r
-            return false;\r
-        }\r
-        if (!isInt(strEndNumber)) {\r
-            return false;\r
-        }\r
-        //\r
-        //And then check if the data is between the scope\r
-        //\r
-        Integer intI = new Integer(strNumber);\r
-        Integer intJ = new Integer(strBeginNumber);\r
-        Integer intK = new Integer(strEndNumber);\r
-        if ((intI.intValue() < intJ.intValue()) || (intI.intValue() > intK.intValue())) {\r
-            return false;\r
-        }\r
-        return true;\r
-    }\r
-\r
-    /**\r
-     Use regex to check if the input data is in valid format\r
-     \r
-     @param strPattern The input regex\r
-     @param strMatcher The input data need be checked\r
-     \r
-     @retval true - The data matches the regex\r
-     @retval false - The data doesn't match the regex\r
-     \r
-     **/\r
-    public static boolean isMatch(String strPattern, String strMatcher) {\r
-        Pattern pattern = Pattern.compile(strPattern);\r
-        Matcher matcher = pattern.matcher(strMatcher);\r
-\r
-        return matcher.find();\r
-    }\r
-\r
-    //\r
-    // The below is used to check common customized data types\r
-    //\r
-\r
-    /**\r
-     Check if the input data is UiNameType\r
-     \r
-     @param arg0 The input string need be checked\r
-     \r
-     @retval true - The input is UiNameType\r
-     @retval false - The input is not UiNameType\r
-     \r
-     **/\r
-    public static boolean isUiNameType(String arg0) {\r
-        if (arg0.length() < 1) {\r
-            return false;\r
-        }\r
-        return isMatch("[^ ].*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is GuidType2\r
-     \r
-     @param arg0 The input string need be checked\r
-     \r
-     @retval true - The input is GuidType2\r
-     @retval false - The input is not GuidType2\r
-     \r
-     **/\r
-    public static boolean isGuidType2(String arg0) {\r
-        return isMatch("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Guid \r
-     \r
-     @param strGuid The input string need be checked\r
-     \r
-     @retval true - The input is Guid\r
-     @retval false - The input is not Guid\r
-     \r
-     **/\r
-    public static boolean isGuid(String arg0) {\r
-        return isGuidType2(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Version \r
-     \r
-     @param arg0 The input string need be checked\r
-     \r
-     @retval true - The input is Version\r
-     @retval false - The input is not Version\r
-     \r
-     **/\r
-    public static boolean isVersionDataType(String arg0) {\r
-        return isMatch("\\d+(\\.\\d+)*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Sentence\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is Sentence\r
-     @retval false - The input is not Sentence\r
-     \r
-     **/\r
-    public static boolean isSentence(String arg0) {\r
-        return isMatch("(\\w+\\W*)+( )+(\\W*\\w*\\W*\\s*)*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is FileNameConventio\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is FileNameConventio\r
-     @retval false - The input is not FileNameConventio\r
-     \r
-     **/\r
-    public static boolean isFileNameConvention(String arg0) {\r
-        return isMatch("[a-zA-Z][a-zA-Z0-9]*((_)*(-)*(.)*[a-zA-Z0-9]*)*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is KeywordType\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is KeywordType\r
-     @retval false - The input is not KeywordType\r
-     \r
-     **/\r
-    public static boolean isKeywordType(String arg0) {\r
-        return isMatch("[a-zA-Z]+(_*[a-zA-Z0-9]*)*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is FeatureFlagExpressionType\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is FeatureFlagExpressionType\r
-     @retval false - The input is not FeatureFlagExpressionType\r
-     \r
-     **/\r
-    public static boolean isFeatureFlagExpressionType(String arg0) {\r
-        return (arg0.length() >= 1);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is FeatureFlag\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is FeatureFlag\r
-     @retval false - The input is not FeatureFlag\r
-     \r
-     **/\r
-    public static boolean isFeatureFlag(String arg0) {\r
-        return isFeatureFlagExpressionType(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is PathAndFilename\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is PathAndFilename\r
-     @retval false - The input is not PathAndFilename\r
-     \r
-     **/\r
-    public static boolean isPathAndFilename(String arg0) {\r
-        return !arg0.equals("");\r
-    }\r
-\r
-    /**\r
-     Check if the input data is ToolsNameConvention\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is ToolsNameConvention\r
-     @retval false - The input is not ToolsNameConvention\r
-     \r
-     **/\r
-    public static boolean isToolsNameConvention(String arg0) {\r
-        return isMatch("[a-zA-Z][a-zA-Z0-9]*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is C_NameType\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is C_NameType\r
-     @retval false - The input is not C_NameType\r
-     \r
-     **/\r
-    public static boolean isC_NameType(String arg0) {\r
-        return isMatch("(_)*[a-zA-Z]+((_)*[a-zA-Z0-9]*)*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is HexWordArrayType\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is HexWordArrayType\r
-     @retval false - The input is not HexWordArrayType\r
-     \r
-     **/\r
-    public static boolean isHexWordArrayType(String arg0) {\r
-        return arg0.length() >=6 && isMatch("((\\s)*0x([a-fA-F0-9]){4}(,)?(\\s)*)+", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Hex64BitDataType\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is Hex64BitDataType\r
-     @retval false - The input is not Hex64BitDataType\r
-     \r
-     **/\r
-    public static boolean isHex64BitDataType(String arg0) {\r
-        return isMatch("(0x)?[a-fA-F0-9]{1,16}", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is UnicodeString\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is UnicodeString\r
-     @retval false - The input is not UnicodeString\r
-     \r
-     **/\r
-    public static boolean isUnicodeString(String arg0) {\r
-        return arg0.length() >= 3 && isMatch("(\\s)*L(\\:)?\"[^\"]*\"(\\s)*", arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is HexByteArrayType\r
-     \r
-     @param strSentence The input string need be checked\r
-     \r
-     @retval true - The input is HexByteArrayType\r
-     @retval false - The input is not HexByteArrayType\r
-     \r
-     **/\r
-    public static boolean isHexByteArrayType(String arg0) {\r
-        return arg0.length() >= 4 && isMatch("((\\s)*0x([a-fA-F0-9]){2}(,)?(\\s)*)+", arg0);\r
-    }\r
-    \r
-\r
-    /**\r
-     Check if the input data is DateType\r
-     \r
-     @param strDateType The input string need be checked\r
-     \r
-     @retval true - The input is DateType\r
-     @retval false - The input is not DateType\r
-     \r
-     **/\r
-    public static boolean isDateType(String strDateType) {\r
-        return isMatch("[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]", strDateType);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is DosPath\r
-     \r
-     @param strDosPath The input string need be checked\r
-     \r
-     @retval true - The input is DosPath\r
-     @retval false - The input is not DosPath\r
-     \r
-     **/\r
-    public static boolean isDosPath(String strDosPath) {\r
-        return isMatch("([a-zA-Z]:\\\\)?(((\\\\?_*-*.*[a-zA-Z0-9]*)*(_*-*.*[a-zA-Z0-9])*)+(\\\\)?)*", strDosPath);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is UnixPath\r
-     \r
-     @param strUnixPath The input string need be checked\r
-     \r
-     @retval true - The input is UnixPath\r
-     @retval false - The input is not UnixPath\r
-     \r
-     **/\r
-    public static boolean isUnixPath(String strUnixPath) {\r
-        return isMatch("(\\/)?(((_*-*.*[a-zA-Z0-9]*)*(_*-*.*[a-zA-Z0-9])*)+(\\/)?)*", strUnixPath);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is DirectoryNamingConvention\r
-     \r
-     @param strDirectoryNamingConvention The input string need be checked\r
-     \r
-     @retval true - The input is DirectoryNamingConvention\r
-     @retval false - The input is not DirectoryNamingConvention\r
-     \r
-     **/\r
-    public static boolean isDirectoryNamingConvention(String strDirectoryNamingConvention) {\r
-        return (isDosPath(strDirectoryNamingConvention) || isUnixPath(strDirectoryNamingConvention));\r
-    }\r
-\r
-    /**\r
-     Check if the input data is HexDoubleWordDataType\r
-     \r
-     @param strHexDoubleWordDataType  The input string need be checked\r
-     \r
-     @retval true - The input is HexDoubleWordDataType\r
-     @retval false - The input is not HexDoubleWordDataType\r
-     \r
-     **/\r
-    public static boolean isHexDoubleWordDataType(String strHexDoubleWordDataType) {\r
-        return isMatch("0x[a-fA-F0-9]{1,8}", strHexDoubleWordDataType);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is V1\r
-     \r
-     @param strV1 The input string need be checked\r
-     \r
-     @retval true - The input is V1\r
-     @retval false - The input is not V1\r
-     \r
-     **/\r
-    public static boolean isV1(String strV1) {\r
-        return isMatch("((%[A-Z](_*[A-Z0-9]*)*%)+((((\\\\)?_*-*.*[a-zA-Z0-9]*)*(_*-*.*[a-zA-Z0-9])*)+(\\\\)?)*)", strV1);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is V2\r
-     \r
-     @param strV2 The input string need be checked\r
-     \r
-     @retval true - The input is V2\r
-     @retval false - The input is not V2\r
-     \r
-     **/\r
-    public static boolean isV2(String strV2) {\r
-        return isMatch(\r
-                       "(($[A-Z](_*[A-Z0-9]*)*)+||($\\([A-Z](_*[A-Z0-9]*)*\\))+||($\\{[A-Z](_*[A-Z0-9]*)*\\})+)+(\\/)?(((((_*-*.*[a-zA-Z0-9]*)*(_*-*.*[a-zA-Z0-9])*)+(\\/)?)*)*)",\r
-                       strV2);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is VariableConvention\r
-     \r
-     @param strVariableConvention The input string need be checked\r
-     \r
-     @retval true - The input is VariableConvention\r
-     @retval false - The input is not VariableConvention\r
-     \r
-     **/\r
-    public static boolean isVariableConvention(String strVariableConvention) {\r
-        return (isV1(strVariableConvention) || isV2(strVariableConvention));\r
-    }\r
-\r
-    /**\r
-     Check if the input data is UCName\r
-     \r
-     @param strUCName The input string need be checked\r
-     \r
-     @retval true - The input is UCName\r
-     @retval false - The input is not UCName\r
-     \r
-     **/\r
-    public static boolean isUCName(String strUCName) {\r
-        return isMatch("[A-Z]+(_*[A-Z0-9]*( )*)*", strUCName);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is HexByteDataType\r
-     \r
-     @param strHex64BitDataType The input string need be checked \r
-     \r
-     @retval true - The input is HexByteDataType\r
-     @retval false - The input is not HexByteDataType\r
-     \r
-     **/\r
-    public static boolean isHexByteDataType(String strHex64BitDataType) {\r
-        return isMatch("(0x)?[a-fA-F0-9]{1,2}", strHex64BitDataType);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is HexWordDataType\r
-     \r
-     @param strHexWordDataType The input string need be checked\r
-     \r
-     @retval true - The input is HexWordDataType\r
-     @retval false - The input is not HexWordDataType\r
-     \r
-     **/\r
-    public static boolean isHexWordDataType(String strHexWordDataType) {\r
-        return isMatch("0x[a-fA-F0-9]{1,4}", strHexWordDataType);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is OverrideID\r
-     \r
-     @param strOverrideID The input string need be checked\r
-     \r
-     @retval true - The input is OverrideID\r
-     @retval false - The input is not OverrideID\r
-     \r
-     **/\r
-    public static boolean isOverrideID(String strOverrideID) {\r
-        return isInt(strOverrideID);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Supported Architectures\r
-     \r
-     @param strSupportedArchitectures\r
-     @retval true - The input is Supported Architectures\r
-     @retval false - The input isn't Supported Architectures\r
-     \r
-     */\r
-    public static boolean isSupportedArchitectures(String strSupportedArchitectures) {\r
-        return isMatch("(ALL){1}|(((IA32)|((X64)|(IPF)|(EBC)){1}((,((IA32)|(X64)|(IPF)|(EBC)){1} ){0,2}))){1}",\r
-                       strSupportedArchitectures);\r
-    }\r
-\r
-    //\r
-    //The below is used to check msaheader data type\r
-    //\r
-\r
-    /**\r
-     Check if the input data is BaseName\r
-     \r
-     @param strBaseName The input string need be checked\r
-     \r
-     @retval true - The input is BaseName\r
-     @retval false - The input is not BaseName\r
-     \r
-     **/\r
-    public static boolean isBaseName(String arg0) {\r
-        return isUiNameType(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Version\r
-     \r
-     @param arg0 The input string need be checked\r
-\r
-     @retval true - The input is Version\r
-     @retval false - The input is not Version\r
-     \r
-     **/\r
-    public static boolean isVersion(String arg0) {\r
-        return isVersionDataType(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Abstract\r
-     \r
-     @param strAbstract The input string need be checked\r
-     \r
-     @retval true - The input is Abstract\r
-     @retval false - The input is not Abstract\r
-     \r
-     **/\r
-    public static boolean isAbstract(String arg0) {\r
-        return isSentence(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Copyright\r
-     \r
-     @param strCopyright The input string need be checked\r
-     \r
-     @retval true - The input is Copyright\r
-     @retval false - The input is not Copyright\r
-     \r
-     **/\r
-    public static boolean isCopyright(String arg0) {\r
-        return !arg0.equals("");\r
-    }\r
-\r
-    /**\r
-     Check if the input data is Specification\r
-     \r
-     @param strCopyright The input string need be checked\r
-     \r
-     @retval true - The input is Specification\r
-     @retval false - The input is not Specification\r
-     \r
-     **/\r
-    public static boolean isSpecification(String arg0) {\r
-        return isSentence(arg0);\r
-    }\r
-\r
-    //\r
-    // The below is used to check ModuleDefinitions data types\r
-    //\r
-    /**\r
-     Check if the input data is OutputFileBasename\r
-     \r
-     @param strCopyright The input string need be checked\r
-     \r
-     @retval true - The input is OutputFileBasename\r
-     @retval false - The input is not OutputFileBasename\r
-     \r
-     **/\r
-    public static boolean isOutputFileBasename(String arg0) {\r
-        return isFileNameConvention(arg0);\r
-    }\r
-\r
-    //\r
-    // The below is used to check LibraryClass data types\r
-    //\r
-    /**\r
-     Check if the input data is LibraryClass\r
-     \r
-     @param strCopyright The input string need be checked\r
-     \r
-     @retval true - The input is LibraryClass\r
-     @retval false - The input is not LibraryClass\r
-     \r
-     **/\r
-    public static boolean isLibraryClass(String arg0) {\r
-        return isKeywordType(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is RecommendedInstanceVersion\r
-     \r
-     @param strCopyright The input string need be checked\r
-     \r
-     @retval true - The input is RecommendedInstanceVersion\r
-     @retval false - The input is not RecommendedInstanceVersion\r
-     \r
-     **/\r
-    public static boolean isRecommendedInstanceVersion(String arg0) {\r
-        return isVersionDataType(arg0);\r
-    }\r
-\r
-    //\r
-    // The below is used to check sourcefiles data types\r
-    //\r
-\r
-    /**\r
-     Check if the input data is Filename\r
-     \r
-     @param strPath The input string need be checked\r
-     \r
-     @retval true - The input is Filename\r
-     @retval false - The input is not Filename\r
-     \r
-     **/\r
-    public static boolean isFilename(String arg0) {\r
-        return isPathAndFilename(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is TagName\r
-     \r
-     @param strPath The input string need be checked\r
-     \r
-     @retval true - The input is TagName\r
-     @retval false - The input is not TagName\r
-     \r
-     **/\r
-    public static boolean isTagName(String arg0) {\r
-        return isToolsNameConvention(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is ToolCode\r
-     \r
-     @param strPath The input string need be checked\r
-     \r
-     @retval true - The input is ToolCode\r
-     @retval false - The input is not ToolCode\r
-     \r
-     **/\r
-    public static boolean isToolCode(String arg0) {\r
-        return isToolsNameConvention(arg0);\r
-    }\r
-\r
-    /**\r
-     Check if the input data is ToolChainFamily\r
-     \r
-     @param strPath The input string need be checked\r
-     \r
-     @retval true - The input is ToolChainFamily\r
-     @retval false - The input is not ToolChainFamily\r
-     \r
-     **/\r
-    public static boolean isToolChainFamily(String arg0) {\r
-        return isToolsNameConvention(arg0);\r
-    }\r
-\r
-    //\r
-    // The below is used to check pcdcoded data types\r
-    //\r
-    /**\r
-    Check if the input data is DefaultValueType\r
-    \r
-    @param strPath The input string need be checked\r
-    \r
-    @retval true - The input is DefaultValueType\r
-    @retval false - The input is not DefaultValueType\r
-    \r
-    **/\r
-   public static boolean isDefaultValueType(String arg0) {\r
-       return isHex64BitDataType(arg0) || isUnicodeString(arg0) || isHexByteArrayType(arg0);\r
-   }\r
-\r
-}\r