LogUtil logUtil = new LogUtil(LogUtil.DEFAULT_LOGGER_NAMES);
logUtil.addHandler(new SystemOutHandler());
logUtil.setUseParentHandler(false);
String[] args = cl.getArgs();
JXL jxl = null;
Destination destination = ClientConfiguration.getDefault().getDestination();
if (cl.hasOption("destination")) {
File dir = new File(cl.getOptionValue("destination"));
if (!dir.exists()) {
System.err.println("ERROR: destination directory " + dir.getAbsolutePath() + " \"does not exist\".");
System.exit(-1);
}
dir = dir.getCanonicalFile();
destination = Destination.createForDirectory(dir);
}
File file = null;
if (cl.hasOption("stdin")) {
URI uri = new File(System.getProperty("user.dir")).toURI();
if (cl.hasOption("uri")) {
uri = uri.resolve(cl.getOptionValue("uri"));
System.err.println(uri);
} else {
uri = uri.resolve("stdin.jxl");
}
InputSource inputSource = new InputSource();
inputSource.setByteStream(System.in);
inputSource.setSystemId(uri.toString());
jxl = new JXL(inputSource);
} else {
if ((args.length == 0) && !cl.hasOption("stdin")) {
System.err.println("ERROR: JXL not specified.");
System.exit(ExitCodes.ERROR_INVALID_NUMBER_OF_ARGUMENTS);
}
file = new File(args[0]);
jxl = new JXL(file);
}
String[] names = cl.getOptionValues("name");
List documentList = new ArrayList();
if (names != null) {
for (int i = 0; i < names.length; i++) {
String name = names[i];
Document document = jxl.getDocument(name);
if (document == null) {
System.err.println("ERROR: Document \"" + name + "\" not found.");
System.exit(1);
}
documentList.add(document);
}
} else {
documentList.addAll(Arrays.asList(jxl.getDocuments()));
if (documentList.size() == 0) {
System.out.println("No documents found in JXL.");
System.exit(0);
}
}