private static XMLStreamWriter getWriter()

in src/main/java/org/apache/commons/scxml2/io/SCXMLWriter.java [1153:1184]


    private static XMLStreamWriter getWriter(final Configuration configuration, final OutputStream stream,
                                             final Writer writer, final Result result)
            throws XMLStreamException {

        // Instantiate the XMLOutputFactory
        final XMLOutputFactory factory = XMLOutputFactory.newInstance();
        /*
        if (configuration.factoryId != null && configuration.factoryClassLoader != null) {
            // TODO StAX API bug means we can't use custom factories yet
            //factory = XMLOutputFactory.newInstance(configuration.factoryId, configuration.factoryClassLoader);
        }
        */
        for (final Map.Entry<String, Object> property : configuration.properties.entrySet()) {
            factory.setProperty(property.getKey(), property.getValue());
        }

        XMLStreamWriter xsw = null;
        if (configuration.usePrettyPrint || configuration.writeToString) {
            xsw = factory.createXMLStreamWriter(configuration.internalWriter);
        } else if (stream != null) {
            if (configuration.encoding != null) {
                xsw = factory.createXMLStreamWriter(stream, configuration.encoding);
            } else {
                xsw = factory.createXMLStreamWriter(stream);
            }
        } else if (writer != null) {
            xsw = factory.createXMLStreamWriter(writer);
        } else if (result != null) {
            xsw = factory.createXMLStreamWriter(result);
        }
        return xsw;
    }