Example usage for javax.xml.stream XMLInputFactory createXMLEventReader

List of usage examples for javax.xml.stream XMLInputFactory createXMLEventReader

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory createXMLEventReader.

Prototype

public abstract XMLEventReader createXMLEventReader(String systemId, java.io.InputStream stream)
        throws XMLStreamException;

Source Link

Document

Create a new XMLEventReader from a java.io.InputStream

Usage

From source file:org.apache.olingo.fit.metadata.Metadata.java

public Metadata(final InputStream is) {
    DEF_NS = Constants.get(ConstantKey.EDM_NS);
    schemas = new HashMap<String, Schema>();

    try {//from  w  w w.j  a v a 2 s.  c  o m
        final XMLInputFactory ifactory = XMLInputFactory.newInstance();
        final XMLEventReader reader = ifactory.createXMLEventReader(is,
                org.apache.olingo.commons.api.Constants.UTF8);

        try {
            while (reader.hasNext()) {
                final XMLEvent event = reader.nextEvent();

                if (event.isStartElement()
                        && event.asStartElement().getName().equals(new QName(DEF_NS, "Schema"))) {
                    final Schema schema = getSchema(event.asStartElement(), reader);
                    schemas.put(schema.getNamespace(), schema);
                }
            }

        } catch (Exception ignore) {
            // ignore
        } finally {
            reader.close();
            IOUtils.closeQuietly(is);
        }
    } catch (Exception e) {
        LOG.error("Error parsing metadata", e);
    }

    for (Map.Entry<String, Schema> schemaEntry : schemas.entrySet()) {
        for (EntityType entityType : schemaEntry.getValue().getEntityTypes()) {
            for (NavigationProperty property : entityType.getNavigationProperties()) {
                property.setFeed(property.getType().startsWith("Collection("));

                final Collection<EntitySet> entitySets = schemaEntry.getValue().getContainers().iterator()
                        .next().getEntitySets(schemaEntry.getKey(), entityType.getName());

                final Iterator<EntitySet> iter = entitySets.iterator();
                boolean found = false;

                while (!found && iter.hasNext()) {
                    final EntitySet entitySet = iter.next();
                    final String target = entitySet.getTarget(property.getName());
                    if (StringUtils.isNotBlank(target)) {
                        property.setTarget(entitySet.getTarget(property.getName()));
                        found = true;
                    }
                }
            }
        }
    }
}

From source file:org.apereo.portal.rest.ImportExportController.java

protected BufferedXMLEventReader createSourceXmlEventReader(MultipartFile multipartFile) throws IOException {
    final InputStream inputStream = multipartFile.getInputStream();
    final String name = multipartFile.getOriginalFilename();

    final XMLInputFactory xmlInputFactory = this.xmlUtilities.getXmlInputFactory();
    final XMLEventReader xmlEventReader;
    try {/*from ww  w.  ja  v a 2s .  c o  m*/
        xmlEventReader = xmlInputFactory.createXMLEventReader(name, inputStream);
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to create XML Event Reader for data Source", e);
    }
    return new BufferedXMLEventReader(xmlEventReader, -1);
}