1 20 package org.openi.xmla; 21 22 import com.tonbeller.jpivot.core.Model; 23 import com.tonbeller.jpivot.core.ModelFactory; 24 import com.tonbeller.jpivot.olap.model.OlapException; 25 import com.tonbeller.jpivot.olap.model.OlapModel; 26 import com.tonbeller.jpivot.olap.navi.ClickableExtension; 27 import com.tonbeller.jpivot.olap.navi.ClickableExtensionImpl; 28 import com.tonbeller.jpivot.table.ClickableMember; 29 import com.tonbeller.jpivot.tags.OlapModelProxy; 30 import com.tonbeller.jpivot.xmla.XMLA_Model; 31 import com.tonbeller.jpivot.xmla.XMLA_OlapModelTag; 32 import com.tonbeller.wcf.controller.RequestContext; 33 import org.apache.log4j.Logger; 34 import org.xml.sax.SAXException ; 35 import java.io.IOException ; 36 import java.net.URL ; 37 import java.net.URLEncoder ; 38 import java.util.ArrayList ; 39 import java.util.List ; 40 41 42 45 public class XMLAQueryTag extends XMLA_OlapModelTag { 46 private static Logger logger = Logger.getLogger(XMLAQueryTag.class); 47 private List clickables; 48 private String user = null; 49 private String password = null; 50 private String mdxQuery = null; 51 private String queryName; 52 private boolean stackMode; 53 54 public void addClickable(ClickableMember clickable) { 55 clickables.add(clickable); 56 } 57 58 protected OlapModel getOlapModel(RequestContext context) 59 throws SAXException , IOException , OlapException { 60 URL url; 61 62 if (getConfig() == null) { 63 url = getClass().getResource("config.xml"); 64 } else { 65 url = pageContext.getServletContext().getResource(getConfig()); 66 } 67 68 Model model = ModelFactory.instance(url); 72 73 if (!(model instanceof XMLA_Model)) { 74 throw new com.tonbeller.jpivot.olap.model.OlapException( 75 "invalid class attribute for model tag, resource=" 76 + getConfig()); 77 } 78 79 XMLA_Model xm = (XMLA_Model) model; 80 xm.setUri(getUri()); 81 xm.setDataSource(getDataSource()); 82 xm.setCatalog(getCatalog()); 83 xm.setUser(URLEncoder.encode(user, "UTF-8")); 85 xm.setPassword(URLEncoder.encode(password, "UTF-8")); 86 xm.setMdxQuery(mdxQuery); 87 88 return xm; 89 } 90 91 public void init(RequestContext context) throws Exception { 92 long start = System.currentTimeMillis(); 93 clickables = new ArrayList (); 95 96 OlapModel om = getOlapModel(context); 97 om = (OlapModel) om.getTopDecorator(); 98 om.setLocale(context.getLocale()); 99 om.setID(id); 100 101 ClickableExtension ext = (ClickableExtension) om.getExtension(ClickableExtension.ID); 102 103 if (ext == null) { 104 ext = new ClickableExtensionImpl(); 105 om.addExtension(ext); 106 } 107 108 ext.setClickables(clickables); 109 110 OlapModelProxy omp = OlapModelProxy.instance(id, context.getSession(), 111 stackMode); 112 113 if (queryName != null) { 114 omp.initializeAndShow(queryName, om); 115 } else { 116 omp.initializeAndShow(om); 117 } 118 119 logger.info("init completed in: " 120 + (System.currentTimeMillis() - start) + " ms"); 121 } 122 123 public String getMdxQuery() { 124 return mdxQuery; 125 } 126 127 public void setMdxQuery(String mdxquery) { 128 mdxQuery = mdxquery; 129 } 130 131 public String getUser() { 132 return user; 133 } 134 135 public String getPassword() { 136 return password; 137 } 138 139 public void setUser(String user) { 140 this.user = user; 141 } 142 143 public void setPassword(String password) { 144 this.password = password; 145 } 146 147 public void setQueryName(String queryName) { 148 this.queryName = queryName; 149 } 150 151 public void setStackMode(boolean stackMode) { 152 this.stackMode = stackMode; 153 } 154 } 155 | Popular Tags |