1 11 12 package org.jivesoftware.admin; 13 14 import org.jivesoftware.util.StringUtils; 15 import org.jivesoftware.util.LocaleUtils; 16 import org.dom4j.Element; 17 18 import javax.servlet.jsp.tagext.BodyTagSupport ; 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.JspWriter ; 21 import javax.servlet.http.HttpServletRequest ; 22 import java.util.List ; 23 import java.io.IOException ; 24 25 53 public class TabsTag extends BodyTagSupport { 54 55 private String bean; 56 private String css; 57 private String currentcss; 58 59 62 public String getBean() { 63 return bean; 64 } 65 66 69 public void setBean(String bean) { 70 this.bean = bean; 71 } 72 73 76 public String getCss() { 77 return clean(css); 78 } 79 80 83 public void setCss(String css) { 84 this.css = css; 85 } 86 87 91 public String getCurrentcss() { 92 return clean(currentcss); 93 } 94 95 98 public void setCurrentcss(String currentcss) { 99 this.currentcss = currentcss; 100 } 101 102 105 public int doStartTag() throws JspException { 106 return EVAL_BODY_BUFFERED; 107 } 108 109 117 public int doEndTag() throws JspException { 118 HttpServletRequest request = (HttpServletRequest )pageContext.getRequest(); 119 String beanName = getBean(); 120 AdminPageBean pageInfo = (AdminPageBean)request.getAttribute(beanName); 122 String pageID = null; 124 if (pageInfo != null) { 125 pageID = pageInfo.getPageID(); 126 } 127 List tabs = AdminConsole.getModel().selectNodes("//tab"); 129 if (tabs.size() > 0) { 130 JspWriter out = pageContext.getOut(); 131 StringBuilder buf = new StringBuilder (); 133 buf.append("<ul>"); 134 String body = getBodyContent().getString(); 135 Element currentTab = null; 137 if (pageID != null) { 138 currentTab = (Element)AdminConsole.getModel().selectSingleNode( 139 "//*[@id='" + pageID + "']/ancestor::tab"); 140 } 141 for (int i=0; i<tabs.size(); i++) { 142 Element tab = (Element)tabs.get(i); 143 String value = body; 144 if (value != null) { 145 value = StringUtils.replace(value, "[id]", clean(tab.attributeValue("id"))); 147 value = StringUtils.replace(value, "[url]", 148 request.getContextPath() + "/" + clean(tab.attributeValue("url"))); 149 value = StringUtils.replace(value, "[name]", clean(i18n(tab.attributeValue("name")))); 150 value = StringUtils.replace(value, "[description]", clean(i18n(tab.attributeValue("description")))); 151 } 152 String css = getCss(); 153 if (tab.equals(currentTab)) { 154 css = getCurrentcss(); 155 } 156 buf.append("<li class=\"").append(css).append("\">"); 157 buf.append(value); 158 buf.append("</li>"); 159 } 160 161 buf.append("</ul>"); 162 try { 163 out.write(buf.toString()); 164 } 165 catch (IOException ioe) { 166 throw new JspException (ioe.getMessage()); 167 } 168 } 169 return EVAL_PAGE; 170 } 171 172 179 private String clean(String in) { 180 return (in == null ? "" : StringUtils.replace(in, "'", "\\'")); 181 } 182 183 private String i18n(String in) { 184 if (in == null) { 185 return null; 186 } 187 if (in.indexOf("${") == 0 && in.indexOf("}") == in.length()-1) { 189 return LocaleUtils.getLocalizedString(in.substring(2, in.length()-1)); 190 } 191 return in; 192 } 193 } | Popular Tags |