1 13 package com.tonbeller.jpivot.tags; 14 15 import java.net.URL ; 16 import java.util.StringTokenizer ; 17 18 import javax.servlet.jsp.JspException ; 19 20 import com.tonbeller.jpivot.core.ModelFactory; 21 import com.tonbeller.jpivot.olap.model.OlapModel; 22 import com.tonbeller.jpivot.test.olap.TestAxis; 23 import com.tonbeller.jpivot.test.olap.TestDimension; 24 import com.tonbeller.jpivot.test.olap.TestOlapModel; 25 import com.tonbeller.jpivot.test.olap.TestOlapModelUtils; 26 import com.tonbeller.wcf.controller.RequestContext; 27 28 31 public class TestOlapModelTag extends OlapModelTag { 32 String onColumns = "Measures"; 33 String onRows = "Products"; 34 String config = null; 35 36 39 protected OlapModel getOlapModel(RequestContext context) throws Exception { 40 URL url; 41 if (config == null) 42 url = getDefaultConfig(); 43 else 44 url = pageContext.getServletContext().getResource(config); 45 TestOlapModel model = (TestOlapModel) ModelFactory.instance(url); 46 model.setAxis(0, createAxis(model, onColumns)); 47 model.setAxis(1, createAxis(model, onRows)); 48 return model; 49 } 50 51 54 protected URL getDefaultConfig() { 55 return getClass().getResource("/com/tonbeller/jpivot/test/olap/config.xml"); 56 } 57 58 TestAxis createAxis(TestOlapModel tom, String names) throws JspException { 59 StringTokenizer st = new StringTokenizer (names); 60 TestAxis a = createAxis1(tom, st.nextToken()); 61 while (st.hasMoreTokens()) { 62 TestAxis b = createAxis1(tom, st.nextToken()); 63 a = TestOlapModelUtils.crossJoin(a, b); 64 } 65 return a; 66 } 67 68 TestAxis createAxis1(TestOlapModel tom, String name) throws JspException { 69 TestDimension dim = (TestDimension)tom.getDimension(name); 70 if (dim == null) 71 throw new JspException ("Dimension " + name + " not found"); 72 return TestOlapModelUtils.createAxis(dim); 73 } 74 75 76 80 public String getOnColumns() { 81 return onColumns; 82 } 83 84 88 public String getOnRows() { 89 return onRows; 90 } 91 92 96 public void setOnColumns(String onColumns) { 97 this.onColumns = onColumns; 98 } 99 100 104 public void setOnRows(String onRows) { 105 this.onRows = onRows; 106 } 107 108 112 public String getConfig() { 113 return config; 114 } 115 116 120 public void setConfig(String config) { 121 this.config = config; 122 } 123 124 } 125 | Popular Tags |