* reported.
*/
public void send(Source source, Receiver receiver, boolean isFinal)
throws XPathException {
Configuration config = pipe.getConfiguration();
receiver.setPipelineConfiguration(pipe);
receiver.setSystemId(source.getSystemId());
Receiver next = receiver;
ParseOptions options = new ParseOptions();
options.setXIncludeAware(config.isXIncludeAware());
int schemaValidation = config.getSchemaValidationMode();
if (isFinal) {
// this ensures that the Validate command produces multiple error messages
schemaValidation |= Validation.VALIDATE_OUTPUT;
}
options.setSchemaValidationMode(schemaValidation);
options.setDTDValidationMode(config.isValidation() ? Validation.STRICT : Validation.STRIP);
options.setXIncludeAware(config.isXIncludeAware());
int stripSpace = Whitespace.UNSPECIFIED;
// boolean xInclude = config.isXIncludeAware();
// boolean xqj = false;
// boolean closeAfterUse = false;
// int schemaValidation = config.getSchemaValidationMode();
// int topLevelNameCode = -1;
// int dtdValidation = config.isValidation() ? Validation.STRICT : Validation.STRIP;
XMLReader parser = null;
SchemaType topLevelType = null;
if (source instanceof AugmentedSource) {
AugmentedSource as = (AugmentedSource)source;
options.setPleaseCloseAfterUse(as.isPleaseCloseAfterUse());
stripSpace = as.getStripSpace();
if (as.isXIncludeAwareSet()) {
options.setXIncludeAware(as.isXIncludeAware());
}
options.setSourceIsXQJ(as.sourceIsXQJ());
int localValidate = ((AugmentedSource)source).getSchemaValidation();
if (localValidate != Validation.DEFAULT) {
schemaValidation = localValidate;
if (isFinal) {
// this ensures that the Validate command produces multiple error messages
schemaValidation |= Validation.VALIDATE_OUTPUT;
}
options.setSchemaValidationMode(schemaValidation);
}
topLevelType = ((AugmentedSource)source).getTopLevelType();
StructuredQName topLevelName = ((AugmentedSource)source).getTopLevelElement();
if (topLevelName != null) {
options.setTopLevelElement(topLevelName);
}
int localDTDValidate = ((AugmentedSource)source).getDTDValidation();
if (localDTDValidate != Validation.DEFAULT) {
options.setDTDValidationMode(localDTDValidate);
}
parser = ((AugmentedSource)source).getXMLReader();
List filters = ((AugmentedSource)source).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;
}
}
source = ((AugmentedSource)source).getContainedSource();
}
if (stripSpace == Whitespace.UNSPECIFIED) {
stripSpace = config.getStripsWhiteSpace();
}
options.setStripSpace(stripSpace);
if (stripSpace == Whitespace.ALL) {
Stripper s = new AllElementStripper();
s.setStripAll();
s.setPipelineConfiguration(pipe);
s.setUnderlyingReceiver(receiver);
next = s;
} else if (stripSpace == 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, stripSpace, 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, stripSpace);
if (ps == ss) {
String url = source.getSystemId();
InputSource is = new InputSource(url);
is.setCharacterStream(ss.getReader());
is.setByteStream(ss.getInputStream());
boolean reuseParser = false;
if (parser == null) {
parser = config.getSourceParser();
reuseParser = true;
}
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, isFinal);
}
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, isFinal);
}
// See if there is a registered external object model that knows about this kind of source
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;