public static String suggestPdfName(Book book) {
   String bn = book.getBookName();
   String ext = ".pdf";
   int i = bn.lastIndexOf('.');
   if (i == 0) {
     bn = "book";
   } else if (i > 0) {
     bn = bn.substring(0, i);
   }
   return bn + ext;
 }
  @Override
  public boolean process(UserActionContext ctx) {
    try {
      Book book = ctx.getBook();
      save(book);
      Clients.showNotification("saved " + book.getBookName(), "info", null, null, 2000, true);

    } catch (Exception e) {
      e.printStackTrace();
    }
    return true;
  }
  /** Gets suggested file name of a book */
  public static String suggestFileName(Book book) {
    String bn = book.getBookName();
    BookType type = book.getType();

    String ext = type == BookType.XLS ? ".xls" : ".xlsx";
    int i = bn.lastIndexOf('.');
    if (i == 0) {
      bn = "book";
    } else if (i > 0) {
      bn = bn.substring(0, i);
    }
    return bn + ext;
  }
  public void save(Book book) throws IOException {
    String savingPath = WebApps.getCurrent().getRealPath("/WEB-INF/books/") + File.separator;
    File targetFile = new File(savingPath + book.getBookName());
    FileOutputStream fos = null;
    try {
      // write to temporary file first to avoid write error damage original file
      File temp = File.createTempFile("temp", targetFile.getName());
      fos = new FileOutputStream(temp);
      Exporters.getExporter().export(book, fos);

      fos.close();
      fos = null;

      copy(temp, targetFile);
      temp.delete();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (fos != null) fos.close();
    }
  }