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.domain;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Locale;
27
28 import org.apache.avalon.framework.configuration.Configurable;
29 import org.apache.avalon.framework.configuration.Configuration;
30 import org.apache.avalon.framework.configuration.ConfigurationException;
31
32
33
34
35 public class XMLDomainList extends AbstractDomainList implements Configurable {
36
37 private List domainNames = null;
38
39 private boolean managementDisabled = false;
40
41
42
43
44 public void configure(Configuration arg0) throws ConfigurationException {
45 Configuration conf = arg0.getChild("domainnames");
46 if (conf != null) {
47
48 Configuration[] serverNameConfs = conf.getChildren( "domainname" );
49 for ( int i = 0; i < serverNameConfs.length; i++ ) {
50 addDomainInternal( serverNameConfs[i].getValue());
51 }
52
53 Configuration autoConf = arg0.getChild("autodetect");
54 if (autoConf != null) {
55 setAutoDetect(autoConf.getValueAsBoolean(true));
56 }
57
58 Configuration autoIPConf = arg0.getChild("autodetectIP");
59 if (autoConf != null) {
60 setAutoDetectIP(autoIPConf.getValueAsBoolean(true));
61 }
62 }
63 }
64
65
66
67
68
69 protected List getDomainListInternal() {
70
71
72
73 managementDisabled = true;
74 return new ArrayList(domainNames);
75 }
76
77
78
79
80 public boolean containsDomain(String domains) {
81 if (domainNames == null) return false;
82 return domainNames.contains(domains);
83 }
84
85
86
87
88
89
90 protected boolean addDomainInternal(String domain) {
91
92 if (managementDisabled) throw new UnsupportedOperationException("Management not supported");
93
94 if (domainNames == null) {
95 domainNames = new ArrayList();
96 }
97
98 String newDomain = domain.toLowerCase(Locale.US);
99 if (containsDomain(newDomain) == false) {
100 domainNames.add(newDomain);
101 return true;
102 } else {
103 return false;
104 }
105 }
106
107
108
109
110 protected boolean removeDomainInternal(String domain) {
111
112 if (managementDisabled) throw new UnsupportedOperationException("Management not supported");
113
114 if (domainNames == null) return false;
115 return domainNames.remove(domain.toLowerCase(Locale.US));
116 }
117 }