1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.common.content;
20
21 import java.io.IOException;
22 import java.io.OutputStream;
23
24 import javax.xml.transform.Source;
25 import javax.xml.transform.dom.DOMSource;
26
27 import org.jdom2.JDOMException;
28 import org.jdom2.input.DOMBuilder;
29 import org.jdom2.output.XMLOutputter;
30 import org.w3c.dom.Document;
31
32
33
34
35
36
37 public class MCRDOMContent extends MCRXMLContent {
38
39 private Document dom;
40
41
42
43
44 public MCRDOMContent(Document dom) {
45 super();
46 this.dom = dom;
47 super.docType = dom.getDoctype() == null ? dom.getDocumentElement().getLocalName() : dom.getDoctype().getName();
48 }
49
50 @Override
51 public Source getSource() {
52 DOMSource source = new DOMSource(dom);
53 source.setSystemId(systemId);
54 return source;
55 }
56
57 @Override
58 public void sendTo(OutputStream out) throws IOException {
59 org.jdom2.Document jdom;
60 try {
61 jdom = asXML();
62 } catch (JDOMException ex) {
63 throw new IOException(ex);
64 }
65 new XMLOutputter(format).output(jdom, out);
66 }
67
68 @Override
69 public org.jdom2.Document asXML() throws JDOMException {
70 return new DOMBuilder().build(dom);
71 }
72 }