vincenzo    2003/06/23 11:51:39

  Modified:    src/java/org/apache/james/transport/matchers Tag:
                        branch_2_1_fcs RecipientIsRegex.java
  Log:
  More javadoc, in sync with new SenderIsRegex, plus better logging of exceptions if 
caught during init.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +24 -14    
jakarta-james/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java
  
  Index: RecipientIsRegex.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- RecipientIsRegex.java     21 May 2003 04:34:44 -0000      1.1.2.1
  +++ RecipientIsRegex.java     23 Jun 2003 18:51:39 -0000      1.1.2.2
  @@ -63,18 +63,22 @@
   
   import org.apache.oro.text.regex.*;
   
  +import javax.mail.MessagingException;
  +
   /**
  - * Uses regular expression
  + * <P>Matches recipients whose address matches a regular expression.</P>
  + * <P>Is equivalent to the [EMAIL PROTECTED] SenderIsRegex} matcher but matching on 
the recipient.</P>
  + * <P>Configuration string: a regular expression.</P>
  + * <PRE><CODE>
  + * &lt;mailet match=&quot;RecipientIsRegex=&lt;regular-expression&gt;&quot; 
class=&quot;&lt;any-class&gt;&quot;&gt;
  + * </CODE></PRE>
  + * <P>The example below will match any recipient in the format [EMAIL PROTECTED]</P>
  + * <PRE><CODE>
  + * &lt;mailet match=&quot;RecipientIsRegex=(.*)@log\.(.*)&quot; 
class=&quot;&lt;any-class&gt;&quot;&gt;
  + * &lt;/mailet&gt;
  + * </CODE></PRE>
    *
  - *<p>&lt;mailet match=&quot;RecipientMatch=&lt;regular-expression&gt;&quot;
  -class=&quot;&lt;any-class&gt;&quot;&gt;</p>
  - * <p>The example below will match any recipient in the format
  [EMAIL PROTECTED]</p>
  - * <p>&lt;mailet match=&quot;RecipientMatch=(.*)@log\.(.*)&quot;
  -class=&quot;&lt;any-class&gt;&quot;&gt;<br>
  - * &lt;/mailet&gt;<br>
  - * </p>
  - * @version 1.0.0, 27/06/2002
  + * @version CVS $Revision$ $Date$
    */
   
   public class RecipientIsRegex extends GenericRecipientMatcher {
  @@ -85,16 +89,22 @@
       Pattern pattern   = null;
   
       public void init() throws javax.mail.MessagingException {
  +        String patternString = getCondition();
  +        if (patternString == null) {
  +            throw new MessagingException("Pattern is missing");
  +        }
  +        
  +        patternString = patternString.trim();
           try {
  -            pattern = compiler.compile( getCondition() );
  -        } catch(MalformedPatternException e) {
  -            e.printStackTrace();
  +            pattern = compiler.compile(patternString);
  +        } catch(MalformedPatternException mpe) {
  +            throw new MessagingException("Malformed pattern: " + patternString, 
mpe);
           }
       }
   
       public boolean matchRecipient(MailAddress recipient) {
           String myRecipient = recipient.toString();
  -        if ( matcher.matches( myRecipient, pattern)  ){
  +        if (matcher.matches(myRecipient, pattern)){
               return true;
           } else {
               return false;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to