java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java | 151 +++++++++++ java/code/src/com/redhat/rhn/frontend/taglibs/rhn-taglib.tld | 15 + 2 files changed, 166 insertions(+)
New commits: commit 5f5a7ed0fe9161f37e75f2d8c4eaa9fd812fcd6a Author: Tomas Kasparek tkasparek@redhat.com Date: Thu Dec 5 13:42:08 2013 +0100
bootstrap tuning: icon tag for simpler icon inserting
diff --git a/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java b/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java new file mode 100644 index 0000000..b513c08 --- /dev/null +++ b/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java @@ -0,0 +1,151 @@ +/** + * Copyright (c) 2009--2013 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ + +package com.redhat.rhn.frontend.taglibs; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +/** + * Tag to easy display the icons + * <pre> + * <rhn:icon type="$type"> + * <c:out escapeXml="false" value="${message}" /> + * </rhn:messages> + * </pre> + * @version $Rev$ + */ +public class IconTag extends TagSupport { + + private String type; + private String title; + private static Map<String, String> icons; + + /** + * Constructor for Icon tag. + */ + public IconTag() { + super(); + type = null; + title = null; + } + + /** + * Set the type of the icon + * @param typeIn the type of the icon + */ + public void setType(String typeIn) { + type = typeIn; + } + + /** + * Get the type of the icon + * @return The type of the icon + */ + public String getType() { + return type; + } + + /** + * Set the title of the icon + * @param titleIn the title of the icon + */ + public void setTitle(String titleIn) { + title = titleIn; + } + + /** + * Get the title of the icon + * @return The title of the icon + */ + public String getTitle() { + return title; + } + + private void setUpSingleton() { + if (icons == null) { + icons = new HashMap<String, String>(); + icons.put("system-ok", "fa fa-check-circle fa-1-5x text-success"); + icons.put("system-crit", "fa fa-exclamation-circle fa-1-5x text-danger"); + icons.put("system-warn", "fa fa-exclamation-triangle fa-1-5x text-warning"); + icons.put("system-unknown", "fa fa-1-5x spacewalk-icon-unknown-system"); + icons.put("system-locked", "fa fa-1-5x spacewalk-icon-locked-system"); + icons.put("system-kickstarting", "fa fa-rocket fa-1-5x"); + icons.put("system-unentitled", "fa fa-1-5x spacewalk-icon-Unentitled"); + icons.put("system-virt-host", "fa fa-1-5x spacewalk-icon-virtual-host"); + icons.put("system-virt-guest", "fa fa-1-5x spacewalk-icon-virtual-guest"); + icons.put("system-physical", "fa fa-desktop fa-1-5x"); + icons.put("actions-pending", "fa fa-clock-o fa-1-5x"); + icons.put("actions-ok", "fa fa-check-circle-o fa-1-5x text-success"); + icons.put("action-failed", "fa fa-times-circle-o fa-1-5x text-danger"); + icons.put("errata-security", "fa fa-shield fa-1-5x"); + icons.put("errata-bugfix", "fa fa-bug fa-1-5x"); + icons.put("errata-enhance", "fa fa-1-5x spacewalk-icon-enhancement"); + icons.put("monitoring-status", "fa fa-1-5x spacewalk-icon-monitoring-status"); + icons.put("monitoring-ok", "fa fa-1-5x spacewalk-icon-health text-success"); + icons.put("monitoring-warn", "fa fa-1-5x spacewalk-icon-health text-warning"); + icons.put("monitoring-crit", "fa fa-1-5x spacewalk-icon-health text-danger"); + icons.put("monitoring-unknown", "fa fa-1-5x spacewalk-icon-health-unknown"); + icons.put("monitoring-pending", "fa fa-1-5x spacewalk-icon-health-pending"); + } + } + + /** {@inheritDoc} + * @throws JspException + */ + public int doStartTag() throws JspException { + + setUpSingleton(); + + if (!icons.containsKey(type)) { + throw new IllegalArgumentException("Unknown icon type: "" + type + ""."); + } + + JspWriter out = null; + + try { + out = pageContext.getOut(); + + StringBuilder result = new StringBuilder(); + + result.append("<i class="" + icons.get(type) + """); + if (title != null) { + result.append(" title="" + title + """); + } + result.append("></i>"); + + out.print(result); + } + catch (IOException ioe) { + throw new JspException("IO error writing to JSP file:", ioe); + } + return SKIP_BODY; + } + + /** + * {@inheritDoc} + */ + public void release() { + type = null; + title = null; + super.release(); + } + +} diff --git a/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-taglib.tld b/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-taglib.tld index 0014d89..851c66e 100644 --- a/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-taglib.tld +++ b/java/code/src/com/redhat/rhn/frontend/taglibs/rhn-taglib.tld @@ -303,6 +303,21 @@ <required>false</required> </attribute> </tag> + + <tag> + <name>icon</name> + <tag-class>com.redhat.rhn.frontend.taglibs.IconTag</tag-class> + <body-content>JSP</body-content> + <attribute> + <name>type</name> + <required>true</required> + </attribute> + <attribute> + <name>title</name> + <required>false</required> + </attribute> + </tag> + <tag> <name>list</name> <tag-class>com.redhat.rhn.frontend.taglibs.ListTag</tag-class>
spacewalk-commits@lists.fedorahosted.org