1 package net.sf.saxon.event; 2 3 import net.sf.saxon.om.NodeInfo; 4 import net.sf.saxon.trans.XPathException; 5 import net.sf.saxon.type.Type; 6 7 12 13 public class DocumentSender implements SaxonLocator { 14 15 private NodeInfo top; 16 17 22 23 public DocumentSender(NodeInfo top) { 24 this.top = top; 25 int kind = top.getNodeKind(); 26 if (kind != Type.DOCUMENT && kind != Type.ELEMENT) { 27 throw new IllegalArgumentException ("DocumentSender can only handle document or element nodes"); 28 } 29 } 30 31 34 35 public void send(Receiver receiver) throws XPathException { 36 37 PipelineConfiguration pipe = receiver.getPipelineConfiguration(); 38 if (top.getNamePool() != pipe.getConfiguration().getNamePool()) { 39 throw new IllegalArgumentException ("DocumentSender source and target must use the same NamePool"); 40 } 41 42 if (pipe.getLocationProvider() == null) { 44 receiver.setSystemId(top.getSystemId()); 45 pipe.setLocationProvider(this); 46 } 47 48 receiver.open(); 50 51 receiver.startDocument(0); 53 top.copy(receiver, NodeInfo.ALL_NAMESPACES, true, 0); 54 receiver.endDocument(); 55 56 receiver.close(); 58 } 59 60 64 68 public int getColumnNumber() { 69 return -1; 70 } 71 72 public int getLineNumber() { 73 return -1; 74 } 75 76 public String getPublicId() { 77 return null; 78 } 79 80 public String getSystemId() { 81 return top.getSystemId(); 82 } 83 84 public String getSystemId(int locationId) { 85 return getSystemId(); 86 } 87 88 public int getLineNumber(int locationId) { 89 return getLineNumber(); 90 } 91 92 } 93 | Popular Tags |