|
27 | 27 | import org.exist.dom.memtree.DocumentBuilderReceiver;
|
28 | 28 | import org.exist.dom.memtree.DocumentImpl;
|
29 | 29 | import org.exist.dom.memtree.MemTreeBuilder;
|
30 |
| -import org.exist.xquery.ErrorCodes; |
31 | 30 | import org.exist.xquery.XPathException;
|
32 | 31 | import org.exist.xquery.XQueryContext;
|
33 |
| -import org.exist.xquery.value.NodeValue; |
34 | 32 | import org.exist.xquery.value.Sequence;
|
35 | 33 | import org.exist.xquery.value.StringValue;
|
36 |
| -import org.exist.xquery.value.ValueSequence; |
37 |
| -import org.w3c.dom.Node; |
38 |
| -import org.w3c.dom.NodeList; |
39 | 34 |
|
40 | 35 | import java.io.StringWriter;
|
| 36 | +import java.util.Objects; |
41 | 37 |
|
42 | 38 | class Delivery {
|
43 | 39 |
|
@@ -120,47 +116,10 @@ Sequence convert() throws XPathException {
|
120 | 116 | case SERIALIZED:
|
121 | 117 | return new StringValue(getSerializedString());
|
122 | 118 | case RAW:
|
123 |
| - //TODO (AP) rawOutput and mediation via document when the Xdm value is complex, is a hack |
124 |
| - final XdmValue xdmValue = getXdmValue(); |
125 |
| - if (xdmValue != null) { |
126 |
| - return Convert.ToExist.of(xdmValue); |
127 |
| - } |
128 |
| - final DocumentImpl document = getDocument(); |
129 |
| - if (document != null) { |
130 |
| - return rawOutput(getDocument()); |
131 |
| - } |
132 |
| - throw new XPathException(ErrorCodes.FOXT0003, "No RAW output has been constructed by the transformation."); |
| 119 | + return Convert.ToExist.of(Objects.requireNonNull(getXdmValue())); |
133 | 120 | case DOCUMENT:
|
134 | 121 | default:
|
135 | 122 | return getDocument();
|
136 | 123 | }
|
137 | 124 | }
|
138 |
| - |
139 |
| - private static Sequence rawOutput(final NodeValue outputDocument) throws XPathException { |
140 |
| - final Node node = outputDocument.getNode(); |
141 |
| - if (node != null) { |
142 |
| - final NodeList children = node.getChildNodes(); |
143 |
| - final int length = children.getLength(); |
144 |
| - if (length == 0) { |
145 |
| - return Sequence.EMPTY_SEQUENCE; |
146 |
| - } else if (length == 1) { |
147 |
| - final Node item = children.item(0); |
148 |
| - if (item instanceof NodeValue) { |
149 |
| - return (NodeValue)item; |
150 |
| - } |
151 |
| - } else { |
152 |
| - final ValueSequence valueSequence = new ValueSequence(); |
153 |
| - for (int i = 0; i < children.getLength(); i++) { |
154 |
| - final Node child = children.item(i); |
155 |
| - if (child instanceof NodeValue) { |
156 |
| - valueSequence.add((NodeValue)child); |
157 |
| - } |
158 |
| - } |
159 |
| - return valueSequence; |
160 |
| - } |
161 |
| - throw new XPathException(ErrorCodes.XPTY0004, "Unable to produce raw output from contents of: " + outputDocument); |
162 |
| - } |
163 |
| - return Sequence.EMPTY_SEQUENCE; |
164 |
| - } |
165 |
| - |
166 | 125 | }
|
0 commit comments