Package loxia.struts2.result

Source Code of loxia.struts2.result.ExcelTableModelResult

package loxia.struts2.result;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import loxia.struts2.table.TableModel;
import loxia.struts2.table.TableModelUtils;

import com.opensymphony.xwork2.ActionInvocation;

public class ExcelTableModelResult extends StrutsResultSupport {

  /**
   *
   */
  private static final long serialVersionUID = -664529035966407899L;
 
  private static final Logger logger = LoggerFactory.getLogger(ExcelTableModelResult.class);
 
  public static final String DEFAULT_CONTENT_TYPE = "application/vnd.ms-excel";

  @SuppressWarnings("unchecked")
  @Override
  protected void doExecute(String finalLocation, ActionInvocation invocation)
      throws Exception {
    Map request  = (Map)invocation.getInvocationContext().get("request");
    TableModel tableModel = (TableModel)request.get("exceltable");
   
    HttpServletResponse response = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE);
    response.setHeader("Content-Disposition", "attachment;filename=" + tableModel.getModelName() + ".xls");
   
   
    if(tableModel != null){
      logger.debug("Output Excel {}.xls", tableModel.getModelName());
      TableModelUtils.outputExcel(response.getOutputStream(), tableModel);
    }
  }

}
TOP

Related Classes of loxia.struts2.result.ExcelTableModelResult

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.