Example usage for javax.xml.stream XMLOutputFactory newInstance

List of usage examples for javax.xml.stream XMLOutputFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.stream XMLOutputFactory newInstance.

Prototype

public static XMLOutputFactory newInstance() throws FactoryConfigurationError 

Source Link

Document

Creates a new instance of the factory in exactly the same manner as the #newFactory() method.

Usage

From source file:de.escidoc.core.common.util.xml.XmlUtility.java

/**
 * Gets an initilized {@code XMLOutputFactory2} instance.<br/> The returned instance is initialized as follows:
 * <ul> <li>If the provided parameter is set to {@code true}, IS_REPAIRING_NAMESPACES is set to true, i.e. the
 * created writers will automatically repair the namespaces, see {@code XMLOutputFactory} for details.</li>
 * <li>For writing escaped attribute values, the {@link StaxAttributeEscapingWriterFactory} is used<./li> <li>For
 * writing escaped text content, the {@link StaxTextEscapingWriterFactory} is used.</li> </ul>
 *
 * @param repairing Flag indicating if the factory shall create namespace repairing writers ({@code true}) or
 *                  non repairing writers ({@code false}).
 * @return Returns the initalized {@code XMLOutputFactory} instance.
 *//*from   w  w w .jav a 2 s  .c  o  m*/
private static XMLOutputFactory getInitilizedXmlOutputFactory(final boolean repairing) {
    final XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
    xmlof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, repairing);
    if (repairing) {
        xmlof.setProperty(XMLOutputFactory2.P_AUTOMATIC_NS_PREFIX, "ext");
    }
    xmlof.setProperty(XMLOutputFactory2.P_ATTR_VALUE_ESCAPER, new StaxAttributeEscapingWriterFactory());
    xmlof.setProperty(XMLOutputFactory2.P_TEXT_ESCAPER, new StaxTextEscapingWriterFactory());
    return xmlof;
}

From source file:com.gtwm.pb.model.manageData.DataManagement.java

/**
 * Based on http://www.vogella.de/articles/RSSFeed/article.html
 */// ww  w  . j  av  a 2s .co  m
private String generateRSS(AppUserInfo user, BaseReportInfo report, List<DataRowInfo> reportDataRows)
        throws XMLStreamException, ObjectNotFoundException {
    // Create a XMLOutputFactory
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    // Create XMLEventWriter
    StringWriter stringWriter = new StringWriter();
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(stringWriter);
    // Create a EventFactory
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEvent end = eventFactory.createDTD("\n");
    // Create and write Start Tag
    StartDocument startDocument = eventFactory.createStartDocument();
    eventWriter.add(startDocument);
    // Create open tag
    eventWriter.add(end);
    StartElement rssStart = eventFactory.createStartElement("", "", "rss");
    eventWriter.add(rssStart);
    eventWriter.add(eventFactory.createAttribute("version", "2.0"));
    eventWriter.add(end);
    eventWriter.add(eventFactory.createStartElement("", "", "channel"));
    eventWriter.add(end);
    // Write the different nodes
    this.createNode(eventWriter, "title", report.getModule().getModuleName() + " - " + report.getReportName());
    // TODO: Don't hard code host part of URL
    String reportLink = "https://appserver.gtportalbase.com/agileBase/AppController.servlet?return=gui/display_application&set_table="
            + report.getParentTable().getInternalTableName() + "&set_report=" + report.getInternalReportName();
    this.createNode(eventWriter, "link", reportLink);
    this.createNode(eventWriter, "description", "A live data feed from www.agilebase.co.uk");
    DateFormat dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    Date lastDataChangeDate = new Date(getLastCompanyDataChangeTime(user.getCompany()));
    this.createNode(eventWriter, "pubdate", dateFormatter.format(lastDataChangeDate));
    for (DataRowInfo reportDataRow : reportDataRows) {
        eventWriter.add(eventFactory.createStartElement("", "", "item"));
        eventWriter.add(end);
        this.createNode(eventWriter, "title", buildEventTitle(report, reportDataRow, false));
        this.createNode(eventWriter, "description", reportDataRow.toString());
        String rowLink = reportLink + "&set_row_id=" + reportDataRow.getRowId();
        this.createNode(eventWriter, "link", rowLink);
        this.createNode(eventWriter, "guid", rowLink);
        eventWriter.add(end);
        eventWriter.add(eventFactory.createEndElement("", "", "item"));
        eventWriter.add(end);
    }
    eventWriter.add(eventFactory.createEndElement("", "", "channel"));
    eventWriter.add(end);
    eventWriter.add(eventFactory.createEndElement("", "", "rss"));
    eventWriter.add(end);
    return stringWriter.toString();
}

From source file:edu.ucsd.library.dams.api.DAMSAPIServlet.java

private void sparqlQuery(String sparql, TripleStore ts, Map<String, String[]> params, String pathInfo,
        HttpServletResponse res) throws Exception {
    if (sparql == null) {
        Map err = error(SC_BAD_REQUEST, "No query specified.", null);
        output(err, params, pathInfo, res);
        return;//from  w  ww  .j  a v a2  s . co m
    } else {
        log.info("sparql: " + sparql);
    }

    // sparql query
    BindingIterator objs = ts.sparqlSelect(sparql);

    // start output
    String sparqlNS = "http://www.w3.org/2005/sparql-results#";
    res.setContentType("application/sparql-results+xml");
    OutputStream out = res.getOutputStream();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter stream = factory.createXMLStreamWriter(out);
    stream.setDefaultNamespace(sparqlNS);
    stream.writeStartDocument();
    stream.writeStartElement("sparql");

    // output bindings
    boolean headerWritten = false;
    while (objs.hasNext()) {
        Map<String, String> binding = objs.nextBinding();

        // write header on first binding
        if (!headerWritten) {
            Iterator<String> it = binding.keySet().iterator();
            stream.writeStartElement("head");
            while (it.hasNext()) {
                String k = it.next();
                stream.writeStartElement("variable");
                stream.writeAttribute("name", k);
                stream.writeEndElement();
            }
            stream.writeEndElement();
            stream.writeStartElement("results"); // ordered='false' distinct='false'
            headerWritten = true;
        }

        stream.writeStartElement("result");
        Iterator<String> it = binding.keySet().iterator();
        while (it.hasNext()) {
            String k = it.next();
            String v = binding.get(k);
            stream.writeStartElement("binding");
            stream.writeAttribute("name", k);
            String type = null;
            if (v.startsWith("\"") && v.endsWith("\"")) {
                type = "literal";
                v = v.substring(1, v.length() - 1);
            } else if (v.startsWith("_:")) {
                type = "bnode";
                v = v.substring(2);
            } else {
                type = "uri";
            }
            stream.writeStartElement(type);
            stream.writeCharacters(v);
            stream.writeEndElement();
            stream.writeEndElement();
        }
        stream.writeEndElement();
    }

    // finish output
    stream.writeEndElement();
    stream.writeEndDocument();
    stream.flush();
    stream.close();
}

From source file:nl.armatiek.xslweb.serializer.RequestSerializer.java

public String serializeToXML() throws Exception {
    StringWriter sw = new StringWriter();

    List<FileItem> fileItems = getMultipartContentItems();

    XMLOutputFactory output = XMLOutputFactory.newInstance();
    this.xsw = output.createXMLStreamWriter(sw);
    if (developmentMode) {
        this.xsw = new IndentingXMLStreamWriter(this.xsw);
    }//from w ww .j av a  2  s  .  c  om

    xsw.writeStartDocument();
    xsw.setPrefix("req", URI);
    xsw.writeStartElement(URI, "request");
    xsw.writeNamespace("req", URI);

    serializeProperties();
    serializeHeaders();
    serializeParameters(fileItems);
    serializeBody(fileItems);
    serializeAttributes();
    serializeFileUploads(fileItems);
    serializeSession();
    serializeCookies();

    xsw.writeEndElement();
    xsw.writeEndDocument();

    return sw.toString();
}

From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    XMLStreamWriter xmlStreamWriter;
    try {//from   w w  w .  j  a v a  2 s  .  com
        xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement("root");
        xmlStreamWriter.writeAttribute("url", getUrl());
        // xmlStreamWriter.writeAttribute("level",
        // String.valueOf(getLevel()));
        process(xmlStreamWriter, getUrl(), getLevel());
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.flush();
        xmlStreamWriter.close();
    } catch (XMLStreamException e) {
        throw new PipeRunException(this, "XMLStreamException", e);
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, "DomBuilderException", e);
    } catch (XPathExpressionException e) {
        throw new PipeRunException(this, "XPathExpressionException", e);
    }

    return new PipeRunResult(getForward(), stringWriter.getBuffer().toString());
}

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

public static void main(String[] args) {

    logger.info("Starting application [ rtd ] ...");

    try {// w w  w  . j a v  a2s. c o m

        config.addConfiguration(
                new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME)));

        HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT);

        EodDataProvider eodDataProvider = null;

        OutputStream out = new FileOutputStream(OUTPUT_FILENAME);
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(out);

        eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME);

        writer.writeStartDocument("utf-8", "1.0");
        writer.writeCharacters(NEWLINE);
        writer.writeComment("Test data for running DataScraper unit tests against");
        writer.writeCharacters(NEWLINE);

        writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI);

        writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME);
        writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI);
        writer.writeCharacters(NEWLINE);

        serializeExchanges(eodDataProvider, writer);
        serializeSymbols(eodDataProvider, writer);
        serializeQuotes(eodDataProvider, writer);

        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
        writer.writeEndDocument();
        writer.flush();
        writer.close();

    } catch (ConfigurationException ce) {

        logger.error(ce.toString());
        ce.printStackTrace();

    } catch (Exception e) {

        logger.error(e.toString());
        logger.error(e);

    }

    logger.info("Exiting application [ rtd ] ...");

}

From source file:org.activiti.bpmn.converter.BpmnXMLConverter.java

public byte[] convertToXML(BpmnModel model, String encoding) {
    try {/*from   w  ww.ja  va2  s . c  o  m*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        DefinitionsRootExport.writeRootElement(model, xtw, encoding);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
        PoolExport.writePools(model, xtw);

        for (Process process : model.getProcesses()) {

            if (process.getFlowElements().size() == 0 && process.getLanes().size() == 0) {
                // empty process, ignore it 
                continue;
            }

            ProcessExport.writeProcess(process, xtw);

            for (FlowElement flowElement : process.getFlowElements()) {
                createXML(flowElement, model, xtw);
            }

            for (Artifact artifact : process.getArtifacts()) {
                createXML(artifact, model, xtw);
            }

            // end process element
            xtw.writeEndElement();
        }

        BPMNDIExport.writeBPMNDI(model, xtw);

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new XMLException("Error writing BPMN XML", e);
    }
}

From source file:org.activiti.dmn.xml.converter.DmnXMLConverter.java

public byte[] convertToXML(DmnDefinition model, String encoding) {
    try {/*from   w w w. j a v  a2  s.c om*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        xtw.writeStartElement(ELEMENT_DEFINITIONS);
        xtw.writeDefaultNamespace(DMN_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_ID, model.getId());
        if (StringUtils.isNotEmpty(model.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, model.getName());
        }
        xtw.writeAttribute(ATTRIBUTE_NAMESPACE, MODEL_NAMESPACE);

        DmnXMLUtil.writeElementDescription(model, xtw);
        DmnXMLUtil.writeExtensionElements(model, xtw);

        for (ItemDefinition itemDefinition : model.getItemDefinitions()) {
            xtw.writeStartElement(ELEMENT_ITEM_DEFINITION);
            xtw.writeAttribute(ATTRIBUTE_ID, itemDefinition.getId());
            if (StringUtils.isNotEmpty(itemDefinition.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, itemDefinition.getName());
            }

            DmnXMLUtil.writeElementDescription(itemDefinition, xtw);
            DmnXMLUtil.writeExtensionElements(itemDefinition, xtw);

            xtw.writeStartElement(ELEMENT_TYPE_DEFINITION);
            xtw.writeCharacters(itemDefinition.getTypeDefinition());
            xtw.writeEndElement();

            xtw.writeEndElement();
        }

        for (Decision decision : model.getDrgElements()) {
            xtw.writeStartElement(ELEMENT_DECISION);
            xtw.writeAttribute(ATTRIBUTE_ID, decision.getId());
            if (StringUtils.isNotEmpty(decision.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, decision.getName());
            }

            DmnXMLUtil.writeElementDescription(decision, xtw);
            DmnXMLUtil.writeExtensionElements(decision, xtw);

            DecisionTable decisionTable = decision.getDecisionTable();
            xtw.writeStartElement(ELEMENT_DECISION_TABLE);
            xtw.writeAttribute(ATTRIBUTE_ID, decisionTable.getId());

            if (decisionTable.getHitPolicy() != null) {
                xtw.writeAttribute(ATTRIBUTE_HIT_POLICY, decisionTable.getHitPolicy().toString());
            }

            DmnXMLUtil.writeElementDescription(decisionTable, xtw);
            DmnXMLUtil.writeExtensionElements(decisionTable, xtw);

            for (InputClause clause : decisionTable.getInputs()) {
                xtw.writeStartElement(ELEMENT_INPUT_CLAUSE);
                if (StringUtils.isNotEmpty(clause.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getId());
                }
                if (StringUtils.isNotEmpty(clause.getLabel())) {
                    xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel());
                }

                DmnXMLUtil.writeElementDescription(clause, xtw);
                DmnXMLUtil.writeExtensionElements(clause, xtw);

                if (clause.getInputExpression() != null) {
                    xtw.writeStartElement(ELEMENT_INPUT_EXPRESSION);
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getInputExpression().getId());

                    if (StringUtils.isNotEmpty(clause.getInputExpression().getTypeRef())) {
                        xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getInputExpression().getTypeRef());
                    }

                    if (StringUtils.isNotEmpty(clause.getInputExpression().getText())) {
                        xtw.writeStartElement(ELEMENT_TEXT);
                        xtw.writeCharacters(clause.getInputExpression().getText());
                        xtw.writeEndElement();
                    }

                    xtw.writeEndElement();
                }

                xtw.writeEndElement();
            }

            for (OutputClause clause : decisionTable.getOutputs()) {
                xtw.writeStartElement(ELEMENT_OUTPUT_CLAUSE);
                if (StringUtils.isNotEmpty(clause.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getId());
                }
                if (StringUtils.isNotEmpty(clause.getLabel())) {
                    xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel());
                }
                if (StringUtils.isNotEmpty(clause.getName())) {
                    xtw.writeAttribute(ATTRIBUTE_NAME, clause.getName());
                }
                if (StringUtils.isNotEmpty(clause.getTypeRef())) {
                    xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getTypeRef());
                }

                DmnXMLUtil.writeElementDescription(clause, xtw);
                DmnXMLUtil.writeExtensionElements(clause, xtw);

                xtw.writeEndElement();
            }

            for (DecisionRule rule : decisionTable.getRules()) {
                xtw.writeStartElement(ELEMENT_RULE);
                if (StringUtils.isNotEmpty(rule.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, rule.getId());
                }

                DmnXMLUtil.writeElementDescription(rule, xtw);
                DmnXMLUtil.writeExtensionElements(rule, xtw);

                for (RuleInputClauseContainer container : rule.getInputEntries()) {
                    xtw.writeStartElement(ELEMENT_INPUT_ENTRY);
                    xtw.writeAttribute(ATTRIBUTE_ID, container.getInputEntry().getId());

                    xtw.writeStartElement(ELEMENT_TEXT);
                    xtw.writeCharacters(container.getInputEntry().getText());
                    xtw.writeEndElement();

                    xtw.writeEndElement();
                }

                for (RuleOutputClauseContainer container : rule.getOutputEntries()) {
                    xtw.writeStartElement(ELEMENT_OUTPUT_ENTRY);
                    xtw.writeAttribute(ATTRIBUTE_ID, container.getOutputEntry().getId());

                    xtw.writeStartElement(ELEMENT_TEXT);
                    xtw.writeCharacters(container.getOutputEntry().getText());
                    xtw.writeEndElement();

                    xtw.writeEndElement();
                }

                xtw.writeEndElement();
            }

            xtw.writeEndElement();

            xtw.writeEndElement();
        }

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new DmnXMLException("Error writing BPMN XML", e);
    }
}

From source file:org.alex73.osm.converters.bel.Convert.java

public static void main(String[] args) throws Exception {
    loadStreetNamesForHouses();/*from  w w w .  j a v  a2 s.c o m*/

    InputStream in = new BZip2CompressorInputStream(
            new BufferedInputStream(new FileInputStream("tmp/belarus-latest.osm.bz2"), BUFFER_SIZE));

    // create xml event reader for input stream
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEvent newLine = eventFactory.createCharacters("\n");
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLEventReader reader = xif.createXMLEventReader(in);
    XMLEventWriter wrCyr = xof.createXMLEventWriter(
            new BufferedOutputStream(new FileOutputStream("tmp/belarus-bel.osm"), BUFFER_SIZE));
    XMLEventWriter wrInt = xof.createXMLEventWriter(
            new BufferedOutputStream(new FileOutputStream("tmp/belarus-intl.osm"), BUFFER_SIZE));

    // initialize jaxb
    JAXBContext jaxbCtx = JAXBContext.newInstance(Node.class, Way.class, Relation.class);
    Unmarshaller um = jaxbCtx.createUnmarshaller();
    Marshaller m = jaxbCtx.createMarshaller();
    m.setProperty(Marshaller.JAXB_FRAGMENT, true);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    XMLEvent e = null;
    while ((e = reader.peek()) != null) {
        boolean processed = false;
        if (e.isStartElement()) {
            StartElement se = (StartElement) e;
            switch (se.getName().getLocalPart()) {
            case "way":
                Way way = um.unmarshal(reader, Way.class).getValue();
                if (way.getId() == 25439425) {
                    System.out.println();
                }
                fixBel(way.getTag(), "name:be", "name");
                String nameBeHouse = houseStreetBe.get(way.getId());
                if (nameBeHouse != null) {
                    setTag(way.getTag(), "addr:street", nameBeHouse);
                }
                m.marshal(way, wrCyr);
                fixInt(way.getTag());
                m.marshal(way, wrInt);
                wrCyr.add(newLine);
                wrInt.add(newLine);
                processed = true;
                break;
            case "node":
                Node node = um.unmarshal(reader, Node.class).getValue();
                fixBel(node.getTag(), "name:be", "name");
                // fixBel(node.getTag(),"addr:street:be","addr:street");
                m.marshal(node, wrCyr);
                fixInt(node.getTag());
                m.marshal(node, wrInt);
                wrCyr.add(newLine);
                wrInt.add(newLine);
                processed = true;
                break;
            case "relation":
                Relation relation = um.unmarshal(reader, Relation.class).getValue();
                fixBel(relation.getTag(), "name:be", "name");
                // fixBel(relation.getTag(),"addr:street:be","addr:street");
                m.marshal(relation, wrCyr);
                fixInt(relation.getTag());
                m.marshal(relation, wrInt);
                wrCyr.add(newLine);
                wrInt.add(newLine);
                processed = true;
                break;
            }
        }
        if (!processed) {
            wrCyr.add(e);
            wrInt.add(e);
        }
        reader.next();
    }

    wrCyr.flush();
    wrCyr.close();
    wrInt.flush();
    wrInt.close();
    System.out.println("UniqueTranslatedTags: " + uniqueTranslatedTags);
}

From source file:org.apache.axiom.om.util.StAXUtils.java

private static XMLOutputFactory newXMLOutputFactory(final ClassLoader classLoader,
        final StAXWriterConfiguration configuration) {
    return (XMLOutputFactory) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            ClassLoader savedClassLoader;
            if (classLoader == null) {
                savedClassLoader = null;
            } else {
                savedClassLoader = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(classLoader);
            }//from  ww  w.  j  av  a  2 s.c o m
            try {
                XMLOutputFactory factory = XMLOutputFactory.newInstance();
                factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
                Map props = loadFactoryProperties("XMLOutputFactory.properties");
                if (props != null) {
                    for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
                        Map.Entry entry = (Map.Entry) it.next();
                        factory.setProperty((String) entry.getKey(), entry.getValue());
                    }
                }
                StAXDialect dialect = StAXDialectDetector.getDialect(factory.getClass());
                if (configuration != null) {
                    factory = configuration.configure(factory, dialect);
                }
                return new ImmutableXMLOutputFactory(dialect.normalize(dialect.makeThreadSafe(factory)));
            } finally {
                if (savedClassLoader != null) {
                    Thread.currentThread().setContextClassLoader(savedClassLoader);
                }
            }
        }
    });
}