1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.transport.matchers;
23
24 import java.io.IOException;
25
26 import org.apache.oro.text.regex.MalformedPatternException;
27 import javax.mail.MessagingException;
28
29
30
31
32
33 public class FileRegexMatcher extends GenericRegexMatcher {
34
35
36
37
38 public void init() throws MessagingException {
39 java.io.RandomAccessFile patternSource = null;
40 try {
41 patternSource = new java.io.RandomAccessFile(getCondition(), "r");
42 int lines = 0;
43 while(patternSource.readLine() != null) lines++;
44 patterns = new Object[lines][2];
45 patternSource.seek(0);
46 for (int i = 0; i < lines; i++) {
47 String line = patternSource.readLine();
48 patterns[i][0] = line.substring(0, line.indexOf(':'));
49 patterns[i][1] = line.substring(line.indexOf(':')+1);
50 }
51 compile(patterns);
52
53 }
54 catch (java.io.FileNotFoundException fnfe) {
55 throw new MessagingException("Could not locate patterns.", fnfe);
56 }
57 catch (java.io.IOException ioe) {
58 throw new MessagingException("Could not read patterns.", ioe);
59 }
60 catch(MalformedPatternException mp) {
61 throw new MessagingException("Could not initialize regex patterns", mp);
62 } finally {
63 if (patternSource != null) {
64
65 try {
66 patternSource.close();
67 } catch (IOException e) {
68
69 }
70 }
71 }
72 }
73 }