| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.jaxp; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.event.Receiver; |
| 12 |
import net.sf.saxon.event.ReceivingContentHandler; |
| 13 |
import net.sf.saxon.event.Stripper; |
| 14 |
import net.sf.saxon.lib.SerializerFactory; |
| 15 |
import net.sf.saxon.om.AllElementsSpaceStrippingRule; |
| 16 |
import net.sf.saxon.serialize.SerializationProperties; |
| 17 |
import net.sf.saxon.trans.XPathException; |
| 18 |
import org.xml.sax.SAXException; |
| 19 |
|
| 20 |
import javax.xml.transform.Result; |
| 21 |
import javax.xml.transform.Transformer; |
| 22 |
import javax.xml.transform.sax.TransformerHandler; |
| 23 |
import javax.xml.transform.stream.StreamResult; |
| 24 |
import java.util.Properties; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class IdentityTransformerHandler extends ReceivingContentHandler implements TransformerHandler { |
| 36 |
|
| 37 |
private Result result; |
| 38 |
private String systemId; |
| 39 |
private IdentityTransformer controller; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
protected IdentityTransformerHandler(IdentityTransformer controller) { |
| 50 |
this.controller = controller; |
| 51 |
setPipelineConfiguration(controller.getConfiguration().makePipelineConfiguration()); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public Transformer getTransformer() { |
| 59 |
return controller; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public void setSystemId(String url) { |
| 67 |
systemId = url; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public String getSystemId() { |
| 75 |
return systemId; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public void setResult(Result result) { |
| 83 |
if (result == null) { |
| 84 |
throw new IllegalArgumentException("Result must not be null"); |
| 85 |
} |
| 86 |
this.result = result; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public Result getResult() { |
| 96 |
return result; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public void startDocument() throws SAXException { |
| 104 |
if (result == null) { |
| 105 |
result = new StreamResult(System.out); |
| 106 |
} |
| 107 |
try { |
| 108 |
Properties props = controller.getOutputProperties(); |
| 109 |
Configuration config = getConfiguration(); |
| 110 |
SerializerFactory sf = config.getSerializerFactory(); |
| 111 |
Receiver out = sf.getReceiver(result, new SerializationProperties(props)); |
| 112 |
setPipelineConfiguration(out.getPipelineConfiguration()); |
| 113 |
if (config.isStripsAllWhiteSpace()) { |
| 114 |
out = new Stripper(AllElementsSpaceStrippingRule.getInstance(), out); |
| 115 |
} |
| 116 |
setReceiver(out); |
| 117 |
} catch (XPathException err) { |
| 118 |
throw new SAXException(err); |
| 119 |
} |
| 120 |
super.startDocument(); |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|