1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import com.jcorporate.expresso.core.misc.ConfigManager; 68 import com.jcorporate.expresso.core.misc.ConfigurationException; 69 import com.jcorporate.expresso.core.misc.StringUtil; 70 import org.apache.log4j.Logger; 71 import org.apache.struts.taglib.bean.DefineTag; 72 import org.apache.struts.util.RequestUtils; 73 74 import javax.servlet.jsp.JspException ; 75 import javax.servlet.jsp.PageContext ; 76 77 78 84 public class ExConfigTag extends DefineTag { 85 protected String db = "default"; 86 protected String dbToUse = "default"; 87 88 private static final Logger log = Logger.getLogger(ExConfigTag.class); 89 90 97 public int doStartTag() 98 throws JspException { 99 100 dbToUse = db; 102 103 if (this.dbToUse.equals("")) { 104 this.dbToUse = "default"; 105 } 106 107 return (SKIP_BODY); 108 } 109 110 public String getDb() { 111 return (this.dbToUse); 112 } 113 114 public void setDb(String newDb) { 115 this.db = newDb; 116 } 117 118 124 public int doEndTag() throws JspException { 125 126 Object value = this.value; 128 if ((value == null) && (name != null)) { 129 value = RequestUtils.lookup(pageContext, name, property, scope); 130 } 131 132 if (value == null) { 133 134 try { 137 if ("images".equals(property)) { 138 value = ConfigManager.getContext(dbToUse).getImages(); 139 } else if ("logDirectory".equals(property)) { 140 value = ConfigManager.getConfig().getLogDirectory(); 141 } else if ("servletAPI".equals(property)) { 142 value = ConfigManager.getConfig().getServletAPI(); 143 } else if ("userInfo".equals(property)) { 144 value = ConfigManager.getClassHandler("userInfo"); 145 } else if ("description".equals(property)) { 146 value = ConfigManager.getContext(dbToUse).getDescription(); 147 } else if ("startJobHandler".equals(property)) { 148 boolean temp = ConfigManager.getContext(dbToUse).startJobHandler(); 149 value = (temp) ? "y" : "n"; 150 } else if ("showStackTrace".equals(property)) { 151 boolean temp = ConfigManager.getContext(dbToUse).showStackTrace(); 152 value = (temp) ? "y" : "n"; 153 } else if ("mailDebug".equals(property)) { 154 boolean temp = ConfigManager.getContext(dbToUse).mailDebug(); 155 value = (temp) ? "y" : "n"; 156 } else if ("language".equals(property)) { 157 value = ConfigManager.getContext(dbToUse).getLanguage(); 158 } else if ("country".equals(property)) { 159 value = ConfigManager.getContext(dbToUse).getCountry(); 160 } else if ("expressoDir".equals(property)) { 161 value = ConfigManager.getContext(dbToUse).getExpressoDir(); 162 } else { 163 value = ConfigManager.getContext(dbToUse).getCustomProperty(property); 164 } 165 } catch (ConfigurationException ex) { 166 log.error("Error getting configuration for db: " + dbToUse, ex); 167 throw new JspException ("Configuration error getting config information. Details in log"); 168 } 169 } 170 171 if (value == null) { 172 JspException e = new JspException ("Unable to find property '" + 173 StringUtil.notNull(property) + 174 "' in configuration for DB/Context '" + 175 dbToUse + "'"); 176 log.error("No value ever defined", e); 177 RequestUtils.saveException(pageContext, e); 178 throw e; 179 } 180 181 int inScope = PageContext.PAGE_SCOPE; 183 if ("request".equals(toScope)) { 184 inScope = PageContext.REQUEST_SCOPE; 185 } else if ("session".equals(toScope)) { 186 inScope = PageContext.SESSION_SCOPE; 187 } else if ("application".equals(toScope)) { 188 inScope = PageContext.APPLICATION_SCOPE; 189 } 190 pageContext.setAttribute(id, value, inScope); 191 192 return (EVAL_PAGE); 194 } 195 196 } 197 | Popular Tags |