KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > plugins > security > MalformedRuleException


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.plugins.security;
10
11 import java.util.regex.Pattern JavaDoc;
12 import java.util.regex.PatternSyntaxException JavaDoc;
13
14 /**
15  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
16  * @version $Revision: 1.1 $
17  */

18 public class MalformedRuleException extends Exception JavaDoc
19 {
20
21    public MalformedRuleException()
22    {
23    }
24
25    public MalformedRuleException(String JavaDoc s)
26    {
27       super(s);
28    }
29
30    static final Pattern JavaDoc validator = Pattern.compile("^[^:]:[^:]:[^:]$");
31
32    static void validate(String JavaDoc 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 JavaDoc 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