]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/validators/URLValidator.java
Fixed a bug related to the extent of variable frames (see test case)
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / validators / URLValidator.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  * Created on 29.12.2005
14  * 
15  */
16 package org.simantics.utils.ui.validators;
17
18 import java.net.MalformedURLException;
19 import java.net.URL;
20
21 import org.eclipse.jface.dialogs.IInputValidator;
22
23 /**
24  * URL Validator
25  * 
26  * @author Toni Kalajainen
27  */
28 public class URLValidator implements IInputValidator {
29
30     private final String supportedProtocols[];
31     
32     public URLValidator() { 
33         supportedProtocols = null;
34     }
35
36     public URLValidator(String... supportedProtocols) {
37         this.supportedProtocols = supportedProtocols;
38     }
39     
40     public String isValid(String newText) {
41         try {
42             URL u = new URL(newText);
43             if (supportedProtocols==null)
44                 return null;
45             for (String p : supportedProtocols)
46                 if (p.equals(u.getProtocol()))
47                     return null;
48             return u.getProtocol()+":// is not supported.";            
49         } catch (MalformedURLException e) {
50             return e.getMessage();
51         }
52     }
53
54 }
55