1 9 package org.jboss.portal.core.plugins.security; 10 11 import java.util.regex.Pattern ; 12 import java.util.regex.PatternSyntaxException ; 13 14 18 public class MalformedRuleException extends Exception 19 { 20 21 public MalformedRuleException() 22 { 23 } 24 25 public MalformedRuleException(String s) 26 { 27 super(s); 28 } 29 30 static final Pattern validator = Pattern.compile("^[^:]:[^:]:[^:]$"); 31 32 static void validate(String pattern) throws MalformedRuleException 33 { 34 if (pattern == null) 35 { 36 throw new MalformedRuleException("Pattern cannot be null"); 37 } 38 try 39 { 40 Pattern.compile(pattern); 41 } 42 catch(PatternSyntaxException e) 43 { 44 throw new MalformedRuleException("Pattern is not a regular expression"); 45 } 46 if (validator.matcher(pattern).matches()) 47 { 48 throw new MalformedRuleException("Pattern is not valid"); 49 } 50 } 51 52 } 53 | Popular Tags |