1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.misc.StringUtil; 69 import com.jcorporate.expresso.services.dbobj.Setup; 70 import org.apache.struts.taglib.bean.DefineTag; 71 72 import javax.servlet.jsp.JspException ; 73 import javax.servlet.jsp.PageContext ; 74 75 76 82 public class ExSetupTag extends DefineTag { 83 86 protected String db = null; 87 protected String dbToUse = null; 88 89 92 protected String optional = null; 93 protected String optionalToUse = null; 94 95 101 protected String schema = null; 102 protected String schemaToUse = null; 103 104 111 public int doStartTag() 112 throws JspException { 113 114 dbToUse = db; 116 117 if ((this.dbToUse == null) || (this.dbToUse.equals(""))) { 118 this.dbToUse = "default"; 119 } 120 121 122 return (SKIP_BODY); 123 } 124 125 public String getDb() { 126 return (this.dbToUse); 127 } 128 129 public void setDb(String newDb) { 130 this.db = newDb; 131 } 132 133 public String getOptional() { 134 return this.optionalToUse; 135 } 136 137 public void setOptional(String newOptional) { 138 this.optional = newOptional; 139 } 140 141 public String getSchema() { 142 return this.schemaToUse; 143 } 144 145 public void setSchema(String newValue) { 146 this.schema = newValue; 147 } 148 149 155 public int doEndTag() throws JspException { 156 157 Object valueToUse = this.value; 159 160 optionalToUse = this.optional; 161 schemaToUse = this.schema; 162 163 if (valueToUse == null) { 164 165 try { 167 if (optionalToUse == null || optionalToUse.equalsIgnoreCase("FALSE")) { 168 if (schemaToUse != null) { 169 valueToUse = Setup.getValueRequired(dbToUse, schemaToUse, property); 170 } else { 171 valueToUse = Setup.getValueRequired(dbToUse, property); 172 } 173 } else { 174 if (schemaToUse != null) { 175 valueToUse = Setup.getValue(dbToUse, schemaToUse, property); 176 } else { 177 valueToUse = Setup.getValue(dbToUse, property); 178 } 179 } 180 } catch (DBException dbe) { 181 throw new JspException ("Database exception trying to find property '" + 182 StringUtil.notNull(property) + 183 "' in configuration for DB/Context '" + dbToUse + 184 "':" + dbe.getMessage()); 185 } 186 } 187 if (valueToUse == null) { 188 throw new JspException ("Unable to find property '" + 189 StringUtil.notNull(property) + 190 "' in configuration for DB/Context '" + 191 dbToUse + "'"); 192 } 193 194 int inScope = PageContext.PAGE_SCOPE; 196 197 if ("request".equals(toScope)) { 198 inScope = PageContext.REQUEST_SCOPE; 199 } else if ("session".equals(toScope)) { 200 inScope = PageContext.SESSION_SCOPE; 201 } else if ("application".equals(toScope)) { 202 inScope = PageContext.APPLICATION_SCOPE; 203 } 204 205 if (this.value == null) { 211 setName(id); 212 } 213 pageContext.setAttribute(id, valueToUse, inScope); 214 215 return (EVAL_PAGE); 217 } 218 219 } | Popular Tags |