Ejemplo n.º 1
0
 public void save(String name, String source, boolean isDirectory) {
   DbTpl bean = new DbTpl();
   bean.setId(name);
   if (!isDirectory && source == null) {
     source = "";
   }
   bean.setSource(source);
   bean.setLastModified(System.currentTimeMillis());
   bean.setDirectory(isDirectory);
   dao.save(bean);
   createParentDir(name);
 }
Ejemplo n.º 2
0
 public int delete(String[] names) {
   int count = 0;
   DbTpl tpl;
   for (String name : names) {
     tpl = dao.deleteById(name);
     count++;
     if (tpl.isDirectory()) {
       count += deleteByDir(tpl.getName());
     }
   }
   return names.length;
 }
Ejemplo n.º 3
0
 private void createParentDir(String name) {
   String[] dirs = DbTpl.getParentDir(name);
   DbTpl dirTpl;
   Tpl parentDir;
   for (String dir : dirs) {
     parentDir = get(dir);
     if (parentDir != null && !parentDir.isDirectory()) {
       throw new ParentDirIsFileExceptioin("parent directory is a file: " + parentDir.getName());
     } else if (parentDir == null) {
       dirTpl = new DbTpl();
       dirTpl.setId(dir);
       dirTpl.setDirectory(true);
       dao.save(dirTpl);
     }
   }
 }
Ejemplo n.º 4
0
 public void rename(String orig, String dist) {
   DbTpl tpl = dao.deleteById(orig);
   if (tpl == null) {
     return;
   }
   dao.deleteById(orig);
   String name = StringUtils.replace(tpl.getId(), orig, dist, 1);
   save(name, tpl.getSource(), tpl.isDirectory());
   createParentDir(name);
   if (tpl.isDirectory()) {
     List<DbTpl> list = dao.getStartWith(orig + "/");
     for (DbTpl t : list) {
       dao.deleteById(t.getId());
       name = StringUtils.replace(t.getId(), orig, dist, 1);
       save(name, t.getSource(), t.isDirectory());
     }
   }
 }
Ejemplo n.º 5
0
 public void update(String name, String source) {
   DbTpl entity = (DbTpl) get(name);
   entity.setSource(source);
   entity.setLastModified(System.currentTimeMillis());
 }