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.course.ReportPrintAction.java

/**
 * ?/*from  ww w .  ja  va2 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 printCalculate(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

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

    int thisTermCounts = 0, lastTermCounts = 0;
    String departClass = null, deptCode = null, histDeptCode = null, currentDeptCode = null, chiName = null;
    ScoreHist scoreHist = null;
    List<Student> students = null;
    List<ScoreHist> scoreHistList = null;
    List<Map> seldInfo = null;
    List csnos = null;

    if (!clazzes.isEmpty()) {

        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, 5000);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

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

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

        // Header
        Toolket.setCellValue(workbook, sheet, 0, 0, "?", fontSize16,
                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 (Clazz clazz : clazzes) {
            departClass = clazz.getClassNo();
            deptCode = StringUtils.substring(departClass, 3, 4);
            if (Toolket.isDelayClass(departClass) || Toolket.isLiteracyClass(departClass))
                continue;

            students = mm.findStudentsByClassNo(departClass);
            if (!students.isEmpty()) {

                if (thisYear.equals(request.getParameter("year")) && thisTerm.equals(sterm)) {
                    // (Seld)
                    for (Student student : students) {
                        seldInfo = cm.findStudentSeldCourse(student.getStudentNo(), sterm);
                        if (!seldInfo.isEmpty()) {
                            for (Map m : seldInfo) {
                                currentDeptCode = StringUtils.substring((String) m.get("depart_class"), 3, 4);
                                if (!deptCode.equalsIgnoreCase(currentDeptCode)
                                        && !Toolket.isLiteracyClass((String) m.get("depart_class"))) {
                                    thisTermCounts++;

                                    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);
                                    Toolket.setCellValue(workbook, sheet, index, 3,
                                            Toolket.getClassFullName((String) m.get("depart_class")),
                                            fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
                                    Toolket.setCellValue(workbook, sheet, index++, 4,
                                            (String) m.get("chi_name"), fontSize10, HSSFCellStyle.ALIGN_CENTER,
                                            true, null);
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    // ?(ScoreHist)
                    for (Student student : students) {
                        scoreHist = new ScoreHist(student.getStudentNo());
                        scoreHist.setSchoolYear((short) Integer.parseInt(request.getParameter("year")));
                        scoreHist.setSchoolTerm(sterm);
                        scoreHistList = sm.findScoreHistBy(scoreHist);
                        HIST: {
                            if (!scoreHistList.isEmpty()) {
                                for (ScoreHist hist : scoreHistList) {
                                    if (StringUtils.isNotBlank(hist.getStdepartClass())
                                            && !Toolket.isLiteracyClass(hist.getStdepartClass())) {
                                        histDeptCode = StringUtils.substring(hist.getStdepartClass(), 3, 4);
                                        if (!deptCode.equalsIgnoreCase(histDeptCode)) {

                                            lastTermCounts++;

                                            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);
                                            Toolket.setCellValue(workbook, sheet, index, 3,
                                                    Toolket.getClassFullName(hist.getStdepartClass()),
                                                    fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);

                                            csnos = cm.getCsnameBy(hist.getCscode());
                                            if (!csnos.isEmpty())
                                                chiName = ((Csno) csnos.get(0)).getChiName();
                                            else
                                                chiName = "";

                                            Toolket.setCellValue(workbook, sheet, index++, 4, chiName,
                                                    fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
                                            break HIST;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        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, "Calculate.xls");
        FileOutputStream fos = new FileOutputStream(output);
        workbook.write(fos);
        fos.close();

        JasperReportUtils.printXlsToFrontEnd(response, output);
        output.delete();
        tempDir.delete();
        System.out.println("This Term: " + thisTermCounts);
        System.out.println("Last Term: " + lastTermCounts);
    }

}

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

/**
 * ?/*from  w  ww . ja 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 printStdSkillList(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(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<StdSkill> skills = null;
        LicenseCode code = null;
        DateFormat df = new SimpleDateFormat("yyyy/MM/dd");

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

        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);
        Toolket.setCellValue(workbook, sheet, 1, 8, "/", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 9, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, 1, 10, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, 1, 11, "", 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) {

                skills = mm.findStdSkillsBy(form.getString("calendarYear"), form.getString("sterm"),
                        student.getStudentNo(), null); // null

                for (StdSkill ss : skills) {
                    Toolket.setCellValue(workbook, sheet, index, 0,
                            ss.getSchoolYear() + "/" + ss.getSchoolTerm(), 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, student.getStudentNo(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 3,
                            Toolket.getClassFullName(student.getDepartClass()), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 6,
                            ss.getAmount() == null ? "" : ss.getAmount().toString(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 7,
                            StringUtils.isBlank(ss.getLicenseNo()) ? "" : ss.getLicenseNo(), fontSize10,
                            HSSFCellStyle.ALIGN_CENTER, true, null);
                    Toolket.setCellValue(workbook, sheet, index, 11,
                            ss.getLicenseValidDate() == null ? "" : df.format(ss.getLicenseValidDate()),
                            fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);

                    code = null;
                    if (StringUtils.isBlank(ss.getLicenseCode()))
                        code = am.findLicenseCodesBy(new LicenseCode(String.valueOf(ss.getLicenseCode())))
                                .get(0);
                    if (code != null) {
                        Toolket.setCellValue(workbook, sheet, index, 4, code.getName(), fontSize10,
                                HSSFCellStyle.ALIGN_CENTER, true, null);
                        Toolket.setCellValue(workbook, sheet, index, 5, code.getDeptName(), fontSize10,
                                HSSFCellStyle.ALIGN_CENTER, true, null);
                        Toolket.setCellValue(workbook, sheet, index, 8, code.getLocale().toString(), fontSize10,
                                HSSFCellStyle.ALIGN_CENTER, true, null);
                        Toolket.setCellValue(workbook, sheet, index, 9, code.getLevel(), fontSize10,
                                HSSFCellStyle.ALIGN_CENTER, true, null);
                        Toolket.setCellValue(workbook, sheet, index, 10, code.getType().toString(), fontSize10,
                                HSSFCellStyle.ALIGN_CENTER, true, null);
                    }

                    index++;
                }

            }

        }

        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, "StdSkillList.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

/**
 * ?/*from  w w  w.  java2 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 printDeptStdSkillList5(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);
    }

    String hql = "SELECT COUNT(*), s.techIdno, s.licenseCode FROM StdSkill s "
            + "WHERE s.deptNo = ? AND s.techIdno IS NOT NULL " + "AND s.licenseValidDate BETWEEN ? AND ? "
            + "GROUP BY s.techIdno, s.licenseCode";

    List<Object> ret = (List<Object>) am.find(hql,
            new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(), cal2.getTime() });

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("?");
    sheet.setColumnWidth(0, 4000);
    sheet.setColumnWidth(1, 6000);
    sheet.setColumnWidth(2, 4000);
    sheet.setColumnWidth(3, 3000);
    sheet.setColumnWidth(4, 4000);
    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;
    Object[] data = null;
    DEmpl dempl = null;

    for (Object o : ret) {

        data = (Object[]) o;

        sheet.addMergedRegion(new CellRangeAddress(index, index + 2, 0, 0));
        empl = mm.findEmplByIdno((String) data[1]);
        if (empl == null) {
            dempl = mm.findDEmplByIdno((String) data[1]);
            //Toolket.setCellValue(workbook, sheet, index, 0, dempl
            //      .getCname(), fontSize10, HSSFCellStyle.ALIGN_CENTER,
            //      true, null);
        } else {
            Toolket.setCellValue(workbook, sheet, index, 0, empl.getCname(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        }

        Toolket.setCellValue(workbook, sheet, index + 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, index + 2, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);

        Toolket.setCellValue(workbook, sheet, index, 1, "", fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index + 1, 1, "", fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index + 2, 1, "", fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);

        Toolket.setCellValue(workbook, sheet, index, 2, "10", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, index + 1, 2, "5", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);
        Toolket.setCellValue(workbook, sheet, index + 2, 2, "2", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                true, null);

        Toolket.setCellValue(workbook, sheet, index, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index + 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);

        //((Integer) data[0]).toString() ?? "" ??
        Toolket.setCellValue(workbook, sheet, index + 2, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        /*???
        Toolket.setCellValue(workbook, sheet, index + 2, 3,
              ((Integer) data[0]).toString(), fontSize10,
              HSSFCellStyle.ALIGN_CENTER, true, null);
        */

        Toolket.setCellValue(workbook, sheet, index, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index + 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);
        Toolket.setCellValue(workbook, sheet, index + 2, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
                null);

        index += 3;
    }

    index++;
    sheet.addMergedRegion(new CellRangeAddress(index, index, 0, 1));
    Toolket.setCellValue(workbook, sheet, index, 0, " : ?20", fontSize10,
            HSSFCellStyle.ALIGN_LEFT, 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, "DeptStdSkillList5.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 printDeptStdSkillList1(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);
    }

    String hql = "SELECT count(*), s FROM StdSkill s WHERE s.deptNo = ? "
            + "AND s.licenseValidDate BETWEEN ? AND ? " + "GROUP BY s.licenseCode";

    List<Object> ret = (List<Object>) am.find(hql, new Object[] {
            //codeEmpls.get(0).getIdno2().trim(), cal1.getTime(),cal2.getTime() });
            empl.getUnit(), cal1.getTime(), cal2.getTime() });

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("");
    sheet.setColumnWidth(0, 1500);
    sheet.setColumnWidth(1, 10000);
    sheet.setColumnWidth(2, 3000);
    sheet.setColumnWidth(3, 3000);
    sheet.setColumnWidth(4, 8000);
    sheet.setColumnWidth(5, 1800);
    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(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);
    Toolket.setCellValue(workbook, sheet, 1, 5, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    int index = 2, totals = 0;
    StdSkill skill = null;
    List<LicenseCode> codes = null;
    List<LicenseCode961> code961s = null;
    LicenseCode code = null;
    LicenseCode961 code961 = null;
    Object[] data = null;

    for (Object o : ret) {

        data = (Object[]) o;
        totals += (Long) data[0];
        skill = (StdSkill) data[1];

        Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index, 5, ((Long) data[0]).toString(), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);

        CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
        LicenseCode c = (LicenseCode) cm
                .hqlGetBy("FROM LicenseCode WHERE code='" + skill.getLicenseCode() + "'").get(0);

        //System.out.println("FROM LicenseCode WHERE code='"+skill.getLicenseCode()+"'");
        codes = (List<LicenseCode>) am.findLicenseCodesBy(c);

        LicenseType type = new LicenseType();

        if (!codes.isEmpty()) {
            code = codes.get(0);

            Toolket.setCellValue(workbook, sheet, index, 1, code.getName(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, code.getLevel(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            try {

                Toolket.setCellValue(workbook, sheet, index, 3, code.getType(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 4, code.getDeptName(), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
            } catch (Exception e) {
                e.printStackTrace();
                Toolket.setCellValue(workbook, sheet, index, 3, null, fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);
                Toolket.setCellValue(workbook, sheet, index, 4, null, fontSize10, HSSFCellStyle.ALIGN_LEFT,
                        true, null);
            }

        } else {
            code961s = (List<LicenseCode961>) am
                    .findLicenseCode961sBy(new LicenseCode961(String.valueOf(skill.getLicenseCode())));
            if (!code961s.isEmpty()) {
                code961 = code961s.get(0);
                Toolket.setCellValue(workbook, sheet, index, 1, code961.getName(), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
                Toolket.setCellValue(workbook, sheet, index, 2, code961.getLevel(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 3, code961.getType().toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 4, code961.getDeptName(), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
            }
        }

        index++;
    }

    sheet.addMergedRegion(new CellRangeAddress(index, index, 0, 4));
    Toolket.setCellValue(workbook, sheet, index, 0, "?", fontSize12, HSSFCellStyle.ALIGN_CENTER, false,
            35.0F, null);
    Toolket.setCellValue(workbook, sheet, index, 5, String.valueOf(totals), fontSize12,
            HSSFCellStyle.ALIGN_CENTER, false, 35.0F, 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, "DeptStdSkillList1.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 .  j a  v a 2  s .  com
 * 
 * @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 printCalculate(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(ADMIN_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    String thisYear = cm.getNowBy("School_year");
    String thisTerm = am.findTermBy(PARAMETER_SCHOOL_TERM);
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), false);

    int thisTermCounts = 0, lastTermCounts = 0;
    String departClass = null, deptCode = null, histDeptCode = null, currentDeptCode = null, chiName = null;
    ScoreHist scoreHist = null;
    List<Student> students = null;
    List<ScoreHist> scoreHistList = null;
    List<Map> seldInfo = null;
    List csnos = null;

    if (!clazzes.isEmpty()) {

        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, 5000);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));

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

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

        // Header
        Toolket.setCellValue(workbook, sheet, 0, 0, "?", fontSize16,
                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 (Clazz clazz : clazzes) {
            departClass = clazz.getClassNo();
            deptCode = StringUtils.substring(departClass, 3, 4);
            if (Toolket.isDelayClass(departClass) || Toolket.isLiteracyClass(departClass))
                continue;

            students = mm.findStudentsByClassNo(departClass);
            if (!students.isEmpty()) {

                if (thisYear.equals(request.getParameter("year")) && thisTerm.equals(sterm)) {
                    // (Seld)
                    for (Student student : students) {
                        seldInfo = cm.findStudentSeldCourse(student.getStudentNo(), sterm);
                        if (!seldInfo.isEmpty()) {
                            for (Map m : seldInfo) {
                                currentDeptCode = StringUtils.substring((String) m.get("depart_class"), 3, 4);
                                if (!deptCode.equalsIgnoreCase(currentDeptCode)
                                        && !Toolket.isLiteracyClass((String) m.get("depart_class"))) {
                                    thisTermCounts++;

                                    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);
                                    Toolket.setCellValue(workbook, sheet, index, 3,
                                            Toolket.getClassFullName((String) m.get("depart_class")),
                                            fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
                                    Toolket.setCellValue(workbook, sheet, index++, 4,
                                            (String) m.get("chi_name"), fontSize10, HSSFCellStyle.ALIGN_CENTER,
                                            true, null);
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    // ?(ScoreHist)
                    for (Student student : students) {
                        scoreHist = new ScoreHist(student.getStudentNo());
                        scoreHist.setSchoolYear((short) Integer.parseInt(request.getParameter("year")));
                        scoreHist.setSchoolTerm(sterm);
                        scoreHistList = sm.findScoreHistBy(scoreHist);
                        HIST: {
                            if (!scoreHistList.isEmpty()) {
                                for (ScoreHist hist : scoreHistList) {
                                    if (StringUtils.isNotBlank(hist.getStdepartClass())
                                            && !Toolket.isLiteracyClass(hist.getStdepartClass())) {
                                        histDeptCode = StringUtils.substring(hist.getStdepartClass(), 3, 4);
                                        if (!deptCode.equalsIgnoreCase(histDeptCode)) {

                                            lastTermCounts++;

                                            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);
                                            Toolket.setCellValue(workbook, sheet, index, 3,
                                                    Toolket.getClassFullName(hist.getStdepartClass()),
                                                    fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);

                                            csnos = cm.getCsnameBy(hist.getCscode());
                                            if (!csnos.isEmpty())
                                                chiName = ((Csno) csnos.get(0)).getChiName();
                                            else
                                                chiName = "";

                                            Toolket.setCellValue(workbook, sheet, index++, 4, chiName,
                                                    fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
                                            break HIST;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        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, "Calculate.xls");
        FileOutputStream fos = new FileOutputStream(output);
        workbook.write(fos);
        fos.close();

        JasperReportUtils.printXlsToFrontEnd(response, output);
        output.delete();
        tempDir.delete();
        System.out.println("This Term: " + thisTermCounts);
        System.out.println("Last Term: " + lastTermCounts);
    }

}

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

/**
 * ???//from  w ww.  j av  a2 s  .  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 
 */
@SuppressWarnings("unchecked")
private void printDeptStdSkillList4(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);
    }

    // Y
    boolean flag = form.getString("amountDateType").equalsIgnoreCase("y");
    String hql = "";
    if (flag)
        hql = "SELECT COUNT(*), SUM(s.amount), s FROM StdSkill s "
                + "WHERE s.amountDate IS NOT NULL AND s.deptNo = ? "
                + "AND s.amountDate IS NOT NULL AND s.licenseValidDate BETWEEN ? AND ? "
                + "GROUP BY s.licenseCode";
    else
        // ?
        hql = "SELECT COUNT(*), SUM(s.amount), s FROM StdSkill s "
                + "WHERE s.amountDate IS NULL AND s.deptNo = ? "
                + "AND s.amountDate IS NULL AND s.licenseValidDate BETWEEN ? AND ? " + "GROUP BY s.licenseCode";

    List<Object> ret = (List<Object>) am.find(hql,
            new Object[] { codeEmpls.get(0).getIdno2().trim(), cal1.getTime(), cal2.getTime() });

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("???");
    sheet.setColumnWidth(0, 1500);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 10000);
    sheet.setColumnWidth(3, 3000);
    sheet.setColumnWidth(4, 5000);
    sheet.setColumnWidth(5, 2400);
    sheet.setColumnWidth(6, 8000);
    sheet.setColumnWidth(7, 1800);
    sheet.setColumnWidth(8, 2200);
    sheet.setColumnWidth(9, 2400);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

    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()) + ") - " + (flag ? "" : ""),
            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);
    Toolket.setCellValue(workbook, sheet, 1, 8, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 9, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);

    int index = 2, totals = 0, sum = 0;
    StdSkill skill = null;
    List<LicenseCode> codes = null;
    List<LicenseCode961> code961s = null;
    LicenseCode code = null;
    LicenseCode961 code961 = null;
    Object[] data = null;

    for (Object o : ret) {

        data = (Object[]) o;
        totals += (Integer) data[0];
        sum += (Integer) data[1];
        skill = (StdSkill) data[2];

        Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index, 7, ((Integer) data[0]).toString(), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index, 8, skill.getAmount().toString(), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index, 9, ((Integer) data[1]).toString(), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);

        codes = (List<LicenseCode>) am
                .findLicenseCodesBy(new LicenseCode(String.valueOf(skill.getLicenseCode())));

        if (!codes.isEmpty()) {
            code = codes.get(0);
            Toolket.setCellValue(workbook, sheet, index, 1, code.getCode(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, code.getName(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, code.getLocale().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 4, code.getLevel(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 5, code.getType().toString(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 6, code.getDeptName(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
        } else {
            code961s = (List<LicenseCode961>) am
                    .findLicenseCode961sBy(new LicenseCode961(String.valueOf(skill.getLicenseCode())));
            if (!code961s.isEmpty()) {
                code961 = code961s.get(0);
                Toolket.setCellValue(workbook, sheet, index, 1, code961.getCode().toString(), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
                Toolket.setCellValue(workbook, sheet, index, 2, code961.getName(), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
                Toolket.setCellValue(workbook, sheet, index, 3, code961.getLocale().toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 4, code961.getLevel(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 5, code961.getType().toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 6, code961.getDeptName(), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
            }
        }

        index++;
    }

    Toolket.setCellValue(workbook, sheet, index, 6, "?", fontSize12, HSSFCellStyle.ALIGN_CENTER, false,
            35.0F, null);
    Toolket.setCellValue(workbook, sheet, index, 7, String.valueOf(totals), fontSize12,
            HSSFCellStyle.ALIGN_CENTER, false, 35.0F, null);
    Toolket.setCellValue(workbook, sheet, index, 9, String.valueOf(sum), fontSize12, HSSFCellStyle.ALIGN_CENTER,
            false, 35.0F, 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, "DeptStdSkillList4.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.  java2s  .  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 printDeptStdSkillList3(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);
    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);
    }

    String hql = "SELECT COUNT(*) CT, ss.licenseValidDate LVD, ss.licenseCode LC, "
            + "s.depart_class DC1, s.sex S1, gs.depart_class DC2, gs.sex S2 "
            + "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 >= ? AND ss.licenseValidDate <= ? "
            + "GROUP BY ss.licenseValidDate, s.depart_class, s.sex, " + "gs.depart_class, gs.sex "
            + "ORDER BY ss.licenseValidDate, s.depart_class, " + "s.sex, gs.depart_class, gs.sex";

    List<Map> ret = (List<Map>) am.findBySQL(hql, new Object[] {
            //codeEmpls.get(0).getIdno().trim(), cal1.getTime(),cal2.getTime() });   
            empl.getUnit(), cal1.getTime(), cal2.getTime() });

    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("");
    sheet.setColumnWidth(0, 1800);
    sheet.setColumnWidth(1, 2000);
    sheet.setColumnWidth(2, 2000);
    sheet.setColumnWidth(3, 3000);
    sheet.setColumnWidth(4, 5000);
    sheet.setColumnWidth(5, 3000);
    sheet.setColumnWidth(6, 8000);
    sheet.setColumnWidth(7, 3000);
    sheet.setColumnWidth(8, 4000);
    sheet.setColumnWidth(9, 2200);
    sheet.setColumnWidth(10, 2200);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));

    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);
    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);
    Toolket.setCellValue(workbook, sheet, 1, 8, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 9, "()", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 10, "()", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    // Toolket.setCellValue(workbook, sheet, 1, 11, "?", fontSize10,
    // HSSFCellStyle.ALIGN_CENTER, true, null);

    int index = 2;
    boolean isGraduate = false;
    String departClass = null;
    List<LicenseCode> codes = null;
    List<LicenseCode961> code961s = null;
    List<DeptCode4Yun> yuns = null;
    LicenseCode code = null;
    LicenseCode961 code961 = null;
    DeptCode4Yun yun = null;
    Example example = null;

    for (Map data : ret) {

        Toolket.setCellValue(workbook, sheet, index, 0, String.valueOf(index - 1), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);

        if (data.get("DC1") != null) {
            departClass = (String) data.get("DC1");
            isGraduate = false;
        } else {
            departClass = (String) data.get("DC2");
            isGraduate = true;
        }

        yun = new DeptCode4Yun();
        yun.setClassNo(StringUtils.substring(departClass, 0, 4));
        example = Example.create(yun).ignoreCase().enableLike(MatchMode.START);
        yuns = (List<DeptCode4Yun>) am.findSQLWithCriteria(DeptCode4Yun.class, example, null, null);
        if (!yuns.isEmpty() && yuns.size() == 1) {
            yun = yuns.get(0);

            Toolket.setCellValue(workbook, sheet, index, 1, yun.getDeptCode(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 2, yun.getCampusCode(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, yun.getCampusName(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        }

        Toolket.setCellValue(workbook, sheet, index, 4, Toolket.getClassFullName(departClass), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);
        Toolket.setCellValue(workbook, sheet, index, 5, (String) data.get("LC"), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);

        codes = (List<LicenseCode>) am
                .findLicenseCodesBy(new LicenseCode(String.valueOf((String) data.get("LC"))));

        if (!codes.isEmpty()) {
            code = codes.get(0);
            Toolket.setCellValue(workbook, sheet, index, 6, code.getName(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 7, code.getLevel(), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
        } else {
            code961s = (List<LicenseCode961>) am
                    .findLicenseCode961sBy(new LicenseCode961(String.valueOf((String) data.get("LC"))));
            if (!code961s.isEmpty()) {
                code961 = code961s.get(0);
                Toolket.setCellValue(workbook, sheet, index, 6, code961.getName(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 7, code961.getLevel(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
            }
        }

        Toolket.setCellValue(workbook, sheet, index, 8, df.format((Date) data.get("LVD")), fontSize10,
                HSSFCellStyle.ALIGN_CENTER, true, null);

        if (!isGraduate) {
            if ("1".equals((String) data.get("S1"))) {
                Toolket.setCellValue(workbook, sheet, index, 9, ((Long) data.get("CT")).toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 10, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);
            } else if ("2".equals((String) data.get("S1"))) {
                Toolket.setCellValue(workbook, sheet, index, 9, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);
                Toolket.setCellValue(workbook, sheet, index, 10, ((Long) data.get("CT")).toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
            }
        } else {
            if ("1".equals((String) data.get("S2"))) {
                Toolket.setCellValue(workbook, sheet, index, 9, ((Long) data.get("CT")).toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
                Toolket.setCellValue(workbook, sheet, index, 10, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);
            } else if ("2".equals((String) data.get("S2"))) {
                Toolket.setCellValue(workbook, sheet, index, 9, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);
                Toolket.setCellValue(workbook, sheet, index, 10, ((Long) data.get("CT")).toString(), fontSize10,
                        HSSFCellStyle.ALIGN_CENTER, true, null);
            }
        }

        index++;
        // Toolket.setCellValue(workbook, sheet, index++, 11, ((Long) m
        // .get("CT")).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, "DeptStdSkillList3.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

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

From source file:org.sakaiproject.site.tool.SiteAction.java

private String setMoreInfoPath(ServletContext ctx) {
    String rpath = ctx.getRealPath("");
    String ctxPath = ctx.getServletContextName();
    String rserve = StringUtils.remove(rpath, ctxPath);
    return rserve;
}

From source file:com.rapid.core.Application.java

public void initialise(ServletContext servletContext, boolean createResources) throws JSONException,
        InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException,
        InvocationTargetException, SecurityException, NoSuchMethodException, IOException {

    // get the logger
    Logger logger = (Logger) servletContext.getAttribute("logger");

    // trace log that we're initialising
    logger.trace("Initialising application " + _name + "/" + _version);

    // initialise the security adapter 
    setSecurityAdapter(servletContext, _securityAdapterType);

    // initialise the form adapter 
    setFormAdapter(servletContext, _formAdapterType);

    // initialise the resource includes collection
    _resources = new Resources();

    // if there is any app JavaScript functions - this is for backwards compatibility as _functions have been moved to JavaScript resources
    if (_functions != null) {
        // initialise app resources if need be
        if (_appResources == null)
            _appResources = new Resources();
        // add _functions as JavaScript resource to top of list
        _appResources.add(0, new Resource("Application functions", 1, _functions));
        // remove the _functions
        _functions = null;/*from   w ww .j  a v a 2  s . c om*/
    }

    // if the created date is null set to today
    if (_createdDate == null)
        _createdDate = new Date();

    // when importing an application we need to initialise but don't want the resource folders made in the old applications name
    if (createResources) {

        // get the jsonControls
        JSONArray jsonControls = (JSONArray) servletContext.getAttribute("jsonControls");

        // get the jsonActions
        JSONArray jsonActions = (JSONArray) servletContext.getAttribute("jsonActions");

        // string builders for the different sections in our rapid.js file
        StringBuilder resourceJS = new StringBuilder();
        StringBuilder initJS = new StringBuilder();
        StringBuilder dataJS = new StringBuilder();
        StringBuilder actionJS = new StringBuilder();

        // string builder for our rapid.css file
        StringBuilder resourceCSS = new StringBuilder();

        // check controls
        if (jsonControls != null) {

            // check control types
            if (_controlTypes != null) {

                // remove the page control (if it's there)
                _controlTypes.remove("page");
                // add it to the top of the list
                _controlTypes.add(0, "page");

                // collection of dependent controls that need adding
                ArrayList<String> dependentControls = new ArrayList<String>();

                // loop control types used by this application
                for (String controlType : _controlTypes) {

                    // loop all available controls
                    for (int i = 0; i < jsonControls.length(); i++) {

                        // get the control
                        JSONObject jsonControl = jsonControls.getJSONObject(i);

                        // check if we're on the type we need
                        if (controlType.equals(jsonControl.optString("type"))) {

                            // look for any dependent control types
                            JSONObject dependantTypes = jsonControl.optJSONObject("dependentTypes");
                            // if we got some
                            if (dependantTypes != null) {
                                // look for an array
                                JSONArray dependantTypesArray = dependantTypes.optJSONArray("dependentType");
                                // if we got one
                                if (dependantTypesArray != null) {
                                    // loop the array
                                    for (int j = 0; j < dependantTypesArray.length(); j++) {
                                        String dependantType = dependantTypesArray.getString(j);
                                        if (!_controlTypes.contains(dependantType)
                                                && !dependentControls.contains(dependantType))
                                            dependentControls.add(dependantType);
                                    }
                                } else {
                                    // just use the object
                                    String dependantType = dependantTypes.getString("dependentType");
                                    if (!_controlTypes.contains(dependantType)
                                            && !dependentControls.contains(dependantType))
                                        dependentControls.add(dependantType);
                                }
                            }

                            // we're done
                            break;
                        } // available control type check

                    } // available control types loop

                } // application control types loop

                // now add all of the dependent controls
                _controlTypes.addAll(dependentControls);

                // loop control types used by this application
                for (String controlType : _controlTypes) {

                    // loop all available controls
                    for (int i = 0; i < jsonControls.length(); i++) {

                        // get the control
                        JSONObject jsonControl = jsonControls.getJSONObject(i);

                        // check if we're on the type we need
                        if (controlType.equals(jsonControl.optString("type"))) {

                            // add any resources (actions can have them too)
                            addResources(jsonControl, "control", resourceJS, resourceCSS);

                            // get any initJavaScript
                            String js = jsonControl.optString("initJavaScript", "");
                            // check we got some
                            if (js.length() > 0) {
                                initJS.append("\nfunction Init_" + jsonControl.getString("type")
                                        + "(id, details) {\n");
                                initJS.append("  " + js.trim().replace("\n", "\n  "));
                                initJS.append("\n}\n");
                            }

                            // check for a getData method
                            String getDataFunction = jsonControl.optString("getDataFunction");
                            // if there was something
                            if (getDataFunction != null) {
                                // clean and print! (if not an empty string)
                                if (getDataFunction.trim().length() > 0)
                                    dataJS.append("\nfunction getData_" + controlType
                                            + "(ev, id, field, details) {\n  "
                                            + getDataFunction.trim().replace("\n", "\n  ") + "\n}\n");

                            }

                            // check for a setData method
                            String setDataFunction = jsonControl.optString("setDataJavaScript");
                            // if there was something
                            if (setDataFunction != null) {
                                // clean and print! (if not an empty string)
                                if (setDataFunction.trim().length() > 0)
                                    dataJS.append("\nfunction setData_" + controlType
                                            + "(ev, id, field, details, data, changeEvents) {\n  "
                                            + setDataFunction.trim().replace("\n", "\n  ") + "\n}\n");
                            }

                            // retrieve any runtimeProperties
                            JSONObject jsonRuntimePropertyCollection = jsonControl
                                    .optJSONObject("runtimeProperties");
                            // check we got some
                            if (jsonRuntimePropertyCollection != null) {

                                // get the first one
                                JSONObject jsonRuntimeProperty = jsonRuntimePropertyCollection
                                        .optJSONObject("runtimeProperty");
                                // get an array
                                JSONArray jsonRunTimeProperties = jsonRuntimePropertyCollection
                                        .optJSONArray("runtimeProperty");

                                // initialise counters
                                int index = 0;
                                int count = 0;

                                // if we got an array
                                if (jsonRunTimeProperties != null) {
                                    // retain the first entry in the object
                                    jsonRuntimeProperty = jsonRunTimeProperties.getJSONObject(0);
                                    // retain the size
                                    count = jsonRunTimeProperties.length();
                                }

                                do {

                                    // get the type
                                    String type = jsonRuntimeProperty.getString("type");

                                    // get the get function
                                    String getFunction = jsonRuntimeProperty.optString("getPropertyFunction",
                                            null);
                                    // print the get function if there was one
                                    if (getFunction != null)
                                        dataJS.append("\nfunction getProperty_" + controlType + "_" + type
                                                + "(ev, id, field, details) {\n  "
                                                + getFunction.trim().replace("\n", "\n  ") + "\n}\n");

                                    // get the set function
                                    String setFunction = jsonRuntimeProperty.optString("setPropertyJavaScript",
                                            null);
                                    // print the get function if there was one
                                    if (setFunction != null)
                                        dataJS.append("\nfunction setProperty_" + controlType + "_" + type
                                                + "(ev, id, field, details, data, changeEvents) {\n  "
                                                + setFunction.trim().replace("\n", "\n  ") + "\n}\n");

                                    // increment index
                                    index++;

                                    // get the next one
                                    if (index < count)
                                        jsonRuntimeProperty = jsonRunTimeProperties.getJSONObject(index);

                                } while (index < count);

                            }

                            // we're done with this jsonControl
                            break;
                        }

                    } // jsonControls loop

                } // control types loop

            } // control types check

        } // jsonControls check

        // check  actions
        if (jsonActions != null) {

            // check action types
            if (_actionTypes != null) {

                // collection of dependent controls that need adding
                ArrayList<String> dependentActions = new ArrayList<String>();

                // loop control types used by this application
                for (String actionType : _actionTypes) {

                    // loop all available controls
                    for (int i = 0; i < jsonActions.length(); i++) {

                        // get the action
                        JSONObject jsonAction = jsonActions.getJSONObject(i);

                        // check if we're on the type we need
                        if (actionType.equals(jsonAction.optString("type"))) {

                            // look for any dependant control types
                            JSONObject dependantTypes = jsonAction.optJSONObject("dependentTypes");
                            // if we got some
                            if (dependantTypes != null) {
                                // look for an array
                                JSONArray dependantTypesArray = dependantTypes.optJSONArray("dependentType");
                                // if we got one
                                if (dependantTypesArray != null) {
                                    // loop the array
                                    for (int j = 0; j < dependantTypesArray.length(); j++) {
                                        String dependantType = dependantTypesArray.getString(j);
                                        if (!_actionTypes.contains(dependantType)
                                                && !dependentActions.contains(dependantType))
                                            dependentActions.add(dependantType);
                                    }
                                } else {
                                    // just use the object
                                    String dependantType = dependantTypes.getString("dependentType");
                                    if (!_actionTypes.contains(dependantType)
                                            && !dependentActions.contains(dependantType))
                                        dependentActions.add(dependantType);
                                }
                            }

                            // we're done
                            break;
                        }

                    }

                }

                // now add all of the dependent controls
                _controlTypes.addAll(dependentActions);

                // loop action types used by this application
                for (String actionType : _actionTypes) {

                    // loop jsonActions
                    for (int i = 0; i < jsonActions.length(); i++) {

                        // get action
                        JSONObject jsonAction = jsonActions.getJSONObject(i);

                        // check the action is the one we want
                        if (actionType.equals(jsonAction.optString("type"))) {

                            // add any resources (controls can have them too)
                            addResources(jsonAction, "action", resourceJS, resourceCSS);

                            // get action JavaScript
                            String js = jsonAction.optString("actionJavaScript");
                            // only produce rapid action is this is rapid app
                            if (js != null && ("rapid".equals(_id) || !"rapid".equals(actionType))) {
                                // clean and print! (if not an empty string)
                                if (js.trim().length() > 0)
                                    actionJS.append("\n" + js.trim() + "\n");
                            }

                            // move onto the next action type
                            break;
                        }

                    } // jsonActions loop

                } // action types loop

            } // action types check

        } // jsonAction check

        // assume no theme css
        String themeCSS = null;
        // assume no theme name
        String themeName = null;

        // check the theme type
        if (_themeType != null) {
            // get the themes
            List<Theme> themes = (List<Theme>) servletContext.getAttribute("themes");
            // check we got some
            if (themes != null) {
                // loop them
                for (Theme theme : themes) {
                    // check type
                    if (_themeType.equals(theme.getType())) {
                        // retain the theme CSS
                        themeCSS = theme.getCSS();
                        // retain the name
                        themeName = theme.getName();
                        // get any resources
                        addResources(theme.getResources(), "theme", themeName, null, resourceJS, resourceCSS);
                        // we're done
                        break;
                    }
                }
            }
        }

        // put the appResources at the end so they can be overrides
        if (_appResources != null) {
            for (Resource resource : _appResources) {
                // create new resource based on this one (so that the dependancy doesn't get written back to the application.xml file)
                Resource appResource = new Resource(resource.getType(), resource.getContent(),
                        ResourceDependency.RAPID);
                // if the type is a file or link prefix with the application folder
                switch (resource.getType()) {
                case Resource.JAVASCRIPTFILE:
                case Resource.CSSFILE:
                    // files are available on the local file system so we prefix with the webfolder
                    appResource.setContent(getWebFolder(this)
                            + (resource.getContent().startsWith("/") ? "" : "/") + resource.getContent());
                    break;
                case Resource.JAVASCRIPTLINK:
                case Resource.CSSLINK:
                    // links are not so go in as-is
                    appResource.setContent(resource.getContent());
                    break;
                }
                // add new resource based on this one but with Rapid dependency
                _resources.add(appResource);
            }
        }

        // create folders to write the rapid.js file
        String applicationPath = getWebFolder(servletContext);
        File applicationFolder = new File(applicationPath);
        if (!applicationFolder.exists())
            applicationFolder.mkdirs();

        // write the rapid.js file
        FileOutputStream fos = new FileOutputStream(applicationPath + "/rapid.js");
        PrintStream ps = new PrintStream(fos);

        // write the rapid.min.js file
        FileOutputStream fosMin = new FileOutputStream(applicationPath + "/rapid.min.js");
        PrintWriter pw = new PrintWriter(fosMin);

        // file header
        ps.print(
                "\n/* This file is auto-generated on application load and save - it is minified when the application status is live */\n");
        // check functions
        if (_functions != null) {
            if (_functions.length() > 0) {
                // header (this is removed by minify)
                ps.print("\n\n/* Application functions JavaScript */\n\n");
                // insert params
                String functionsParamsInserted = insertParameters(servletContext, _functions);
                // print
                ps.print(functionsParamsInserted);
                // print minify 
                Minify.toWriter(functionsParamsInserted, pw, Minify.JAVASCRIPT);
            }
        }
        // check resource js
        if (resourceJS.length() > 0) {
            // header
            ps.print("\n\n/* Control and Action resource JavaScript */\n\n");
            // insert params
            String resourceJSParamsInserted = insertParameters(servletContext, resourceJS.toString());
            // print
            ps.print(resourceJS.toString());
            // print minify 
            Minify.toWriter(resourceJSParamsInserted, pw, Minify.JAVASCRIPT);
        }
        // check init js
        if (initJS.length() > 0) {
            // header
            ps.print("\n\n/* Control initialisation methods */\n\n");
            // insert params
            String initJSParamsInserted = insertParameters(servletContext, initJS.toString());
            // print
            ps.print(initJS.toString());
            // print minify 
            Minify.toWriter(initJSParamsInserted, pw, Minify.JAVASCRIPT);
        }
        // check datajs
        if (dataJS.length() > 0) {
            // header
            ps.print("\n\n/* Control getData and setData methods */\n\n");
            // insert params
            String dataJSParamsInserted = insertParameters(servletContext, dataJS.toString());
            // print
            ps.print(dataJS.toString());
            // print minify 
            Minify.toWriter(dataJSParamsInserted, pw, Minify.JAVASCRIPT);
        }
        // check action js
        if (actionJS.length() > 0) {
            // header
            ps.print("\n\n/* Action methods */\n\n");
            // insert params
            String actionParamsInserted = insertParameters(servletContext, actionJS.toString());
            // print
            ps.print(actionJS.toString());
            // print minify 
            Minify.toWriter(actionParamsInserted, pw, Minify.JAVASCRIPT);
        }

        // close debug writer and stream
        ps.close();
        fos.close();
        // close min writer and stream
        pw.close();
        fosMin.close();

        // get the rapid CSS into a string and insert parameters
        String resourceCSSWithParams = insertParameters(servletContext, resourceCSS.toString());
        String appThemeCSSWithParams = insertParameters(servletContext, themeCSS);
        String appCSSWithParams = insertParameters(servletContext, _styles);

        // write the rapid.css file
        fos = new FileOutputStream(applicationPath + "/rapid.css");
        ps = new PrintStream(fos);
        ps.print(
                "\n/* This file is auto-generated on application load and save - it is minified when the application status is live */\n\n");
        if (resourceCSSWithParams != null) {
            ps.print(resourceCSSWithParams.trim());
        }
        if (appThemeCSSWithParams != null) {
            ps.print("\n\n/* " + themeName + " theme styles */\n\n");
            ps.print(appThemeCSSWithParams.trim());
        }
        if (appCSSWithParams != null) {
            ps.print("\n\n/* Application styles */\n\n");
            ps.print(appCSSWithParams.trim());
        }
        ps.close();
        fos.close();

        // minify it to a rapid.min.css file
        Minify.toFile(resourceCSSWithParams + appCSSWithParams, applicationPath + "/rapid.min.css", Minify.CSS);

        // check the status
        if (_status == STATUS_LIVE) {
            // add the application js min file as a resource
            _resources.add(new Resource(Resource.JAVASCRIPTFILE, getWebFolder(this) + "/rapid.min.js",
                    ResourceDependency.RAPID));
            // add the application css min file as a resource          
            _resources.add(new Resource(Resource.CSSFILE, getWebFolder(this) + "/rapid.min.css",
                    ResourceDependency.RAPID));
        } else {
            // add the application js file as a resource
            _resources.add(new Resource(Resource.JAVASCRIPTFILE, getWebFolder(this) + "/rapid.js",
                    ResourceDependency.RAPID));
            // add the application css file as a resource          
            _resources.add(new Resource(Resource.CSSFILE, getWebFolder(this) + "/rapid.css",
                    ResourceDependency.RAPID));
        }

        // loop all resources and minify js and css files
        for (Resource resource : _resources) {
            // get the content (which is the filename)
            String fileName = resource.getContent();
            // only interested in js and css files
            switch (resource.getType()) {
            case Resource.JAVASCRIPTFILE:
                // get a file for this
                File jsFile = new File(
                        servletContext.getRealPath("/") + (fileName.startsWith("/") ? "" : "/") + fileName);
                // if the file exists, and it's in the scripts folder and ends with .js
                if (jsFile.exists() && fileName.startsWith("scripts/") && fileName.endsWith(".js")) {
                    // derive the min file name by modifying the start and end
                    String fileNameMin = "scripts_min/" + fileName.substring(8, fileName.length() - 3)
                            + ".min.js";
                    // get a file for minifying 
                    File jsFileMin = new File(servletContext.getRealPath("/") + "/" + fileNameMin);
                    // if this file does not exist
                    if (!jsFileMin.exists()) {
                        // make any dirs it may need
                        jsFileMin.getParentFile().mkdirs();
                        // minify to it
                        Minify.toFile(jsFile, jsFileMin, Minify.JAVASCRIPT);
                    }
                    // if this application is live, update the resource to the min file
                    if (_status == STATUS_LIVE)
                        resource.setContent(fileNameMin);
                }
                break;
            case Resource.CSSFILE:
                // get a file for this
                File cssFile = new File(
                        servletContext.getRealPath("/") + (fileName.startsWith("/") ? "" : "/") + fileName);
                // if the file exists, and it's in the scripts folder and ends with .js
                if (cssFile.exists() && fileName.startsWith("styles/") && fileName.endsWith(".css")) {
                    // derive the min file name by modifying the start and end
                    String fileNameMin = "styles_min/" + fileName.substring(7, fileName.length() - 4)
                            + ".min.css";
                    // get a file for minifying 
                    File cssFileMin = new File(servletContext.getRealPath("/") + "/" + fileNameMin);
                    // if this file does not exist
                    if (!cssFileMin.exists()) {
                        // make any dirs it may need
                        cssFileMin.getParentFile().mkdirs();
                        // minify to it
                        Minify.toFile(cssFile, cssFileMin, Minify.CSS);
                    }
                    // if this application is live, update the resource to the min file
                    if (_status == STATUS_LIVE)
                        resource.setContent(fileNameMin);
                }
                break;
            }

        } // loop resources

        // a list for all of the style classes we're going to send up with
        _styleClasses = new ArrayList<String>();

        // populate the list of style classes by scanning the global styles
        scanStyleClasses(_styles, _styleClasses);
        // and any theme
        scanStyleClasses(appThemeCSSWithParams, _styleClasses);

        // remove any that have the same name as controls
        if (jsonControls != null) {
            // loop them
            for (int i = 0; i < jsonControls.length(); i++) {
                // remove any classes with this controls type
                _styleClasses.remove(jsonControls.getJSONObject(i).getString("type"));
            }
        }

    } // create resources

    // empty the list of page variables so it's regenerated
    _pageVariables = null;

    // debug log that we initialised
    logger.debug(
            "Initialised application " + _name + "/" + _version + (createResources ? "" : " (no resources)"));

}