View Javadoc

1   /**
2    * This file Copyright (c) 2008-2012 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
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   * Info Badge Support used by the RenderingModel implementation class.
46   * @author pbracher
47   * @version $Id$
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       * Not configured.
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 }