X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fvalidators%2FRegexpValidator.java;fp=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fvalidators%2FRegexpValidator.java;h=9ddea8adc904f9aadd63ae485c6f18a40e24975d;hp=78ff62d92c2da4677c81916509a9b5afc0021690;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/validators/RegexpValidator.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/validators/RegexpValidator.java index 78ff62d92..9ddea8adc 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/validators/RegexpValidator.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/validators/RegexpValidator.java @@ -1,52 +1,52 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.utils.ui.validators; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.eclipse.jface.dialogs.IInputValidator; - -/** - * Regular expression validator - * - * @author Toni Kalajainen - */ -public class RegexpValidator implements IInputValidator { - - // Hostname mask - //^([a-zA-Z0-9\\*]([a-zA-Z0-9\\-\\*]{0,61}[a-zA-Z0-9\\*])?\\.)*[a-zA-Z0-9\\*]([a-zA-Z0-9\\-\\*]{0,61}[a-zA-Z0-9\\*])?$ - - // Untested - //public static final String URL_VALIDATOR_STRING = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\\?\\/.=]+$"; - //public static RegexpValidator URL_VALIDATOR = new RegexpValidator(URL_VALIDATOR_STRING, "Invalid URL"); - - private final Pattern pattern; - private final String errorMsg; - - public RegexpValidator(String regexp, String errorMsg) { - pattern = Pattern.compile(regexp); - this.errorMsg = errorMsg; - } - - public RegexpValidator(Pattern pattern, String errorMsg) { - this.pattern = pattern; - this.errorMsg = errorMsg; - } - - public String isValid(String newText) { - Matcher m = pattern.matcher(newText); - if (m.matches()) return null; - return errorMsg; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.utils.ui.validators; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.jface.dialogs.IInputValidator; + +/** + * Regular expression validator + * + * @author Toni Kalajainen + */ +public class RegexpValidator implements IInputValidator { + + // Hostname mask + //^([a-zA-Z0-9\\*]([a-zA-Z0-9\\-\\*]{0,61}[a-zA-Z0-9\\*])?\\.)*[a-zA-Z0-9\\*]([a-zA-Z0-9\\-\\*]{0,61}[a-zA-Z0-9\\*])?$ + + // Untested + //public static final String URL_VALIDATOR_STRING = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\\?\\/.=]+$"; + //public static RegexpValidator URL_VALIDATOR = new RegexpValidator(URL_VALIDATOR_STRING, "Invalid URL"); + + private final Pattern pattern; + private final String errorMsg; + + public RegexpValidator(String regexp, String errorMsg) { + pattern = Pattern.compile(regexp); + this.errorMsg = errorMsg; + } + + public RegexpValidator(Pattern pattern, String errorMsg) { + this.pattern = pattern; + this.errorMsg = errorMsg; + } + + public String isValid(String newText) { + Matcher m = pattern.matcher(newText); + if (m.matches()) return null; + return errorMsg; + } + +}