Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.h2gis.drivers.gpx.model;
  
  
  import java.util.List;
Abstract class of the parsers dedicated to routes. A specific parser for version 1.0 and version 1.1 will extend this class.

Author(s):
Erwan Bocher and Antonin Piasco
 
 public abstract class AbstractGpxParserRte extends AbstractGpxParser {
 
     // Indicates if we are in a point or not
     private boolean point;
     // Reference to the default contentHandler of the class GpxParserDefault
     private AbstractGpxParserDefault parent;
     // A list which will contain the coordinates of the route
     private List<CoordinaterteList;
     private int idRtPt = 1;

    
Create a new specific parser. It has in memory the default parser, the contentBuffer, the elementNames, the currentLine and the rteID.

Parameters:
reader The XMLReader used in the default class
parent The parser used in the default class
 
     public void initialise(XMLReader readerAbstractGpxParserDefault parent) {
         setReader(reader);
         setParent(parent);
         setContentBuffer(parent.getContentBuffer());
         setRtePreparedStmt(parent.getRtePreparedStmt());
         setRteptPreparedStmt(parent.getRteptPreparedStmt());
         setElementNames(parent.getElementNames());
         setCurrentLine(parent.getCurrentLine());
         setRteList(new ArrayList<Coordinate>());
     }

    
Fires whenever an XML start markup is encountered. It creates a new routePoint when a <rtept> markup is encountered.

Parameters:
uri URI of the local element
localName Name of the local element (without prefix)
qName qName of the local element (with prefix)
attributes Attributes of the local element (contained in the markup)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception
 
     @Override
     public void startElement(String uriString localNameString qNameAttributes attributesthrows SAXException {
         if (localName.equalsIgnoreCase(.)) {
              = true;
             GPXPoint routePoint = new GPXPoint(.);
             try {
                 Coordinate coordinate = GPXCoordinate.createCoordinate(attributes);
                 routePoint.setValue(.getGeometryFactory().createPoint(coordinate));
                 routePoint.setValue(.coordinate.y);
                 routePoint.setValue(.coordinate.x);
                 routePoint.setValue(.coordinate.z);
                 routePoint.setValue(.++);
                 routePoint.setValue(.getCurrentLine().getValues()[.]);
                 .add(coordinate);
             } catch (NumberFormatException ex) {
                 throw new SAXException(ex);
             }
             setCurrentPoint(routePoint);
         }
 
         // Clear content buffer
         getContentBuffer().delete(0, getContentBuffer().length());
 
         // Store name of current element in stack
         getElementNames().push(qName);
     }

    
Fires whenever an XML end markup is encountered. It catches attributes of routePoints or routes and saves them in corresponding values[].

Parameters:
uri URI of the local element
localName Name of the local element (without prefix)
qName qName of the local element (with prefix)
Throws:
org.xml.sax.SAXException Any SAX exception, possibly wrapping another exception
 
     @Override
     public void endElement(String uriString localNameString qNamethrows SAXException {
         // currentElement represents the last string encountered in the document
        if (getCurrentElement().equalsIgnoreCase(.)) {
            Coordinate[] rteArray = new Coordinate[.size()];
            rteArray = .toArray(rteArray);
            // If there are more than one routepoint, we can set a geometry to the route
            if (.size() > 1) {
                LineString geometry = getGeometryFactory().createLineString(rteArray);
                getCurrentLine().setGeometry(geometry);
            }
            // if </rte> markup is found, the currentLine is added in the table rtedbd and the default contentHandler is setted.
            try {
                PreparedStatement pStm = getRtePreparedStmt();
                int i = 1;
                Object[] values = getCurrentLine().getValues();
                for (Object object : values) {
                    pStm.setObject(iobject);
                    i++;
                }
                pStm.execute();
            } catch (SQLException ex) {
                throw new SAXException("Cannot import the route line "ex);
            }
            getReader().setContentHandler();
        } else if (getCurrentElement().equalsIgnoreCase(.)) {
            // if </rtept> markup is found, the currentPoint is added in the table rteptdbd.
             = false;
            try {
                PreparedStatement pStm = getRteptPreparedStmt();
                int i = 1;
                Object[] values = getCurrentPoint().getValues();
                for (Object object : values) {
                    pStm.setObject(iobject);
                    i++;
                }
                pStm.execute();
            } catch (SQLException ex) {
                throw new SAXException("Cannot import the route points "ex);
            }
        } else if () {
        } else {
        }
    }

    
***************************** GETTERS AND SETTERS ***** *****************************

    
Set the parent of this specific parser.

Parameters:
parent
    public void setParent(AbstractGpxParserDefault parent) {
        this. = parent;
    }

    
Indicates if we are in a point.

Returns:
true if we are in a point, false else
    public boolean isPoint() {
        return ;
    }

    
Set the list corresponding to the points' coordinates of the actual route.

Parameters:
rteList
    public void setRteList(List<CoordinaterteList) {
        this. = rteList;
    }
New to GrepCode? Check out our FAQ X