浏览代码

Add some new validators for use later on

Change-Id: I1857299965ebbc60983b158791cee2cec39c1e95
Reviewed-on: http://gerrit.dmdirc.com/1567
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.5
Chris Smith 13 年前
父节点
当前提交
7bb4ea7a92

+ 40
- 0
src/com/dmdirc/util/validators/ColourValidator.java 查看文件

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates that the value is a valid IRC colour (hex or mIRC).
27
+ *
28
+ * @since 0.6.5
29
+ * @author chris
30
+ */
31
+public class ColourValidator extends RegexStringValidator implements Validator<String> {
32
+
33
+    /**
34
+     * Creates a new colour validator.
35
+     */
36
+    public ColourValidator() {
37
+        super("^[0-9]|1[0-5]|[A-F0-9]{6}$", "Must be a valid colour");
38
+    }
39
+
40
+}

+ 44
- 0
src/com/dmdirc/util/validators/DisabledOptionValidator.java 查看文件

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Validates that the value is not a disabled option (i.e., it is not prefixed
27
+ * with "false:".
28
+ *
29
+ * @since 0.6.5
30
+ * @author chris
31
+ */
32
+public class DisabledOptionValidator implements Validator<String> {
33
+
34
+    /** {@inheritDoc} */
35
+    @Override
36
+    public ValidationResponse validate(final String object) {
37
+        if (object != null && object.startsWith("false:")) {
38
+            return new ValidationResponse("Setting is disabled");
39
+        }
40
+
41
+        return new ValidationResponse();
42
+    }
43
+
44
+}

+ 0
- 3
src/com/dmdirc/util/validators/PermissiveValidator.java 查看文件

@@ -21,9 +21,6 @@
21 21
  */
22 22
 package com.dmdirc.util.validators;
23 23
 
24
-import com.dmdirc.util.validators.ValidationResponse;
25
-import com.dmdirc.util.validators.Validator;
26
-
27 24
 /**
28 25
  * A validator that permits everything.
29 26
  *

正在加载...
取消
保存