001 /*
002 *
003 * $Revision$ $Date$
004 *
005 * This file is part of *** M y C o R e ***
006 * See http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, in a file called gpl.txt or license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.mycore.access.mcrimpl;
025
026 import java.text.DateFormat;
027 import java.text.SimpleDateFormat;
028 import java.util.Date;
029
030 import org.jdom.Attribute;
031 import org.jdom.Element;
032 import org.mycore.parsers.bool.MCRCondition;
033 import org.mycore.parsers.bool.MCRConditionVisitor;
034
035 /**
036 * Implementation of a (date > xy) clause
037 *
038 * @author Matthias Kramm
039 */
040 class MCRDateAfterClause implements MCRCondition {
041 private Date date;
042 private static DateFormat dateformat = new SimpleDateFormat("dd.MM.yyyy");
043
044 MCRDateAfterClause(Date date) {
045 this.date = date;
046 }
047
048 public boolean evaluate(Object o) {
049 MCRAccessData data = (MCRAccessData) o;
050
051 return data.getDate().after(this.date);
052 }
053
054 public String toString() {
055 return "date > " + dateformat.format(date) + " ";
056 }
057
058 public Element toXML() {
059 Element cond = new Element("condition");
060 cond.setAttribute("field", "date");
061 cond.setAttribute("operator", ">");
062 cond.setAttribute("value", dateformat.format(date));
063 return cond;
064 }
065
066 public Element info() {
067 Element el = new Element("info");
068 el.setAttribute(new Attribute("type", "DATE"));
069 return el;
070 }
071
072 public void accept(MCRConditionVisitor visitor) {
073 visitor.visitType(info());
074 }
075 };