public static Receiver getReceiver( Result result,
Configuration config,
Properties props,
HashMap characterMapIndex)
throws XPathException {
NamePool namePool = config.getNamePool();
if (result instanceof Emitter) {
((Emitter)result).setOutputProperties(props);
return (Emitter)result;
} else if (result instanceof Receiver) {
return (Receiver)result;
} else if (result instanceof SAXResult) {
ContentHandlerProxy proxy = new ContentHandlerProxy();
proxy.setUnderlyingContentHandler(((SAXResult)result).getHandler());
proxy.setConfiguration(config);
return proxy;
} else if (result instanceof StreamResult) {
// The "target" is the start of the output pipeline, the Receiver that
// instructions will actually write to (except that other things like a
// NamespaceReducer may get added in front of it). The "emitter" is the
// last thing in the output pipeline, the Receiver that actually generates
// characters or bytes that are written to the StreamResult.
Receiver target;
Emitter emitter;
CharacterMapExpander characterMapExpander = null;
String method = props.getProperty(OutputKeys.METHOD);
String useMaps = props.getProperty(SaxonOutputKeys.USE_CHARACTER_MAPS);
if (useMaps != null && characterMapIndex != null) {
List characterMaps = new ArrayList(5);
StringTokenizer st = new StringTokenizer(useMaps);
while (st.hasMoreTokens()) {
String expandedName = st.nextToken();
int f = namePool.getFingerprintForExpandedName(expandedName);
HashMap map = (HashMap)characterMapIndex.get(new Integer(f));
if (map==null) {
throw new DynamicError("Character map '" + expandedName + "' has not been defined");
}
characterMaps.add(map);