Ignore:
Timestamp:
2009-01-01T18:28:53+01:00 (17 years ago)
Author:
stoecker
Message:

removed tab stop usage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/waypoints/src/WaypointReader.java

    r9949 r12778  
    1 package waypoints; 
     1package waypoints;
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
     
    2323public class WaypointReader {
    2424
    25         private static class Parser extends DefaultHandler {
    26                 /**
    27                 * Current track to be read. The last entry is the current trkpt.
    28                 * If in wpt-mode, it contain only one GpsPoint.
    29                 */
    30             private DataSet dataSet;
    31                 private LatLon currentLatLon;
    32                 private String curWptName;
    33                 private  boolean inName = false;
     25    private static class Parser extends DefaultHandler {
     26        /**
     27        * Current track to be read. The last entry is the current trkpt.
     28        * If in wpt-mode, it contain only one GpsPoint.
     29        */
     30        private DataSet dataSet;
     31        private LatLon currentLatLon;
     32        private String curWptName;
     33        private  boolean inName = false;
    3434
    35                 // NW start     
    36                 // data now has two components: the GPS points and an OsmDataLayer.
    37                 // This is to allow us to convert waypoints straight to nodes.
    38                 // The way this works is that waypoints with a name not beginning
    39                 // with 0 - i.e. waypoints specially named - will be loaded in as
    40                 // nodes, in addition to going into the gpx layer. Other waypoints will
    41                 // only go into the gpx layer.
    42                 public Parser()
    43                 {
    44                         dataSet = new DataSet();
    45                 }
    46                 // NW end
     35        // NW start
     36        // data now has two components: the GPS points and an OsmDataLayer.
     37        // This is to allow us to convert waypoints straight to nodes.
     38        // The way this works is that waypoints with a name not beginning
     39        // with 0 - i.e. waypoints specially named - will be loaded in as
     40        // nodes, in addition to going into the gpx layer. Other waypoints will
     41        // only go into the gpx layer.
     42        public Parser()
     43        {
     44            dataSet = new DataSet();
     45        }
     46        // NW end
    4747
    48                 @Override public void startElement(String namespaceURI, 
    49                                 String localName, String qName, Attributes atts) 
    50                                         throws SAXException {
    51                         if (qName.equals("wpt")) {
    52                                 try {
    53                         double lat = Double.parseDouble(atts.getValue("lat"));
    54                         double lon = Double.parseDouble(atts.getValue("lon"));
    55                                 if (Math.abs(lat) > 90)
    56                                         throw new SAXException
    57                                                 (tr("Data error: lat value \"{0}\" is out of bound.", 
    58                                                         lat));
    59                                 if (Math.abs(lon) > 180)
    60                                         throw new SAXException
    61                                                 (tr("Data error: lon value \"{0}\" is out of bound.", 
    62                                                         lon));
    63                         currentLatLon = new LatLon(lat, lon);
     48        @Override public void startElement(String namespaceURI,
     49                String localName, String qName, Attributes atts)
     50                    throws SAXException {
     51            if (qName.equals("wpt")) {
     52                try {
     53                    double lat = Double.parseDouble(atts.getValue("lat"));
     54                    double lon = Double.parseDouble(atts.getValue("lon"));
     55                    if (Math.abs(lat) > 90)
     56                        throw new SAXException
     57                        (tr("Data error: lat value \"{0}\" is out of bound.",
     58                            lat));
     59                    if (Math.abs(lon) > 180)
     60                        throw new SAXException
     61                        (tr("Data error: lon value \"{0}\" is out of bound.",
     62                            lon));
     63                    currentLatLon = new LatLon(lat, lon);
    6464                } catch (NumberFormatException e) {
    65                         e.printStackTrace();
    66                         throw new SAXException(e);
     65                    e.printStackTrace();
     66                    throw new SAXException(e);
    6767                }
    68                         }
    69                         else if (qName.equals("name")) {
    70                                 inName = true;
    71                                 curWptName = "";       
    72                         }       
    73                 }
     68            }
     69            else if (qName.equals("name")) {
     70                inName = true;
     71                curWptName = "";
     72            }
     73        }
    7474
    75                 @Override public void characters(char[] ch, int start, int length) {
    76                         // NW start
    77                         if (inName) {
    78                                 curWptName = new String (ch,start,length);
    79                         }
    80                         // NW end
    81                 }
     75        @Override public void characters(char[] ch, int start, int length) {
     76            // NW start
     77            if (inName) {
     78                curWptName = new String (ch,start,length);
     79            }
     80            // NW end
     81        }
    8282
    83                 @Override public void endElement(String namespaceURI, String localName,
    84                                                                                 String qName) {
    85                         if (qName.equals("wpt") && curWptName!="") { 
    86                                 // create a new node from the latitude and longitude
    87                                 System.out.println("Found a waypoint to convert to a node: " 
    88                                                                                 + curWptName);
    89                                 Node node = new Node(currentLatLon);
    90                                 node.put("name",curWptName);
    91                                 dataSet.nodes.add(node);
    92                         }
    93                         else if (qName.equals("name")) {
    94                                 inName = false;
    95                         }
     83        @Override public void endElement(String namespaceURI, String localName,
     84                                        String qName) {
     85            if (qName.equals("wpt") && curWptName!="") {
     86                // create a new node from the latitude and longitude
     87                System.out.println("Found a waypoint to convert to a node: "
     88                                        + curWptName);
     89                Node node = new Node(currentLatLon);
     90                node.put("name",curWptName);
     91                dataSet.nodes.add(node);
     92            }
     93            else if (qName.equals("name")) {
     94                inName = false;
     95            }
    9696        }
    97         }
     97    }
    9898
    99         /**
    100         * Parse and return the read data
    101         */
    102         public static DataSet parse(InputStream source) 
    103                         throws SAXException, IOException, ParserConfigurationException {
    104                 Parser parser = new Parser();
    105                 SAXParserFactory.newInstance().newSAXParser().parse(new InputSource(new InputStreamReader(source, "UTF-8")), parser);
    106                 return parser.dataSet;
    107         }
     99    /**
     100    * Parse and return the read data
     101    */
     102    public static DataSet parse(InputStream source)
     103            throws SAXException, IOException, ParserConfigurationException {
     104        Parser parser = new Parser();
     105        SAXParserFactory.newInstance().newSAXParser().parse(new InputSource(new InputStreamReader(source, "UTF-8")), parser);
     106        return parser.dataSet;
     107    }
    108108}
Note: See TracChangeset for help on using the changeset viewer.