} catch (InvocationTargetException nsme) {
// nop; oh, well
logger.debug(MessageFormatter.nodeMessage(step.getNode(), "Cannot reset schema cache."));
}
XdmNode doc = source.read();
docBaseURI = doc.getBaseURI();
String namespace = S9apiUtils.getDocumentElement(doc).getNodeName().getNamespaceURI();
boolean tryNamespaces = getOption(_try_namespaces, false) && !"".equals(namespace);
// Populate the URI cache so that URI references in schema documents will find
// the schemas provided preferentially
Vector<XdmNode> schemaDocuments = new Vector<XdmNode> ();
while (schemas.moreDocuments()) {
XdmNode schemaNode = schemas.read();
String targetNS = schemaNode.getBaseURI().toASCIIString();
logger.debug(MessageFormatter.nodeMessage(step.getNode(), "Caching input schema: " + targetNS));
if (targetNS.equals(namespace)) {
tryNamespaces = false;
}
schemaDocuments.add(schemaNode);
runtime.getResolver().cache(schemaNode, schemaNode.getBaseURI());
}
if (tryNamespaces) {
// Need to load one more schema
try {
XdmNode nsSchemaDoc = runtime.parse(namespace, doc.getBaseURI().toASCIIString(), false);
schemaDocuments.add(nsSchemaDoc);
runtime.getResolver().cache(nsSchemaDoc, nsSchemaDoc.getBaseURI());
} catch (Exception e) {
// nevermind
}
}
// FIXME: HACK! Do this the right way
for (XdmNode schemaNode : schemaDocuments) {
InputSource schemaSource = S9apiUtils.xdmToInputSource(runtime, schemaNode);
schemaSource.setSystemId(schemaNode.getBaseURI().toASCIIString());
SAXSource source = new SAXSource(schemaSource);
manager.load(source);
}
XdmDestination destination = new XdmDestination();
Controller controller = new Controller(config);
Receiver receiver = destination.getReceiver(controller.getConfiguration());
PipelineConfiguration pipe = controller.makePipelineConfiguration();
pipe.setRecoverFromValidationErrors(!getOption(_assert_valid,false));
receiver.setPipelineConfiguration(pipe);
SchemaValidator validator = manager.newSchemaValidator();
validator.setDestination(destination);
validator.setErrorListener(new XSDErrorHandler());
String mode = getOption(_mode, "strict");
validator.setLax("lax".equals(mode));
boolean useHints = getOption(_use_location_hints, false);
validator.setUseXsiSchemaLocation(useHints);
try {
logger.trace(MessageFormatter.nodeMessage(step.getNode(),
"Validating: " + doc.getBaseURI().toASCIIString()));
validator.validate(doc.asSource());
if (validationException != null) {
throw (SaxonApiException) validationException;
}
} catch (SaxonApiException sae) {
if (getOption(_assert_valid,false)) {
throw new XProcException(XProcConstants.stepError(53), sae);
}
}
XdmNode valid = destination.getXdmNode();
result.write(valid);
}