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:com.krawler.esp.servlets.ProfileImageServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    // Get the absolute path of the image
    ServletContext sc = getServletContext();
    String uri = req.getRequestURI();
    String servletBase = req.getServletPath();
    if (!StringUtil.isNullOrEmpty(req.getParameter("flag"))) {
        try {//w  ww. j a  v a2 s. c o  m
            // TODO: Fix hardcoded url
            if (!StringUtil.isNullOrEmpty(req.getParameter("trackid"))) {
                String url = "/remoteapi.jsp?action=100&data={\"iscommit\":true}&trackid="
                        + req.getParameter("trackid");
                RequestDispatcher rd = req.getRequestDispatcher(url);
                rd.include(req, resp);
            }
            String fileName = StorageHandler.GetProfileImgStorePath() + "blankImage.png";
            File file = new File(fileName);
            if (file.exists()) {
                FileInputStream in = new FileInputStream(file);
                OutputStream out = resp.getOutputStream();

                // Copy the contents of the file to the output stream
                byte[] buf = new byte[4096];
                int count = 0;
                while ((count = in.read(buf)) >= 0) {
                    out.write(buf, 0, count);
                }
                in.close();
                out.close();
            }
        } catch (Exception e) {
            logger.warn(e.getMessage(), e);
        }
    } else {
        boolean Companyflag = (req.getParameter("company") != null) ? true : false;
        String imagePath = defaultImgPath;
        String requestedFileName = "";
        if (Companyflag) {
            imagePath = defaultCompanyImgPath;
            String companyId = null;
            try {
                companyId = sessionHandlerImpl.getCompanyid(req);
            } catch (Exception ee) {
                logger.warn(ee.getMessage(), ee);
            }
            if (StringUtil.isNullOrEmpty(companyId)) {
                String domain = URLUtil.getDomainName(req);
                if (!StringUtil.isNullOrEmpty(domain)) {
                    //@@@
                    //                        companyId = sessionHandlerImpl.getCompanyid(domain);
                    requestedFileName = "/original_" + companyId + ".png";
                } else {
                    requestedFileName = "logo.gif";
                }
            } else {
                requestedFileName = "/" + companyId + ".png";
            }
        } else {
            requestedFileName = uri.substring(uri.lastIndexOf(servletBase) + servletBase.length());
        }
        String fileName = null;

        fileName = StorageHandler.GetProfileImgStorePath() + requestedFileName;
        // Get the MIME type of the image
        String mimeType = sc.getMimeType(fileName);
        if (mimeType == null) {
            sc.log("Could not get MIME type of " + fileName);
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        // Set content type
        resp.setContentType(mimeType);

        // Set content size
        File file = new File(fileName);
        if (!file.exists()) {
            if (fileName.contains("_100.")) {
                file = new File(fileName.replaceAll("_100.", "."));
            }
            if (!file.exists()) {
                file = new File(sc.getRealPath(imagePath));
            }
        }

        resp.setContentLength((int) file.length());

        // Open the file and output streams
        FileInputStream in = new FileInputStream(file);
        OutputStream out = resp.getOutputStream();

        // Copy the contents of the file to the output stream
        byte[] buf = new byte[4096];
        int count = 0;
        while ((count = in.read(buf)) >= 0) {
            out.write(buf, 0, count);
        }
        in.close();
        out.close();
    }
}

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

public String insertParameters(ServletContext servletContext, String string) {
    // check for non-null
    if (string != null) {
        // get pos of [[
        int pos = string.indexOf("[[");
        // check string contains [[ 
        if (pos > -1) {
            // if it has ]] thereafter
            if (string.indexOf("]]") > pos) {
                // webfolder is the client web facing resources
                if (string.contains("[[webfolder]]"))
                    string = string.replace("[[webfolder]]", getWebFolder(this));
                // appfolder and configfolder are the hidden server app resources
                if (string.contains("[[appfolder]]"))
                    string = string.replace("[[appfolder]]", getConfigFolder(servletContext, _id, _version));
                if (string.contains("[[configfolder]]"))
                    string = string.replace("[[configfolder]]", getConfigFolder(servletContext, _id, _version));
                // root folder is WEB-INF
                if (string.contains("[[rootfolder]]"))
                    string = string.replace("[[rootfolder]]", servletContext.getRealPath("WEB-INF/"));
                // if we have parameters
                if (_parameters != null) {
                    // loop them
                    for (Parameter parameter : _parameters) {
                        // define the match string
                        String matchString = "[[" + parameter.getName() + "]]";
                        // if the match string is present replace it with the value
                        if (string.contains(matchString))
                            string = string.replace(matchString, parameter.getValue());
                    }/*from w w w.j  a  v  a2  s.  c  o  m*/
                }
            }
        }
    }
    // return it
    return string;
}

From source file:com.inverse2.ajaxtoaster.AjaxToasterServlet.java

/**
 * Perform initialisation necessary to setup AjaxToaster database pools...
 *///from ww w. ja  va  2s.co m
private void initDBPools(Properties servletProperties, ServletContext context) {

    // Read the default JNDI name or connection pool name to use when creating database connections.
    // held in AjaxToaster.properties as the "default_db_jndi_name" property.
    // This is used if there is no properties file with an overriding "db_jndi_name" property supplied for a toaster script.

    default_db_jndi_name = servletProperties.getProperty(PROP_DEFAULT_JNDI_DATABASE);
    default_db_jdbc_name = servletProperties.getProperty(PROP_DEFAULT_JDBC_POOL);

    println("**** Default JDBC pool = " + default_db_jdbc_name);
    println("**** Default JNDI name = " + default_db_jndi_name);

    /**
     *  Create any jdbc connection pools
     *
     * Properties file format for connection pools is :
     *        jdbc.class.[poolId]    = [driver classname]
     *        jdbc.database.[poolId] = [database to connect to]
     *        jdbc.username.[poolId] = [user to connect as]
     *        jdbc.password.[poolId] = [password]
       *
     * ...Where [id] is a unique identifier for the pool. It can be anything as long as it's unique per pool.
     *
     * There is no restriction on the number of connection pools that can be defined.
       */

    for (Enumeration e = servletProperties.propertyNames(); e.hasMoreElements();) {

        String propertyName = (String) e.nextElement();

        println("**** checking property.... " + propertyName);

        if (propertyName.startsWith("jdbc.database.")) {

            String poolId = propertyName.substring(propertyName.lastIndexOf("."));

            poolId = poolId.replaceFirst("\\.", "");

            String driver = servletProperties.getProperty("jdbc.driver." + poolId);
            String url = servletProperties.getProperty("jdbc.database." + poolId);
            String username = servletProperties.getProperty("jdbc.username." + poolId);
            String password = servletProperties.getProperty("jdbc.password." + poolId);

            // Not using a container managed database connection pool.... lets make our own!
            // Create a database connection pool...

            println("**** INFO: JDBC CONNECTION PROPERTIES FOR " + poolId + " - ("
                    + servletProperties.getProperty(propertyName) + ")");
            println("****       driver=" + driver);
            println("****       url=" + url);
            println("****       username=" + username);
            println("****       password=" + password);

            try {
                String contextDirectory = context.getRealPath("/");
                DBConnectionPool dbpool = new DBConnectionPool(poolId, driver, url, username, password,
                        contextDirectory);
                String attr = ATTRIB_JDBC_CONN_POOL + "." + poolId;

                println("Storing JDBC pool in " + attr);

                context.setAttribute(attr, dbpool);
            } catch (Exception ex) {
                println("**** ERROR: Exception creating a database connection pool: " + ex.toString());
                // continue... some pools might be ok...
            }

        }

    }

}

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

/**
 * ?//  w  w w .j  a  v  a2s. 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 printCscodeList(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);
    ServletContext context = request.getSession().getServletContext();
    Example example = Example.create(new Csno());
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("cscode"));
    List<Csno> csnos = (List<Csno>) am.findSQLWithCriteria(Csno.class, example, null, orders);

    File templateXLS = new File(context.getRealPath("/WEB-INF/reports/Csnos.xls"));
    HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
    HSSFSheet sheet = workbook.getSheetAt(0);

    int index = 2;

    for (Csno csno : csnos) {
        Toolket.setCellValue(sheet, index, 0, csno.getCscode().trim().toUpperCase());
        Toolket.setCellValue(sheet, index, 1, csno.getChiName().trim());
        Toolket.setCellValue(sheet, index++, 2, StringUtils.defaultIfEmpty(csno.getEngName(), "").trim());
    }

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

/**
 * 962??//from  w  w  w  .  ja v a  2s .  co m
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void printLicenseCodes(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);
    ServletContext context = request.getSession().getServletContext();
    Example example = Example.create(new LicenseCode());
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("code"));
    List<LicenseCode> codes = (List<LicenseCode>) am.findSQLWithCriteria(LicenseCode.class, example, null,
            orders, 20000);

    File templateXLS = new File(context.getRealPath("/WEB-INF/reports/LicenseCodes.xls"));
    HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
    HSSFSheet sheet = workbook.getSheetAt(0);

    int index = 2;

    for (LicenseCode code : codes) {
        Toolket.setCellValue(sheet, index, 0, code.getCode().toString());
        Toolket.setCellValue(sheet, index, 1, code.getName());
        Toolket.setCellValue(sheet, index, 2, code.getLocale().toString());
        Toolket.setCellValue(sheet, index, 3, code.getLevel());
        Toolket.setCellValue(sheet, index, 4, code.getType().toString());
        Toolket.setCellValue(sheet, index++, 5, code.getDeptName());
    }

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

/**
 * 961?(?)??//from  w  w w.ja v a  2 s  . c om
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void printLicenseCodes961(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);
    ServletContext context = request.getSession().getServletContext();
    Example example = Example.create(new LicenseCode961());
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("code"));
    List<LicenseCode961> codes961 = (List<LicenseCode961>) am.findSQLWithCriteria(LicenseCode961.class, example,
            null, orders);

    File templateXLS = new File(context.getRealPath("/WEB-INF/reports/LicenseCodes.xls"));
    HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
    HSSFSheet sheet = workbook.getSheetAt(0);

    int index = 2;

    for (LicenseCode961 code961 : codes961) {
        Toolket.setCellValue(sheet, index, 0, code961.getCode().toString());
        Toolket.setCellValue(sheet, index, 1, code961.getName());
        Toolket.setCellValue(sheet, index, 2, code961.getLocale().toString());
        Toolket.setCellValue(sheet, index, 3, code961.getLevel());
        Toolket.setCellValue(sheet, index, 4, code961.getType().toString());
        Toolket.setCellValue(sheet, index++, 5, code961.getDeptName());
    }

    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, "LicenseCodes961.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  .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 printIntroduction(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Integer year = Integer.valueOf(cm.getNowBy("School_year"));
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), true);

    if (!clazzes.isEmpty()) {

        File templateXLS = new File(context.getRealPath("/WEB-INF/reports/CourseIntrosListPrint.xls"));
        HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
        HSSFSheet sheet = null;
        int sheetIndex = 0;
        String departClass = null, emplName = null;
        Dtime dtime = null;
        DEmpl de = null;
        Csno csno = null;
        CourseIntroduction ci = null;
        Employee employee = null;
        List<Dtime> dtimes = null;
        List<CourseIntroduction> cis = null;

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

            dtime = new Dtime();
            dtime.setDepartClass(departClass);
            dtime.setSterm(sterm);
            dtimes = cm.findDtimeBy(dtime, "cscode");
            if (!dtimes.isEmpty()) {

                for (Dtime d : dtimes) {
                    cis = cm.getCourseIntroByDtimeOid(d.getOid(), year, Integer.valueOf(sterm));

                    if (cis.isEmpty())
                        continue;

                    ci = cis.get(0);
                    csno = cm.findCourseInfoByCscode(d.getCscode());
                    employee = mm.findEmployeeByIdno(d.getTechid());
                    if (employee == null) {
                        if (StringUtils.isBlank(d.getTechid())) {
                            emplName = "";
                        } else {
                            if (StringUtils.isBlank(d.getTechid())) {
                                emplName = "";
                            } else {
                                de = mm.findDEmplBy(new DEmpl(d.getTechid())).get(0);
                                emplName = de.getCname();
                            }
                        }
                    } else
                        emplName = employee.getName();

                    sheet = workbook.getSheetAt(sheetIndex);
                    workbook.setSheetName(sheetIndex++, departClass + " "
                            + StringUtils.replace(csno.getChiName().replaceAll("/", " "), "", ""));

                    Toolket.setCellValue(sheet, 2, 0,
                            Toolket.getCellValue(sheet, 2, 0).replaceAll("TECH", emplName).replaceAll("DEPT",
                                    Toolket.getClassFullName(d.getDepartClass())));
                    Toolket.setCellValue(sheet, 3, 0,
                            Toolket.getCellValue(sheet, 3, 0).replaceAll("TITLE", csno.getChiName()));
                    Toolket.setCellValue(sheet, 4, 0, Toolket.getCellValue(sheet, 4, 0).replaceAll("ENG",
                            StringUtils.isBlank(csno.getEngName()) ? "" : csno.getEngName()));
                    Toolket.setCellValue(sheet, 5, 0,
                            Toolket.getCellValue(sheet, 5, 0).replaceAll("YEAR", ci.getSchoolYear().toString())
                                    .replaceAll("TERM", d.getSterm())
                                    .replaceAll("CREDIT", d.getCredit().toString()));
                    Toolket.setCellValue(sheet, 7, 0, Toolket.getCellValue(sheet, 7, 0).replaceAll("CHIINTRO",
                            StringUtils.isBlank(ci.getChiIntro()) ? "" : ci.getChiIntro()));
                    Toolket.setCellValue(sheet, 20, 0, Toolket.getCellValue(sheet, 20, 0).replaceAll("ENGINTRO",
                            StringUtils.isBlank(ci.getEngIntro()) ? "" : ci.getEngIntro()));
                }
            }

        }

        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, "CourseIntros.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. ja  va 2s.  c o  m
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printSyllabus(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Integer year = Integer.valueOf(cm.getNowBy("School_year"));
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), true);

    if (!clazzes.isEmpty()) {

        File templateXLS = new File(context.getRealPath("/WEB-INF/reports/CourseSyllabusListPrint.xls"));
        HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
        HSSFSheet sheet = null;
        int sheetIndex = 0;
        String departClass = null, emplName = null;
        Dtime dtime = null;
        DEmpl de = null;
        Csno csno = null;
        CourseSyllabus cs = null;
        Employee employee = null;
        List<Dtime> dtimes = null;
        List<Syllabus> syllabus = null;

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

            dtime = new Dtime();
            dtime.setDepartClass(departClass);
            dtime.setSterm(sterm);
            dtimes = cm.findDtimeBy(dtime, "cscode");
            if (!dtimes.isEmpty()) {

                for (Dtime d : dtimes) {
                    cs = cm.getCourseSyllabusByDtimeOid(d.getOid(), year, Integer.valueOf(sterm));

                    if (cs == null)
                        continue;

                    csno = cm.findCourseInfoByCscode(d.getCscode());
                    employee = mm.findEmployeeByIdno(d.getTechid());
                    if (employee == null) {
                        if (StringUtils.isBlank(d.getTechid())) {
                            emplName = "";
                        } else {
                            if (StringUtils.isBlank(d.getTechid())) {
                                emplName = "";
                            } else {
                                de = mm.findDEmplBy(new DEmpl(d.getTechid())).get(0);
                                emplName = de.getCname();
                            }
                        }
                    } else
                        emplName = employee.getName();

                    sheet = workbook.getSheetAt(sheetIndex);
                    workbook.setSheetName(sheetIndex++,
                            departClass + " " + csno.getChiName().replaceAll("/", " ").replaceAll("", " "));

                    Toolket.setCellValue(sheet, 2, 0,
                            Toolket.getCellValue(sheet, 2, 0).replaceAll("TECH", emplName).replaceAll("DEPT",
                                    Toolket.getClassFullName(d.getDepartClass())));
                    Toolket.setCellValue(sheet, 3, 0,
                            Toolket.getCellValue(sheet, 3, 0).replaceAll("HOUR", cs.getOfficeHours()));
                    Toolket.setCellValue(sheet, 4, 0,
                            Toolket.getCellValue(sheet, 4, 0).replaceAll("TITLE", csno.getChiName()));
                    Toolket.setCellValue(sheet, 5, 0, Toolket.getCellValue(sheet, 5, 0).replaceAll("ENG",
                            StringUtils.isBlank(csno.getEngName()) ? "" : csno.getEngName()));
                    Toolket.setCellValue(sheet, 6, 0,
                            Toolket.getCellValue(sheet, 6, 0).replaceAll("YEAR", cs.getSchoolYear().toString())
                                    .replaceAll("TERM", d.getSterm())
                                    .replaceAll("CREDIT", d.getCredit().toString()));
                    Toolket.setCellValue(sheet, 7, 0,
                            Toolket.getCellValue(sheet, 7, 0).replaceAll("PRE", cs.getPrerequisites().trim()));
                    Toolket.setCellValue(sheet, 9, 0,
                            Toolket.getCellValue(sheet, 9, 0).replaceAll("OBJ", cs.getObjectives().trim()));

                    syllabus = cs.getSyllabuses();
                    if (!syllabus.isEmpty()) {
                        int index = 12;
                        for (Syllabus s : syllabus) {
                            Toolket.setCellValue(sheet, index, 0,
                                    (s == null || s.getTopic() == null ? "" : s.getTopic().trim()));
                            Toolket.setCellValue(sheet, index, 1,
                                    (s == null || s.getContent() == null ? "" : s.getContent().trim()));
                            Toolket.setCellValue(sheet, index, 2,
                                    (s == null || s.getHours() == null ? "" : s.getHours().trim()));
                            Toolket.setCellValue(sheet, index, 3,
                                    (s == null || s.getWeek() == null ? "" : s.getWeek().trim()));
                            Toolket.setCellValue(sheet, index++, 4,
                                    (s == null || s.getRemarks() == null ? "" : s.getRemarks().trim()));
                        }
                    }
                }
            }

        }

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

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

}

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

/**
 * ?// www  .jav  a 2s . c  om
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
@SuppressWarnings("unchecked")
private void 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);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    MemberManager mm = (MemberManager) getBean(MEMBER_MANAGER_BEAN_NAME);
    DynaActionForm aForm = (DynaActionForm) form;
    ServletContext context = request.getSession().getServletContext();

    StdSkill skill = new StdSkill();
    skill.setAmount(null); // ??
    Example example = Example.create(skill).ignoreCase().enableLike(MatchMode.ANYWHERE);
    List<Order> orders = new LinkedList<Order>();
    orders.add(Order.asc("schoolYear"));
    orders.add(Order.asc("schoolTerm"));
    orders.add(Order.asc("studentNo"));

    List<Criterion> cris = new LinkedList<Criterion>();
    Criterion cri = null;

    if (aForm.getStrings("year").length != 0) {
        cri = Restrictions.eq("schoolYear", aForm.getStrings("year")[0]);
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("sterm"))) {
        cri = Restrictions.eq("schoolTerm", aForm.getString("sterm"));
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("deptCodeOpt"))) {
        cri = Restrictions.eq("deptNo", aForm.getString("deptCodeOpt"));
        cris.add(cri);
    }

    if (StringUtils.isNotBlank(aForm.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(aForm.getString("licenseValidDateEnd"))) {
        Date from = StringUtils.isBlank(aForm.getString("licenseValidDateStart")) ? null
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateStart"));
        // ???
        Date to = StringUtils.isBlank(aForm.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime()
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateEnd"));

        if (from != null) {
            cri = Restrictions.between("licenseValidDate", from, to);
            cris.add(cri);
        }
    }

    List<StdSkill> skills = (List<StdSkill>) am.findSQLWithCriteria(StdSkill.class, example, null, orders,
            cris);

    int index = 2;
    List<LicenseCode> codes = null;
    Student student = null;
    Graduate graduate = null;
    Empl empl = null;
    DEmpl dempl = null;
    Csno csno = null;
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    DateFormat df1 = new SimpleDateFormat("yyyy/MM");

    File templateXLS = new File(context.getRealPath("/WEB-INF/reports/DeptStdSkillList.xls"));
    HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);
    HSSFSheet sheet = workbook.getSheetAt(0);

    for (StdSkill ss : skills) {
        codes = (List<LicenseCode>) am
                .findLicenseCodesBy(new LicenseCode(Integer.valueOf(ss.getLicenseCode())));

        if (!codes.isEmpty())
            ss.setLicense(codes.get(0));

        student = mm.findStudentByNo(ss.getStudentNo().trim());
        if (student == null) {
            graduate = mm.findGraduateByStudentNo(ss.getStudentNo().trim());
            if (graduate != null) {
                ss.setStudentName(graduate.getStudentName().trim());
                ss.setDepartClass(Toolket.getClassFullName(graduate.getDepartClass()));
            }
        } else {
            ss.setStudentName(student.getStudentName().trim());
            ss.setDepartClass(Toolket.getClassFullName(student.getDepartClass()));
        }

        Toolket.setCellValue(sheet, index, 0, ss.getSchoolYear() + "." + ss.getSchoolTerm());
        Toolket.setCellValue(sheet, index, 1, ss.getStudentNo().toUpperCase());
        Toolket.setCellValue(sheet, index, 2, ss.getStudentName());
        Toolket.setCellValue(sheet, index, 3, ss.getDepartClass());
        Toolket.setCellValue(sheet, index, 4, ss.getLicense().getCode().toString());
        Toolket.setCellValue(sheet, index, 5, ss.getLicense().getName().trim());
        Toolket.setCellValue(sheet, index, 6, ss.getLicense().getLocale().toString());
        Toolket.setCellValue(sheet, index, 7, ss.getLicense().getLevel().trim());
        Toolket.setCellValue(sheet, index, 8, ss.getLicense().getType().toString());
        Toolket.setCellValue(sheet, index, 9, ss.getAmount().toString());
        Toolket.setCellValue(sheet, index, 10, Toolket.getAmountType(ss.getAmountType()));
        Toolket.setCellValue(sheet, index, 11,
                ss.getAmountDate() == null ? "" : df1.format(ss.getAmountDate()));
        Toolket.setCellValue(sheet, index, 12, ss.getLicenseNo());
        Toolket.setCellValue(sheet, index, 13, df.format(ss.getLicenseValidDate()));

        if (StringUtils.isBlank(ss.getCscode())) {
            csno = cm.findCourseInfoByCscode(ss.getCscode());
            if (csno != null)
                Toolket.setCellValue(sheet, index, 14, csno.getChiName().trim());
        } else
            Toolket.setCellValue(sheet, index, 14, "");

        if (StringUtils.isBlank(ss.getTechIdno())) {
            empl = mm.findEmplByIdno(ss.getTechIdno());
            if (empl != null)
                Toolket.setCellValue(sheet, index, 15, empl.getEname().trim());
            else {
                dempl = mm.findDEmplByIdno(ss.getTechIdno());
                if (dempl != null)
                    Toolket.setCellValue(sheet, index, 15, dempl.getEname().trim());
            }
        } else
            Toolket.setCellValue(sheet, index, 15, "");

        Toolket.setCellValue(sheet, index, 16, ss.getSerialNo());
        Toolket.setCellValue(sheet, index, 17, Toolket.getCustomNo(ss.getCustomNo()));
        Toolket.setCellValue(sheet, index++, 18, Toolket.getPass(ss.getPass()));
    }

    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

/**
 * ?/*w w w.  jav a2s . c  om*/
 * 
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @param sterm
 * @throws Exception
 */
@SuppressWarnings("unchecked")
private void printStayTimePrint(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    CourseManager cm = (CourseManager) getBean(IConstants.COURSE_MANAGER_BEAN_NAME);
    ScoreManager sm = (ScoreManager) getBean(IConstants.SCORE_MANAGER_BEAN_NAME);
    ServletContext context = request.getSession().getServletContext();
    Integer year = Integer.valueOf(cm.getNowBy("School_year"));
    String term = form.getString("sterm");
    List<Clazz> clazzes = sm.findClassBy(new Clazz(processClassInfo(form)),
            getUserCredential(session).getClassInChargeAry(), true);

    if (!clazzes.isEmpty()) {

        File templateXLS = new File(context.getRealPath("/WEB-INF/reports/TeachSchedAll.xls"));
        HSSFWorkbook workbook = Toolket.getHSSFWorkbook(templateXLS);

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

        HSSFSheet sheet = null;
        int sheetIndex = 0, colOffset = 1, col = 0;
        boolean isLocationNull = false;
        String departClass = null;
        Dtime dtime = null;
        Empl empl = null;
        Set<String> idnoSet = new HashSet<String>();
        Short colorForStayTime = HSSFColor.AUTOMATIC.index;
        Short colorForLifeCounseling = HSSFColor.LIGHT_GREEN.index;
        List<TeacherStayTime> tsts = null;
        List<LifeCounseling> lcs = null;
        List<Dtime> dtimes = null;
        List<Map> map = null;
        Map content = null;

        for (Clazz clazz : clazzes) {
            departClass = clazz.getClassNo();

            dtime = new Dtime();
            dtime.setDepartClass(departClass);
            dtime.setSterm(sterm);
            dtimes = cm.findDtimeBy(dtime, "cscode");
            if (!dtimes.isEmpty()) {
                for (Dtime d : dtimes) {
                    if (StringUtils.isNotBlank(d.getTechid()))
                        idnoSet.add(d.getTechid());
                }
            }
        }

        for (String idno : idnoSet) {
            empl = mm.findEmplByIdno(idno);
            if (empl != null && "1".equalsIgnoreCase(empl.getCategory())) {

                sheet = workbook.getSheetAt(sheetIndex);
                workbook.setSheetName(sheetIndex++, empl.getCname());
                isLocationNull = empl.getLocation() == null;

                Toolket.setCellValue(sheet, 0, 1, year + "" + term + "" + empl.getCname()
                        + "?" + " (:"
                        + (isLocationNull ? ""
                                : StringUtils.defaultIfEmpty(empl.getLocation().getExtension(), ""))
                        + " ?:"
                        + (isLocationNull ? "" : StringUtils.defaultIfEmpty(empl.getLocation().getRoomId(), ""))
                        + ")");

                map = cm.findCourseByTeacherTermWeekdaySched(empl.getIdno(), term.toString());

                for (int i = 0; i < 14; i++) {
                    for (int j = 0; j < 7; j++) {
                        content = map.get(j * 15 + i);
                        if (!CollectionUtils.isEmpty(content)) {
                            Toolket.setCellValue(sheet, i + 2, j + 2, (String) content.get("ClassName") + "\n"
                                    + (String) content.get("chi_name") + "\n" + (String) content.get("place"));
                        }
                    }
                }

                //tsts = empl.getStayTime();
                List<TeacherStayTime> myTsts = cm.ezGetBy(
                        " Select Week, Node1, Node2, Node3, Node4, Node5, Node6, Node7, Node8, Node9, Node10, "
                                + "        Node11, Node12, Node13, Node14 " + " From TeacherStayTime "
                                + " Where SchoolYear='" + year + "'" + "   And SchoolTerm='" + term + "' "
                                + "   And parentOid='" + empl.getOid() + "'");

                List myTsts2 = new ArrayList();

                for (int i = 0; i < myTsts.size(); i++) {
                    //for (TeacherStayTime tst : tsts) {                                    
                    myTsts2.add(myTsts.get(i));
                    String s = myTsts2.get(i).toString();
                    col = Integer.parseInt(s.substring(6, 7)) + colOffset; //Week   
                    //col = tst.getWeek() + colOffset;
                    //if (tst.getNode1() != null && tst.getNode1() == 1) {                  
                    if (Integer.parseInt(s.substring(15, 16)) == 1) { //Node1
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 2, col)))
                            Toolket.setCellValue(workbook, sheet, 2, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode2() != null && tst.getNode2() == 1) {
                    if (Integer.parseInt(s.substring(24, 25)) == 1) { //Node2
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 3, col)))
                            Toolket.setCellValue(workbook, sheet, 3, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode3() != null && tst.getNode3() == 1) {
                    if (Integer.parseInt(s.substring(33, 34)) == 1) { //Node3
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 4, col)))
                            Toolket.setCellValue(workbook, sheet, 4, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode4() != null && tst.getNode4() == 1) {
                    if (Integer.parseInt(s.substring(42, 43)) == 1) { //Node4
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 5, col)))
                            Toolket.setCellValue(workbook, sheet, 5, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode5() != null && tst.getNode5() == 1) {
                    if (Integer.parseInt(s.substring(51, 52)) == 1) { //Node5
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 6, col)))
                            Toolket.setCellValue(workbook, sheet, 6, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode6() != null && tst.getNode6() == 1) {
                    if (Integer.parseInt(s.substring(60, 61)) == 1) { //Node6
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 7, col)))
                            Toolket.setCellValue(workbook, sheet, 7, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode7() != null && tst.getNode7() == 1) {
                    if (Integer.parseInt(s.substring(69, 70)) == 1) { //Node7
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 8, col)))
                            Toolket.setCellValue(workbook, sheet, 8, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode8() != null && tst.getNode8() == 1) {
                    if (Integer.parseInt(s.substring(78, 79)) == 1) { //Node8
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 9, col)))
                            Toolket.setCellValue(workbook, sheet, 9, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode9() != null && tst.getNode9() == 1) {
                    if (Integer.parseInt(s.substring(87, 88)) == 1) { //Node9
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 10, col)))
                            Toolket.setCellValue(workbook, sheet, 10, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode10() != null && tst.getNode10() == 1) {
                    if (Integer.parseInt(s.substring(97, 98)) == 1) { //Node10
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 11, col)))
                            Toolket.setCellValue(workbook, sheet, 11, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode11() != null && tst.getNode11() == 1) {
                    if (Integer.parseInt(s.substring(107, 108)) == 1) { //Node11
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 12, col)))
                            Toolket.setCellValue(workbook, sheet, 12, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode12() != null && tst.getNode12() == 1) {
                    if (Integer.parseInt(s.substring(117, 118)) == 1) { //Node12
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 13, col)))
                            Toolket.setCellValue(workbook, sheet, 13, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode13() != null && tst.getNode13() == 1) {
                    if (Integer.parseInt(s.substring(127, 128)) == 1) { //Node13
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 14, col)))
                            Toolket.setCellValue(workbook, sheet, 14, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                    //if (tst.getNode14() != null && tst.getNode14() == 1) {
                    if (Integer.parseInt(s.substring(137, 138)) == 1) { //Node14
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 15, col)))
                            Toolket.setCellValue(workbook, sheet, 15, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForStayTime);
                    }
                }

                //lcs = empl.getLifeCounseling();
                List<LifeCounseling> myLcs = cm.ezGetBy(
                        " Select Week, Node1, Node2, Node3, Node4, Node5, Node6, Node7, Node8, Node9, Node10, "
                                + "        Node11, Node12, Node13, Node14 "
                                + " From LifeCounseling Where ParentOid='" + empl.getOid() + "'");
                List myLcs2 = new ArrayList();

                colOffset = 1;
                col = 0;
                //for (LifeCounseling lc : lcs) {
                for (int y = 0; y < myLcs.size(); y++) {
                    myLcs2.add(myLcs.get(y));
                    String st = myLcs2.get(y).toString();
                    col = Integer.parseInt(st.substring(6, 7)) + colOffset;
                    //col = lc.getWeek() + colOffset;                                 
                    //if (lc.getNode1() != null && lc.getNode1() == 1) {
                    if (Integer.parseInt(st.substring(15, 16)) == 1) { //Node1
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 2, col)))
                            Toolket.setCellValue(workbook, sheet, 2, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode2() != null && lc.getNode2() == 1) {
                    if (Integer.parseInt(st.substring(24, 25)) == 1) { //Node2
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 3, col)))
                            Toolket.setCellValue(workbook, sheet, 3, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode3() != null && lc.getNode3() == 1) {
                    if (Integer.parseInt(st.substring(33, 34)) == 1) { //Node3
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 4, col)))
                            Toolket.setCellValue(workbook, sheet, 4, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode4() != null && lc.getNode4() == 1) {
                    if (Integer.parseInt(st.substring(42, 43)) == 1) { //Node4
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 5, col)))
                            Toolket.setCellValue(workbook, sheet, 5, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode5() != null && lc.getNode5() == 1) {
                    if (Integer.parseInt(st.substring(51, 52)) == 1) { //Node5
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 6, col)))
                            Toolket.setCellValue(workbook, sheet, 6, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode6() != null && lc.getNode6() == 1) {
                    if (Integer.parseInt(st.substring(60, 61)) == 1) { //Node6
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 7, col)))
                            Toolket.setCellValue(workbook, sheet, 7, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode7() != null && lc.getNode7() == 1) {
                    if (Integer.parseInt(st.substring(69, 70)) == 1) { //Node7
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 8, col)))
                            Toolket.setCellValue(workbook, sheet, 8, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode8() != null && lc.getNode8() == 1) {
                    if (Integer.parseInt(st.substring(78, 79)) == 1) { //Node8
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 9, col)))
                            Toolket.setCellValue(workbook, sheet, 9, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode9() != null && lc.getNode9() == 1) {
                    if (Integer.parseInt(st.substring(87, 88)) == 1) { //Node9
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 10, col)))
                            Toolket.setCellValue(workbook, sheet, 10, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode10() != null && lc.getNode10() == 1) {
                    if (Integer.parseInt(st.substring(97, 98)) == 1) { //Node10
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 11, col)))
                            Toolket.setCellValue(workbook, sheet, 11, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode11() != null && lc.getNode11() == 1) {
                    if (Integer.parseInt(st.substring(107, 108)) == 1) { //Node11
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 12, col)))
                            Toolket.setCellValue(workbook, sheet, 12, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode12() != null && lc.getNode12() == 1) {
                    if (Integer.parseInt(st.substring(117, 118)) == 1) { //Node12
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 13, col)))
                            Toolket.setCellValue(workbook, sheet, 13, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode13() != null && lc.getNode13() == 1) {
                    if (Integer.parseInt(st.substring(127, 128)) == 1) { //Node13
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 14, col)))
                            Toolket.setCellValue(workbook, sheet, 14, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                    //if (lc.getNode14() != null && lc.getNode14() == 1) {
                    if (Integer.parseInt(st.substring(137, 138)) == 1) { //Node14
                        if (StringUtils.isEmpty(Toolket.getCellValue(sheet, 15, col)))
                            Toolket.setCellValue(workbook, sheet, 15, col, "", fontSize12,
                                    HSSFCellStyle.ALIGN_CENTER, true, colorForLifeCounseling);
                    }
                }

            }
        }

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

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

    }
}