Example usage for javax.servlet ServletContext getRealPath

List of usage examples for javax.servlet ServletContext getRealPath

Introduction

In this page you can find the example usage for javax.servlet ServletContext getRealPath.

Prototype

public String getRealPath(String path);

Source Link

Document

Gets the real path corresponding to the given virtual path.

Usage

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * 1-13???/*  w  w w .j av a2  s .c o  m*/
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printRc113(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Employee employee = (Employee) getUserCredential(session).getMember();
    List<Empl> empls = mm.findTeacherByUnit(employee.getUnit());
    String calendarYear = form.getString("calendarYear");

    Rchono rchono = null;
    List<Rchono> rchonos = null;

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("1-13??");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 12000);
    sheet.setColumnWidth(3, 5000);
    sheet.setColumnWidth(4, 10000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(employee.getUnit()) + "1-13??", fontSize12,
            HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "????", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    for (Empl e : empls) {

        rchono = new Rchono();
        rchono.setIdno(e.getIdno().toUpperCase());
        rchono.setSchoolYear(Short.valueOf(calendarYear));

        rchonos = mm.findRchonosBy(rchono);
        for (Rchono rc : rchonos) {
            Toolket.setCellValue(workbook, sheet, index, 0, rc.getSchoolYear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, e.getCname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, rc.getTitle().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, rc.getNation().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 4, rc.getInst().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "printRc113.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * 1-9?/*from   w  w w .  j  a  v  a  2s. c  o  m*/
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printRc19(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Employee employee = (Employee) getUserCredential(session).getMember();
    List<Empl> empls = mm.findTeacherByUnit(employee.getUnit());
    String calendarYear = form.getString("calendarYear");

    Rcjour rcjour = null;
    List<Rcjour> rcjours = null;

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("1-9");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 12000);
    sheet.setColumnWidth(3, 12000);
    sheet.setColumnWidth(4, 3000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(employee.getUnit()) + "1-9", fontSize12,
            HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    for (Empl e : empls) {

        rcjour = new Rcjour();
        rcjour.setIdno(e.getIdno().toUpperCase());
        rcjour.setSchoolYear(Short.valueOf(calendarYear));

        rcjours = mm.findRcjoursBy(rcjour);
        for (Rcjour rc : rcjours) {
            Toolket.setCellValue(workbook, sheet, index, 0, rc.getSchoolYear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, e.getCname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, rc.getTitle().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, rc.getJname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 4, rc.getPyear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "printRc19.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * 1-10?//w  w  w  .  ja va 2 s.c  om
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printRc110(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Employee employee = (Employee) getUserCredential(session).getMember();
    List<Empl> empls = mm.findTeacherByUnit(employee.getUnit());
    String calendarYear = form.getString("calendarYear");

    Rcconf rcconf = null;
    List<Rcconf> rcconfs = null;

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("1-10");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 12000);
    sheet.setColumnWidth(3, 12000);
    sheet.setColumnWidth(4, 3000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(employee.getUnit()) + "1-10",
            fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    for (Empl e : empls) {

        rcconf = new Rcconf();
        rcconf.setIdno(e.getIdno().toUpperCase());
        rcconf.setSchoolYear(Short.valueOf(calendarYear));

        rcconfs = mm.findRcconfsBy(rcconf);
        for (Rcconf rc : rcconfs) {
            Toolket.setCellValue(workbook, sheet, index, 0, rc.getSchoolYear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, e.getCname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, rc.getTitle().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, rc.getJname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 4, rc.getPyear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "printRc110.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:tw.edu.chit.struts.action.course.ReportPrintAction.java

/**
 * // w w  w  .j  ava2s  .c o  m
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printIntroCheck(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    String year = am.findTermBy(IConstants.PARAMETER_SCHOOL_YEAR);
    // ???
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), true);

    if (!clazzes.isEmpty()) {

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("");
        sheet.setColumnWidth(0, 3000);
        sheet.setColumnWidth(1, 5000);
        sheet.setColumnWidth(2, 3000);
        sheet.setColumnWidth(3, 8000);
        sheet.setColumnWidth(4, 2000);
        sheet.setColumnWidth(5, 5000);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

        HSSFFont fontSize16 = workbook.createFont();
        fontSize16.setFontHeightInPoints((short) 16);
        fontSize16.setFontName("Arial Unicode MS");

        HSSFFont fontSize12 = workbook.createFont();
        fontSize12.setFontHeightInPoints((short) 12);
        fontSize12.setFontName("Arial Unicode MS");

        // Header
        Toolket.setCellValue(workbook, sheet, 0, 0,
                year + "" + sterm + "", fontSize16,
                HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

        // Column Header
        Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 1, "???", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 2, "", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 3, "??", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize12, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 5, "??", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        int index = 2;
        List<Object> maps = null;
        Dtime dtime = null;
        Csno csno = null;
        CourseIntroduction ci = null;
        Empl empl = null;
        String[] excluded = { "50000", "T0001", "T0002" };

        for (Clazz clazz : clazzes) {
            if (Toolket.isDelayClass(clazz.getClassNo()))
                continue;

            //maps = cm.findDtimeCsnoBy(new Dtime(clazz.getClassNo(), sterm),
            //"cscode");

            if (maps != null) {

                for (Object o : maps) {
                    dtime = (Dtime) ((Object[]) o)[0];
                    csno = (Csno) ((Object[]) o)[1];

                    // ?
                    if (!ArrayUtils.contains(excluded, csno.getCscode())
                            && !ArrayUtils.contains(IConstants.COURSE_SYLLABUS_INTRO, dtime.getCscode())
                            && StringUtils.isNotBlank(dtime.getTechid().trim())) {

                        ci = cm.getCourseIntrosByDtimeOid(dtime.getOid(), Integer.parseInt(year),
                                Integer.parseInt(sterm));
                        if (ci == null) {

                            empl = mm.findEmplByIdno(dtime.getTechid());
                            Toolket.setCellValue(workbook, sheet, index, 0, clazz.getClassNo(), null,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 1,
                                    Toolket.getClassFullName(clazz.getClassNo()), null,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 2, csno.getCscode(), null,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 3, csno.getChiName().trim(), null,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 4, dtime.getCredit().toString(), null,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index++, 5,
                                    (empl == null ? "" : empl.getCname().trim()), null,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                        } else {
                            ci = null;
                        }
                    }

                    dtime = null;
                    csno = null;
                }
            }
        }

        File tempDir = new File(
                context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                        + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
        if (!tempDir.exists())
            tempDir.mkdirs();

        File output = new File(tempDir, "RegisterList.xls");
        FileOutputStream fos = new FileOutputStream(output);
        workbook.write(fos);
        fos.close();

        JasperReportUtils.printXlsToFrontEnd(response, output);
        output.delete();
        tempDir.delete();
    } else {
        Map<String, String> param = new HashMap<String, String>();
        File image = new File(context.getRealPath("/pages/images/2002chitS.jpg"));
        param.put("IMAGE", image.getAbsolutePath());
        byte[] bytes = JasperRunManager.runReportToPdf(JasperReportUtils.getNoResultReport(context), param,
                new JREmptyDataSource());
        JasperReportUtils.printPdfToFrontEnd(response, bytes);
    }

}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * 1-12?/*from  w  ww . j a v a  2  s  . c  o m*/
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printRc112(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Employee employee = (Employee) getUserCredential(session).getMember();
    List<Empl> empls = mm.findTeacherByUnit(employee.getUnit());
    String calendarYear = form.getString("calendarYear");

    Rcpet rcpet = null;
    List<Rcpet> rcpets = null;

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("1-12");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 12000);
    sheet.setColumnWidth(3, 3000);
    sheet.setColumnWidth(4, 3000);
    sheet.setColumnWidth(5, 6000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(employee.getUnit()) + "1-12", fontSize12,
            HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 5, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    for (Empl e : empls) {

        rcpet = new Rcpet();
        rcpet.setIdno(e.getIdno().toUpperCase());
        rcpet.setSchoolYear(Short.valueOf(calendarYear));

        rcpets = mm.findRcpetsBy(rcpet);
        for (Rcpet rc : rcpets) {
            Toolket.setCellValue(workbook, sheet, index, 0, rc.getSchoolYear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, e.getCname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, rc.getTitle().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, rc.getBdate().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 4, rc.getEdate().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 5, rc.getInst().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "printRc112.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * 1-7?/*from   www. jav a2 s.c o m*/
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printRc17(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Employee employee = (Employee) getUserCredential(session).getMember();
    List<Empl> empls = mm.findTeacherByUnit(employee.getUnit());
    String calendarYear = form.getString("calendarYear");

    Rcact rcact = null;
    List<Rcact> rcacts = null;

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("1-7");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 12000);
    sheet.setColumnWidth(3, 8000);
    sheet.setColumnWidth(4, 3000);
    sheet.setColumnWidth(5, 3500);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(employee.getUnit()) + "1-7", fontSize12,
            HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 5, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    for (Empl e : empls) {

        rcact = new Rcact();
        rcact.setIdno(e.getIdno().toUpperCase());
        rcact.setSchoolYear(Short.valueOf(calendarYear));

        rcacts = mm.findRcactsBy(rcact);
        for (Rcact rc : rcacts) {
            Toolket.setCellValue(workbook, sheet, index, 0, rc.getSchoolYear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, e.getCname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, rc.getActname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, rc.getSponoff().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 4, rc.getBdate().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 5, rc.getEdate().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "printRc17.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * 1-8?// www .  j  av  a 2s  . c o  m
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printRc18(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Employee employee = (Employee) getUserCredential(session).getMember();
    List<Empl> empls = mm.findTeacherByUnit(employee.getUnit());
    String calendarYear = form.getString("calendarYear");

    Rcproj rcproj = null;
    List<Rcproj> rcprojs = null;

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("1-8");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 8000);
    sheet.setColumnWidth(3, 12000);
    sheet.setColumnWidth(4, 3000);
    sheet.setColumnWidth(5, 3000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(employee.getUnit())
                    + "1-8",
            fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 5, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    for (Empl e : empls) {

        rcproj = new Rcproj();
        rcproj.setIdno(e.getIdno().toUpperCase());
        rcproj.setSchoolYear(Short.valueOf(calendarYear));

        rcprojs = mm.findRcprojsBy(rcproj);
        for (Rcproj rc : rcprojs) {
            Toolket.setCellValue(workbook, sheet, index, 0, rc.getSchoolYear().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, e.getCname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, rc.getProjno().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, rc.getProjname().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 4, rc.getBdate().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index++, 5, rc.getEdate().trim(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "printRc18.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:tw.edu.chit.struts.action.course.ReportPrintAction.java

/**
 * ?//w  ww . j a va 2 s  . c om
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void printSyllabusCheck(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    String year = am.findTermBy(IConstants.PARAMETER_SCHOOL_YEAR);
    // ???
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), true);
    String hql = "SELECT COUNT(*) FROM Dtime d WHERE d.techid != '' AND d.techid IS NOT NULL "
            + "AND d.sterm = ? AND d.departClass LIKE ?";
    List<Object> count = (List<Object>) am.find(hql, new Object[] { sterm, processClassInfo(form) + "%" });

    if (!clazzes.isEmpty()) {

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("?");
        sheet.setColumnWidth(0, 3000);
        sheet.setColumnWidth(1, 5500);
        sheet.setColumnWidth(2, 3000);
        sheet.setColumnWidth(3, 8000);
        sheet.setColumnWidth(4, 2000);
        sheet.setColumnWidth(5, 5000);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

        HSSFFont fontSize16 = workbook.createFont();
        fontSize16.setFontHeightInPoints((short) 16);
        fontSize16.setFontName("Arial Unicode MS");

        HSSFFont fontSize12 = workbook.createFont();
        fontSize12.setFontHeightInPoints((short) 12);
        fontSize12.setFontName("Arial Unicode MS");

        // Header
        Toolket.setCellValue(workbook, sheet, 0, 0,
                year + "" + sterm + "?", fontSize16,
                HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

        // Column Header
        Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 1, "???", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 2, "", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 3, "??", fontSize12, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize12, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 5, "??", fontSize12, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        int index = 2;
        List<Object> maps = null;
        Dtime dtime = null;
        Csno csno = null;
        CourseSyllabus cs = null, target = null;
        Empl empl = null;
        String[] excluded = { "50000", "T0001", "T0002" };
        target = new CourseSyllabus();
        target.setSchoolYear(Integer.parseInt(year));
        target.setSchoolTerm(Integer.parseInt(sterm));

        for (Clazz clazz : clazzes) {
            if (Toolket.isDelayClass(clazz.getClassNo()))
                continue;

            //maps = cm.findDtimeCsnoBy(new Dtime(clazz.getClassNo(), sterm),
            //"cscode");

            if (maps != null) {

                for (Object o : maps) {
                    dtime = (Dtime) ((Object[]) o)[0];
                    csno = (Csno) ((Object[]) o)[1];

                    // ?
                    if (!ArrayUtils.contains(excluded, csno.getCscode())
                            && !ArrayUtils.contains(IConstants.COURSE_SYLLABUS_INTRO, dtime.getCscode())
                            && StringUtils.isNotBlank(dtime.getTechid().trim())) {

                        target.setDepartClass(clazz.getClassNo());
                        target.setCscode(csno.getCscode());
                        cs = cm.findCourseSyllabusBy1(target);
                        if (cs == null) {

                            empl = mm.findEmplByIdno(dtime.getTechid());
                            Toolket.setCellValue(workbook, sheet, index, 0, clazz.getClassNo(), fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 1,
                                    Toolket.getClassFullName(clazz.getClassNo()), fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 2, csno.getCscode(), fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 3, csno.getChiName().trim(),
                                    fontSize12, HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index, 4, dtime.getCredit().toString(),
                                    fontSize12, HSSFCellStyle.ALIGN_CENTER, true, null);
                            Toolket.setCellValue(workbook, sheet, index++, 5,
                                    (empl == null ? "" : empl.getCname().trim()), fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, null);
                        } else {
                            cs = null;
                        }
                    }

                    dtime = null;
                    csno = null;
                }
            }
        }

        int xx = index - 2; // ?
        int yy = (Integer) count.get(0); // ?
        index++;

        sheet.addMergedRegion(new CellRangeAddress(index, index, 3, 5));
        Toolket.setCellValue(workbook, sheet, index++, 3,
                " : " + xx + " / " + yy + " = " + ((float) xx / (float) yy), fontSize16,
                HSSFCellStyle.ALIGN_RIGHT, false, null);

        File tempDir = new File(
                context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                        + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
        if (!tempDir.exists())
            tempDir.mkdirs();

        File output = new File(tempDir, "RegisterList.xls");
        FileOutputStream fos = new FileOutputStream(output);
        workbook.write(fos);
        fos.close();

        JasperReportUtils.printXlsToFrontEnd(response, output);
        output.delete();
        tempDir.delete();
    } else {
        Map<String, String> param = new HashMap<String, String>();
        File image = new File(context.getRealPath("/pages/images/2002chitS.jpg"));
        param.put("IMAGE", image.getAbsolutePath());
        byte[] bytes = JasperRunManager.runReportToPdf(JasperReportUtils.getNoResultReport(context), param,
                new JREmptyDataSource());
        JasperReportUtils.printPdfToFrontEnd(response, bytes);
    }

}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * ?//  w  w w  . j  a  v a 2s  .co m
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printAbilityList(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), false);
    if (!clazzes.isEmpty()) {

        List<Student> students = null;
        List<StdAbility> stdAbilities = null;
        DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
        String abilityName = null;

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("?");
        sheet.setColumnWidth(0, 3000);
        sheet.setColumnWidth(1, 3000);
        sheet.setColumnWidth(2, 5000);
        sheet.setColumnWidth(3, 5000);
        sheet.setColumnWidth(4, 6000);
        sheet.setColumnWidth(5, 3500);
        sheet.setColumnWidth(6, 6000);
        sheet.setColumnWidth(7, 4000);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));

        HSSFFont fontSize12 = workbook.createFont();
        fontSize12.setFontHeightInPoints((short) 12);
        fontSize12.setFontName("Arial Unicode MS");

        HSSFFont fontSize10 = workbook.createFont();
        fontSize10.setFontHeightInPoints((short) 10);
        fontSize10.setFontName("Arial Unicode MS");

        // Header
        Toolket.setCellValue(workbook, sheet, 0, 0, "?", fontSize12,
                HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

        // Column Header
        Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 1, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 2, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 4, "??", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 5, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 6, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 7, "", fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        int index = 2;

        for (Clazz clazz : clazzes) {
            if (Toolket.isDelayClass(clazz.getClassNo()) || Toolket.isLiteracyClass(clazz.getClassNo()))
                continue;

            students = mm.findStudentsByClassNo(clazz.getClassNo());
            for (Student student : students) {
                stdAbilities = mm.findStudentAbilityByStudentNoAndAbilityNo(student.getStudentNo(), null); // null?

                for (StdAbility sa : stdAbilities) {
                    Toolket.setCellValue(workbook, sheet, index, 0, student.getStudentNo(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 1, student.getStudentName(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 2,
                            Toolket.getClassFullName(student.getDepartClass()), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    abilityName = "4".equals(sa.getAbilityNo().toString()) ? "?" //101.02.06?? 1->4
                            : ("2".equals(sa.getAbilityNo().toString()) ? "" //101.02.06?? 3->2
                                    : "");
                    Toolket.setCellValue(workbook, sheet, index, 3, abilityName, fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 4, sa.getDescription(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 5, sa.getLevelDesc(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 6, sa.getDeptDesc(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index++, 7, df.format(sa.getLastModified()),
                            fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
                }

            }

        }

        File tempDir = new File(
                context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                        + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
        if (!tempDir.exists())
            tempDir.mkdirs();

        File output = new File(tempDir, "AbilityList.xls");
        FileOutputStream fos = new FileOutputStream(output);
        workbook.write(fos);
        fos.close();

        JasperReportUtils.printXlsToFrontEnd(response, output);
        output.delete();
        tempDir.delete();
    }
}

From source file:tw.edu.chit.struts.action.deptassist.ReportPrintAction.java

/**
 * ?/* w  w w .  jav a2  s  . c o m*/
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void printDeptStdSkillList6(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);

    Member member = (Member) getUserCredential(session).getMember();
    Empl empl = mm.findEmplByOid(member.getOid());
    ServletContext context = request.getSession().getServletContext();

    CodeEmpl codeEmpl = new CodeEmpl();
    codeEmpl.setIdno(empl.getUnit());
    Example example4CodeEmpl = Example.create(codeEmpl).ignoreCase().enableLike(MatchMode.START);
    List<CodeEmpl> codeEmpls = (List<CodeEmpl>) am.findSQLWithCriteria(CodeEmpl.class, example4CodeEmpl, null,
            null);

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    Calendar cal = Calendar.getInstance();
    Calendar cal1 = (Calendar) cal.clone();
    Calendar cal2 = (Calendar) cal.clone();
    if (StringUtils.isNotBlank(form.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(form.getString("licenseValidDateEnd"))) {
        Date from = StringUtils.isBlank(form.getString("licenseValidDateStart")) ? null
                : Toolket.parseNativeDate(form.getString("licenseValidDateStart"));
        // ???
        Date to = StringUtils.isBlank(form.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime()
                : Toolket.parseNativeDate(form.getString("licenseValidDateEnd"));

        cal1.setTime(from);
        cal1.set(Calendar.HOUR_OF_DAY, 0);
        cal1.set(Calendar.MINUTE, 0);
        cal1.set(Calendar.SECOND, 0);
        cal1.set(Calendar.MILLISECOND, 0);

        cal2.setTime(to);
        cal2.set(Calendar.HOUR_OF_DAY, 23);
        cal2.set(Calendar.MINUTE, 59);
        cal2.set(Calendar.SECOND, 59);
        cal2.set(Calendar.MILLISECOND, 999);
    }

    DeptCode4Yun yun = new DeptCode4Yun();
    yun.setClassNo("___" + codeEmpls.get(0).getIdno2().trim());
    Example example = Example.create(yun).ignoreCase().enableLike(MatchMode.START);
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("classNo"));
    List<DeptCode4Yun> yuns = (List<DeptCode4Yun>) am.findSQLWithCriteria(DeptCode4Yun.class, example, null,
            orders);

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("?");
    sheet.setColumnWidth(0, 2000);
    sheet.setColumnWidth(1, 6000);
    sheet.setColumnWidth(2, 4000);
    sheet.setColumnWidth(3, 3000);
    sheet.setColumnWidth(4, 6000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

    HSSFFont fontSize12 = workbook.createFont();
    fontSize12.setFontHeightInPoints((short) 12);
    fontSize12.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0,
            "?" + Toolket.getEmpUnit(empl.getUnit())
                    + "? (" + df.format(cal1.getTime()) + "~"
                    + df.format(cal2.getTime()) + ")",
            fontSize12, HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "????", fontSize10, HSSFCellStyle.ALIGN_CENTER,
            true, null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);

    int index = 2;
    String sql = "SELECT s.student_no ST1, gs.student_no ST2 "
            + "FROM StdSkill ss LEFT JOIN stmd s ON ss.studentNo = s.student_no "
            + "LEFT JOIN Gstmd gs ON ss.studentNo = gs.student_no "
            + "WHERE ss.deptNo = ? AND ss.licenseValidDate BETWEEN ? AND ? "
            + "AND (s.depart_class LIKE ? OR gs.depart_class LIKE ?)";
    String classNo = null;
    List<Map> ret = null;
    Set<String> set = new HashSet<String>();

    for (DeptCode4Yun y : yuns) {
        classNo = y.getClassNo() + "%";
        ret = (List<Map>) am.findBySQL(sql, new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(),
                cal2.getTime(), classNo, classNo });

        set = new HashSet<String>();
        if (!ret.isEmpty()) {
            for (Map o : ret) {
                if (o.get("ST1") != null)
                    set.add((String) o.get("ST1"));
                else if (o.get("ST2") != null)
                    set.add((String) o.get("ST2"));
            }

            if (!set.isEmpty()) {
                Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 1, y.getCampusName(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 2, y.getDeptName(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 3, String.valueOf(set.size()), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index++, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);
            }
        }
    }

    index++;
    Toolket.setCellValue(workbook, sheet, index, 4, "", fontSize10,
            HSSFCellStyle.ALIGN_RIGHT, false, null);

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "DeptStdSkillList6.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}