1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.templatingkit.badge;
35
36 import info.magnolia.context.MgnlContext;
37
38 import java.text.MessageFormat;
39 import java.util.Random;
40
41 import org.apache.commons.lang.BooleanUtils;
42
43
44
45
46
47
48
49
50 public final class BadgeSupport {
51
52 private static final String BADGE_TEMPLATE = "<p id=\"copyright-magnolia\"><span>Powered by</span> <a href=\"http://www.magnolia-cms.com\"><strong>Magnolia</strong> - {0}</a></p>";
53
54 private static final String HAS_BEEN_CALLED_ATTRIBUTE = BadgeSupport.class.getName() + ".hasBeenCalled";
55
56 private static final String EMPTY_BADGE = "";
57
58
59
60
61 private static BadgeSupport instance = new BadgeSupport();
62
63 private String[] badges = {
64 "based on Java Content Repository",
65 "based on JSR-170",
66 "Intuitive CMS Software",
67 "Intuitive CMS System",
68 "intuitive Content Management Software",
69 "Intuitive Content Management Solutions",
70 "Intuitive Content Management Tool",
71 "Intuitive Opensource CMS",
72 "Intuitive Web CMS",
73 "Intuitive Web Content Management System",
74 "Intuitive Website CMS",
75 "Intuitive Website Content Management System",
76 "Java Content Management System",
77 "Java Open-Source CMS",
78 "Open-Source Content Management System",
79 "Open-Source Enterprise Content Management",
80 "Open-Source Java CMS",
81 "Open-Source Java Content Management",
82 "SEO-friendly CMS",
83 "Simple Open-Source CMS",
84 "Simple Open-Source Content Management",
85 "Web-Site Content Management System",
86 "Website Content Management"
87 };
88
89 private MessageFormat template = new MessageFormat(BADGE_TEMPLATE);
90
91 private Random numberGenerator = new Random();
92
93 public String renderBadge(){
94 MgnlContext.setAttribute(HAS_BEEN_CALLED_ATTRIBUTE, Boolean.TRUE);
95 final int randomIndex = numberGenerator.nextInt(badges.length);
96 final String badge = badges[randomIndex];
97 return template.format(new Object[] { badge });
98 }
99
100 public boolean hasBeenCalled(){
101 Boolean value = (Boolean) MgnlContext.getAttribute(HAS_BEEN_CALLED_ATTRIBUTE);
102 return BooleanUtils.toBoolean(value);
103 }
104
105 public static BadgeSupport getInstance() {
106 return instance;
107 }
108
109 }