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();
    }
  }
 private File getFile(String path) {
   return new File(WebApps.getCurrent().getRealPath(path));
 }
示例#3
0
 /**
  * This method will make the given component instance become a ZK Composite(an ZK MVC Controller).
  * <br>
  * If the instance's class(Composite class) has {@link Composite} annotation, this method will
  * based on the given meta to generate content children.<br>
  * If there's no proper zuml content provided, this method will assume the application developer
  * will assemble the content Component tree themselves.
  *
  * @since ZK 6.0
  * @param composite the composite instance that need to be processed
  * @param args ZK parser Context variables, the value inside can be accessed by EL[arg.varName] in
  *     zuml.(can be null)
  */
 public static void doCompose(Component composite, Map args) {
   CompositeDef def = DEF_CACHE.get(composite.getClass(), WebApps.getCurrent());
   doCompose(def, composite, composite, args);
 }