01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.search.filters;
19:
20: import java.util.Iterator;
21: import java.util.LinkedList;
22: import java.util.List;
23:
24: import de.finix.contelligent.CallData;
25: import de.finix.contelligent.ComponentPath;
26: import de.finix.contelligent.search.engine.CrawlerFilter;
27: import de.finix.contelligent.search.engine.FilterEngine;
28: import de.finix.contelligent.search.engine.FilterException;
29: import de.finix.contelligent.xml.elements.IndexBuilderFilterElement;
30:
31: public abstract class BinaryFilterBase implements CrawlerFilter {
32:
33: /**
34: *
35: */
36: public BinaryFilterBase() {
37: }
38:
39: /*
40: * (non-Javadoc)
41: *
42: * @see de.finix.contelligent.search.engine.CrawlerFilter#filter(de.finix.contelligent.Component,
43: * de.finix.contelligent.xml.elements.IndexBuilderFilterElement)
44: */
45: public boolean filter(ComponentPath componentPath,
46: IndexBuilderFilterElement configuration, CallData callData)
47: throws FilterException {
48: List subFilters = new LinkedList(configuration.getFilters());
49: if (subFilters.size() != 2)
50: throw new IllegalArgumentException(
51: "Binary filter must have exactly 2 subfilters configured");
52:
53: Iterator i = subFilters.iterator();
54: IndexBuilderFilterElement filter1 = (IndexBuilderFilterElement) i
55: .next();
56: IndexBuilderFilterElement filter2 = (IndexBuilderFilterElement) i
57: .next();
58:
59: CrawlerFilter f1 = FilterEngine.getInstance()
60: .getFilterInstance(filter1);
61: CrawlerFilter f2 = FilterEngine.getInstance()
62: .getFilterInstance(filter2);
63:
64: return applyLogic(f1.filter(componentPath, filter1, callData),
65: f2.filter(componentPath, filter2, callData),
66: configuration.getStringArgs());
67: }
68:
69: /**
70: * binary filter implementations should implement this method in order to
71: * decide, whether they accept a certain component or not.
72: *
73: * @param b
74: * the first sub filter element result
75: * @param c
76: * the first sub filter element result
77: *
78: * @return should return the overall outcome of this filter test
79: */
80: protected abstract boolean applyLogic(boolean b, boolean c,
81: String[] arguments);
82:
83: public boolean supportsNestedFilters() {
84: return true;
85: }
86: }
|