%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.portlet.webcontent.WebContentHistoryList |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
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 | // Constructors |
|
40 | ||
41 | public WebContentHistoryList() |
|
42 | { |
|
43 | 0 | this( -1 ); |
44 | 0 | } |
45 | public WebContentHistoryList( int maxLength ) |
|
46 | { |
|
47 | 0 | super(); |
48 | ||
49 | 0 | this.maxLength = maxLength; |
50 | 0 | this.history = new ArrayList(); |
51 | 0 | this.currentIndex = -1; |
52 | 0 | } |
53 | ||
54 | // Methods |
|
55 | ||
56 | public boolean isEmpty() |
|
57 | { |
|
58 | 0 | return this.history.isEmpty(); |
59 | } |
|
60 | public boolean hasCurrentPage() |
|
61 | { |
|
62 | 0 | return this.currentIndex >= 0; |
63 | } |
|
64 | public boolean hasPreviousPage() |
|
65 | { |
|
66 | 0 | return !isEmpty() && this.currentIndex-1 >= 0; |
67 | } |
|
68 | public boolean hasNextPage() |
|
69 | { |
|
70 | 0 | return !isEmpty() && this.currentIndex+1 < class="keyword">this.history.size(); |
71 | } |
|
72 | ||
73 | public WebContentHistoryPage getCurrentPage() |
|
74 | { |
|
75 | 0 | if (!hasCurrentPage()) |
76 | 0 | return null ; |
77 | 0 | return (WebContentHistoryPage)this.history.get(class="keyword">this.currentIndex); |
78 | } |
|
79 | public WebContentHistoryPage getPreviousPage() |
|
80 | { |
|
81 | 0 | if (!hasPreviousPage()) |
82 | 0 | return null; |
83 | 0 | this.currentIndex = class="keyword">this.currentIndex-1; |
84 | 0 | return getCurrentPage(); |
85 | } |
|
86 | public WebContentHistoryPage getNextPage() |
|
87 | { |
|
88 | 0 | if (!hasNextPage()) |
89 | 0 | return null; |
90 | 0 | this.currentIndex = class="keyword">this.currentIndex+1; |
91 | 0 | return getCurrentPage(); |
92 | } |
|
93 | ||
94 | public void visitPage(WebContentHistoryPage page) |
|
95 | { |
|
96 | 0 | if (page==null) |
97 | 0 | throw new IllegalArgumentException("WebContentHistoryList.addPage() - non-null page required."); |
98 | ||
99 | 0 | int i = this.history.indexOf(page); |
100 | 0 | if (i >= 0 && i == this.currentIndex) |
101 | { |
|
102 | // just visiting the current page |
|
103 | 0 | return; |
104 | } |
|
105 | ||
106 | // otherwise - new page... |
|
107 | 0 | while (hasNextPage()) |
108 | { |
|
109 | // ...visiting a page discards any pages we have visited by going "back" |
|
110 | 0 | this.history.remove(class="keyword">this.currentIndex+1); |
111 | } |
|
112 | 0 | if (i >= 0 && i < history.size()) |
113 | { |
|
114 | // ...actually, new visit to an old page, only keep one reference to it |
|
115 | 0 | this.history.remove(i); |
116 | } |
|
117 | ||
118 | // add in the new page, at the end |
|
119 | 0 | this.history.add(page); |
120 | 0 | this.currentIndex = class="keyword">this.history.size()-1; |
121 | ||
122 | // System.out.println("WebContentHistoryList.visitPage() - current index is: "+this.currentIndex+"\nhistory list..."+ArrayUtils.toString(this.history)); |
|
123 | 0 | } |
124 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |