public void parse(IXmlStreamReader parser, GPEDefaultGmlParser handler) throws XmlStreamException, IOException { boolean endFeature = false; int currentTag; this.parser = parser; QName tag = parser.getName(); currentTag = parser.getEventType(); while (!endFeature) { switch (currentTag) { case IXmlStreamReader.START_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_LOWERCORNER)) { parser.next(); String coordinatesTag = parser.getText().trim(); dimension = caculateDimension(coordinatesTag); coordinatesString = new StringTokenizer(coordinatesTag, TUPLES_SEPARATOR); // //String[] coordinates = parser.getText().trim().split(TUPLES_SEPARATOR); // String[] coordinates = // org.gvsig.gpe.gml.utils.StringUtils.splitString(parser.getText().trim(),TUPLES_SEPARATOR); // aCoordinates = new double[3]; // for (int i=0 ; i < coordinates.length; i++){ // aCoordinates[i] = DoubleTypeBinding.parse(coordinates[i],"."); // } // if (coordinates.length == 2){ // aCoordinates[2] = 0.0; // } // else if (coordinates.length == 1){ // aCoordinates[1] = 0.0; // aCoordinates[2] = 0.0; // } // else // { // aCoordinates[0] = 0.0; // aCoordinates[1] = 0.0; // aCoordinates[2] = 0.0; // } } break; case IXmlStreamReader.END_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_LOWERCORNER)) { endFeature = true; } break; case IXmlStreamReader.CHARACTERS: break; } if (!endFeature) { currentTag = parser.next(); tag = parser.getName(); } } }
/** * @param parser * @param handler * @param tag * @param coordsContainer * @return * @throws XmlStreamException * @throws IOException */ protected ICoordinateIterator parseTag_( IXmlStreamReader parser, GPEDefaultGmlParser handler, QName tag) throws XmlStreamException, IOException { if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_COORDINATES)) { CoordinatesTypeIterator coordinatesIterator = handler.getProfile().getCoordinatesTypeBinding(); coordinatesIterator.initialize(parser, handler, GMLTags.GML_LINEARRING); return coordinatesIterator; } else if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_COORD)) { CoordTypeIterator coordinatesIterator = handler.getProfile().getCoordTypeBinding(); coordinatesIterator.initialize(parser, handler, GMLTags.GML_LINEARRING); return coordinatesIterator; } return null; }
/** * It parses the XML tag * * @param parser * @param handler * @param tag * @param id * @param multipolygon * @param srsName * @throws XmlStreamException * @throws IOException */ protected void parseTag( IXmlStreamReader parser, GPEDefaultGmlParser handler, QName tag, String id, Object multiPolygon, String srsName) throws XmlStreamException, IOException { if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_POLYGONMEMBER)) { Object polygon = handler.getProfile().getPolygonMemberTypeBinding().parse(parser, handler); handler.getContentHandler().addPolygonToMultiPolygon(polygon, multiPolygon); } if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_GEOMETRYMEMBER)) { Object polygon = handler.getProfile().getPolygonMemberTypeBinding().parse(parser, handler); handler.getContentHandler().addPolygonToMultiPolygon(polygon, multiPolygon); } }
/** * It parses the LineQName tag * * @param parser The XML parser * @param handler The GPE parser that contains the content handler and the error handler * @return A line string * @throws IOException * @throws XmlStreamException * @throws XmlStreamException * @throws IOException */ public Object parse(IXmlStreamReader parser, GPEDeafultKmlParser handler) throws XmlStreamException, IOException { boolean endFeature = false; int currentTag; Object lineString = null; String id = handler.getProfile().getGeometryBinding().getID(parser, handler); QName tag = parser.getName(); currentTag = parser.getEventType(); while (!endFeature) { switch (currentTag) { case IXmlStreamReader.START_ELEMENT: if (CompareUtils.compareWithNamespace(tag, Kml2_1_Tags.COORDINATES)) { CoordinatesTypeIterator coordinatesIterator = handler.getProfile().getCoordinatesTypeBinding(); coordinatesIterator.initialize(parser, handler, Kml2_1_Tags.LINESTRING); lineString = handler .getContentHandler() .startLineString(id, coordinatesIterator, Kml2_1_Tags.DEFAULT_SRS); return lineString; } break; case IXmlStreamReader.END_ELEMENT: if (CompareUtils.compareWithNamespace(tag, Kml2_1_Tags.LINESTRING)) { endFeature = true; handler.getContentHandler().endLineString(lineString); } break; case IXmlStreamReader.CHARACTERS: break; } if (!endFeature) { currentTag = parser.next(); tag = parser.getName(); } } return lineString; }
/** * It parses the gml:MultiPoint tag * * @param parser The XML parser * @param handler The GPE parser that contains the content handler and the error handler * @return A multipoint * @throws XmlStreamException * @throws IOException */ public Object parse(IXmlStreamReader parser, GPEDefaultGmlParser handler) throws XmlStreamException, IOException { boolean endFeature = false; int currentTag; Object multiPoint = null; super.setAtributtes(parser, handler.getErrorHandler()); multiPoint = handler.getContentHandler().startMultiPoint(id, srsName); QName tag = parser.getName(); currentTag = parser.getEventType(); while (!endFeature) { switch (currentTag) { case IXmlStreamReader.START_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_POINTMEMBER)) { Object point = handler.getProfile().getPointMemberTypeBinding().parse(parser, handler); handler.getContentHandler().addPointToMultiPoint(point, multiPoint); } break; case IXmlStreamReader.END_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTIPOINT)) { endFeature = true; handler.getContentHandler().endMultiPoint(multiPoint); } break; case IXmlStreamReader.CHARACTERS: break; } if (!endFeature) { currentTag = parser.next(); tag = parser.getName(); } } return multiPoint; }
/** * It goes to the lower corner end tag * * @throws XmlStreamException */ private void parseLowerCorner() throws XmlStreamException { parser.next(); QName tag = parser.getName(); int currentTag = parser.getEventType(); if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_LOWERCORNER)) { parser.next(); String coordinatesTag = parser.getText().trim(); coordinatesString = new StringTokenizer(coordinatesTag, TUPLES_SEPARATOR); boolean endLowerCorner = false; while (!endLowerCorner) { switch (currentTag) { case IXmlStreamReader.END_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_LOWERCORNER)) { endLowerCorner = true; } break; } if (!endLowerCorner) { currentTag = parser.next(); tag = parser.getName(); } } } }
/** * It parses the gml:multiPointProperty tag * * @param parser The XML parser * @param handler The GPE parser that contains the content handler and the error handler * @return A multipoint * @throws XmlStreamException * @throws IOException */ public Object parse(IXmlStreamReader parser, GPEDefaultGmlParser handler) throws XmlStreamException, IOException { boolean endFeature = false; int currentTag; Object multiPoint = null; super.setAtributtes(parser, handler.getErrorHandler()); QName tag = parser.getName(); currentTag = parser.getEventType(); while (!endFeature) { switch (currentTag) { case IXmlStreamReader.START_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTIPOINT)) { multiPoint = handler.getProfile().getMultiPointTypeBinding().parse(parser, handler); } break; case IXmlStreamReader.END_ELEMENT: if ((CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTIPOINTPROPERTY)) || (CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTILOCATION)) || (CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTICENTEROF)) || (CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTIPOSITION))) { endFeature = true; } break; case IXmlStreamReader.CHARACTERS: break; } if (!endFeature) { currentTag = parser.next(); tag = parser.getName(); } } return multiPoint; }
/** * It parses the gml:LinearRing tag and return the coordinates * * @param parser The XML parser * @param handler The GPE parser that contains the content handler and the error handler * @return An array of coordinates * @throws XmlStreamException * @throws IOException * @throws PolygonNotClosedWarning */ public ICoordinateIterator parseCoordinates(IXmlStreamReader parser, GPEDefaultGmlParser handler) throws XmlStreamException, IOException { boolean endFeature = false; int currentTag; QName tag = parser.getName(); currentTag = parser.getEventType(); while (!endFeature) { switch (currentTag) { case IXmlStreamReader.START_ELEMENT: ICoordinateIterator iterator = parseTag_(parser, handler, tag); if (iterator != null) { return iterator; } case IXmlStreamReader.END_ELEMENT: if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_LINEARRING)) {} break; case IXmlStreamReader.CHARACTERS: break; } if (!endFeature) { currentTag = parser.next(); tag = parser.getName(); } } // The first and the last coordinates has to be the same // if ((coordinates[0][0] != coordinates[0][coordinates[0].length - 1]) // || // (coordinates[1][0] != coordinates[1][coordinates[1].length - 1]) || // (coordinates[2][0] != coordinates[2][coordinates[2].length - 1])){ // handler.getErrorHandler().addWarning(new // PolygonNotClosedWarning(coordinates)); // } return null; }
/** * Parses the last tag * * @param parser * @param handler * @param tag * @return */ protected boolean parseLastTag(IXmlStreamReader parser, GPEDefaultGmlParser handler, QName tag) { if (CompareUtils.compareWithNamespace(tag, GMLTags.GML_MULTIPOLYGON)) { return true; } return false; }