Prev | Current Page 314 | Next

Frank Zammetti

"Practical DWR 2 Projects"


Collection contacts = retrieveContacts(sc);
// Now we iterate over it, adding each to a Properties object. Remember
// that for each contact we are writing out three properties, the name,
// the address, and the note. To name each uniquely, we append a number
// onto it.
Properties props = new Properties();
int i = 1;
for (Iterator it = contacts.iterator(); it.hasNext();) {
ContactDTO contact = (ContactDTO)it.next();
props.setProperty("name" + i, contact.getName());
props.setProperty("address" + i, contact.getAddress());
props.setProperty("note" + i, contact.getNote());
i++;
}
// Now we add the new contact
props.setProperty("name" + i, inName);
props.setProperty("address" + i, inAddress);
props.setProperty("note" + i, inNote);
CHAPTER 4 n INSTAMAIL: AN AJAX-BASED WEBMAIL CLIENT 170
// Lastly, delete any existing addrBookFilename file in WEB-INF and
// write out a new version from the Properties object we just populated.
// Return a message saying the operation was complete, or if any problems
// occur, a message saying what went wrong.
FileOutputStream fos = null;
try {
new File(sc.getRealPath("WEB-INF") + "/" + addrBookFilename).delete();
fos = new FileOutputStream(sc.


Pages:
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326