| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.jaxp; |
| 9 |
|
| 10 |
import net.sf.saxon.Version; |
| 11 |
import net.sf.saxon.event.ContentHandlerProxy; |
| 12 |
import org.xml.sax.InputSource; |
| 13 |
import org.xml.sax.SAXException; |
| 14 |
|
| 15 |
import javax.xml.transform.Transformer; |
| 16 |
import javax.xml.transform.TransformerException; |
| 17 |
import javax.xml.transform.sax.SAXSource; |
| 18 |
import java.io.IOException; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class FilterImpl extends AbstractXMLFilter { |
| 29 |
|
| 30 |
private TransformerImpl transformer; |
| 31 |
|
| 32 |
FilterImpl(TransformerImpl transformer) { |
| 33 |
this.transformer = transformer; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public void parse(InputSource input) throws IOException, SAXException { |
| 55 |
if (parser == null) { |
| 56 |
try { |
| 57 |
parser = Version.platform.loadParser(); |
| 58 |
} catch (Exception err) { |
| 59 |
throw new SAXException(err); |
| 60 |
} |
| 61 |
} |
| 62 |
SAXSource source = new SAXSource(); |
| 63 |
source.setInputSource(input); |
| 64 |
source.setXMLReader(parser); |
| 65 |
ContentHandlerProxy result = new ContentHandlerProxy(); |
| 66 |
result.setPipelineConfiguration(transformer.getConfiguration().makePipelineConfiguration()); |
| 67 |
result.setUnderlyingContentHandler(contentHandler); |
| 68 |
|
| 69 |
if (lexicalHandler != null) { |
| 70 |
result.setLexicalHandler(lexicalHandler); |
| 71 |
} |
| 72 |
try { |
| 73 |
|
| 74 |
result.setOutputProperties(transformer.getOutputProperties()); |
| 75 |
transformer.transform(source, result); |
| 76 |
} catch (TransformerException err) { |
| 77 |
Throwable cause = err.getException(); |
| 78 |
if (cause != null && cause instanceof SAXException) { |
| 79 |
throw (SAXException) cause; |
| 80 |
} else if (cause != null && cause instanceof IOException) { |
| 81 |
throw (IOException) cause; |
| 82 |
} else { |
| 83 |
throw new SAXException(err); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public Transformer getTransformer() { |
| 98 |
return transformer; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
} |
| 103 |
|