1 15 package org.apache.tapestry.vlib.components; 16 17 import java.sql.Timestamp ; 18 19 import org.apache.tapestry.BaseComponent; 20 import org.apache.tapestry.IEngine; 21 import org.apache.tapestry.vlib.Visit; 22 import org.apache.tapestry.vlib.ejb.Book; 23 24 55 56 public abstract class BookLink extends BaseComponent 57 { 58 64 65 private static final long ONE_WEEK_MILLIS = 1000l * 60l * 60l * 24l * 7l; 66 67 public boolean isNewlyAdded() 68 { 69 IEngine engine = getPage().getEngine(); 70 Visit visit = (Visit) engine.getVisit(); 71 Timestamp lastAccess = null; 72 73 if (visit != null) 74 lastAccess = visit.getLastAccess(); 75 76 Book book = getBook(); 77 78 Timestamp dateAdded = book.getDateAdded(); 79 80 82 if (dateAdded == null) 83 return false; 84 85 89 if (lastAccess == null) 90 { 91 long now = System.currentTimeMillis(); 92 93 return (now - dateAdded.getTime()) <= ONE_WEEK_MILLIS; 94 } 95 96 98 return lastAccess.compareTo(dateAdded) <= 0; 99 } 100 101 public abstract Book getBook(); 102 } | Popular Tags |