| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.event; |
| 9 |
|
| 10 |
import net.sf.saxon.Controller; |
| 11 |
import net.sf.saxon.om.NodeInfo; |
| 12 |
import net.sf.saxon.trans.XPathException; |
| 13 |
import net.sf.saxon.trans.XsltController; |
| 14 |
|
| 15 |
import javax.xml.transform.TransformerException; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class TransformerReceiver extends ProxyReceiver { |
| 26 |
|
| 27 |
private XsltController controller; |
| 28 |
private Builder builder; |
| 29 |
private Receiver destination; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public TransformerReceiver(XsltController controller) { |
| 38 |
super(controller.makeBuilder()); |
| 39 |
this.controller = controller; |
| 40 |
this.builder = (Builder) getNextReceiver(); |
| 41 |
this.builder.setUseEventLocation(false); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public void open() throws XPathException { |
| 49 |
builder.setSystemId(systemId); |
| 50 |
Receiver stripper = controller.makeStripper(builder); |
| 51 |
if (controller.isStylesheetStrippingTypeAnnotations()) { |
| 52 |
stripper = controller.getConfiguration().getAnnotationStripper(stripper); |
| 53 |
} |
| 54 |
setUnderlyingReceiver(stripper); |
| 55 |
nextReceiver.open(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public Controller getController() { |
| 65 |
return controller; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public void setSystemId(String systemId) { |
| 73 |
super.setSystemId(systemId); |
| 74 |
controller.setBaseOutputURI(systemId); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public void setDestination(Receiver destination) { |
| 85 |
this.destination = destination; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public Receiver getDestination() { |
| 96 |
return destination; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public void close() throws XPathException { |
| 105 |
if (builder == null) { |
| 106 |
|
| 107 |
} else { |
| 108 |
nextReceiver.close(); |
| 109 |
NodeInfo doc = builder.getCurrentRoot(); |
| 110 |
builder.reset(); |
| 111 |
builder = null; |
| 112 |
if (doc == null) { |
| 113 |
throw new XPathException("No source document has been built"); |
| 114 |
} |
| 115 |
doc.getTreeInfo().setSpaceStrippingRule(controller.getSpaceStrippingRule()); |
| 116 |
if (destination == null) { |
| 117 |
throw new XPathException("No output destination has been supplied"); |
| 118 |
} |
| 119 |
try { |
| 120 |
controller.setGlobalContextItem(doc); |
| 121 |
controller.applyTemplates(doc, destination); |
| 122 |
} catch (TransformerException e) { |
| 123 |
throw XPathException.makeXPathException(e); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
} |
| 129 |
|