File home = Configuration.getExistHome();
    public void run(String args[]) throws Exception {                // Resolve exist.home        String home = System.getProperty("exist.home");        if (home == null)            home = System.getProperty("user.dir");                // initialize with default properties, before add client properties        properties = new Properties(defaultProps);                // get default configuration filename from the driver class and set it in properties        Class cl = Class.forName(properties.getProperty(DRIVER));        Field CONF_XML=cl.getDeclaredField("CONF_XML");        if (CONF_XML != null) {            File configuration=new File(home, (String)CONF_XML.get(new String()));            properties.setProperty(CONFIGURATION, configuration.getAbsolutePath());        }                properties.putAll(loadClientProperties());                // parse command-line options        CommandlineOptions cOpt = getCommandlineOptions(args, properties);        if(cOpt==null){            // An error occured during parsing. exit program.            return;        }                // Fix "uri" property: Excalibur CLI can't parse dashes, so we need to URL encode them:        properties.setProperty("uri", java.net.URLDecoder.decode(properties.getProperty("uri"), "UTF-8"));                if (!quiet)            printNotice();                // prompt for password if needed        if (cOpt.interactive && startGUI) {                        boolean haveLoginData = getGuiLoginData(properties);            if(!haveLoginData){                System.exit(0);            }                    } else if (cOpt.needPasswd) {            try {                properties.setProperty("password", Readline                        .readline("password: "));            } catch (Exception e) {            }        }                historyFile = new File(home + File.separatorChar + ".exist_history");        queryHistoryFile = new File(home + File.separatorChar                + ".exist_query_history");                if (queryHistoryFile.canRead())            readQueryHistory();                if (cOpt.interactive) {            // in gui mode we use Readline for history management            // initialize Readline library            try {                Readline.load(ReadlineLibrary.GnuReadline);                System.out                        .println("GNU Readline found. IMPORTANT: Don't use GNU Readline");                System.out                        .println("to work with other character encodings than ISO-8859-1.");            } catch (UnsatisfiedLinkError ule) {                if (!quiet) {                    System.out                            .println("GNU Readline not found. Using System.in.");                    System.out                            .println("If GNU Readline is available on your system,");                    System.out                            .println("add directory ./lib to your LD_LIBRARY_PATH");                }            }            Readline.setEncoding("UTF-8");            Readline.initReadline("exist");            Readline.setCompleter(new CollectionCompleter());            if (historyFile.canRead())                try {                    Readline.readHistoryFile(historyFile.getAbsolutePath());                } catch (Exception e) {                    // No error handling                }        }                // connect to the db        connectToDatabase();                if (current == null) {            if (startGUI && frame != null)                frame.setStatus("Could not retrieve collection " + path);            else                System.err.println("Could not retrieve collection " + path);            shutdown(false);            return;        }                boolean processingOK = processCommandLineActions(cOpt);        if(!processingOK){            return;        }                if (cOpt.interactive) {            if (startGUI) {                frame = new ClientFrame(this, path, properties);                frame.setLocation(100, 100);                frame.setSize(500, 500);                frame.setVisible(true);            }                        // enter interactive mode            if( (!startGUI) || (frame == null) ){                                // No gui                try {                    getResources();                } catch (XMLDBException e) {                    System.out.println("XMLDBException while "                            + "retrieving collection contents: "                            + getExceptionMessage(e));                    e.getCause().printStackTrace();                }                            } else {                                // with gui ; re-login posibility                boolean retry=true;                                while(retry){                                        String errorMessage="";                    try {                        getResources();                    } catch (XMLDBException e) {                                                errorMessage=getExceptionMessage(e);                        ClientFrame.showErrorMessage(                                "XMLDBException occurred while retrieving collection: "                                + errorMessage, e);                    }                                        // Determine error text. For special reasons we can retry                    // to connect.                    if( errorMessage.matches("^.*Invalid password for user.*$") ||                            errorMessage.matches("^.*User .* unknown.*") ||                            errorMessage.matches("^.*Connection refused: connect.*") ){                                                boolean haveLoginData = getGuiLoginData(properties);                        if(!haveLoginData){                            // pressed cancel                            System.exit(0);                        }                                                // Need to shutdown ?? ask wolfgang                        shutdown(false);                                                // connect to the db                        connectToDatabase();                                            } else {                                                if(errorMessage!=""){                            // No pattern match, but we have an error. stop here                            frame.dispose();                            System.exit(1);                        } else {                            // No error message, continue startup.                            retry=false;                        }                    }                }            }                        messageln("\ntype help or ? for help.");                        if (cOpt.openQueryGui) {                QueryDialog qd = new QueryDialog(this, current, properties);                qd.setLocation(100, 100);                qd.setVisible(true);            } else if (!startGUI)                readlineInputLoop(home);            else                frame.displayPrompt();        } else            shutdown(false);    }