View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.jdiagnose.library.web.breadcrumb;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Locale;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  /***
25   * @author jamie
26   */
27  public class ParamIncludeCrumbFactory implements CrumbFactory {
28  
29      private CrumbFactory crumbFactory = null;
30      private List includeParams = null;
31      
32      /***
33       * Default Constructor
34       */
35      public ParamIncludeCrumbFactory() {
36          super();
37      }
38  
39      /***
40       * @param parameter
41       */
42      public ParamIncludeCrumbFactory(CrumbFactory crumbFactory, List includeParams) {
43          this.crumbFactory = crumbFactory;
44          this.includeParams = includeParams;
45      }
46  
47      /* (non-Javadoc)
48       * @see org.jdiagnose.library.web.breadcrumb.CrumbFactory#getCrumb(javax.servlet.http.HttpServletRequest, java.lang.String)
49       */
50      public Crumb getCrumb(HttpServletRequest request, String url) {
51          final Crumb crumb = crumbFactory.getCrumb(request, url);
52          final StringBuffer query = new StringBuffer();
53          for (Iterator paramIterator = includeParams.iterator(); paramIterator.hasNext();) {
54              String param = (String) paramIterator.next();
55              query.append(param + '=' + request.getParameter(param));
56              if(paramIterator.hasNext()) {
57                  query.append('&');
58              }
59          }
60          return new Crumb() {
61              public String getUrl() {
62                  String crumbUrl = crumb.getUrl();
63                  return crumbUrl + (crumbUrl.indexOf('?') > 0 ? '&' : '?') + query;
64              }
65              public String getDescription(Locale locale) {
66                  return crumb.getDescription(locale);
67              }
68          };
69      }
70  
71      public void setCrumbFactory(CrumbFactory crumbFactory) {
72          this.crumbFactory = crumbFactory;
73      }
74  
75      public void setIncludeParams(List includeParams) {
76          this.includeParams = includeParams;
77      }
78  }