| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.dom; |
| 9 |
|
| 10 |
import net.sf.saxon.Transform; |
| 11 |
import net.sf.saxon.trans.XPathException; |
| 12 |
import org.w3c.dom.Document; |
| 13 |
import org.xml.sax.InputSource; |
| 14 |
import org.xml.sax.SAXException; |
| 15 |
|
| 16 |
import javax.xml.parsers.DocumentBuilder; |
| 17 |
import javax.xml.parsers.DocumentBuilderFactory; |
| 18 |
import javax.xml.parsers.ParserConfigurationException; |
| 19 |
import javax.xml.transform.Source; |
| 20 |
import javax.xml.transform.stream.StreamSource; |
| 21 |
import java.io.IOException; |
| 22 |
import java.util.ArrayList; |
| 23 |
import java.util.List; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class DOMTransform extends Transform { |
| 33 |
|
| 34 |
public List<Source> preprocess(List<Source> sources) throws XPathException { |
| 35 |
try { |
| 36 |
ArrayList<Source> domSources = new ArrayList<>(sources.size()); |
| 37 |
for (Object source : sources) { |
| 38 |
StreamSource src = (StreamSource) source; |
| 39 |
InputSource ins = new InputSource(src.getSystemId()); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 48 |
factory.setNamespaceAware(true); |
| 49 |
DocumentBuilder builder = factory.newDocumentBuilder(); |
| 50 |
Document doc = builder.parse(ins); |
| 51 |
DocumentWrapper dom = new DocumentWrapper(doc, src.getSystemId(), getConfiguration()); |
| 52 |
domSources.add(dom.getRootNode()); |
| 53 |
} |
| 54 |
return domSources; |
| 55 |
} catch (ParserConfigurationException | IOException | SAXException e) { |
| 56 |
throw new XPathException(e); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
public static void main(String[] args) { |
| 61 |
new DOMTransform().doTransform(args, "DOMTransform"); |
| 62 |
} |
| 63 |
} |
| 64 |
|