1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

24 package net.sf.jasperreports.engine.export;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import net.sf.jasperreports.engine.JRPrintElement;
30 import net.sf.jasperreports.engine.JRRuntimeException;
31
32 /**
33  * An exporter filter that consists of several exporter filter, and filters
34  * elements through each of them.
35  * 
36  * @author Lucian Chirita (lucianc@users.sourceforge.net)
37  * @see #isToExport(JRPrintElement)
38  */

39 public class ExporterFilterContainer implements ResetableExporterFilter
40 {
41     public static final String EXCEPTION_MESSAGE_KEY_NULL_FILTERS_LIST = "export.filter.null.filters.list";
42
43     private final List<ExporterFilter> filters;
44     
45     /**
46      * Constructs a container for a list of exporter filters.
47      * 
48      * @param filters the list of filters
49      */

50     public ExporterFilterContainer(List<ExporterFilter> filters)
51     {
52         if (filters == null)
53         {
54             throw 
55             new JRRuntimeException(
56                 EXCEPTION_MESSAGE_KEY_NULL_FILTERS_LIST,
57                 (Object[])null);
58         }
59         
60         this.filters = filters;
61     }
62
63     /**
64      * Returns <code>true</code> if the element is not filtered by any of
65      * the contained filters.
66      */

67     @Override
68     public boolean isToExport(JRPrintElement element)
69     {
70         boolean export = true;
71         for (Iterator<ExporterFilter> it = filters.iterator(); it.hasNext();)
72         {
73             ExporterFilter filter = it.next();
74             if (!filter.isToExport(element))
75             {
76                 export = false;
77                 break;
78             }
79         }
80         return export;
81     }
82
83     @Override
84     public void reset()
85     {
86         for (ExporterFilter filter : filters)
87         {
88             if (filter instanceof ResetableExporterFilter)
89             {
90                 ((ResetableExporterFilter) filter).reset();
91             }
92         }
93     }
94
95 }
96