1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
13 * Created on 29.12.2005
16 package org.simantics.utils.ui.validators;
18 import java.net.MalformedURLException;
21 import org.eclipse.jface.dialogs.IInputValidator;
26 * @author Toni Kalajainen
28 public class URLValidator implements IInputValidator {
30 private final String supportedProtocols[];
32 public URLValidator() {
33 supportedProtocols = null;
36 public URLValidator(String... supportedProtocols) {
37 this.supportedProtocols = supportedProtocols;
40 public String isValid(String newText) {
42 URL u = new URL(newText);
43 if (supportedProtocols==null)
45 for (String p : supportedProtocols)
46 if (p.equals(u.getProtocol()))
48 return u.getProtocol()+":// is not supported.";
49 } catch (MalformedURLException e) {
50 return e.getMessage();