1 21 package com.jaspersoft.jasperserver.war.tags; 22 23 24 import java.util.HashMap ; 25 26 import javax.servlet.ServletContext ; 27 import javax.servlet.jsp.JspException ; 28 import javax.servlet.jsp.tagext.Tag ; 29 import javax.servlet.jsp.tagext.TagSupport ; 30 31 import net.sf.jasperreports.engine.JasperPrint; 32 import net.sf.jasperreports.j2ee.servlets.BaseHttpServlet; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 import org.springframework.web.context.WebApplicationContext; 37 import org.springframework.web.context.support.WebApplicationContextUtils; 38 39 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl; 40 import com.jaspersoft.jasperserver.api.engine.common.service.EngineService; 41 import com.jaspersoft.jasperserver.api.engine.jasperreports.domain.impl.ReportUnitRequest; 42 import com.jaspersoft.jasperserver.api.engine.jasperreports.domain.impl.ReportUnitResult; 43 44 45 49 public class ViewReportTag extends TagSupport { 50 51 private static final Log log = LogFactory.getLog(ViewReportTag.class); 52 53 private String reportName; 54 55 58 public int doStartTag() throws JspException { 59 if (getReportName() == null) { 60 return Tag.SKIP_BODY; 61 } 62 63 try { 64 ServletContext servletContext = pageContext.getServletContext(); 65 66 WebApplicationContext wac = WebApplicationContextUtils. 67 getRequiredWebApplicationContext(servletContext); 68 69 EngineService engine = (EngineService) wac.getBean("engineService"); 70 71 ReportUnitResult result = 72 (ReportUnitResult)engine.execute( 73 new ExecutionContextImpl(), 74 new ReportUnitRequest(getReportName(), new HashMap ()) 75 ); 76 77 JasperPrint jasperPrint = result.getJasperPrint(); 78 pageContext.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); 79 } catch (Exception _exc) { 80 if (log.isErrorEnabled()) 81 log.error(_exc, _exc); 82 throw new JspException (_exc); 83 } 84 return Tag.SKIP_BODY; 85 } 86 87 91 public int doEndTag() { 92 return Tag.EVAL_PAGE; 93 } 94 95 public String getReportName() { 96 return reportName; 97 } 98 99 public void setReportName(String reportName) { 100 this.reportName = reportName; 101 } 102 103 } 104 | Popular Tags |