⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportvieweraction.java

📁 The ability to create groups of reports, and grant users access to reports by group. The ability to
💻 JAVA
字号:
/*
 * Copyright (C) 2004 Erik Swenson - eswenson@opensourcesoft.net
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */

package org.efs.openreports.actions;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;

import org.apache.log4j.Logger;
import org.efs.openreports.ORStatics;
import org.jfree.chart.encoders.SunPNGEncoderAdapter;

import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;

public class ReportViewerAction extends ActionSupport
{
	protected static Logger log = Logger.getLogger(ReportViewerAction.class);

	private int pageIndex = 1;
	private int pageCount = 0;
	private float zoom = 1.0f;
	
	public String execute()
	{		
		JasperPrint jasperPrint = (JasperPrint) ActionContext.getContext().getSession().get(
				ORStatics.JASPERPRINT);
		
		if (jasperPrint != null && jasperPrint.getPages() != null)
		{
			pageCount = jasperPrint.getPages().size();
		}

		byte[] imageData = null; 
		
		if (jasperPrint != null)
		{
			try
			{
				BufferedImage image = (BufferedImage) JasperPrintManager.printPageToImage(jasperPrint, pageIndex -1, zoom);
				imageData = new SunPNGEncoderAdapter().encode(image);
			}
			catch(Exception e)
			{
				addActionError(e.getMessage());
				log.error(e.toString());
			}
		}			
		
		if (imageData != null)
		{

			HttpServletResponse response = ServletActionContext.getResponse();

			try
			{
				response.setContentLength(imageData.length);
				ServletOutputStream ouputStream = response.getOutputStream();
				ouputStream.write(imageData, 0, imageData.length);
				ouputStream.flush();
				ouputStream.close();
			}
			catch (IOException ioe)
			{
				log.warn(ioe.toString());
			}
		}

		return NONE;
	}
	
	public int getPageIndex()
	{
		return pageIndex;
	}
	
	public void setPageIndex(int pageIndex)
	{
		this.pageIndex = pageIndex;
	}
	
	public float getZoom()
	{
		return zoom;
	}
	
	public void setZoom(float zoom)
	{
		this.zoom = zoom;
	}
	
	public int getPageCount()
	{
		return pageCount;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -