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.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  /***
25   * @author jamie
26   */
27  public class DefaultTrail implements Trail {
28      
29      private static final org.apache.log4j.Category log = org.apache.log4j.Category
30              .getInstance(DefaultTrail.class);
31      
32      private CrumbStrategy crumbStrategy = null;
33      private CrumbFactory crumbFactory = null;
34      
35      public DefaultTrail() {
36          
37      }
38  
39      /***
40       * @param crumbStrategy
41       * @param crumbFactory
42       */
43      public DefaultTrail(CrumbStrategy crumbStrategy, CrumbFactory crumbFactory) {
44          super();
45          this.crumbStrategy = crumbStrategy;
46          this.crumbFactory = crumbFactory;
47      }
48  
49      /* (non-Javadoc)
50       * @see org.jdiagnose.library.web.spring.Trail#getBreadcrumb(javax.servlet.http.HttpServletRequest)
51       */
52      public List getBreadcrumb(HttpServletRequest request) {
53          List urls = crumbStrategy.getUrls(request);
54          List result = new ArrayList(urls.size());
55          for (Iterator urlIterator = urls.iterator(); urlIterator.hasNext();) {
56              final String url = (String) urlIterator.next();
57              Crumb crumb = crumbFactory.getCrumb(request, url);
58              if(crumb != null) {
59                  result.add(crumb);
60              } else {
61                  log.warn("no crumb found for url " + url);
62              }
63          }
64          return result;
65      }
66      
67      public void setCrumbStrategy(CrumbStrategy crumbStrategy) {
68          this.crumbStrategy = crumbStrategy;
69      }
70      public void setCrumbFactory(CrumbFactory crumbFactory) {
71          this.crumbFactory = crumbFactory;
72      }
73  }