*/
public class AddressBookManager {
/**
* Log instance.
*/
private static Log log = LogFactory.getLog(AddressBookManager.class);
CHAPTER 4 n INSTAMAIL: AN AJAX-BASED WEBMAIL CLIENT 168
/**
* File name of the Address Book.
*/
private static final String addrBookFilename = "addrbook.properties";
/**
* This method retrieves the contents of the Address Book.
*
* @param sc ServletContext associates with the request.
* @return A collection of ContactDTOs.
*/
public Collection retrieveContacts(ServletContext sc) {
// Read in the Address Book.
InputStream isFeedFile =
sc.getResourceAsStream("/WEB-INF/" + addrBookFilename);
Properties props = new Properties();
int numContacts = 0;
try {
if (isFeedFile == null) {
throw new IOException(addrBookFilename + " not found");
}
props.load(isFeedFile);
isFeedFile.close();
// Now we need to determine how many contacts there are. To do this, we
// divide the total number of properties read in by 3, since each
// contact always has 3 items stored about them.
if (props.size() != 0) {
numContacts = props.size() / 3;
}
} catch (IOException e) {
log.info("No " + addrBookFilename + " file, an empty address book will " +
"be returned.
Pages:
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324