fetchedSourceDoc = null;
transformInvoked = false;
if (asyncSourceURI != null) {
final String URI = asyncSourceURI;
final Node transformTarget = target;
logger.log(Level.FINE, "Aynchronous GET for: " + asyncSourceURI);
final HTTPHandler hr = new HTTPHandler();
hr.doGet(asyncSourceURI, new RequestCallback() {
public void onError(Request request, Throwable exception) {
//hr.setErrorMessage(exception.getMessage());
String msg = "HTTP Error " + exception.getMessage() + " for URI " + URI;
handleException (new RuntimeException(msg), "onError");
}
public void onResponseReceived(Request request, Response response) {
int statusCode = response.getStatusCode();
if (statusCode == 200) {
Logger.getLogger("ResponseReceived").fine("GET Ok for: " + URI);
Node responseNode;
try {
responseNode = (Node)XMLDOM.parseXML(response.getText());
} catch(Exception e) {
handleException (new RuntimeException(e.getMessage()), "onResponseReceived");
return;
}
DocumentInfo responseDoc = config.wrapXMLDocument(responseNode, URI);
// now document is here, we can transform it
Node result = invokeTransform(responseDoc, transformTarget);
hr.setResultNode(result); // TODO: This isn't used yet
// handle OK response from the server
} else if (statusCode < 400) {
// transient
} else {
String msg = "HTTP Error " + statusCode + " " + response.getStatusText() + " for URI " + URI;
handleException (new RuntimeException(msg), "onResponseReceived");
//hr.setErrorMessage(statusCode + " " + response.getStatusText());
}
} // ends inner method
}// ends inner class
); // ends doGet method call
}
// -------------- End async code
/// we can compile - even while sourcedoc is being fetched asynchronously
if (stylesheet == null) {
if (LogConfiguration.loggingIsEnabled()) {
LogController.InitializeTraceListener();
}
logger.log(Level.FINE, "Compiling Stylesheet...");
PreparedStylesheet sheet = new PreparedStylesheet(config, info);
sheet.prepare(styleDoc);
stylesheet = sheet;
logger.log(Level.FINE, "Stylesheet compiled OK");
}
// for async operation - this is called within the callback - so don't call here
if (asyncSourceURI == null && inSourceDoc != null) {
int nodeType = (Node.is(inSourceDoc))? ((Node)inSourceDoc).getNodeType() : 0;
if (nodeType > 0 && nodeType != Node.DOCUMENT_NODE) {
// add a document node wrapper
Node sourceNode = (Node)inSourceDoc;
Document sourceDoc = sourceNode.getOwnerDocument();
HTMLDocumentWrapper htmlDoc = new HTMLDocumentWrapper(sourceDoc, sourceDoc.getURL(), config, DocType.UNKNOWN);
fetchedSourceDoc = htmlDoc.wrap(sourceNode);
} else {
fetchedSourceDoc = SaxonceApi.getDocSynchronously(inSourceDoc, config);
}