Search in sources :

Example 86 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project hibernate-orm by hibernate.

the class JaxbCfgProcessor method buildStaxFactory.

@SuppressWarnings({ "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
    XMLInputFactory staxFactory = XMLInputFactory.newInstance();
    staxFactory.setXMLResolver(xmlResourceResolver);
    return staxFactory;
}
Also used : XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 87 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project hibernate-orm by hibernate.

the class AbstractBinder method buildStaxFactory.

@SuppressWarnings({ "UnnecessaryLocalVariable" })
private XMLInputFactory buildStaxFactory() {
    XMLInputFactory staxFactory = XMLInputFactory.newInstance();
    staxFactory.setXMLResolver(xmlResourceResolver);
    return staxFactory;
}
Also used : XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 88 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project languagetool by languagetool-org.

the class IpaExtractor method run.

private void run(FileInputStream fis) throws XMLStreamException {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLEventReader reader = factory.createXMLEventReader(fis);
    String title = null;
    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
            String elementName = event.asStartElement().getName().getLocalPart();
            switch(elementName) {
                case "title":
                    XMLEvent nextEvent = reader.nextEvent();
                    title = nextEvent.asCharacters().getData();
                    articleCount++;
                    break;
                case "text":
                    ipaCount += handleTextElement(title, reader);
                    break;
            }
        }
    }
}
Also used : XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 89 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project languagetool by languagetool-org.

the class AtomFeedParser method getAtomFeedItems.

List<AtomFeedItem> getAtomFeedItems(InputStream xml) throws XMLStreamException {
    String id = null;
    String title = null;
    Date date = null;
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLEventReader eventReader = inputFactory.createXMLEventReader(xml);
    try {
        List<AtomFeedItem> items = new ArrayList<>();
        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();
            if (event.isStartElement()) {
                String localPart = event.asStartElement().getName().getLocalPart();
                switch(localPart) {
                    case "id":
                        id = getCharacterData(eventReader);
                        break;
                    case "title":
                        title = getCharacterData(eventReader);
                        break;
                    case "updated":
                        String dateString = getCharacterData(eventReader);
                        try {
                            // e.g. 2013-12-03T09:48:29Z - got this from http://stackoverflow.com/questions/6038136,
                            // with SimpleDateParser the hour is off by one:
                            date = DatatypeFactory.newInstance().newXMLGregorianCalendar(dateString).toGregorianCalendar().getTime();
                        } catch (Exception e) {
                            throw new RuntimeException("Could not parse date string '" + dateString + "'", e);
                        }
                        break;
                    case "summary":
                        if (id == null || title == null || date == null) {
                            throw new RuntimeException("id, title and/or date is null: id=" + id + ", title=" + title + ", date=" + date);
                        }
                        items.add(new AtomFeedItem(id, title, getCharacterData(eventReader), date));
                        id = null;
                        title = null;
                        date = null;
                        break;
                }
            }
        }
        return items;
    } finally {
        eventReader.close();
    }
}
Also used : ArrayList(java.util.ArrayList) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) Date(java.util.Date) XMLInputFactory(javax.xml.stream.XMLInputFactory) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 90 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project sonarqube by SonarSource.

the class DebtRulesXMLImporter method initStax.

private static SMInputFactory initStax() {
    XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
    xmlFactory.setProperty(IS_COALESCING, TRUE);
    xmlFactory.setProperty(IS_NAMESPACE_AWARE, FALSE);
    xmlFactory.setProperty(SUPPORT_DTD, FALSE);
    xmlFactory.setProperty(IS_VALIDATING, FALSE);
    return new SMInputFactory(xmlFactory);
}
Also used : SMInputFactory(org.codehaus.staxmate.SMInputFactory) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

XMLInputFactory (javax.xml.stream.XMLInputFactory)154 XMLStreamReader (javax.xml.stream.XMLStreamReader)98 XMLStreamException (javax.xml.stream.XMLStreamException)63 StringReader (java.io.StringReader)43 InputStream (java.io.InputStream)41 IOException (java.io.IOException)33 XMLEventReader (javax.xml.stream.XMLEventReader)30 Test (org.junit.Test)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStreamReader (java.io.InputStreamReader)14 JAXBException (javax.xml.bind.JAXBException)14 StAXSource (javax.xml.transform.stax.StAXSource)14 StreamSource (javax.xml.transform.stream.StreamSource)14 Unmarshaller (javax.xml.bind.Unmarshaller)13 ArrayList (java.util.ArrayList)12 XMLEvent (javax.xml.stream.events.XMLEvent)12 DOMSource (javax.xml.transform.dom.DOMSource)11 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)10 JAXBContext (javax.xml.bind.JAXBContext)9 HashMap (java.util.HashMap)8