Example usage for javax.xml.stream XMLEventReader hasNext

List of usage examples for javax.xml.stream XMLEventReader hasNext

Introduction

In this page you can find the example usage for javax.xml.stream XMLEventReader hasNext.

Prototype

@Override
public boolean hasNext();

Source Link

Document

Check if there are more events.

Usage

From source file:org.apache.olingo.client.core.serialization.AtomDeserializer.java

private ODataError error(final XMLEventReader reader, final StartElement start) throws XMLStreamException {
    final ODataError error = new ODataError();

    boolean setCode = false;
    boolean codeSet = false;
    boolean setMessage = false;
    boolean messageSet = false;
    boolean setTarget = false;
    boolean targetSet = false;

    boolean foundEndElement = false;
    while (reader.hasNext() && !foundEndElement) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement()) {
            if (errorCodeQName.equals(event.asStartElement().getName())) {
                setCode = true;/* w w  w .j  a  v  a2 s.  com*/
            } else if (errorMessageQName.equals(event.asStartElement().getName())) {
                setMessage = true;
            } else if (errorTargetQName.equals(event.asStartElement().getName())) {
                setTarget = true;
            }
        }

        if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
            if (setCode && !codeSet) {
                error.setCode(event.asCharacters().getData());
                setCode = false;
                codeSet = true;
            }
            if (setMessage && !messageSet) {
                error.setMessage(event.asCharacters().getData());
                setMessage = false;
                messageSet = true;
            }
            if (setTarget && !targetSet) {
                error.setTarget(event.asCharacters().getData());
                setTarget = false;
                targetSet = true;
            }
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndElement = true;
        }
    }

    return error;
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private List<Point> points(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

    final List<Point> result = new ArrayList<Point>();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
            final String[] pointInfo = event.asCharacters().getData().split(" ");

            final Point point = new Point(GeoUtils.getDimension(type), srid);
            try {
                point.setX(EdmDouble.getInstance().valueOfString(pointInfo[0], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
                point.setY(EdmDouble.getInstance().valueOfString(pointInfo[1], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
            } catch (EdmPrimitiveTypeException e) {
                throw new XMLStreamException("While deserializing point coordinates as double", e);
            }/*from  www .j a v a2 s . c om*/
            result.add(point);
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    // handles bad input, e.g. things like <gml:pos/>
    if (result.isEmpty()) {
        result.add(new Point(GeoUtils.getDimension(type), srid));
    }

    return result;
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private MultiPoint multipoint(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

    List<Point> points = Collections.<Point>emptyList();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POINTMEMBERS)) {
            points = points(reader, event.asStartElement(), type, null);
        }// w w  w .j a v  a2 s . c  o m

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return new MultiPoint(GeoUtils.getDimension(type), srid, points);
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private Polygon polygon(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type,
        final SRID srid) throws XMLStreamException {

    List<Point> extPoints = null;
    List<Point> intPoints = null;

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement()) {
            if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_EXTERIOR)) {
                extPoints = points(reader, event.asStartElement(), type, null);
            }/*w ww.  j a va 2s  .  c o m*/
            if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_INTERIOR)) {
                intPoints = points(reader, event.asStartElement(), type, null);
            }
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return new Polygon(GeoUtils.getDimension(type), srid, intPoints, extPoints);
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private MultiLineString multiLineString(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

    final List<LineString> lineStrings = new ArrayList<LineString>();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_LINESTRING)) {
            lineStrings.add(lineString(reader, event.asStartElement(), type, null));
        }//from   ww w .  j  av a 2 s  .  co  m

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return new MultiLineString(GeoUtils.getDimension(type), srid, lineStrings);
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

    final List<Polygon> polygons = new ArrayList<Polygon>();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POLYGON)) {
            polygons.add(polygon(reader, event.asStartElement(), type, null));
        }/*www .java  2 s .  co  m*/

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return new MultiPolygon(GeoUtils.getDimension(type), srid, polygons);
}

From source file:org.apache.olingo.client.core.serialization.AtomGeoValueDeserializer.java

private GeospatialCollection collection(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

    final List<Geospatial> geospatials = new ArrayList<Geospatial>();

    boolean foundEndCollection = false;
    while (reader.hasNext() && !foundEndCollection) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_GEOMEMBERS)) {
            boolean foundEndMembers = false;
            while (reader.hasNext() && !foundEndMembers) {
                final XMLEvent subevent = reader.nextEvent();

                if (subevent.isStartElement()) {
                    geospatials.add(deserialize(reader, subevent.asStartElement(), GeoUtils.getType(
                            GeoUtils.getDimension(type), subevent.asStartElement().getName().getLocalPart())));
                }/*from w  w w .j  av a  2  s.  co  m*/

                if (subevent.isEndElement()
                        && Constants.QNAME_GEOMEMBERS.equals(subevent.asEndElement().getName())) {
                    foundEndMembers = true;
                }
            }
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndCollection = true;
        }
    }

    return new GeospatialCollection(GeoUtils.getDimension(type), srid, geospatials);
}

From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java

private List<Point> points(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {

    final List<Point> result = new ArrayList<Point>();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
            final String[] pointInfo = event.asCharacters().getData().split(" ");

            final Point point = new Point(GeoUtils.getDimension(type), crs);
            try {
                point.setX(EdmDouble.getInstance().valueOfString(pointInfo[0], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
                point.setY(EdmDouble.getInstance().valueOfString(pointInfo[1], null, null,
                        Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class));
            } catch (EdmPrimitiveTypeException e) {
                throw new XMLStreamException("While deserializing point coordinates as double", e);
            }/*from ww  w  . j av  a2  s . com*/
            result.add(point);
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return result;
}

From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java

private MultiPoint multipoint(final XMLEventReader reader, final StartElement start,
        final EdmPrimitiveTypeKind type, final String crs) throws XMLStreamException {

    List<Point> points = Collections.<Point>emptyList();

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POINTMEMBERS)) {
            points = points(reader, event.asStartElement(), type, null);
        }/*  w w w.ja v a  2s  .  c  o m*/

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return new MultiPoint(GeoUtils.getDimension(type), crs, points);
}

From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java

private Polygon polygon(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type,
        final String crs) throws XMLStreamException {

    List<Point> extPoints = null;
    List<Point> intPoints = null;

    boolean foundEndProperty = false;
    while (reader.hasNext() && !foundEndProperty) {
        final XMLEvent event = reader.nextEvent();

        if (event.isStartElement()) {
            if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_EXTERIOR)) {
                extPoints = points(reader, event.asStartElement(), type, null);
            }/*from  w  w w .  j  a  v a  2s .c  o  m*/
            if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_INTERIOR)) {
                intPoints = points(reader, event.asStartElement(), type, null);
            }
        }

        if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
            foundEndProperty = true;
        }
    }

    return new Polygon(GeoUtils.getDimension(type), crs, intPoints, extPoints);
}