1 package geekblog; 2 3 4 import java.io.*; 5 import java.util.*; 6 import javax.servlet.*; 7 8 9 /** 10 * 11 */ 12 public interface DataManager 13 { 14 /** 15 * Key to use when storing the DataManager in the ServletContext. 16 */ 17 public static final String KEY = "datamanager"; 18 19 20 // ================================================================ 21 // DataManager lifecycle API 22 // ================================================================ 23 /** 24 * Set everything up 25 */ 26 public void init(ServletContext context); 27 /** 28 * Tear everything down 29 */ 30 public void destroy(ServletContext context); 31 32 33 // ================================================================ 34 // Weblog entry API 35 // ================================================================ 36 /** 37 * Retrieve an entry by ID. 38 */ 39 public BlogEntry getEntry(long entryID); 40 /** 41 * Retrieve every single last one. 42 */ 43 public Collection getAllEntries(); 44 /** 45 * Retrieve the last "n" entries. 46 */ 47 public Collection getLastNEntries(int n); 48 /** 49 * Retrieve a list of entries for a given date. 50 * 51 * @param date Day/month/year tuple to find entries for. 52 * Ignores hour, minutes, seconds. 53 */ 54 public Collection getEntriesForDate(Date date); 55 /** 56 * Retrieve a list of entries for a given month/year. 57 * 58 * @param date Month/year tuple to find entries for. 59 * Ignores day, hour, minutes, seconds. 60 */ 61 public Collection getEntriesForMonth(Date date); 62 /** 63 * Retrieve a count of the entries for a given date. 64 * 65 * @param date Day/month/year to find count of entries for. 66 * Ignores hour, minutes, seconds. 67 */ 68 public int getEntryCountForDate(Date date); 69 /** 70 * Retrieve a count of the entries for a given month. 71 * 72 * @param date Month and year to find count of entries for. 73 * Ignores day, hour, minutes, seconds. 74 */ 75 public int getEntryCountForMonth(Date date); 76 /** 77 * Mark an entry as an article. It is the responsibility of this method to 78 * ensure that marking an entry as an article doesn't create two articles 79 * out of the same entry. 80 */ 81 public void markAsArticle(BlogEntry entry); 82 /** 83 * Retrieve a list of all the entries marked as articles. 84 */ 85 public Collection getArticleEntries(); 86 /** 87 * Find all entries containing some text expression 88 */ 89 public Collection findEntries(String text); 90 /** 91 * Post an entry (either new or edited). Posting an entry that already exists 92 * (as indicated by BlogEntry.getID() ) is an update, otherwise insert the 93 * new entry into the data store. 94 * 95 * @param entry The BlogEntry to mark as an article. 96 */ 97 public void postEntry(BlogEntry entry); 98 /** 99 * Remove an entry. Also removes all comments associated with that entry. 100 * Silently fail if the entry doesn't exst--no exception is thrown. 101 * 102 * @param entryID The ID of the entry to remove. 103 */ 104 public void removeEntry(long entryID); 105 106 107 // ================================================================ 108 // Weblog comments API 109 // ================================================================ 110 /** 111 * Retrieve the list of comments for a given entry. 112 */ 113 public int getCommentCountForEntry(long entryID); 114 /** 115 * Retrieve the list of comments for a given entry. 116 */ 117 public Collection getCommentsForEntry(long entryID); 118 /** 119 * Post a comment to an entry. 120 */ 121 public void postComment(long entryID, BlogComment comment); 122 } 123