Example #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);
 }
Example #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);
  }
 public void clearFile() {
   System.out.println("Files to clear: " + this.clearedFile);
   Iterator<UploadedFile> i = files.iterator();
   while (i.hasNext()) {
     UploadedFile file = i.next();
     if (file.getName().equals(this.clearedFile)) {
       i.remove();
       break;
     }
   }
 }
  public void release() {
    super.release();

    if (uploadedFiles != null) {
      for (UploadedFile uploadedFile : uploadedFiles) {
        try {
          uploadedFile.delete();
        } catch (IOException e) {
          LOGGER.error(e.getMessage(), e);
        }
      }
    }
  }
  /**
   * 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ě."));
  }