if (args.length == 0) return true;
    protected boolean process(String line) {        if (startGUI)            frame.setPath(path);        String args[];        if (line.startsWith("find")) {            args = new String[2];            args[0] = "find";            args[1] = line.substring(5);        } else {            StreamTokenizer tok = new StreamTokenizer(new StringReader(line));            tok.resetSyntax();            tok.wordChars(0x21, 0x7FFF);            tok.quoteChar('"');            tok.whitespaceChars(0x20, 0x20);                        List argList = new ArrayList(3);            // int i = 0;            int token;            try {                while ((token = tok.nextToken()) != StreamTokenizer.TT_EOF) {                    if (token == StreamTokenizer.TT_WORD || token == '"') {                        argList.add(tok.sval);                    }                }            } catch (IOException e) {                System.err.println("Could not parse command line.");                return true;            }            args = new String[argList.size()];            argList.toArray(args);        }        String newPath = path;        try {            if (args[0].equalsIgnoreCase("ls")) {                // list collection contents                getResources();                if (properties.getProperty("permissions").equals("true")) {                    for (int i = 0; i < resources.length; i++)                        messageln(resources[i]);                } else {                    StringBuffer buf;                    for (int i = 0; i < resources.length; i++) {                        buf = new StringBuffer();                        int k = 0;                        for (int j = 0; i < resources.length && j < 5; i++, j++) {                            buf.append(resources[i] + '\t');                            k = j;                        }                        if (k == 4 && i < resources.length)                            i--;                        messageln(buf.toString());                    }                }            } else if (args[0].equalsIgnoreCase("cd")) {                // change current collection                completitions.clear();                String tempPath = newPath;                Collection temp;                //TODO : use dedicated function in XmldbURI                if (args.length < 2 || args[1] == null) {                    tempPath = DBBroker.ROOT_COLLECTION;                    temp = DatabaseManager.getCollection(                            properties.getProperty("uri") + DBBroker.ROOT_COLLECTION,                             properties.getProperty("user"),                             properties.getProperty("password"));                } else {                    //TODO : use dedicated function in XmldbURI                    if (args[1].equals("..")) {                        tempPath = newPath.equals(DBBroker.ROOT_COLLECTION) ?                         DBBroker.ROOT_COLLECTION :                         tempPath.substring(0, newPath.lastIndexOf("/"));                        if (tempPath.length() == 0)                            tempPath = DBBroker.ROOT_COLLECTION;                    } else if (args[1].startsWith("/"))                        tempPath = args[1];                    else                        tempPath = tempPath + "/" + args[1];                                        XmldbURI uri = new XmldbURI(properties.getProperty("uri"), tempPath);                                       temp = DatabaseManager.getCollection(                    		uri.toString(),                     		properties.getProperty("user"),                            properties.getProperty("password"));                }                if (temp != null) {                    current = temp;                    newPath = tempPath;                    if (startGUI)                        frame.setPath(newPath);                } else {                    messageln("no such collection.");                }                getResources();            } else if (args[0].equalsIgnoreCase("cp")) {                if (args.length != 3) {                    messageln("cp requires two arguments.");                    return true;                }                copy(args[1], args[2]);                getResources();                            } else if (args[0].equalsIgnoreCase("edit")) {                if (args.length == 2) {                    editResource(args[1]);                } else {                    messageln("Please specify a resource.");                }            } else if (args[0].equalsIgnoreCase("get")) {                if (args.length < 2) {                    System.err.println("wrong number of arguments.");                    return true;                }                Resource res = retrieve(args[1]);                // display document                if (res != null) {                    String data;                    if (res.getResourceType().equals("XMLResource"))                        data = (String) res.getContent();                    else                        data = new String((byte[]) res.getContent());                    if (startGUI) {                        frame.setEditable(false);                        frame.display(data);                        frame.setEditable(true);                    } else {                        String content = data;                        more(content);                    }                }                return true;            } else if (args[0].equalsIgnoreCase("find")) {                // search                if (args.length < 2) {                    messageln("no query argument found.");                    return true;                }                messageln(args[1]);                long start = System.currentTimeMillis();                result = find(args[1]);                if (result == null)                    messageln("nothing found");                else                    messageln("found " + result.getSize() + " hits in "                            + (System.currentTimeMillis() - start) + "ms.");                                nextInSet = 1;                            } else if (args[0].equalsIgnoreCase("run")) {                if (args.length < 2) {                    messageln("please specify a query file.");                    return true;                }                try {                    BufferedReader reader = new BufferedReader(new FileReader(                            args[1]));                    StringBuffer buf = new StringBuffer();                    String nextLine;                    while ((nextLine = reader.readLine()) != null) {                        buf.append(nextLine);                        buf.append('\n');                    }                    args[1] = buf.toString();                    long start = System.currentTimeMillis();                    result = find(args[1]);                    if (result == null)                        messageln("nothing found");                    else                        messageln("found " + result.getSize() + " hits in "                                + (System.currentTimeMillis() - start) + "ms.");                                        nextInSet = 1;                } catch (Exception e) {                    messageln("An error occurred: " + e.getMessage());                }            } else if (args[0].equalsIgnoreCase("show")) {                // show search results                if (result == null) {                    messageln("no result set.");                    return true;                }                try {                    int start = nextInSet;                    int count = 1;                    if (args.length > 1)                        start = Integer.parseInt(args[1]);                                        if (args.length > 2)                        count = Integer.parseInt(args[2]);                                        final int s = (int) result.getSize();                    if (start < 1 || start > s) {                        messageln("start offset out of range");                        return true;                    }                    --start;                    if (start + count > s)                        count = s - start;                                        nextInSet = start + count + 1;                    for (int i = start; i < start + count; i++) {                        Resource r = result.getResource(i);                        if (startGUI)                            frame.display((String) r.getContent());                        else                            more((String) r.getContent());                    }                    messageln("displayed items " + (start + 1) + " to "                            + (start + count) + " of " + result.getSize());                } catch (NumberFormatException nfe) {                    messageln("wrong argument");                    return true;                }                            } else if (args[0].equalsIgnoreCase("mkcol")) {                // create collection                if (args.length < 2) {                    messageln("missing argument.");                    return true;                }                CollectionManagementService mgtService = (CollectionManagementService) current                        .getService("CollectionManagementService", "1.0");                Collection newCollection = mgtService.createCollection(args[1]);                if (newCollection == null)                    messageln("could not create collection.");                else                    messageln("created collection.");                                // re-read current collection                current = DatabaseManager.getCollection(properties                        .getProperty("uri")                        + path, properties.getProperty("user"), properties                        .getProperty("password"));                getResources();                            } else if (args[0].equalsIgnoreCase("put")) {                // put a document or directory into the database                if (args.length < 2) {                    messageln("missing argument.");                    return true;                }                boolean r = parse(args[1]);                getResources();                return r;                            } else if (args[0].equalsIgnoreCase("blob")) {                // put a document or directory into the database                if (args.length < 2) {                    messageln("missing argument.");                    return true;                }                storeBinary(args[1]);                getResources();                            } else if (args[0].equalsIgnoreCase("rm")) {                // remove document                if (args.length < 2) {                    messageln("missing argument.");                    return true;                }                                remove(args[1]);                                // re-read current collection                current = DatabaseManager.getCollection(properties                        .getProperty("uri")                        + path, properties.getProperty("user"), properties                        .getProperty("password"));                getResources();                            } else if (args[0].equalsIgnoreCase("rmcol")) {                // remove collection                if (args.length < 2) {                    messageln("wrong argument count.");                    return true;                }                rmcol(args[1]);                // re-read current collection                current = DatabaseManager.getCollection(properties                        .getProperty("uri")                        + path, properties.getProperty("user"), properties                        .getProperty("password"));                getResources();            } else if (args[0].equalsIgnoreCase("adduser")) {                if (args.length < 2) {                    System.err.println("Usage: adduser name");                    return true;                }                if (startGUI) {                    messageln("command not supported in GUI mode. Please use the \"Edit users\" menu option.");                    return true;                }                try {                    UserManagementService mgtService = (UserManagementService) current                            .getService("UserManagementService", "1.0");                                        String p1;                    String p2;                    while (true) {                        p1 = console.readLine("password: ", new Character('*'));                        p2 = console.readLine("re-enter password: ", new Character('*'));                        if (p1.equals(p2)) break;                        System.out.println("\nentered passwords differ. Try again...");                                            }                    String home = console.readLine("home collection [none]: ");                    User user = new User(args[1], p1);                    if (home != null && home.length() > 0)                        user.setHome(home);                    String groups = console.readLine("enter groups: ");                    StringTokenizer tok = new StringTokenizer(groups, " ,");                    String group;                    while (tok.hasMoreTokens()) {                        group = tok.nextToken();                        if (group.length() > 0)                            user.addGroup(group);                    }                                        mgtService.addUser(user);                    System.out.println("user " + user + " created.");                } catch (Exception e) {                    System.out.println("ERROR: " + e.getMessage());                    e.printStackTrace();                }            } else if (args[0].equalsIgnoreCase("users")) {                UserManagementService mgtService = (UserManagementService) current                        .getService("UserManagementService", "1.0");                User users[] = mgtService.getUsers();                System.out.println("User\t\tGroups");                System.out.println("-----------------------------------------");                for (int i = 0; i < users.length; i++) {                    System.out.print(users[i].getName() + "\t\t");                    String[] groups = users[i].getGroups();                    for (int j = 0; j < groups.length; j++) {                        System.out.print(groups[j]);                        if (j + 1< groups.length)                            System.out.print(", ");                    }                    System.out.println();                }            } else if (args[0].equalsIgnoreCase("passwd")) {                if (startGUI) {                    messageln("command not supported in GUI mode. Please use the \"Edit users\" menu option.");                    return true;                }                if (args.length < 2) {                    System.out.println("Usage: passwd username");                    return true;                }                try {                    UserManagementService mgtService = (UserManagementService) current                            .getService("UserManagementService", "1.0");                    User user = mgtService.getUser(args[1]);                    if (user == null) {                        System.out.println("no such user.");                        return true;                    }                    String p1;                    String p2;                    while (true) {                        p1 = console.readLine("password: ", new Character('*'));                        p2 = console.readLine("re-enter password: ", new Character('*'));                        if (p1.equals(p2)) break;                        System.out.println("\nentered passwords differ. Try again...");                    }                    user.setPassword(p1);                    mgtService.updateUser(user);                    properties.setProperty("password", p1);                } catch (Exception e) {                    System.err.println("ERROR: " + e.getMessage());                }            } else if (args[0].equalsIgnoreCase("chmod")) {                if (args.length < 2) {                    System.out.println("Usage: chmod [resource] mode");                    return true;                }                                Collection temp = null;                if (args.length == 3) {                    System.out.println("trying collection: " + args[1]);                    temp = current.getChildCollection(args[1]);                    if (temp == null) {                        System.out.println("\ntrying resource: " + args[1]);                        Resource r = current.getResource(args[1]);                        if (r != null) {                            UserManagementService mgtService = (UserManagementService) current                                    .getService("UserManagementService", "1.0");                            mgtService.chmod(r, args[2]);                        } else                            System.err.println("Resource " + args[1]                                    + " not found.");                    } else {                        UserManagementService mgtService = (UserManagementService) temp                                .getService("UserManagementService", "1.0");                        mgtService.chmod(args[2]);                    }                } else {                    UserManagementService mgtService = (UserManagementService) current                            .getService("UserManagementService", "1.0");                    mgtService.chmod(args[1]);                }                // re-read current collection                current = DatabaseManager.getCollection(properties                        .getProperty("uri")                        + path, properties.getProperty("user"), properties                        .getProperty("password"));                getResources();            } else if (args[0].equalsIgnoreCase("chown")) {                if (args.length < 3) {                    System.out                            .println("Usage: chown username group [resource]");                    return true;                }                                Collection temp;                if (args.length == 4)                    temp = current.getChildCollection(args[3]);                else                    temp = current;                if (temp != null) {                    UserManagementService mgtService = (UserManagementService) temp                            .getService("UserManagementService", "1.0");                    User u = mgtService.getUser(args[1]);                    if (u == null) {                        System.out.println("unknown user");                        return true;                    }                    mgtService.chown(u, args[2]);                    System.out.println("owner changed.");                    getResources();                    return true;                }                Resource res = current.getResource(args[3]);                if (res != null) {                    UserManagementService mgtService = (UserManagementService) current                            .getService("UserManagementService", "1.0");                    User u = mgtService.getUser(args[1]);                    if (u == null) {                        System.out.println("unknown user");                        return true;                    }                    mgtService.chown(res, u, args[2]);                    getResources();                    return true;                }                System.err.println("Resource " + args[3] + " not found.");                            } else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {                if(args.length < 2) {                    messageln("Usage: lock resource");                    return true;                }                Resource res = current.getResource(args[1]);                if (res != null) {                    UserManagementService mgtService = (UserManagementService)                    current.getService("UserManagementService", "1.0");                    User user = mgtService.getUser(properties.getProperty("user", "guest"));                    if(args[0].equalsIgnoreCase("lock"))                        mgtService.lockResource(res, user);                    else                        mgtService.unlockResource(res);                }                            } else if (args[0].equalsIgnoreCase("elements")) {                System.out.println("Element occurrences in collection "                        + current.getName());                System.out                        .println("--------------------------------------------"                        + "-----------");                IndexQueryService service = (IndexQueryService) current                        .getService("IndexQueryService", "1.0");                Occurrences[] elements = service.getIndexedElements(true);                for (int i = 0; i < elements.length; i++) {                    System.out                            .println(formatString(elements[i].getTerm().toString(),                            Integer.toString(elements[i]                            .getOccurrences()), 50));                }                return true;                            } else if (args[0].equalsIgnoreCase("terms")) {                if (args.length < 3) {                    System.out                            .println("Usage: terms [xpath] sequence-start sequence-end");                    return true;                }                IndexQueryService service = (IndexQueryService) current                        .getService("IndexQueryService", "1.0");                Occurrences[] terms;                if (args.length == 3)                    terms = service.scanIndexTerms(args[1], args[2], true);                else                    terms = service.scanIndexTerms(args[1], args[2], args[3]);                System.out.println("Element occurrences in collection "                        + current.getName());                System.out                        .println("--------------------------------------------"                        + "-----------");                for (int i = 0; i < terms.length; i++) {                    System.out.println(formatString(terms[i].getTerm().toString(), Integer                            .toString(terms[i].getOccurrences()), 50));                }            } else if (args[0].equalsIgnoreCase("xupdate")) {                if (startGUI) {                    messageln("command not supported in GUI mode.");                    return true;                }                String lastLine, command = "";                try {                    while (true) {                        lastLine = console.readLine("| ");                        if (lastLine == null || lastLine.length() == 0)                            break;                        command += lastLine;                    }                } catch (EOFException e) {                } catch (IOException e) {                }                String xupdate = "<xu:modifications version=\"1.0\" "                        + "xmlns:xu=\"http://www.xmldb.org/xupdate\">"                        + command + "</xu:modifications>";                XUpdateQueryService service = (XUpdateQueryService) current                        .getService("XUpdateQueryService", "1.0");                long mods = service.update(xupdate);                System.out.println(mods + " modifications processed.");                            } else if (args[0].equalsIgnoreCase("map")) {                StringTokenizer tok = new StringTokenizer(args[1], "= ");                String prefix;                if (args[1].startsWith("="))                    prefix = "";                else {                    if (tok.countTokens() < 2) {                        messageln("please specify a namespace/prefix mapping as: prefix=namespaceURI");                        return true;                    }                    prefix = tok.nextToken();                }                String uri = tok.nextToken();                namespaceMappings.put(prefix, uri);                            } else if (args[0].equalsIgnoreCase("set")) {                if (args.length == 1)                    properties.list(System.out);                else                    try {                        StringTokenizer tok = new StringTokenizer(args[1], "= ");                        if (tok.countTokens() < 2) {                            System.err                                    .println("please specify a key=value pair");                            return true;                        }                        String key = tok.nextToken();                        String val = tok.nextToken();                        System.out.println(key + " = " + val);                        properties.setProperty(key, val);                        current.setProperty(key, val);                        getResources();                    } catch (Exception e) {                        System.err.println("Exception: " + e.getMessage());                    }            } else if (args[0].equalsIgnoreCase("shutdown")) {                DatabaseInstanceManager mgr = (DatabaseInstanceManager) current                        .getService("DatabaseInstanceManager", "1.0");                if (mgr == null) {                    messageln("Service is not available");                    return true;                }                mgr.shutdown();                return true;            } else if (args[0].equalsIgnoreCase("help") || args[0].equals("?"))                displayHelp();            else if (args[0].equalsIgnoreCase("quit")) {                return false;                            }  else if (args[0].equalsIgnoreCase("validate")) {                if (args.length < 2)                    messageln("missing document name.");                else {                    ValidationService validationService = (ValidationService) current.getService("ValidationService", "1.0");                    if (validationService.validateResource(args[1]))                        messageln("document is valid.");                    else                        messageln("document is not valid.");                }                            } else {                messageln("unknown command");                return true;            }            path = newPath;            return true;        } catch (Throwable e) {            if (startGUI)                ClientFrame.showErrorMessage(getExceptionMessage(e), e);            else {                messageln(getExceptionMessage(e));                e.printStackTrace();            }            return true;        }    }