|
@@ -19,37 +19,26 @@
|
19
|
19
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
20
|
* SOFTWARE.
|
21
|
21
|
*/
|
22
|
|
-
|
23
|
22
|
package com.dmdirc.util.validators;
|
24
|
23
|
|
25
|
|
-import java.net.URI;
|
26
|
|
-import java.net.URISyntaxException;
|
27
|
|
-
|
28
|
24
|
/**
|
29
|
25
|
* Validates a server name, prepending an irc protocol if no protocol is
|
30
|
26
|
* specified.
|
31
|
27
|
*/
|
32
|
|
-public class ServerNameValidator implements Validator<String> {
|
|
28
|
+public class ServerNameValidator extends URIValidator {
|
33
|
29
|
|
34
|
|
- /** {@inheritDoc} */
|
|
30
|
+ /**
|
|
31
|
+ * {@inheritDoc}
|
|
32
|
+ */
|
35
|
33
|
@Override
|
36
|
34
|
public ValidationResponse validate(final String object) {
|
37
|
|
- try {
|
38
|
|
- if (object == null || object.isEmpty()) {
|
39
|
|
- return new ValidationResponse("Server name is required.");
|
40
|
|
- }
|
41
|
|
- if (!object.matches(".*://")) {
|
42
|
|
- new URI("irc://" + object);
|
43
|
|
- } else {
|
44
|
|
- new URI(object);
|
45
|
|
- }
|
46
|
|
- return new ValidationResponse();
|
47
|
|
- } catch (URISyntaxException ex) {
|
48
|
|
- if ("Expected authority".equals(ex.getReason())) {
|
49
|
|
- return new ValidationResponse("Address requires a hostname.");
|
50
|
|
- } else {
|
51
|
|
- return new ValidationResponse(ex.getReason());
|
52
|
|
- }
|
|
35
|
+ if (object == null || object.isEmpty()) {
|
|
36
|
+ return new ValidationResponse("Server name is required.");
|
|
37
|
+ }
|
|
38
|
+ if (!object.matches(".*://")) {
|
|
39
|
+ return super.validate("irc://" + object);
|
|
40
|
+ } else {
|
|
41
|
+ return super.validate(object);
|
53
|
42
|
}
|
54
|
43
|
}
|
55
|
44
|
}
|