optionXpath = stdin.readLine();
StringBuffer buf = new StringBuffer(); String line; while((line = stdin.readLine()) != null) buf.append(line); optionXpath = buf.toString();
	public void run(String args[]) {		// read properties		properties = new Properties(defaultProps);		try {			String home = System.getProperty("exist.home");			File propFile;			if (home == null)				propFile = new File("client.properties");			else				propFile =					new File(						home + System.getProperty("file.separator", "/") + "client.properties");			InputStream pin;			if (propFile.canRead())				pin = new FileInputStream(propFile);			else				pin = InteractiveClient.class.getResourceAsStream("client.properties");			if (pin != null)				properties.load(pin);		} catch (IOException ioe) {		}		// parse command-line options		CLArgsParser optParser = new CLArgsParser(args, OPTIONS);		if (optParser.getErrorString() != null) {			System.err.println("ERROR: " + optParser.getErrorString());			return;		}		List opt = optParser.getArguments();		int size = opt.size();		CLOption option;		boolean needPasswd = false;		boolean passwdSpecified = false;		boolean interactive = true;		boolean foundCollection = false;		boolean doParse = false;		String optionRemove = null;		String optionGet = null;		String optionMkcol = null;		String optionRmcol = null;		String optionXpath = null;		String optionQueryFile = null;		String optionXUpdate = null;		String optionResource = null;		List optionalArgs = new ArrayList();		for (int i = 0; i < size; i++) {			option = (CLOption) opt.get(i);			switch (option.getId()) {				case HELP_OPT :					printUsage();					return;				case NO_GUI_OPT :					startGUI = false;					break;				case QUIET_OPT :					quiet = true;					break;				case VERBOSE_OPT :					verbose = true;					break;				case LOCAL_OPT :					properties.setProperty("uri", "xmldb:exist://");					break;				case USER_OPT :					properties.setProperty("user", option.getArgument());					if (!passwdSpecified)						needPasswd = true;					break;				case PASS_OPT :					properties.setProperty("password", option.getArgument());					needPasswd = false;					passwdSpecified = true;					break;				case CONFIG_OPT :					properties.setProperty("configuration", option.getArgument());					break;				case COLLECTION_OPT :					path = option.getArgument();					foundCollection = true;					break;				case RESOURCE_OPT :					optionResource = option.getArgument();					break;				case PARSE_OPT :					doParse = true;					if (option.getArgumentCount() == 1)						optionalArgs.add(option.getArgument());					interactive = false;					break;				case RECURSE_DIRS_OPT :					recurseDirs = true;					break;				case REMOVE_OPT :					optionRemove = option.getArgument();					interactive = false;					break;				case GET_OPT :					optionGet = option.getArgument();					interactive = false;					break;				case MKCOL_OPT :					optionMkcol = option.getArgument();					foundCollection = true;					break;				case RMCOL_OPT :					optionRmcol = option.getArgument();					foundCollection = true;					interactive = false;					break;				case FIND_OPT :					optionXpath = (option.getArgumentCount() == 1 ? option.getArgument() : "stdin");					interactive = false;					break;				case RESULTS_OPT :					try {						maxResults = Integer.parseInt(option.getArgument());					} catch (NumberFormatException e) {						System.err.println("parameter -n needs a valid number");						return;					}					break;				case OPTION_OPT :					properties.setProperty(option.getArgument(0), option.getArgument(1));					break;				case QUERY_FILE_OPT :					optionQueryFile = option.getArgument();					interactive = false;					break;				case THREADS_OPT :					try {						PARALLEL_THREADS = Integer.parseInt(option.getArgument());					} catch (NumberFormatException e) {						System.err.println("parameter -t needs a valid number");					}					break;				case XUPDATE_OPT :					optionXUpdate = option.getArgument();					interactive = false;					break;				case TRACE_QUERIES_OPT :					String traceFile = option.getArgument();					File f = new File(traceFile);					try {						traceWriter =							new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8");						traceWriter.write("<?xml version=\"1.0\"?>\r\n");						traceWriter.write("<query-log>\r\n");					} catch (UnsupportedEncodingException e1) {					} catch (FileNotFoundException e1) {						messageln("Cannot open file " + traceFile);					} catch (IOException e) {					}					break;				case CLOption.TEXT_ARGUMENT :					optionalArgs.add(option.getArgument());					break;			}		}		if (!quiet)			printNotice();		// prompt for password if needed		if (interactive && startGUI) {			String[] loginData = ClientFrame.getLoginData(properties.getProperty("user"));			if (loginData == null) {				System.exit(0);			}			properties.setProperty("user", loginData[0]);			properties.setProperty("password", loginData[1]);		} else if (needPasswd) {			try {				properties.setProperty("password", Readline.readline("password: "));			} catch (Exception e) {			}		}		String pathSep = System.getProperty("file.separator", "/");		String home = System.getProperty("exist.home");		if (home == null)			home = System.getProperty("user.dir");		File history = new File(home + File.separatorChar + ".exist_history");		if (interactive && (!startGUI)) {			// 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 (history.canRead())				try {					Readline.readHistoryFile(history.getAbsolutePath());				} catch (Exception e) {				}		}		// connect to the db		try {			connect();		} catch (XMLDBException xde) {			if (startGUI && frame != null)				frame.setStatus("Connection to database failed; message: " + xde.getMessage());			else				System.err.println("Connection to database failed; message: " + xde.getMessage());			xde.printStackTrace();			return;		} catch (Exception cnf) {			if (startGUI && frame != null)				frame.setStatus("Connection to database failed; message: " + cnf.getMessage());			else				System.err.println("Connection to database failed; message: " + cnf.getMessage());			cnf.printStackTrace();			return;		}		if (current == null) {			if (startGUI && frame != null)				frame.setStatus("Could not retrieve collection " + path);			else				System.err.println("Could not retrieve collection " + path);			return;		}		// process command-line actions		if (optionRmcol != null) {			if (!foundCollection) {				System.err.println("Please specify target collection with --collection");				return;			}			try {				rmcol(optionRmcol);			} catch (XMLDBException e) {				System.err.println("XMLDBException while removing collection: " + e.getMessage());				e.printStackTrace();			}		}		if (optionMkcol != null) {			try {				mkcol(optionMkcol);			} catch (XMLDBException e) {				System.err.println("XMLDBException during mkcol: " + e.getMessage());				e.printStackTrace();			}		}		if (optionGet != null) {			try {				XMLResource res = retrieve(optionGet);				if (res != null)					System.out.println(res.getContent());			} catch (XMLDBException e) {				System.err.println(					"XMLDBException while trying to retrieve document: " + e.getMessage());				e.printStackTrace();			}		} else if (optionRemove != null) {			if (!foundCollection) {				System.err.println("Please specify target collection with --collection");			} else {				try {					remove(optionRemove);				} catch (XMLDBException e) {					System.out.println("XMLDBException during parse: " + e.getMessage());					e.printStackTrace();				}			}			return;		} else if (doParse) {			if (!foundCollection) {				System.err.println("Please specify target collection with --collection");			} else {				for (Iterator i = optionalArgs.iterator(); i.hasNext();)					try {						parse((String) i.next());					} catch (XMLDBException e) {						System.out.println("XMLDBException during parse: " + e.getMessage());						e.printStackTrace();					}			}		} else if (optionXpath != null) {			// if no argument has been found, read query from stdin			if (optionXpath.equals("stdin")) {				try {					BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));					optionXpath = stdin.readLine();				} catch (IOException e) {					System.err.println("failed to read query from stdin");					optionXpath = null;				}			}			if (optionXpath != null) {				try {					ResourceSet result = find(optionXpath);					for (int i = 0; i < maxResults && i < result.getSize(); i++)						System.out.println(((Resource) result.getResource((long) i)).getContent());				} catch (XMLDBException e) {					System.err.println("XMLDBException during query: " + e.getMessage());					e.printStackTrace();				}			}		} else if (optionQueryFile != null) {			testQuery(optionQueryFile);		} else if (optionXUpdate != null) {			try {				xupdate(optionResource, optionXUpdate);			} catch (XMLDBException e) {				System.err.println("XMLDBException during xupdate: " + e.getMessage());			} catch (IOException e) {				System.err.println("IOException during xupdate: " + e.getMessage());			}		}		if (interactive) {			if (startGUI) {				frame = new ClientFrame(this, path, properties);				frame.setLocation(100, 100);				frame.setSize(500, 450);				frame.setVisible(true);			}			// enter interactive mode			try {				getResources();			} catch (XMLDBException e1) {				System.out.println(					"XMLDBException while retrieving collection " + "contents: " + e1.getMessage());				e1.getCause().printStackTrace();				ClientFrame.showErrorMessage(					"XMLDBException occurred while retrieving collection: " + e1.getMessage(),					e1);				frame.setVisible(false);				System.exit(0);			}			messageln("\ntype help or ? for help.");			if (!startGUI)				readlineInputLoop(home, history);			else				frame.displayPrompt();		} else			shutdown(false);	}