1 package com.jaspersoft.jasperserver.war.tags; 2 3 import java.io.FileInputStream ; 4 import java.io.FileOutputStream ; 5 import java.io.ObjectInputStream ; 6 import java.io.ObjectOutputStream ; 7 import java.io.Serializable ; 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 import javax.servlet.ServletContext ; 12 import javax.servlet.http.HttpSession ; 13 import javax.servlet.jsp.JspException ; 14 import javax.servlet.jsp.tagext.BodyTagSupport ; 15 16 import org.apache.log4j.Logger; 17 import org.springframework.web.context.WebApplicationContext; 18 import org.springframework.web.context.support.WebApplicationContextUtils; 19 20 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl; 21 import com.jaspersoft.jasperserver.api.engine.common.service.EngineService; 22 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService; 23 import com.jaspersoft.jasperserver.api.metadata.olap.domain.OlapUnit; 24 import com.jaspersoft.jasperserver.api.metadata.olap.service.OlapConnectionService; 25 import com.tonbeller.jpivot.mondrian.MondrianModel; 26 import com.tonbeller.jpivot.olap.model.CachingOlapModel; 27 import com.tonbeller.jpivot.olap.model.OlapModel; 28 import com.tonbeller.jpivot.olap.navi.ClickableExtension; 29 import com.tonbeller.jpivot.olap.navi.ClickableExtensionImpl; 30 import com.tonbeller.jpivot.table.ClickableMember; 31 import com.tonbeller.jpivot.tags.OlapModelProxy; 32 import com.tonbeller.jpivot.tags.OlapModelTag; 33 import com.tonbeller.wcf.controller.RequestContext; 34 35 38 public abstract class JasperOlapModelTag extends OlapModelTag { 39 40 private static Logger logger = Logger.getLogger(JasperOlapModelTag.class); 41 42 private List clickables; 43 private String queryName; 44 private boolean stackMode; 45 private String olapUnitName; 46 47 public JasperOlapModelTag() { 48 } 49 50 public void addClickable(ClickableMember clickable) { 51 clickables.add(clickable); 52 } 53 54 public int doStartTag() throws JspException { 55 clickables = new ArrayList (); 56 return EVAL_BODY_BUFFERED; 57 } 58 59 public int doEndTag() throws JspException { 60 try 61 { 62 logger.info("enter"); 63 RequestContext context = RequestContext.instance(); 64 OlapModel om = (MondrianModel) createOlapModel(); 65 66 om = (OlapModel) ((MondrianModel) om).getTopDecorator(); 68 om.setLocale(context.getLocale()); 69 om.setServletContext(context.getSession().getServletContext()); 70 72 om = (OlapModel) om.getTopDecorator(); 73 om.setLocale(context.getLocale()); 74 om.setID(id); 75 76 HttpSession session = pageContext.getSession(); 77 om.setServletContext(session.getServletContext()); 78 79 ClickableExtension ext = (ClickableExtension) om.getExtension(ClickableExtension.ID); 80 if (ext == null) { 81 ext = new ClickableExtensionImpl(); 82 om.addExtension(ext); 83 } 84 ext.setClickables(clickables); 85 86 OlapModelProxy omp = OlapModelProxy.instance(id, session, stackMode); 87 if (queryName != null) 88 omp.initializeAndShow(queryName, om); 89 else 90 omp.initializeAndShow(om); 91 92 return EVAL_PAGE; 93 94 } 95 catch (Exception e) 96 { 97 logger.error(null, e); 98 throw new JspException (e); 99 } 100 } 101 102 protected abstract OlapModel getOlapModel(RequestContext context) throws Exception ; 103 104 public void setQueryName(String queryName) { 105 this.queryName = queryName; 106 } 107 108 public void setStackMode(boolean stackMode) { 109 this.stackMode = stackMode; 110 } 111 112 public void setOlapUnitName(String olapUnitName) { 113 this.olapUnitName = olapUnitName; 114 } 115 116 123 private OlapModel createOlapModel() throws JspException { 124 125 OlapModel result = null; 126 127 try { 128 ServletContext servletContext = pageContext.getServletContext(); 129 130 WebApplicationContext wac = WebApplicationContextUtils 131 .getRequiredWebApplicationContext(servletContext); 132 133 OlapConnectionService olapConnection = (OlapConnectionService) wac 134 .getBean("olapConnectionService"); 135 136 RepositoryService repository = (RepositoryService) wac 137 .getBean("repositoryService"); 138 139 ExecutionContextImpl executionContext = new ExecutionContextImpl(); 140 141 OlapUnit olapUnit = (OlapUnit) repository.getResource(executionContext, 142 olapUnitName); 143 144 result = olapConnection.createOlapModel(executionContext, olapUnit); 145 } 146 catch (Exception e) 147 { 148 logger.error(null, e); 149 throw new JspException (e); 150 } 151 152 return result; 153 } 154 } 155 | Popular Tags |