1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import com.jcorporate.expresso.core.misc.CurrentLogin; 68 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 69 import com.jcorporate.expresso.services.dbobj.Setup; 70 import org.apache.log4j.Logger; 71 72 import javax.servlet.http.HttpServletRequest ; 73 import javax.servlet.jsp.JspWriter ; 74 import javax.servlet.jsp.PageContext ; 75 import javax.servlet.jsp.tagext.TagSupport ; 76 77 90 public class StyleSheetTag extends TagSupport { 91 94 protected String component = null; 95 protected String componentToUse = null; 96 97 private static Logger log = Logger.getLogger(StyleSheetTag.class); 98 99 100 103 public StyleSheetTag() { 104 105 } 106 107 108 115 public int doStartTag() 116 throws javax.servlet.jsp.JspTagException { 117 return SKIP_BODY; 118 } 119 120 127 public int doEndTag() throws javax.servlet.jsp.JspTagException { 128 componentToUse = component; 129 String styleSheetName = getComponent(); 130 131 if (componentToUse == null || componentToUse.length() == 0) { 132 styleSheetName = "default"; 133 } 134 135 String dbName = "default"; 136 CurrentLogin cl = (CurrentLogin) pageContext.getAttribute(CurrentLogin.LOGIN_KEY, 137 PageContext.PAGE_SCOPE); 138 139 if (cl != null) { 140 dbName = cl.getDBName(); 141 } 142 143 String contextPath = ((HttpServletRequest ) pageContext.getRequest()).getContextPath(); 144 String cssSuffix = null; 145 try { 146 cssSuffix = Setup.getValue(dbName, "defaultCSS"); 147 } catch (com.jcorporate.expresso.core.db.DBException dbe) { 148 log.warn("Unable to get setup value 'defaultCSS'. You may need to re-run DBCreate get the entry added." 149 , dbe); 150 } 151 152 FastStringBuffer styleURL = FastStringBuffer.getInstance(); 153 try { 154 styleURL.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\""); 155 styleURL.append(contextPath); 156 styleURL.append("/expresso"); 157 styleURL.append("/style/"); 158 styleURL.append(styleSheetName); 159 160 if (cssSuffix != null && cssSuffix.length() > 0) { 161 styleURL.append("-"); 162 styleURL.append(cssSuffix); 163 } 164 styleURL.append(".css"); 165 166 styleURL.append("\">"); 167 168 JspWriter writer = pageContext.getOut(); 169 try { 170 writer.println(styleURL.toString()); 171 } catch (java.io.IOException ioe) { 172 log.error("Unable to write tag entry: ", ioe); 173 } 174 } finally { 175 styleURL.release(); 176 } 177 return EVAL_PAGE; 178 } 179 180 181 186 public String getComponent() { 187 return componentToUse; 188 } 189 190 196 public void setComponent(java.lang.String newValue) { 197 component = newValue; 198 } 199 200 201 } | Popular Tags |