@SuppressWarnings("unchecked")
  private SeldDataInfo getSeldDataInfoByIndex(HttpServletRequest request) {

    HttpSession session = request.getSession(false);
    String index = Toolket.getSelectedIndexFromCookie(request, SELD_LIST_NAME);
    List seldDataList = (List) session.getAttribute(SELD_LIST_NAME);
    Matcher matcher = pattern.matcher(index);
    SeldDataInfo sdi = null;
    if (matcher.matches())
      sdi = (SeldDataInfo) seldDataList.get(Integer.parseInt(matcher.group(1)));

    return sdi;
  }
  @SuppressWarnings("unchecked")
  private List<SeldDataInfo> getSeldDataListByIndex(HttpServletRequest request) {

    List<SeldDataInfo> aList = new ArrayList<SeldDataInfo>();
    HttpSession session = request.getSession(false);
    String index = Toolket.getSelectedIndexFromCookie(request, SELD_LIST_NAME);
    List<SeldDataInfo> seldDataList = (List<SeldDataInfo>) session.getAttribute(SELD_LIST_NAME);
    for (SeldDataInfo sdi : seldDataList) {
      if (Toolket.isValueInCookie(sdi.getPosition().toString(), index)) {
        aList.add(sdi);
      }
    }

    return aList;
  }
Пример #3
0
  // Private Method Here ============================>>
  private List getInspectedSelectedList(HttpServletRequest request) {

    HttpSession session = request.getSession(false);
    String oids = Toolket.getSelectedIndexFromCookie(request, "StudInspected");
    List<Keep> keeps = (List<Keep>) session.getAttribute("StudInspectedList");
    List<Keep> selKeeps = new ArrayList<Keep>();
    Keep keep;

    StudAffairDAO dao = (StudAffairDAO) getBean("studAffairDAO");
    for (Iterator<Keep> keepIter = keeps.iterator(); keepIter.hasNext(); ) {
      keep = keepIter.next();
      if (Toolket.isValueInCookie(keep.getOid().toString(), oids)) {
        selKeeps.add(keep);
      }
    }
    return selKeeps;
  }
Пример #4
0
  /**
   * 下載
   *
   * @throws IOException
   */
  public ActionForward Download(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException {

    // Toolket.resetCheckboxCookie(response, "FN");
    // Toolket.resetCheckboxCookie(response, "FNList");
    // Toolket.resetCheckboxCookie(response, "FN_List");
    // Toolket.resetCheckboxCookie(response, "FA_List");

    Toolket.resetCheckboxCookie(response, "FNList");
    HttpSession session = request.getSession(false);
    CourseManager manager = (CourseManager) getBean("courseManager");
    // DynaActionForm aForm = (DynaActionForm) form;

    // UserCredential user = (UserCredential) session.getAttribute("Credential");
    // ActionMessages messages = new ActionMessages();

    String ids = Toolket.getSelectedIndexFromCookie(request, "FNList");
    String FL_id = ids.substring(1, ids.length() - 1);
    String FN_id =
        manager.ezGetString("Select FN_Oid From File_DataList Where Oid = '" + FL_id + "'");
    String SelType =
        manager.ezGetString("Select FN_Type From File_Name Where Oid = '" + FN_id + "'");
    String FD_ShareType =
        manager.ezGetString("Select ShareType From File_DataList Where Oid = '" + FL_id + "'");
    String FN_Share =
        manager.ezGetString("Select Share From File_Name Where Oid = '" + FN_id + "'");
    String URL =
        manager.ezGetString("Select Data_URL From File_DataList Where Oid = '" + FL_id + "'");
    String pristineData =
        manager.ezGetString("Select pristineData From File_DataList Where Oid = '" + FL_id + "'");

    manager.DownloadFileFTPServer(
        URL, pristineData, session.getServletContext().getRealPath("/UserFiles/").toString());

    try {
      response.setContentType("application/octet-stream; charset=utf-8");
      String path = session.getServletContext().getRealPath("/UserFiles/") + "/" + pristineData;
      File file = new File(path);

      if (!file.exists()) {
        if (!file.exists()) {
          file = new File(path);
        }
      }

      try {
        String realName = java.net.URLEncoder.encode(file.getName(), "utf-8");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + realName + "\"");
        if (file.exists()) {
          FileInputStream in = new FileInputStream(file);
          OutputStream out = response.getOutputStream();
          byte[] b = new byte[100];
          int len;

          while ((len = in.read(b)) > 0) {
            out.write(b, 0, len);
          }

          if (in != null) {
            in.close();
          }

          if (out != null) {
            out.close();
          }

          file.delete();
        }
      } catch (Exception e) {
        System.out.println(path + " generate errors!");
        e.printStackTrace();
      }

    } catch (Exception e) {

      response.setHeader("Content-Disposition", "attachment;filename=ProjectReport.doc");
      response.setContentType("application/vnd.ms-word; charset=UTF-8");
      PrintWriter out = response.getWriter();

      out.println("<html>");
      out.println("<body>");
      out.println("下載檔案方式不正確!");
      out.println("</body>");
      out.println("</html>");

      out.close();
    }
    Toolket.resetCheckboxCookie(response, "FNList");
    return mapping.findForward("File_OutDownload");
    // return nul
    // System.out.println(session.getServletContext().getRealPath("/UserFiles/")+"/"+pristineData)

  }