示例#1
0
 public void listener(FileUploadEvent event) throws Exception {
   UploadedFile item = event.getUploadedFile();
   UploadedImage file = new UploadedImage();
   file.setLength(item.getData().length);
   file.setName(item.getName());
   file.setData(item.getData());
   files.add(file);
 }
示例#2
0
  public void fileUploadListener(FileUploadEvent fue) {

    UploadedFile file = fue.getUploadedFile();

    logger.info("File Uploaded successfully");
    logger.info("File Name : {}", file.getName());
    logger.info("File Size : {}", file.getSize());

    files.add(file);
  }
示例#3
0
  /**
   * File upload listener
   *
   * @param event
   * @throws Exception
   */
  public void listener(FileUploadEvent event) throws Exception {
    UploadedFile file = event.getUploadedFile();

    try {

      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(file.getInputStream());
      doc.getDocumentElement().normalize();

      processUsers(doc.getElementsByTagName("users"));
      processAuthors(doc.getElementsByTagName("authors"));
      processPublishers(doc.getElementsByTagName("publishers"));
      processGenres(doc.getElementsByTagName("genres"));
      processBooks(doc.getElementsByTagName("books"));
      processExemplars(doc.getElementsByTagName("exemplars"));
      processBookings(doc.getElementsByTagName("bookings"));
      processBorrows(doc.getElementsByTagName("borrows"));

      userMgr.flush();
      bookMgr.flush();
      authorMgr.flush();
      bookingMgr.flush();
      exemplarMgr.flush();
      genreMgr.flush();
      publisherMgr.flush();
      borrowMgr.flush();

      userMgr.clear();
      bookMgr.clear();
      authorMgr.clear();
      bookingMgr.clear();
      exemplarMgr.clear();
      genreMgr.clear();
      publisherMgr.clear();
      borrowMgr.clear();

    } catch (Exception e) {
      FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Import se nezdařil."));
      e.printStackTrace(System.out);

      return;
    }

    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Import proběhl úspěšně."));
  }