View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.access.mcrimpl;
20  
21  import java.text.DateFormat;
22  import java.text.SimpleDateFormat;
23  import java.util.Date;
24  import java.util.Locale;
25  
26  import org.jdom2.Element;
27  import org.mycore.parsers.bool.MCRCondition;
28  
29  /**
30   * Implementation of a (date &gt; xy) clause
31   * 
32   * @author Matthias Kramm
33   */
34  class MCRDateAfterClause implements MCRCondition<MCRAccessData> {
35      private Date date;
36  
37      private DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
38  
39      MCRDateAfterClause(Date date) {
40          this.date = date;
41      }
42  
43      public boolean evaluate(MCRAccessData data) {
44          return data.getDate().after(date);
45      }
46  
47      @Override
48      public String toString() {
49          return "date > " + dateformat.format(date) + " ";
50      }
51  
52      public Element toXML() {
53          Element cond = new Element("condition");
54          cond.setAttribute("field", "date");
55          cond.setAttribute("operator", ">");
56          cond.setAttribute("value", dateformat.format(date));
57          return cond;
58      }
59  
60  }