![]() |
|||
DateSubset.javaGo to the documentation of this file.00001 /* 00002 * DateInterval.java 00003 * 00004 * Created on 19 mars 2003, 13:16 00005 * Copyright (C) 2003 Philippe MOULIN 00006 * www.net2map.org 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00021 */ 00022 00023 package org.net2map.pov.dimension.date; 00024 import java.beans.*; 00025 import org.apache.lucene.document.DateField; 00026 import java.util.Date; 00027 import org.apache.lucene.document.Document; 00028 00029 /*modif AMN 09/10/03*/ 00030 //import org.net2map.pov.documentsManager.*; 00031 /*fin modif AMN 09/10/03*/ 00032 00037 public class DateSubset 00038 extends org.net2map.pov.dimension.Subset 00039 implements PropertyChangeListener 00040 { 00041 private static org.apache.log4j.Logger logger = 00042 org.apache.log4j.Logger.getLogger(DateSubset.class.getName()); 00043 private DateValue earliestDate; 00044 private DateValue latestDate; 00045 00046 00048 public DateSubset(org.net2map.pov.dimension.Container paramContainer) 00049 { 00050 super(paramContainer); 00051 logger.setLevel((org.apache.log4j.Level)org.apache.log4j.Priority.DEBUG); 00052 logger.warn("Creating..."); 00053 earliestDate = new DateValue(); 00054 latestDate = new DateValue(); 00055 java.util.Calendar initializer = java.util.Calendar.getInstance (); 00056 latestDate.setValue(initializer); 00057 logger.warn("...Created"); 00058 } 00059 00060 public DateSubset(org.net2map.pov.dimension.Container paramContainer, 00061 String paramXMLinitializer) 00062 { 00063 super(paramContainer); 00064 logger.setLevel((org.apache.log4j.Level)org.apache.log4j.Priority.DEBUG); 00065 logger.warn("Creating from \n" + paramXMLinitializer); 00066 earliestDate = new DateValue(); 00067 latestDate = new DateValue(); 00068 java.util.Calendar initializer = java.util.Calendar.getInstance (); 00069 latestDate.setValue(initializer); 00070 logger.warn("...Created"); 00071 } 00072 00073 public DateSubset( org.net2map.pov.dimension.Container paramContainer, 00074 Date paramEarliestDate, 00075 Date paramLatestDate) 00076 { 00077 super(paramContainer); 00078 logger.setLevel((org.apache.log4j.Level)org.apache.log4j.Priority.DEBUG); 00079 logger.warn("Creating..."); 00080 earliestDate = new DateValue(paramEarliestDate); 00081 latestDate = new DateValue(paramLatestDate); 00082 java.util.Calendar initializer = java.util.Calendar.getInstance (); 00083 latestDate.setValue(initializer); 00084 logger.warn("...Created"); 00085 } 00086 00087 public void addPropertyChangeListener (PropertyChangeListener listener) 00088 { 00089 //super.addPropertyChangeListener (listener); 00090 } 00091 00092 public void removePropertyChangeListener (PropertyChangeListener listener) 00093 { 00094 //super.removePropertyChangeListener (listener); 00095 } 00096 00097 public void setSampleProperty (String value) 00098 { 00099 //super.setSampleProperty (value); 00100 } 00101 00103 public void setEarliestDate( Date date ) 00104 { 00105 earliestDate.setValue(date); 00106 } 00107 public void setEarliestDate(String date) 00108 { 00109 earliestDate.setValue(date); 00110 } 00111 00113 public void setLatestDate( Date date ) 00114 { 00115 latestDate.setValue(date); 00116 } 00117 public void setLatestDate(String date) 00118 { 00119 latestDate.setValue(date); 00120 } 00121 00122 public void setSubset( String paramXMLinitializer) 00123 { 00124 00125 } 00126 00132 public void propertyChange (PropertyChangeEvent evt) 00133 { 00134 System.out.println("Evenement recu: " + evt.getPropertyName () ); 00135 if (evt.getPropertyName() == DateGUI.PROP_EARLIEST_DATE_PROPERTY) 00136 { 00137 earliestDate.setValue ((java.util.Calendar)evt.getNewValue ()); 00138 System.out.println( "New value: " + 00139 earliestDate.toString () + 00140 "\n(" + 00141 earliestDate.toLong () + 00142 "ms)"); 00143 } 00144 else if (evt.getPropertyName() == DateGUI.PROP_LATEST_DATE_PROPERTY) 00145 { 00146 latestDate.setValue ((java.util.Calendar)evt.getNewValue ()); 00147 System.out.println( "New value: " + 00148 latestDate.toString () + 00149 "\n(" + 00150 latestDate.toLong () + 00151 "ms)"); 00152 } 00153 } 00154 00155 public long getLeftmostValue () 00156 { 00157 return (earliestDate.toLong ()); 00158 } 00159 00160 public long getRightmostValue () 00161 { 00162 return (latestDate.toLong ()); 00163 } 00164 00165 public long toLong (org.net2map.pov.server.Result theResult) throws java.rmi.RemoteException 00166 { 00167 return(theResult.getLastModTime ().getTime ()); 00168 } 00169 00170 public String toString (long value) 00171 { 00172 java.util.Calendar theCalendar = java.util.Calendar.getInstance (); 00173 theCalendar.setTimeInMillis (value); 00174 return ( "" + 00175 theCalendar.get(java.util.Calendar.DATE) + 00176 "/" + 00177 (theCalendar.get(java.util.Calendar.MONTH) +1) + 00178 "/" + 00179 theCalendar.get(java.util.Calendar.YEAR) ); 00180 } 00181 00182 public void addPropertyChangeListener(String PropertyName, PropertyChangeListener listener) 00183 { 00184 } 00185 00186 public void removePropertyChangeListener(String PropertyName, PropertyChangeListener listener) 00187 { 00188 } 00189 00190 public String toXml() 00191 { 00192 String result = ""; 00193 result = "<Criteria>\n"; 00194 result += "<Name>" + this.getClass().getName() + "</Name>\n"; 00195 00196 //result += "<From>" + DateField.dateToString( earliestDate.toDate() ) + "</From>\n"; 00197 result += "<From>" + earliestDate.toLong() + "</From>\n"; 00198 //result += "<To>" + DateField.dateToString( latestDate.toDate() ) + "</To>\n"; 00199 result += "<To>" + latestDate.toLong() + "</To>\n"; 00200 00201 result += "</Criteria>\n"; 00202 return (result); 00203 } 00204 00205 public String getLuceneFieldName() 00206 { 00207 return("modified"); 00208 } 00209 00214 public boolean isValid(Document lucenedoc) 00215 { 00216 if(null == lucenedoc) logger.fatal("NULL lucenedoc!"); 00217 return ( earliestDate.compareTo( DateField.stringToDate( lucenedoc.get( getLuceneFieldName() ) ) ) <= 0 ) && 00218 ( latestDate.compareTo( DateField.stringToDate( lucenedoc.get( getLuceneFieldName() ) ) ) >= 0 ); 00219 } 00220 00222 public String toString() 00223 { 00224 return "from " + earliestDate.toString() + " to " + latestDate.toString(); 00225 } 00226 } |
|||
|
Accueil | Téléchargement | Manuel
| Doc. technique | Sources CVS |
Faq | Nous contacter
©2003 - All Rights Reserved |
|||