01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.components;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.responders.editing.EditResponder;
07: import java.util.Random;
08:
09: public class SaveRecorder {
10: public static Random ticketNumGen = new Random();
11:
12: public static long pageSaved(PageData data) throws Exception {
13: long id = newIdNumber();
14: data.setAttribute(EditResponder.SAVE_ID, id + "");
15: return id;
16: }
17:
18: public static boolean changesShouldBeMerged(long time, long ticket,
19: PageData data) throws Exception {
20: boolean returnValue = false;
21: String ticketAttrib = data
22: .getAttribute(EditResponder.TICKET_ID);
23: String saveAttrib = data.getAttribute(EditResponder.SAVE_ID);
24:
25: if (saveAttrib != null) {
26: long pageSaveId = Long.parseLong(saveAttrib);
27: if (pageSaveId > time) {
28: returnValue = true;
29: }
30: }
31:
32: if (ticketAttrib != null) {
33: long pageTicketId = Long.parseLong(ticketAttrib);
34: if (pageTicketId == ticket) {
35: returnValue = false;
36: }
37: }
38: return returnValue;
39: }
40:
41: public static long newIdNumber() {
42: return System.currentTimeMillis();
43: }
44:
45: public static long newTicket() {
46: return ticketNumGen.nextLong();
47: }
48: }
|