if (args.length == 0) {
System.out.println(getLongUsage());
return -1;
}
Getopt getopt = new Getopt(getProgramName(), args, ":", longOpts, true);
//Getopt getopt = new Getopt(getCommandString(), argv, "-:h:vf:b:pc:u:t:y:w:drq", longOpts, true);
//getopt.setOpterr(false); // We'll do our own error handling
int c;
while ((c = getopt.getopt()) != -1) {
// log.trace("longind="+g.getLongind());
switch (c) {
case 'h' : // --help
System.out.println(getLongUsage());
return -1;
case 'v' : // --version
System.out.println(getVersionInfo());
return -1;
case 's' : // --strip
stripWhitespace = true;
break;
case 'x' : // --xinclude
xinclude = true;
break;
case 'e' : // --explain
explain = true;
break;
case 'n' : // --noexternal
System.setProperty("nux.xom.xquery.XQuery.allowExternalFunctions", "false");
break;
case 'd' : // --debug
debug = true;
break;
case 'p' : // --nobuilderpool
noBuilderPool = true;
break;
case 'N' : // --xomxpath
xomXPath = true;
break;
case 0 :
String arg = getopt.getOptarg();
char val = (char) (new Integer(sb.toString())).intValue();
String optionName = longOpts[getopt.getLongind()].getName();
// log.trace("Got long option with value '" + val + "' with argument " + ((arg != null) ? arg : "null"));
switch (val) {
case 'q' : // --query
arg = arg.trim();
if (arg.startsWith("{") && arg.endsWith("}")) {
// query is given inline between curly brackets, ala Saxon command line tool
queries.add(arg.substring(1, arg.length()-1));
} else {
if (arg.equals("nop"))
queries.add(null); // disable xquery for benchmarking
else
queries.add(parsePath(arg));
}
break;
case 'u' : // --update
arg = arg.trim();
if (arg.startsWith("{") && arg.endsWith("}")) {
// update query is given inline between curly brackets, ala Saxon command line tool
update = arg.substring(1, arg.length()-1);
} else {
update = parsePath(arg);
}
break;
case 'b' : // --base
baseURI = parsePath(arg).toURI();
break;
case 'P' : { // --var
int i = arg.indexOf(':');
if (i < 0) throw new UsageException("Missing name:value pair");
String name = arg.substring(0, i).trim();
String value = arg.substring(i+1);
if (false && value.startsWith("doc(") && value.endsWith(")")) {
try {
value = value.substring("doc(".length()-1);
value = value.substring(1, value.length()-1);
variables.put(name, new Builder().build(new File(value)));
} catch (Exception e) {
throw new UsageException(e);
}
} else {
variables.put(name, value);
}
break;
}
case 'o' : // --out
outputFiles.add(parsePath(arg));
break;
case 'S' : // --algo
arg = arg.trim();
checkValidity(arg, new String[] {
ResultSequenceSerializer.W3C_ALGORITHM,
ResultSequenceSerializer.WRAP_ALGORITHM}, optionName);
algorithm = arg;
break;
case 'E' : // --encoding
encoding = arg.trim();
break;
case 'I' : // --indent
indent = Math.max(0, parseInt(arg, optionName));
break;
case 'r' : // --runs
runs = parseIntGreaterThanZero(arg, optionName);
break;
case 'i' : // --iterations
iterations = Math.max(0, parseInt(arg, optionName));
break;
case 'C' : // --docpoolcapacity
docPoolCapacity = 1024L * 1024L * parseInt(arg, optionName);
break;
case 'D' : // --docpoolcompression
docPoolCompression = parseInt(arg, optionName);
break;
case 'V' : // --validate
arg = arg.trim();
checkValidity(arg, new String[] {
"wf", "dtd", "schema", "relaxng", "html"}, optionName);
validate = arg;
break;
case 'W' : // --namespace
namespace = arg.trim();
break;
case 'w' : { // --schema
// if the schema file location is a relative path,
// xerces interprets it relative to the XML instance document file,
// not the current working directory.
// This may be surprising and errorprone, so we convert it to an absolute path
// Also, there are some obscure work arounds to make this work both on Unix and Windows, in all cases...
schema = parsePath(arg).getAbsoluteFile();
break;
}
case 'f' : // --filterpath
try {
filter = new StreamingPathFilter(arg, null);
} catch (StreamingPathFilterException e) {
throw new UsageException(e);
}
break;
case 'F' : // --filterquery
arg = arg.trim();
if (arg.startsWith("{") && arg.endsWith("}")) {
// query is given inline between curly brackets, ala Saxon command line tool
filterQuery = arg.substring(1, arg.length()-1);
} else {
try {
filterQuery = FileUtil.toString(
new FileInputStream(parsePath(arg)), null);
} catch (IOException e) {
throw new UsageException(e);
}
}
break;
//// case 'l' : // --loglevel
//// setLogLevels(toLevel(arg));
//// break;
default :
throw new InternalError("Oops. Should never reach here. val='" + val + "'");
}
break;
case ':' :
throw new UsageException("Option '" + longOpts[getopt.getLongind()].getName() + "' requires an argument");
//throw new UsageException("Argument missing for option " + (char) g.getOptopt() + ", errname=" + longopts[g.getLongind()].getName());
case '?' :
System.err.println(getLongUsage());
return -1;
// throw new UsageException("The option '" + (char) g.getOptopt() + "' is not valid");
default :
throw new InternalError("Oops. Should never reach here. getopt() returned '" + (char) c + "'");
}
}
if (queries.size() == 0) throw new UsageException("Missing required argument --query");
inputFiles = parseNonOptionArguments(args, getopt.getOptind(), true, 0, Integer.MAX_VALUE);
if (inputFiles.length == 0) inputFiles = new String[] { null };
// fill in default, if necessary
File file = null;