001 /*
002 *
003 * $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
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.backend.jdom;
025
026 import org.mycore.common.MCRUtils;
027
028 /**
029 * This class implements Xalan extension functions for the JDOM search.
030 *
031 * @author Jens Kupferschmidt
032 * @version $Revision: 13085 $ $Date: 2008-02-06 18:27:24 +0100 (Mi, 06 Feb 2008) $
033 */
034 public class MCRXalanExtensions {
035 /**
036 * This method implements a XSLT function to compare two date values.
037 *
038 * @param date_one
039 * the date that should be compared with date_two
040 * @param date_two
041 * the data that date_one is compared with
042 * @param compare_operator
043 * The operator to compare in the form 'date_one compare_operator
044 * date_two'
045 * @return true if the test is correct, else return false
046 */
047 public static boolean compareDates(String date_one, String date_two, String compare_operator) {
048 String date1iso = MCRUtils.covertDateToISO(date_one);
049 String date2iso = MCRUtils.covertDateToISO(date_two);
050
051 if ((date1iso == null) || (date2iso == null) || (date1iso.length() == 0) || (date2iso.length() == 0)) {
052 return false;
053 }
054
055 if ((compare_operator == null) || ((compare_operator = compare_operator.trim()).length() == 0)) {
056 return false;
057 }
058
059 int result = date1iso.compareTo(date2iso);
060
061 if (compare_operator.equals("=")) {
062 return (result == 0);
063 } else if (compare_operator.equals("!=")) {
064 return (result != 0);
065 } else if (compare_operator.equals("<=")) {
066 return (result <= 0);
067 } else if (compare_operator.equals(">=")) {
068 return (result >= 0);
069 } else if (compare_operator.equals("<")) {
070 return (result < 0);
071 } else if (compare_operator.equals(">")) {
072 return (result > 0);
073 } else {
074 return false;
075 }
076 }
077 }