1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.library.web.breadcrumb;
17
18 import java.util.Iterator;
19 import java.util.Locale;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import javax.servlet.http.HttpServletRequest;
24
25 /***
26 * @author jmccrindle
27 */
28 public class PropertiesCrumbFactory extends CrumbFactoryWrapper implements CrumbFactory {
29
30 private Properties properties = null;
31
32 /***
33 *
34 */
35 public PropertiesCrumbFactory() {
36 super();
37 }
38
39 /***
40 * @param crumbFactory
41 */
42 public PropertiesCrumbFactory(CrumbFactory crumbFactory) {
43 super(crumbFactory);
44 }
45
46
47
48
49 public Crumb getCrumb(HttpServletRequest request, final String url) {
50 final String simpleDescription = getSimpleDescription(url);
51 if(simpleDescription != null) {
52 return new Crumb() {
53 public String getUrl() {
54 return url;
55 }
56 public String getDescription(Locale locale) {
57 return simpleDescription;
58 }
59 };
60 }
61 CrumbFactory delegate = getCrumbFactory();
62 if(delegate != null ) {
63 return delegate.getCrumb(request, url);
64 } else {
65 return null;
66 }
67 }
68
69 protected String getSimpleDescription(String url) {
70 for (Iterator propIterator = properties.entrySet().iterator(); propIterator.hasNext();) {
71 Map.Entry entry = (Map.Entry) propIterator.next();
72 String key = (String) entry.getKey();
73 if(url.endsWith(key)) {
74 return (String) entry.getValue();
75 }
76 }
77 return null;
78 }
79
80 public void setProperties(Properties properties) {
81 this.properties = properties;
82 }
83 }