List of usage examples for javax.xml.stream XMLEventReader nextEvent
public XMLEvent nextEvent() throws XMLStreamException;
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); }// w ww.j a v a 2 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); }//from w ww .ja v a 2s .c om 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 ww . j a v a 2 s .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); }
From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java
private MultiLineString multiLineString(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final String crs) 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.ja v a2 s . co m if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return new MultiLineString(GeoUtils.getDimension(type), crs, lineStrings); }
From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java
private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final String crs) 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)); }// ww w. j a v a2s.c om if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return new MultiPolygon(GeoUtils.getDimension(type), crs, polygons); }
From source file:org.apache.olingo.commons.core.data.AtomGeoValueDeserializer.java
private GeospatialCollection collection(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final String crs) 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()))); }// w w w .j av a 2 s . com 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), crs, geospatials); }
From source file:org.apache.olingo.commons.core.data.AtomPropertyDeserializer.java
private Value fromPrimitive(final XMLEventReader reader, final StartElement start, final EdmTypeInfo typeInfo) throws XMLStreamException { Value value = null;/*w ww. ja va 2 s . c o m*/ boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement() && typeInfo != null && typeInfo.getPrimitiveTypeKind().isGeospatial()) { final EdmPrimitiveTypeKind geoType = EdmPrimitiveTypeKind.valueOfFQN(version, typeInfo.getFullQualifiedName().toString()); value = new GeospatialValueImpl( this.geoDeserializer.deserialize(reader, event.asStartElement(), geoType)); } if (event.isCharacters() && !event.asCharacters().isWhiteSpace() && (typeInfo == null || !typeInfo.getPrimitiveTypeKind().isGeospatial())) { value = new PrimitiveValueImpl(event.asCharacters().getData()); } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return value; }
From source file:org.apache.olingo.commons.core.data.AtomPropertyDeserializer.java
private ComplexValue fromComplex(final XMLEventReader reader, final StartElement start) throws XMLStreamException { final ComplexValue value = new ComplexValueImpl(); boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { value.get().add(deserialize(reader, event.asStartElement())); }/*from ww w . ja v a 2s . c om*/ if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return value; }
From source file:org.apache.olingo.commons.core.data.AtomPropertyDeserializer.java
private CollectionValue fromCollection(final XMLEventReader reader, final StartElement start, final EdmTypeInfo typeInfo) throws XMLStreamException { final CollectionValueImpl value = new CollectionValueImpl(); final EdmTypeInfo type = typeInfo == null ? null : new EdmTypeInfo.Builder().setTypeExpression(typeInfo.getFullQualifiedName().toString()).build(); boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { switch (guessPropertyType(reader)) { case COMPLEX: value.get().add(fromComplex(reader, event.asStartElement())); break; case PRIMITIVE: value.get().add(fromPrimitive(reader, event.asStartElement(), type)); break; default: // do not add null or empty values }//from ww w .j a v a 2 s . c o m } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return value; }
From source file:org.apache.olingo.commons.core.data.AtomPropertyDeserializer.java
private ODataPropertyType guessPropertyType(final XMLEventReader reader) throws XMLStreamException { XMLEvent child = null;//from w w w . ja v a2s . co m while (reader.hasNext() && child == null) { final XMLEvent event = reader.peek(); if (event.isCharacters() && event.asCharacters().isWhiteSpace()) { reader.nextEvent(); } else { child = event; } } final ODataPropertyType type; if (child == null) { type = ODataPropertyType.PRIMITIVE; } else { if (child.isStartElement()) { if (Constants.NS_GML.equals(child.asStartElement().getName().getNamespaceURI())) { type = ODataPropertyType.PRIMITIVE; } else if (elementQName.equals(child.asStartElement().getName())) { type = ODataPropertyType.COLLECTION; } else { type = ODataPropertyType.COMPLEX; } } else if (child.isCharacters()) { type = ODataPropertyType.PRIMITIVE; } else { type = ODataPropertyType.EMPTY; } } return type; }