1 /** 2 * This file Copyright (c) 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.templating.jsp.taglib; 35 36 import info.magnolia.cms.license.LicenseFileExtractor; 37 38 import javax.servlet.jsp.JspException; 39 import javax.servlet.jsp.tagext.SimpleTagSupport; 40 import java.io.IOException; 41 import java.io.Writer; 42 import java.text.MessageFormat; 43 44 import org.tldgen.annotations.BodyContent; 45 import org.tldgen.annotations.Tag; 46 47 /** 48 * A simple tag which can display the version and edition of the running Magnolia instance. 49 * @jsp.tag name="poweredBy" body-content="empty" 50 * 51 * @author gjoseph 52 * @version $Revision: $ ($Author: $) 53 */ 54 @Tag(name="poweredBy", bodyContent=BodyContent.EMPTY) 55 56 public class PoweredByTag extends SimpleTagSupport { 57 private String pattern = "Powered by <a href=\"http://{3}\">Magnolia</a> {0} {1}."; 58 59 /** 60 * Sets a different message pattern than the default. This uses the java.text.MessageFormat syntax. 61 * Available parameters are: 62 * {0} Magnolia edition 63 * {1} Magnolia version 64 * {2} Magnolia build number or date 65 * {3} Magnolia product url 66 * {4} Magnolia provider name 67 * {5} Magnolia provider address 68 * {6} Magnolia provider email 69 * 70 * <strong>Warning: since this is using java.text.MessageFormat, you need to escape single quotes, for example: 71 * "I''m showing my Magnolia love by using the {0} version {1}."</strong> 72 * @jsp.attribute required="false" rtexprvalue="true" 73 */ 74 public void setPattern(String pattern) { 75 this.pattern = pattern; 76 } 77 78 @Override 79 public void doTag() throws JspException, IOException { 80 final Writer out = getJspContext().getOut(); 81 final LicenseFileExtractor license = LicenseFileExtractor.getInstance(); 82 final String[] licenseValues = new String[] { 83 license.get(LicenseFileExtractor.EDITION), 84 license.get(LicenseFileExtractor.VERSION_NUMBER), 85 license.get(LicenseFileExtractor.BUILD_NUMBER), 86 license.get(LicenseFileExtractor.PRODUCT_DOMAIN), 87 license.get(LicenseFileExtractor.PROVIDER), 88 license.get(LicenseFileExtractor.PROVIDER_ADDRESS), 89 license.get(LicenseFileExtractor.PROVIDER_EMAIL), 90 }; 91 92 final String message = MessageFormat.format(pattern, licenseValues); 93 out.write(message); 94 } 95 }