Package org.sd_network.vfsshell

Examples of org.sd_network.vfsshell.Session


    // Implements to CommandHandler.
   
    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String fileName = commandLine.getArgs()[0];
        String parentFileID = session.getCurrentDirectory().getID();

        try {
            vfsService.createFile(sessionID, parentFileID, fileName);
        } catch (SessionException e) {
            session.clearSessionID();
            throw new IllegalStateException("ERROR: session time out.");
        } catch (VfsIOException e) {
            System.out.println("ERROR: " + e.getMessage());
        }
    }
View Full Code Here


    // Implements to CommandHandler.
   
    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String dirName = commandLine.getArgs()[0];
        VfsFile parent = session.getCurrentDirectory();

        try {
            VfsFile targetFile = null;
            if (dirName.equals("..")) {
                if (parent.getParentID().equals("-1"))
                    return;
                targetFile = vfsService.getVfsFile(
                        sessionID, parent.getParentID());
            } else {
                targetFile = vfsService.getVfsFile(
                        sessionID, parent.getID(), dirName);
            }
            if (targetFile == null) {
                System.out.println(
                        "ERROR: [" + dirName + "] not found.");
                return;
            }
            if (targetFile.getType() != VfsFile.FileType.DIRECTORY) {
                System.out.println(
                        "ERROR: [" + dirName + "] is not directory.");
                return;
            }
            session.setCurrentDirectory(targetFile);
        } catch (SessionException e) {
            session.clearSessionID();
            throw new IllegalStateException("ERROR: Session time out.");
        }
    }
View Full Code Here

    // Implements to CommandHandler.
   
    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        // parse command line parameters.
        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        // retrives command line parameters.
        boolean isAdmin = commandLine.hasOption("a");
        String[] buf = commandLine.getArgs();
        if (buf.length == 0) {
            printUsage("ERROR: Login name not found.");
            return;
        }

        String loginName = buf[0];
        String password = null;
        while (true) {
            String password1 = ConsoleUtil.readRequiredData("input password");
            if (password1 == null || password1.trim().length() == 0) {
                System.out.println("BAD PASSWORD. ");
                continue;
            }
            String password2 = ConsoleUtil.readRequiredData("input confirm");
            if (!password1.equals(password2)) {
                System.out.println("UNMATCH PASSWORD.");
                continue;
            }
            password = password1;
            break;
        }

        try {
            vfsService.addUser(sessionID, loginName, password, isAdmin);
            System.out.println("User [" + loginName + "] added.");
        } catch (PermissionException e) {
            System.out.println("ERROR: add user failed. (" + e.getMessage() + ")");
        } catch (SessionException e) {
            session.clearSessionID();
            System.out.println("ERROR: Session time out.");
        }
    }
View Full Code Here

    // Implements to CommandHandler.
   
    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        if (session.getSessionID() != null) {
            System.out.println("You must logout from previous session.");
            return;
        }

        // parse command line parameters.
        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(new Options(), args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        // retrive login name.
        // If login_name contains in command line, retrive from command line,
        // otherwise, get it from console.
        String loginName = null;
        String[] buf = commandLine.getArgs();
        if (buf.length > 0)
            loginName = buf[0];
        else
            loginName = ConsoleUtil.readRequiredData("login name");

        // get password from console.
        String password = ConsoleUtil.readRequiredData("password");

        try {
            VfsService vfsService = VfsContext.getService();
            session.setSessionID(vfsService.login(loginName, password));
            String sessionID = session.getSessionID();
            VfsFile home = vfsService.getVfsFile(sessionID, "-1", "Home");
            if (home == null)
                throw new IllegalStateException(
                        "User home directory not found.");
            session.setCurrentDirectory(home);
            System.out.println("SessionID = " + session.getSessionID());
            System.out.println("Logged in.");
        } catch (AuthenticationException e) {
            System.out.println("login failed. (" + e.getMessage() + ")");
        } catch (SessionException e) {
            throw new IllegalStateException(
View Full Code Here

    // Implements to CommandHandler.
   
    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        VfsFile curDir = session.getCurrentDirectory();

        try {
            VfsFile parent = curDir;
            LinkedList<VfsFile> pathList = new LinkedList<VfsFile>();
            while (!parent.getParentID().equals("-1")) {
                pathList.addFirst(parent);
                String parentID = parent.getParentID();
                parent = vfsService.getVfsFile(sessionID, parentID);
                if (parent == null)
                    throw new IllegalStateException(
                            "ERROR: parent directory not found.");
            }
            StringBuffer sb = new StringBuffer();
            for (int idx = 0; idx < pathList.size(); idx++) {
                sb.append("/").append(pathList.get(idx).getName());
            }
            if (sb.length() > 0)
                System.out.println(sb.toString());
            else
                System.out.println("/");
        } catch (SessionException e) {
            session.clearSessionID();
            throw new IllegalStateException("ERROR: Session time out.");
        }
    }
View Full Code Here

    // Implements to CommandHandler.

    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String dirName = commandLine.getArgs()[0];
        String parentFileID = session.getCurrentDirectory().getID();

        try {
            VfsFile targetFile =
                vfsService.getVfsFile(sessionID, parentFileID, dirName);
            if (targetFile == null) {
                System.out.println("ERROR: [" + dirName + "] not found.");
                return;
            }
            if (targetFile.getType() != VfsFile.FileType.DIRECTORY) {
                System.out.println(
                        "ERROR: [" + dirName + "] is not directory.");
                return;
            }
            vfsService.deleteObject(sessionID, targetFile.getID());
        } catch (VfsIOException e) {
            System.out.println("ERROR: " + e.getMessage());
        } catch (SessionException e) {
            session.clearSessionID();
            System.out.println("ERROR: Session time out.");
        }
    }
View Full Code Here

        _options = buf;
    };

    public void execute(String[] args) {
        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine cl = null;
        try {
            cl = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        if (cl.getArgs() == null || cl.getArgs().length != 2) {
            printUsage("ERROR: require local_file_path and vfs_file_name");
            return;
        }

        // get local file path.
        File file = new File(cl.getArgs()[0]);
        if (!file.exists()) {
            System.out.println("ERROR: the file not found.");
            return;
        }

        if (!file.isFile()) {
            System.out.println("ERROR: the file not file.");
            return;
        }

        if (!file.canRead()) {
            System.out.println("ERROR: the file access denied.");
            return;
        }

        SystemInfo systemInfo = vfsService.getSystemInfo();
        String parentFileID = session.getCurrentDirectory().getID();
        String fileSessionID = null;
        try {
            VfsFile vfsFile = vfsService.createFile(
                    sessionID, parentFileID, cl.getArgs()[1]);
View Full Code Here

    // Implements to CommandHandler.

    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine commandLine = null;
        try {
            commandLine = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        String dirName = commandLine.getArgs()[0];
        String parentFileID = session.getCurrentDirectory().getID();

        try {
            vfsService.createDirectory(sessionID, parentFileID, dirName);
        } catch (VfsIOException e) {
            System.out.println("ERROR: " + e.getMessage());
        } catch (SessionException e) {
            session.clearSessionID();
            System.out.println("ERROR: Session time out.");
        }
    }
View Full Code Here

        _options = buf;
    };

    public void execute(String[] args) {
        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null) {
            System.out.println("ERROR: You must login.");
            return;
        }
        VfsService vfsService = VfsContext.getService();

        CommandLine cl = null;
        try {
            cl = new PosixParser().parse(_options, args);
        } catch (ParseException e) {
            printUsage(e.getMessage());
            return;
        }

        if (cl.getArgs() == null || cl.getArgs().length != 2) {
            printUsage("ERROR: require local_file_path and vfs_file_name");
            return;
        }

        // check file path.
        File file = new File(cl.getArgs()[1]);
        if (file.exists()) {
            System.out.println("ERROR: the local file already exists.");
            return;
        }

        SystemInfo systemInfo = vfsService.getSystemInfo();
        String parentFileID = session.getCurrentDirectory().getID();
        String fileSessionID = null;
        try {

            VfsFile vfsFile = vfsService.getVfsFile(
                    sessionID, parentFileID, cl.getArgs()[0]);
View Full Code Here

    // Implements to CommandHandler.
   
    public void execute(String[] args) {

        // check session.
        Session session = Session.getInstance();
        String sessionID = session.getSessionID();
        if (sessionID == null)
            System.out.println("You have already logged out.");

        // logout.
        VfsService vfsService = VfsContext.getService();
        try {
            vfsService.logout(sessionID);
        } catch (VfsIOException e) {
            System.out.println("ERROR: some file session close failed.");
        }
        session.clearSessionID();

        System.out.println("You were logged out.");
    }
View Full Code Here

TOP

Related Classes of org.sd_network.vfsshell.Session

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.