String query = "define variable $uri as xs:string external "; query += "if(doc($uri)) then doc($uri) else \"Document not found.\""; try { XQDataSource dataSource = env.getDataSource(); XQuery xquery = dataSource.newQuery(query); xquery.setVariable(dataSource.newVariable("uri", XQVariableType.XS_STRING, arg)); env.runXQuery(xquery); } catch (XQException e) { env.printError(e);
if(env instanceof Shell) { Shell shell = (Shell)env; String query = "if(doc(\"" + arg + "\")) then doc(\"" + arg + "\") else \"Document not found.\""; ShellQuery squery = new ShellQuery(query, shell); try { env.runXQuery(squery.asXQuery()); } catch (XQException e) { env.printError(e); }
	public void execute(Environment env, String arg) {		if( arg != null && arg.length() > 0 ) {			String query = "define variable $uri as xs:string external ";				   query += "if(doc($uri)) then doc($uri) else \"Document not found.\"";			try {				XQDataSource dataSource = env.getDataSource();				XQuery xquery = dataSource.newQuery(query);				xquery.setVariable(dataSource.newVariable("uri", XQVariableType.XS_STRING, arg));				env.runXQuery(xquery);			} catch (XQException e) {				env.printError(e);			}		} else {				env.printLine("Please specify a document to view: cat [document uri]");		}	}