@Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        // currentElement represents the last string encountered in the document
        setCurrentElement(getElementNames().pop());
        if (getCurrentElement().equalsIgnoreCase(GPXTags.TRK)) {
            //parent.setTrksegID(getTrksegID());
            //parent.setTrkptID(getTrkptID());
            // Set the track geometry.
            MultiLineString geometry = getGeometryFactory().createMultiLineString(trkList.toArray(new LineString[0]));
            geometry.setSRID(4326);
            getCurrentLine().setGeometry(geometry);
            // if </trk> markup is found, the currentLine is added in the table rtedbd and the default contentHandler is setted.
            try {
                PreparedStatement pStm = getTrkPreparedStmt();
                int i = 1;
                Object[] values = getCurrentLine().getValues();
                for (Object object : values) {
                    pStm.setObject(i, object);
                    i++;
                }
                pStm.execute();
            } catch (SQLException ex) {
                throw new SAXException("Cannot import the track line ", ex);
            }
            getReader().setContentHandler(parent);

        } else if (getCurrentElement().compareToIgnoreCase("trkseg") == 0) {
            Coordinate[] trksegArray = trksegList.toArray(new Coordinate[0]);
            // If there are more than one trackpoint, we can set a geometry to the track segment
            if (trksegList.size() > 1) {
                LineString geometry = getGeometryFactory().createLineString(trksegArray);
                geometry.setSRID(4326);
                getCurrentSegment().setGeometry(geometry);
                trkList.add(geometry);
            }
            // if </trkseg> markup is found, the currentSegment is added in the table trksegdbd.
            try {
                PreparedStatement pStm = getTrkSegmentsPreparedStmt();
                int i = 1;
                Object[] values = getCurrentSegment().getValues();
                for (Object object : values) {
                    pStm.setObject(i, object);
                    i++;
                }
                pStm.execute();
            } catch (SQLException ex) {
                throw new SAXException("Cannot import the track segment ", ex);
            }

        } else if (getCurrentElement().equalsIgnoreCase(GPXTags.TRKPT)) {
            // if </trkpt> markup is found, the currentPoint is added in the table trkptdbd.
            point = false;
            try {
                PreparedStatement pStm = getTrkPointsPreparedStmt();
                int i = 1;
                Object[] values = getCurrentPoint().getValues();
                for (Object object : values) {
                    pStm.setObject(i, object);
                    i++;
                }
                pStm.execute();
            } catch (SQLException ex) {
                throw new SAXException("Cannot import the track waypoints.", ex);
            }
        } else if (point) {
            getCurrentPoint().setAttribute(getCurrentElement(), getContentBuffer());
        } else if (segment) {
            getCurrentSegment().setExtensions();
        } else {
            getCurrentLine().setAttribute(getCurrentElement(), getContentBuffer());
        }
    }
@ Override public void endElement ( String uri , String localName , String qName ) throws SAXException { setCurrentElement ( getElementNames ( ) . pop ( ) ) ; if ( getCurrentElement ( ) . equalsIgnoreCase ( GPXTags . TRK ) ) { MultiLineString geometry = getGeometryFactory ( ) . createMultiLineString ( trkList . toArray ( new LineString [ 0 ] ) ) ; geometry . setSRID ( 4326 ) ; getCurrentLine ( ) . setGeometry ( geometry ) ; try { PreparedStatement pStm = getTrkPreparedStmt ( ) ; int i = 1 ; Object [ ] values = getCurrentLine ( ) . getValues ( ) ; for ( Object object : values ) { pStm . setObject ( i , object ) ; i ++ ; } pStm . execute ( ) ; } catch ( SQLException ex ) { throw new SAXException ( "Cannot import the track line " , ex ) ; } getReader ( ) . setContentHandler ( parent ) ; } else if ( getCurrentElement ( ) . compareToIgnoreCase ( "trkseg" ) == 0 ) { Coordinate [ ] trksegArray = trksegList . toArray ( new Coordinate [ 0 ] ) ; if ( trksegList . size ( ) > 1 ) { LineString geometry = getGeometryFactory ( ) . createLineString ( trksegArray ) ; geometry . setSRID ( 4326 ) ; getCurrentSegment ( ) . setGeometry ( geometry ) ; trkList . add ( geometry ) ; } try { PreparedStatement pStm = getTrkSegmentsPreparedStmt ( ) ; int i = 1 ; Object [ ] values = getCurrentSegment ( ) . getValues ( ) ; for ( Object object : values ) { pStm . setObject ( i , object ) ; i ++ ; } pStm . execute ( ) ; } catch ( SQLException ex ) { throw new SAXException ( "Cannot import the track segment " , ex ) ; } } else if ( getCurrentElement ( ) . equalsIgnoreCase ( GPXTags . TRKPT ) ) { point = false ; try { PreparedStatement pStm = getTrkPointsPreparedStmt ( ) ; int i = 1 ; Object [ ] values = getCurrentPoint ( ) . getValues ( ) ; for ( Object object : values ) { pStm . setObject ( i , object ) ; i ++ ; } pStm . execute ( ) ; } catch ( SQLException ex ) { throw new SAXException ( "Cannot import the track waypoints." , ex ) ; } } else if ( point ) { getCurrentPoint ( ) . setAttribute ( getCurrentElement ( ) , getContentBuffer ( ) ) ; } else if ( segment ) { getCurrentSegment ( ) . setExtensions ( ) ; } else { getCurrentLine ( ) . setAttribute ( getCurrentElement ( ) , getContentBuffer ( ) ) ; } }
Fires whenever an XML end markup is encountered. It catches attributes of
trackPoints, trackSegments or routes and saves them in corresponding
values[].

@param uri URI of the local element
@param localName Name of the local element (without prefix)
@param qName qName of the local element (with prefix)
@throws SAXException Any SAX exception, possibly wrapping another
exception