1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jetspeed.portlet.webcontent;
19
20 import java.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25 /***
26 * A history of content navigations in the WebContentPortlet
27 *
28 * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
29 * @version $Id: $
30 */
31
32 public class WebContentHistoryList extends Object
33 implements Serializable
34 {
35 int maxLength;
36 List history;
37 int currentIndex;
38
39
40
41 public WebContentHistoryList()
42 {
43 this( -1 );
44 }
45 public WebContentHistoryList( int maxLength )
46 {
47 super();
48
49 this.maxLength = maxLength;
50 this.history = new ArrayList();
51 this.currentIndex = -1;
52 }
53
54
55
56 public boolean isEmpty()
57 {
58 return this.history.isEmpty();
59 }
60 public boolean hasCurrentPage()
61 {
62 return this.currentIndex >= 0;
63 }
64 public boolean hasPreviousPage()
65 {
66 return !isEmpty() && this.currentIndex-1 >= 0;
67 }
68 public boolean hasNextPage()
69 {
70 return !isEmpty() && this.currentIndex+1 < this.history.size();
71 }
72
73 public WebContentHistoryPage getCurrentPage()
74 {
75 if (!hasCurrentPage())
76 return null ;
77 return (WebContentHistoryPage)this.history.get(this.currentIndex);
78 }
79 public WebContentHistoryPage getPreviousPage()
80 {
81 if (!hasPreviousPage())
82 return null;
83 this.currentIndex = this.currentIndex-1;
84 return getCurrentPage();
85 }
86 public WebContentHistoryPage getNextPage()
87 {
88 if (!hasNextPage())
89 return null;
90 this.currentIndex = this.currentIndex+1;
91 return getCurrentPage();
92 }
93
94 public void visitPage(WebContentHistoryPage page)
95 {
96 if (page==null)
97 throw new IllegalArgumentException("WebContentHistoryList.addPage() - non-null page required.");
98
99 int i = this.history.indexOf(page);
100 if (i >= 0 && i == this.currentIndex)
101 {
102
103 return;
104 }
105
106
107 while (hasNextPage())
108 {
109
110 this.history.remove(this.currentIndex+1);
111 }
112 if (i >= 0 && i < history.size())
113 {
114
115 this.history.remove(i);
116 }
117
118
119 this.history.add(page);
120 this.currentIndex = this.history.size()-1;
121
122
123 }
124 }