1 13 package com.tonbeller.jpivot.tags; 14 15 import java.io.IOException ; 16 import java.net.URL ; 17 18 import javax.servlet.jsp.JspException ; 19 20 import org.xml.sax.SAXException ; 21 22 import com.tonbeller.jpivot.mondrian.MondrianModel; 23 import com.tonbeller.jpivot.olap.model.OlapException; 24 import com.tonbeller.jpivot.olap.model.OlapModel; 25 import com.tonbeller.jpivot.tags.MondrianModelFactory.Config; 26 import com.tonbeller.tbutils.res.Resources; 27 import com.tonbeller.wcf.controller.RequestContext; 28 29 32 public class MondrianOlapModelTag extends OlapModelTag { 33 34 String dataSource; 35 String jdbcDriver; 36 String jdbcUser; 37 String jdbcPassword; 38 String jdbcUrl; 39 String catalogUri; 40 String config; 41 String role; 42 String dynResolver; 43 String dynLocale; 44 String connectionPooling; 45 String dataSourceChangeListener; 46 47 Resources res = Resources.instance(); 48 49 protected OlapModel getOlapModel(RequestContext context) throws JspException , OlapException, SAXException , IOException { 50 MondrianModelFactory.Config cfg = new MondrianModelFactory.Config(); 51 URL schemaUrl; 52 if (catalogUri.startsWith("/")) 53 schemaUrl = pageContext.getServletContext().getResource(catalogUri); 54 else 55 schemaUrl = new URL (catalogUri); 56 if (schemaUrl == null) 57 throw new JspException ("could not find Catalog \"" + catalogUri + "\""); 58 59 60 cfg.setMdxQuery(getBodyContent().getString()); 61 cfg.setSchemaUrl("\"" + schemaUrl.toExternalForm() + "\""); 64 cfg.setJdbcUrl(jdbcUrl); 65 cfg.setJdbcDriver(jdbcDriver); 66 cfg.setJdbcUser(jdbcUser); 67 cfg.setJdbcPassword(jdbcPassword); 68 cfg.setDataSource(dataSource); 69 cfg.setRole(role); 70 cfg.setDynResolver(dynResolver); 71 cfg.setDynLocale(dynLocale); 72 cfg.setConnectionPooling(connectionPooling); 73 cfg.setDataSourceChangeListener(dataSourceChangeListener); 74 75 allowOverride(context, cfg); 76 77 URL url; 78 if (config == null) 79 url = getDefaultConfig(); 80 else 81 url = pageContext.getServletContext().getResource(config); 82 83 MondrianModel mm = MondrianModelFactory.instance(url, cfg); 84 OlapModel om = (OlapModel) mm.getTopDecorator(); 85 om.setLocale(context.getLocale()); 86 om.setServletContext(context.getSession().getServletContext()); 87 return om; 88 } 89 90 93 protected void allowOverride(RequestContext context, Config cfg) { 94 cfg.allowOverride(context); 95 } 96 97 protected URL getDefaultConfig() { 98 return MondrianOlapModelTag.class.getResource("/com/tonbeller/jpivot/mondrian/config.xml"); 99 } 100 101 102 107 public String getCatalogUri() { 108 return catalogUri; 109 } 110 111 116 public String getJdbcDriver() { 117 return jdbcDriver; 118 } 119 120 125 public String getJdbcUrl() { 126 return jdbcUrl; 127 } 128 129 135 public void setCatalogUri(String catalogUri) { 136 this.catalogUri = catalogUri; 137 } 138 139 145 public void setJdbcDriver(String jdbcDriver) { 146 this.jdbcDriver = jdbcDriver; 147 } 148 149 155 public void setJdbcUrl(String jdbcUrl) { 156 this.jdbcUrl = jdbcUrl; 157 } 158 159 164 public String getJdbcPassword() { 165 return jdbcPassword; 166 } 167 168 173 public String getJdbcUser() { 174 return jdbcUser; 175 } 176 177 183 public void setJdbcPassword(String jdbcPassword) { 184 this.jdbcPassword = jdbcPassword; 185 } 186 187 193 public void setJdbcUser(String jdbcUser) { 194 this.jdbcUser = jdbcUser; 195 } 196 197 202 public String getConfig() { 203 return config; 204 } 205 206 212 public void setConfig(String config) { 213 this.config = config; 214 } 215 216 219 public void setDataSource(String string) { 220 dataSource = string; 221 } 222 223 227 public void setRole(String role) { 228 this.role = role; 229 } 230 231 234 public String getDynResolver() { 235 return dynResolver; 236 } 237 238 241 public void setDynResolver(String dynResolver) { 242 this.dynResolver = dynResolver; 243 } 244 245 248 public void setConnectionPooling(String connectionPooling) { 249 this.connectionPooling = connectionPooling; 250 } 251 252 255 public String getConnectionPooling() { 256 return connectionPooling; 257 } 258 public String getDataSource() { 259 return dataSource; 260 } 261 public String getRole() { 262 return role; 263 } 264 268 public String getDynLocale() { 269 return this.dynLocale; 270 } 271 275 public void setDynLocale(String dynLocale) { 276 this.dynLocale = dynLocale; 277 } 278 279 282 public String getDataSourceChangeListener() { 283 return dataSourceChangeListener; 284 } 285 286 289 public void setDataSourceChangeListener(String dataSourceChangeListener) { 290 this.dataSourceChangeListener = dataSourceChangeListener; 291 } 292 293 294 } 295 | Popular Tags |