Package org.jboss.fresh.vfs

Examples of org.jboss.fresh.vfs.VFS


      log.debug("done");
      return;
    }

    Shell sh = getShell();
    VFS vfs = sh.getVFS();
    String to = params[0];
    FileName fname = new FileName(to);
    if (fname.isRelative())
      fname = new FileName(sh.getEnvProperty("PWD")).absolutize(fname);

//    System.out.println("****");
//    System.out.println("****  fname: " + fname);
//    System.out.println("****");
//    if(vfs.exists(null, fname, false)) {
//      sh._setPWD(fname.toString());
//    }


    FileInfo info = vfs.getFileInfo(null, fname, false);
    if (info == null || !info.isDirectory()) {
      if (canThrowEx()) {
        throw new RuntimeException("Can't find the path specified: " + fname + "\n\n");
      } else {
        out.put("Can't find the path specified: " + fname + "\n\n", 10000L);
View Full Code Here


      log.debug("done");
      return;
    }

    BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
    VFS vfs = shell.getVFS();

    FileName pwd = new FileName(shell.getEnvProperty("PWD"));
    String out = OUTPUT_STRING;
    FileName target = null;
    Collection result = new HashSet();


    if (params.length <= 2) {
      for (int i = 0; i < params.length; i++) {
        String param = params[i];

        if (param.startsWith(OUTPUT))
          out = param.substring(OUTPUT.length());

        else {
          FileName path = new FileName(param);
          if (path.isRelative())
            path = pwd.absolutize(path);

          target = path;
        }
      }
    }

    if ((params.length >= 3) || (target == null)) {
      if (canThrowEx()) {
        throw new RuntimeException("Usage: lslns [-out=string|filename|fileinfo] TARGET");
      } else {
        PrintWriter pw = new PrintWriter(new BufferWriter(getStdOut()));
        pw.println("Usage: lslns [-out=string|filename|fileinfo] TARGET");
      }
    } else {
      Collection links = vfs.getLinks(shell.getUserCtx(), target, true);
      Iterator it = links.iterator();

      if (out.equals(OUTPUT_STRING)) {
        result = new LinkedList();
View Full Code Here

        return newID();
    }


    public VFS getVFS() {
        VFS vfs = null;
        try {
            RegistryContext ctx = new RegistryContext();
            vfs = (VFS) ctx.lookup(vfsName);
        } catch (NamingException ex) {
            log.error(ex.getMessage(), ex);
View Full Code Here

    public Shell startSession(UserCtx uctx, boolean interactive) {
        // create new shell object
        // assign id to it
        // assign uctx to it
        String id = newID();
        VFS vfs = getVFS();
        ShellImpl shell = new ShellImpl(id, interactive, this, uctx, vfs);
        shell.setRegistry(registry);

        // put it in shellmap
        shellmap.put(id, shell);
View Full Code Here

      out.close();
      log.debug("done");
      return;
    }

    VFS vfs = shell.getVFS();
    FileName pwd = new FileName(shell.getEnvProperty("PWD"));
    FileName path = null;
    boolean add = false;
    HashMap attrs = new HashMap();

    for (int i = 0; i < params.length; i++) {
      String param = params[i];

      if ((i == 0) && param.equals(ADD))
        add = true;

      else if (add && (i == 1) || (i == 0)) {
        FileName filepath = new FileName(param);
        if (filepath.isRelative())
          filepath = pwd.absolutize(filepath);

//        filepath = vfs.resolve(shell.getUserCtx(), filepath, true);
        if (vfs.exists(shell.getUserCtx(), filepath, true)) {
          path = filepath;
        } else {
          if (canThrowEx()) {
            throw new RuntimeException(filepath + ": Path does not exist!");
          } else {
            out.println(filepath + ": Path does not exist!");
          }
        }

      } else {
        String name = param;
        String value = null;
        if (params.length > ++i)
          value = params[i];

        attrs.put(name, value);
      }
    }

    if (path == null) {
      out.println("Usage: setattr [-ex] [-a] FILE NAME VALUE {NAME VALUE}");
      out.println("       -a = add attributes insted of set");

    } else {
      FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
      if (add) {
        HashMap oldAttrs = info.getAttributes();
        oldAttrs.putAll(attrs);
      } else
        info.setAttributes(attrs);

      vfs.updateFile(shell.getUserCtx(), info);
    }

    out.close();

    log.debug("done");
View Full Code Here

    }
   

    String path = params[0];
    String jndi = params[1];
    VFS vfs = null;

    try {
      vfs = (VFS) ctx.lookup(jndi);
    } catch(NameNotFoundException ex) {
      error("No VFS bound at: " + jndi);
View Full Code Here

      return;
    }

    try {
      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
      VFS vfs = shell.getVFS();
      FileName pwd = new FileName(shell.getEnvProperty("PWD"));

      LinkedList paths = new LinkedList();
      boolean force = false;
      boolean errors = false;

      for (int i = 0; i < params.length; i++) {
        String param = params[i];
        log.debug("param:" + param);
        if ((i == 0) && param.equals(FORCE))
          force = true;
        else {
          FileName path = new FileName(param);
          if (path.isRelative())
            path = pwd.absolutize(path);

          //path = vfs.resolve(shell.getUserCtx(), path, true);

          if (!vfs.exists(shell.getUserCtx(), path, true) && i != params.length - 1) {
            if (canThrowEx()) {
              throw new RuntimeException(param + ": Path already exists!");
            } else {
              out.println(param + ": Path does not exists!");
              errors = true;
            }
            break;
          } else
            paths.add(path);
        }
      }

      if ((paths.size() <= 1) || (errors && !force)) {
        out.println("Usage: mv FILES DEST_DIR");
        out.println("       mv FILE DEST_FILE");

      } else {
        FileName lastPath = (FileName) paths.removeLast();
        boolean lastPathXsists = vfs.exists(shell.getUserCtx(), lastPath, true);

        if (lastPathXsists) {
          FileInfo lastInfo = vfs.getFileInfo(shell.getUserCtx(), lastPath, false);

          if (lastInfo.isDirectory() && (force || !errors)) {
            log.debug("1.Moving multiple files to dir.");
            Iterator it = paths.iterator();
            while (it.hasNext()) {
              FileName path = (FileName) it.next();
              FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
              if (move(info, lastPath.absolutize(path.getName()), force, vfs, out) && !force)
                return;
            }
          } else if ((paths.size() == 1) && force) {
            log.debug("1.Moving file (overwrite).");
            FileName path = (FileName) paths.getFirst();
            FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
            if (move(info, lastPath, force, vfs, out) && !force)
              return;

          } else {
            if (canThrowEx()) {
              throw new RuntimeException(lastPath + ": Destination path is not a directory!");
            } else {
              out.println(lastPath + ": Destination path is not a directory!");
            }
          }

        } else if (paths.size() == 1) {
          log.debug("1.Moving file.");
          FileName path = (FileName) paths.getFirst();
          FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
          if (move(info, lastPath, force, vfs, out) && !force)
            return;

        } else {
          if (canThrowEx()) {
View Full Code Here

      log.debug("done");
      return;
    }

    PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
    VFS vfs = shell.getVFS();
    FileName pwd = new FileName(shell.getEnvProperty("PWD"));

    List paths = new LinkedList();

    for (int i = 0; i < params.length; i++) {

      String param = params[i];

      FileName path = new FileName(param);
      if (path.isRelative())
        path = pwd.absolutize(path);

//      path = vfs.resolve(shell.getUserCtx(), path, true);

      log.debug("FREAKING PATH = " + path);
      if (vfs.exists(shell.getUserCtx(), path, true)) {
        vfs.remove(shell.getUserCtx(), path, true);
        out.println(param + ": Path and all children removed!");
      } else {
        if (canThrowEx()) {
          throw new RuntimeException(param + ": Path does not exist! Cannot delete inexisting path!");
        } else {
View Full Code Here

      return;
    }

    PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));

    VFS vfs = shell.getVFS();
    FileName pwd = new FileName(shell.getEnvProperty("PWD"));

    boolean direct = false;
    LinkedList paths = new LinkedList();

    for (int i = 0; i < params.length; i++) {
      String param = params[i];

      if (!direct && param.equals(DIRECT))
        direct = true;

      else {
        FileName filepath = new FileName(param);
        if (filepath.isRelative())
          filepath = pwd.absolutize(filepath);

//        filepath = vfs.resolve(shell.getUserCtx(), filepath, true);
        if (vfs.exists(shell.getUserCtx(), filepath, true)) {
          paths.add(filepath);
        } else {
          if (canThrowEx()) {
            throw new NoSuchFileException("Path does not exist: " + filepath);
          } else {
            out.println("Path does not exist: " + filepath);
          }
        }
      }
    }

    if (paths.isEmpty()) {
      if (canThrowEx()) {
        throw new Exception("No path specified.");
      } else {
        out.println("Usage: info [-d] FILES");
        out.println("       -d = direct (links are not resolved)");
      }
    } else {
      Iterator it = paths.iterator();
      while (it.hasNext()) {
        FileName file = (FileName) it.next();

        FileInfo info = vfs.getFileInfo(shell.getUserCtx(), file, direct);
        log.debug("Got info: " + info);

        out.println(info);
      }
    }
View Full Code Here

      return;
    }

    try {
      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
      VFS vfs = shell.getVFS();
      FileName pwd = new FileName(shell.getEnvProperty("PWD"));

      LinkedList paths = new LinkedList();
      boolean force = false;
      boolean errors = false;

      for (int i = 0; i < params.length; i++) {
        String param = params[i];

        if ((i == 0) && param.equals(FORCE))
          force = true;

        else {
          FileName path = new FileName(param);
          if (path.isRelative())
            path = pwd.absolutize(path);

          //      path = vfs.resolve(shell.getUserCtx(), path, true);

          if (!vfs.exists(shell.getUserCtx(), path, true) && i != params.length - 1) {
            out.println(param + ": Path does not exists!");
            errors = true;
            break;
          } else
            paths.add(path);
        }
      }

      if ((paths.size() <= 1) || (errors && !force)) {
        out.println("Usage: cp FILES DEST_DIR");
        out.println("       cp FILE DEST_FILE");

      } else {
        FileName lastPath = (FileName) paths.removeLast();
        boolean lastPathXsists = vfs.exists(shell.getUserCtx(), lastPath, true);

        if (lastPathXsists) {
          FileInfo lastInfo = vfs.getFileInfo(shell.getUserCtx(), lastPath, false);

          if (lastInfo.isDirectory() && (force || !errors)) {
            log.debug("1.Copying multiple files to dir.");
            Iterator it = paths.iterator();
            while (it.hasNext()) {
              FileName path = (FileName) it.next();
              FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
              if (copy(info, lastPath.absolutize(path.getName()), force, vfs, out) && !force) {
                log.debug("done");
                return;
              }
            }

          } else if ((paths.size() == 1) && force) {
            log.debug("1.Copying file (overwrite).");
            FileName path = (FileName) paths.getFirst();
            FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
            if (copy(info, lastPath, force, vfs, out) && !force) {
              log.debug("done");
              return;
            }

          } else
            out.println(lastPath + ": Destination path is not a directory!");

        } else if (paths.size() == 1) {
          log.debug("1.Copying file");
          FileName path = (FileName) paths.getFirst();
          FileInfo info = vfs.getFileInfo(shell.getUserCtx(), path, true);
          if (copy(info, lastPath, force, vfs, out) && !force) {
            log.debug("done");
            return;
          }
View Full Code Here

TOP

Related Classes of org.jboss.fresh.vfs.VFS

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.