01: /*
02: *
03: * Jsmtpd, Java SMTP daemon
04: * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21: package org.jsmtpd.core.common.filter;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.jsmtpd.core.mail.Email;
26:
27: /**
28: * Jsmtpd<br>
29: * A node of the filter chain.<br>
30: * The whole tree is an image of the configuration file element filterchain<br>
31: * A true empty child causes the chain to be validated<br>
32: * A false empty child causes the chain to be rejected<br>
33: * @author Jean-Francois POUX
34: */
35: public class FilterTreeNode {
36:
37: private FilterTreeNode parent = null;
38: private FilterTreeNode trueNode = null;
39: private FilterTreeNode falseNode = null;
40:
41: private IFilter filter;
42: private Log log = LogFactory.getLog(FilterTreeNode.class);
43:
44: public void doFilter(Email in) throws FilterTreeFailureException,
45: FilterTreeSuccesException, Throwable {
46: if (filter.doFilter(in)) {
47: log.debug("Filter true with " + filter.getPluginName());
48: if (trueNode == null)//No filter apended, EOC succes
49: {
50: log.debug("FILTER END OK by " + filter.getPluginName());
51: throw new FilterTreeSuccesException();
52: }
53: trueNode.doFilter(in);
54: } else {
55: log.debug("Filter false with " + filter.getPluginName());
56: if (falseNode == null) {
57: log.debug("FILTER END FAIL by "
58: + filter.getPluginName());
59: throw new FilterTreeFailureException();
60: }
61: falseNode.doFilter(in);
62: }
63: }
64:
65: public FilterTreeNode getFalseNode() {
66: return falseNode;
67: }
68:
69: public void setFalseNode(FilterTreeNode falseNode) {
70: this .falseNode = falseNode;
71: }
72:
73: public FilterTreeNode getParent() {
74: return parent;
75: }
76:
77: public void setParent(FilterTreeNode parent) {
78: this .parent = parent;
79: }
80:
81: public FilterTreeNode getTrueNode() {
82: return trueNode;
83: }
84:
85: public void setTrueNode(FilterTreeNode trueNode) {
86: this .trueNode = trueNode;
87: }
88:
89: public IFilter getFilter() {
90: return filter;
91: }
92:
93: public void setFilter(IFilter filter) {
94: this.filter = filter;
95: }
96: }
|