Debian Codegraph @

net/sf/saxon/stax/StAXResultHandlerImpl.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2015 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.stax;
9
10 import net.sf.saxon.event.Receiver;
11 import net.sf.saxon.lib.StAXResultHandler;
12
13 import javax.xml.transform.Result;
14 import javax.xml.transform.stax.StAXResult;
15 import java.util.Properties;
16
17 /**
18 * StAxResultHandler is used to allow a transformation result to be supplied as a StAXResult.
19 * It is loaded dynamically in case StAXResult is not present in the JDK.
20 */
21 public class StAXResultHandlerImpl implements StAXResultHandler {
22
23 public Receiver getReceiver(Result result, Properties properties) {
24 if (((StAXResult) result).getXMLStreamWriter() != null) {
25 return new ReceiverToXMLStreamWriter(((StAXResult) result).getXMLStreamWriter());
26 } else if (((StAXResult) result).getXMLEventWriter() != null) {
27 throw new UnsupportedOperationException("XMLEventWriter is currently not supported as a Saxon output destination");
28 } else {
29 throw new IllegalStateException("StAXResult contains neither an XMLStreamWriter nor XMLEventWriter");
30 }
31 }
32 }
33