boolean isFinal = options.isContinueAfterValidationErrors();
if (source instanceof AugmentedSource) {
options.merge(((AugmentedSource)source).getParseOptions());
source = ((AugmentedSource)source).getContainedSource();
}
Configuration config = pipe.getConfiguration();
options.applyDefaults(config);
receiver.setPipelineConfiguration(pipe);
receiver.setSystemId(source.getSystemId());
Receiver next = receiver;
int schemaValidation = options.getSchemaValidationMode();
if (isFinal) {
// this ensures that the Validate command produces multiple error messages
schemaValidation |= Validation.VALIDATE_OUTPUT;
}
SchemaType topLevelType = options.getTopLevelType();
List filters = options.getFilters();
if (filters != null) {
for (int i=filters.size()-1; i>=0; i--) {
ProxyReceiver filter = (ProxyReceiver)filters.get(i);
filter.setPipelineConfiguration(pipe);
filter.setSystemId(source.getSystemId());
filter.setUnderlyingReceiver(next);
next = filter;
}
}
if (options.getStripSpace() == Whitespace.ALL) {
Stripper s = new AllElementStripper();
s.setStripAll();
s.setPipelineConfiguration(pipe);
s.setUnderlyingReceiver(receiver);
next = s;
} else if (options.getStripSpace() == Whitespace.XSLT) {
Controller controller = pipe.getController();
if (controller != null) {
next = controller.makeStripper(next);
}
}
if (source instanceof NodeInfo) {
NodeInfo ns = (NodeInfo)source;
String baseURI = ns.getBaseURI();
int val = schemaValidation & Validation.VALIDATION_MODE_MASK;
if (val != Validation.PRESERVE) {
StructuredQName topLevelName = options.getTopLevelElement();
int topLevelNameCode = -1;
if (topLevelName != null) {
topLevelNameCode = config.getNamePool().allocate(
topLevelName.getPrefix(), topLevelName.getNamespaceURI(), topLevelName.getLocalName());
}
next = config.getDocumentValidator(
next, baseURI, val, options.getStripSpace(), topLevelType, topLevelNameCode);
}
int kind = ns.getNodeKind();
if (kind != Type.DOCUMENT && kind != Type.ELEMENT) {
throw new IllegalArgumentException("Sender can only handle document or element nodes");
}
next.setSystemId(baseURI);
sendDocumentInfo(ns, next);
return;
} else if (source instanceof PullSource) {
sendPullSource((PullSource)source, next, options);
return;
} else if (source instanceof PullEventSource) {
sendPullEventSource((PullEventSource)source, next, options);
return;
} else if (source instanceof EventSource) {
((EventSource)source).send(next);
return;
} else if (source instanceof SAXSource) {
sendSAXSource((SAXSource)source, next, options);
return;
} else if (source instanceof StreamSource) {
StreamSource ss = (StreamSource)source;
// Following code allows the .NET platform to use a Pull parser
boolean dtdValidation = options.getDTDValidationMode() == Validation.STRICT;
Source ps = Configuration.getPlatform().getParserSource(
pipe, ss, schemaValidation, dtdValidation, options.getStripSpace());
if (ps == ss) {
String url = source.getSystemId();
InputSource is = new InputSource(url);
is.setCharacterStream(ss.getReader());
is.setByteStream(ss.getInputStream());
boolean reuseParser = false;
XMLReader parser = options.getXMLReader();
if (parser == null) {
parser = config.getSourceParser();
if (options.getEntityResolver() != null) {
parser.setEntityResolver(options.getEntityResolver());
}
reuseParser = true;
}
//System.err.println("Using parser: " + parser.getClass().getName());
SAXSource sax = new SAXSource(parser, is);
sax.setSystemId(source.getSystemId());
sendSAXSource(sax, next, options);
if (reuseParser) {
config.reuseSourceParser(parser);
}
} else {
// the Platform substituted a different kind of source
// On .NET with a default URIResolver we can expect an AugnmentedSource wrapping a PullSource
send(ps, next, options);
}
return;
} else if (staxSourceClass != null && staxSourceClass.isAssignableFrom(source.getClass())) {
// Test for a StAXSource
// Use reflection to avoid problems if JAXP 1.4 not installed
XMLStreamReader reader = null;
try {
Method getReaderMethod = staxSourceClass.getMethod("getXMLStreamReader", EMPTY_CLASS_ARRAY);
reader = (XMLStreamReader)getReaderMethod.invoke(source);
} catch (Exception e) {
// no action
}
//XMLStreamReader reader = ((StAXSource)source).getXMLStreamReader();
if (reader == null) {
throw new XPathException("Saxon can only handle a StAXSource that wraps an XMLStreamReader");
}
StaxBridge bridge = new StaxBridge();
bridge.setXMLStreamReader(reader);
sendPullSource(new PullSource(bridge), next, options);
return;
} else {
next = makeValidator(next, source.getSystemId(), options);
// See if there is a registered SourceResolver than can handle it
Source newSource = config.getSourceResolver().resolveSource(source, config);
if (newSource instanceof StreamSource ||
newSource instanceof SAXSource ||
newSource instanceof NodeInfo ||
newSource instanceof PullSource ||
newSource instanceof AugmentedSource ||
newSource instanceof EventSource) {
send(newSource, next, options);
}
// See if there is a registered external object model that knows about this kind of source
// (Note, this should pick up the platform-specific DOM model)
List externalObjectModels = config.getExternalObjectModels();
for (int m=0; m<externalObjectModels.size(); m++) {
ExternalObjectModel model = (ExternalObjectModel)externalObjectModels.get(m);
boolean done = model.sendSource(source, next, pipe);
if (done) {
return;