View Javadoc

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.HashMap;
22  import java.util.Iterator;
23  import java.util.Map;
24  
25  import org.apache.commons.lang.ArrayUtils;
26  
27  
28  /***
29   * Information required to re-visit a page in the WebContentPortlet
30   *
31   * @author <a href="mailto:dyoung@phase2systems.com">David L Young</a>
32   * @version $Id: $ 
33   */
34  
35  public class WebContentHistoryPage extends Object
36      implements Serializable
37  {
38      private String url;
39      private Map params;
40      private boolean is_post;
41  
42      // Constructors
43      
44      public WebContentHistoryPage(String url)
45      {
46          this(url, null, null);
47      }
48      public WebContentHistoryPage(String url, Map params, String method)
49      {
50          super();
51  
52          // guarantee non-null, so that equals() is well-behaved
53          if (url==null)
54              throw new IllegalArgumentException("WebContentHistoryPage() - url required");
55          
56          this.url = url;
57          this.params = params != null ? params : new HashMap();
58          this.is_post = method != null && method.equalsIgnoreCase("post");
59      }
60      
61      // Base Class Protocol
62      
63      public boolean equals(Object o)
64      {
65          if (o == null || !(o instanceof WebContentHistoryPage))
66              return false ;
67  
68          WebContentHistoryPage page = (WebContentHistoryPage)o;
69          
70          return page.url.equals(this.url) && page.params.equals(this.params) && page.isPost() == this.isPost() ;
71      }
72      public String toString()
73      {
74          StringBuffer buff = new StringBuffer();
75          buff.append( "[" ).append(isPost() ? "POST: " : "GET: ").append( getUrl() ).append( ", " ).append( getParams().size() ).append(" params: {");
76          Iterator iter = getParams().entrySet().iterator();
77          while ( iter.hasNext() )
78          {
79              Map.Entry entry = (Map.Entry)iter.next();
80              buff.append("(").append(entry.getKey()).append(" . ").append(ArrayUtils.toString(entry.getKey())).append(")");
81          }
82          buff.append("}]");
83          return buff.toString();
84      }
85      
86      // Data Access
87      
88      public String getUrl()
89      {
90          return this.url;
91      }
92      public Map getParams()
93      {
94          return this.params;
95      }
96      public boolean isPost()
97      {
98          return this.is_post;
99      }
100 }