}
public void run() throws SaxonApiException {
super.run();
RuntimeValue href = getOption(_href);
URI uri = href.getBaseURI().resolve(href.getString());
boolean failOnError = getOption(_fail_on_error, true);
logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Checking info for " + uri));
TreeWriter tree = new TreeWriter(runtime);
tree.startDocument(step.getNode().getBaseURI());
if ("file".equals(uri.getScheme())) {
File file = new File(uri.getPath());
if (!file.exists()) {
if (failOnError) {
throw new XProcException(err_fu01);
} else {
tree.addStartElement(c_error);
tree.addText("File not found");
tree.addEndElement();
tree.endDocument();
result.write(tree.getResult());
return;
}
}
if (file.isDirectory()) {
tree.addStartElement(c_directory);
} else if (file.isFile()) {
tree.addStartElement(c_file);
} else {
tree.addStartElement(c_other);
}
tree.addAttribute(_href, uri.toASCIIString());
if (file.canRead()) { tree.addAttribute(_readable, "true"); }
if (file.canWrite()) { tree.addAttribute(_writable, "true"); }
if (file.isHidden()) { tree.addAttribute(_hidden, "true"); }
tree.addAttribute(_size, "" + file.length());
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(file.lastModified());
TimeZone tz = TimeZone.getDefault();
long gmt = file.lastModified() - tz.getRawOffset();
if (tz.useDaylightTime() && tz.inDaylightTime(cal.getTime())) {
gmt -= tz.getDSTSavings();
}
cal.setTimeInMillis(gmt);
tree.addAttribute(_last_modified, String.format("%1$04d-%2$02d-%3$02dT%4$02d:%5$02d:%6$02dZ",
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)));
tree.startContent();
tree.addEndElement();
} else {
tree.addStartElement(c_uri);
// Let's try HTTP
HttpRequest httpReq = new HttpRequest(runtime, step);
Pipe inputPipe = new Pipe(runtime);
Pipe outputPipe = new Pipe(runtime);
httpReq.setInput("source", inputPipe);
httpReq.setOutput("result", outputPipe);
TreeWriter req = new TreeWriter(runtime);
req.startDocument(step.getNode().getBaseURI());
req.addStartElement(XProcConstants.c_request);
req.addAttribute(_method, "HEAD");
req.addAttribute(_href, uri.toASCIIString());
req.addAttribute(_status_only, "true");
req.addAttribute(_detailed, "true");
for (QName name : new QName[] {_username, _password, _auth_method, _send_authorization } ) {
RuntimeValue v = getOption(name);
if (v != null) { req.addAttribute(name, v.getString()); }
}
req.startContent();
req.addEndElement();
req.endDocument();