Ignore:
Timestamp:
2016-06-19T01:55:37+02:00 (8 years ago)
Author:
donvip
Message:

OSMRec: fix security issues (XXE parsing) + code cleanup

Location:
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java

    r31106 r32320  
    11package org.openstreetmap.josm.plugins.extractor;
    22
    3 import org.openstreetmap.josm.plugins.container.OSMNode;
    4 import org.openstreetmap.josm.plugins.container.OSMRelation;
    5 import org.openstreetmap.josm.plugins.container.OSMWay;
    63import java.io.IOException;
    74import java.util.ArrayList;
     
    96import java.util.List;
    107import java.util.Map;
     8
    119import javax.xml.parsers.ParserConfigurationException;
    12 import javax.xml.parsers.SAXParser;
    13 import javax.xml.parsers.SAXParserFactory;
     10
     11import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.plugins.container.OSMNode;
     13import org.openstreetmap.josm.plugins.container.OSMRelation;
     14import org.openstreetmap.josm.plugins.container.OSMWay;
     15import org.openstreetmap.josm.tools.Utils;
    1416import org.xml.sax.Attributes;
    1517import org.xml.sax.SAXException;
     
    5052
    5153    public void parseDocument() {
    52         // parse
    53         System.out.println("extracting frequencies...");
    54         SAXParserFactory factory = SAXParserFactory.newInstance();
     54        Main.info("extracting frequencies...");
    5555        try {
    56             SAXParser parser = factory.newSAXParser();
    57             parser.parse(osmXmlFileName, this);
    58         } catch (ParserConfigurationException e) {
    59             System.out.println("ParserConfig error " + e);
    60         } catch (SAXException e) {
    61             System.out.println("SAXException : xml not well formed " + e);
    62         } catch (IOException e) {
    63             System.out.println("IO error " + e);
    64         }
    65     //LOG.info("Frequencies from OSM/XML file parsed!");   
     56            Utils.newSafeSAXParser().parse(osmXmlFileName, this);
     57        } catch (ParserConfigurationException | IOException | SAXException e) {
     58            Main.error(e);
     59        }
    6660    }
    6761
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java

    r31461 r32320  
    11package org.openstreetmap.josm.plugins.extractor;
     2
     3import java.io.File;
     4import java.io.IOException;
     5import java.io.InputStream;
     6import java.nio.file.Files;
     7import java.util.logging.Level;
     8import java.util.logging.Logger;
     9
     10import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.tools.Utils;
    212
    313import com.cybozu.labs.langdetect.Detector;
    414import com.cybozu.labs.langdetect.DetectorFactory;
    515import com.cybozu.labs.langdetect.LangDetectException;
    6 import java.io.File;
    7 import java.io.FileNotFoundException;
    8 import java.io.FileOutputStream;
    9 import java.io.IOException;
    10 import java.io.InputStream;
    11 import java.util.logging.Level;
    12 import java.util.logging.Logger;
    1316
    1417/**
     
    2629
    2730    public static LanguageDetector getInstance(String languageProfilesPath) {
    28         //System.out.println("language profile path: \n" + languageProfilesPath + "/el");
    2931        if (languageDetector == null) {
    3032            languageDetector = new LanguageDetector();
     
    5254
    5355        if (!new File(languageProfilesPath).exists()) {
    54             //new File(languageProfilesPath).mkdir();
    55             new File(languageProfilesPath).mkdirs();
     56            Utils.mkDirs(new File(languageProfilesPath));
    5657        }
    5758       
     
    6768
    6869        try {
    69 
    7070            languageProfilesOutputFileEl.createNewFile();
    7171            languageProfilesOutputFileEn.createNewFile();
     
    7777            languageProfilesOutputFileZh.createNewFile();
    7878            languageProfilesOutputFileHi.createNewFile();
    79            
    8079        } catch (IOException ex) {
    8180            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
    82         }
    83 
    84         FileOutputStream outputStreamEl = null;
    85         FileOutputStream outputStreamEn = null;
    86         FileOutputStream outputStreamDe = null;
    87         FileOutputStream outputStreamFr = null;
    88         FileOutputStream outputStreamEs = null;
    89         FileOutputStream outputStreamRu = null;
    90         FileOutputStream outputStreamTr = null;
    91         FileOutputStream outputStreamZh = null;
    92         FileOutputStream outputStreamHi = null;
    93        
    94         try {
    95            
    96             outputStreamEl = new FileOutputStream(languageProfilesOutputFileEl);
    97             outputStreamEn = new FileOutputStream(languageProfilesOutputFileEn);
    98             outputStreamDe = new FileOutputStream(languageProfilesOutputFileDe);
    99             outputStreamFr = new FileOutputStream(languageProfilesOutputFileFr);
    100             outputStreamEs = new FileOutputStream(languageProfilesOutputFileEs);
    101             outputStreamRu = new FileOutputStream(languageProfilesOutputFileRu);
    102             outputStreamTr = new FileOutputStream(languageProfilesOutputFileTr);
    103             outputStreamZh = new FileOutputStream(languageProfilesOutputFileZh);
    104             outputStreamHi = new FileOutputStream(languageProfilesOutputFileHi);
    105            
    106         } catch (FileNotFoundException ex) {
    107             Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
    108         }
    109 
    110         int read = 0;
    111         byte[] bytes = new byte[1024];
    112         try {
    113 
    114             while ((read = languageProfilesInputStreamEl.read(bytes)) != -1) {
    115                 outputStreamEl.write(bytes, 0, read);
    116             }
    117 
    118             read = 0;
    119             bytes = new byte[1024];
    120 
    121             while ((read = languageProfilesInputStreamEn.read(bytes)) != -1) {
    122                 outputStreamEn.write(bytes, 0, read);
    123             }
    124 
    125             read = 0;
    126             bytes = new byte[1024];
    127 
    128             while ((read = languageProfilesInputStreamDe.read(bytes)) != -1) {
    129                 outputStreamDe.write(bytes, 0, read);
    130             }
    131 
    132             read = 0;
    133             bytes = new byte[1024];
    134 
    135             while ((read = languageProfilesInputStreamFr.read(bytes)) != -1) {
    136                 outputStreamFr.write(bytes, 0, read);
    137             }
    138            
    139             read = 0;
    140             bytes = new byte[1024];
    141 
    142             while ((read = languageProfilesInputStreamEs.read(bytes)) != -1) {
    143                 outputStreamEs.write(bytes, 0, read);
    144             } 
    145            
    146             read = 0;
    147             bytes = new byte[1024];
    148 
    149             while ((read = languageProfilesInputStreamRu.read(bytes)) != -1) {
    150                 outputStreamRu.write(bytes, 0, read);
    151             }
    152 
    153             read = 0;
    154             bytes = new byte[1024];
    155 
    156             while ((read = languageProfilesInputStreamTr.read(bytes)) != -1) {
    157                 outputStreamTr.write(bytes, 0, read);
    158             }
    159            
    160             read = 0;
    161             bytes = new byte[1024];
    162 
    163             while ((read = languageProfilesInputStreamZh.read(bytes)) != -1) {
    164                 outputStreamZh.write(bytes, 0, read);
    165             }
    166            
    167             read = 0;
    168             bytes = new byte[1024];
    169 
    170             while ((read = languageProfilesInputStreamHi.read(bytes)) != -1) {
    171                 outputStreamHi.write(bytes, 0, read);
    172             }
    173            
    174         } catch (IOException ex) {
    175             Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
     81            Main.error(ex);
    17682        }
    17783
    17884        try {
     85                Files.copy(languageProfilesInputStreamEl, languageProfilesOutputFileEl.toPath());
     86                Files.copy(languageProfilesInputStreamEn, languageProfilesOutputFileEn.toPath());
     87                Files.copy(languageProfilesInputStreamDe, languageProfilesOutputFileDe.toPath());
     88                Files.copy(languageProfilesInputStreamFr, languageProfilesOutputFileFr.toPath());
     89                Files.copy(languageProfilesInputStreamEs, languageProfilesOutputFileEs.toPath());
     90                Files.copy(languageProfilesInputStreamRu, languageProfilesOutputFileRu.toPath());
     91                Files.copy(languageProfilesInputStreamTr, languageProfilesOutputFileTr.toPath());
     92                Files.copy(languageProfilesInputStreamZh, languageProfilesOutputFileZh.toPath());
     93                Files.copy(languageProfilesInputStreamHi, languageProfilesOutputFileHi.toPath());
     94        } catch (IOException ex) {
     95            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
     96            Main.error(ex);
     97        }
    17998
     99        try {
    180100            DetectorFactory.loadProfile(languageProfilesPath);
    181 
    182101        } catch (LangDetectException ex) {
    183102            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
     103            Main.error(ex);
    184104        }
    185105    }
     
    189109            Detector detector = DetectorFactory.create();
    190110            detector.append(text);
    191             String lang = detector.detect();
    192             //System.out.println("language detected: " + lang);
    193             return lang;
     111            return detector.detect();
    194112        } catch (LangDetectException ex) {
    195113            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
     114            Main.error(ex);
    196115            return "en"; //default lang to return if anything goes wrong at detection
    197116        }
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/HistoryParser.java

    r31106 r32320  
    1 
    21package org.openstreetmap.josm.plugins.osmrec.personalization;
    32
    4 import com.vividsolutions.jts.geom.Coordinate;
    5 import com.vividsolutions.jts.geom.Geometry;
    6 import com.vividsolutions.jts.geom.GeometryFactory;
    7 import com.vividsolutions.jts.geom.LineString;
    8 import com.vividsolutions.jts.geom.LinearRing;
    9 import com.vividsolutions.jts.geom.Point;
    10 import com.vividsolutions.jts.geom.Polygon;
    113import java.io.IOException;
    124import java.io.InputStream;
    13 import java.net.HttpURLConnection;
    14 import java.net.MalformedURLException;
    155import java.net.URL;
    166import java.util.ArrayList;
     7import java.util.HashMap;
     8import java.util.HashSet;
    179import java.util.List;
     10import java.util.Map;
    1811import java.util.logging.Level;
    1912import java.util.logging.Logger;
    20 import javax.xml.parsers.DocumentBuilder;
    21 import javax.xml.parsers.DocumentBuilderFactory;
     13
    2214import javax.xml.parsers.ParserConfigurationException;
    23 import org.w3c.dom.Document;
    24 import org.w3c.dom.Node;
    25 import org.w3c.dom.NodeList;
    26 import org.xml.sax.SAXException;
    27 import java.util.HashMap;
    28 import java.util.HashSet;
    29 import java.util.Map;
     15
    3016import org.geotools.geometry.jts.JTS;
    3117import org.geotools.referencing.CRS;
     
    3723import org.opengis.referencing.operation.MathTransform;
    3824import org.opengis.referencing.operation.TransformException;
     25import org.openstreetmap.josm.Main;
     26import org.openstreetmap.josm.io.OsmApi;
    3927import org.openstreetmap.josm.plugins.container.OSMNode;
    4028import org.openstreetmap.josm.plugins.container.OSMWay;
    41 
     29import org.openstreetmap.josm.tools.HttpClient;
     30import org.openstreetmap.josm.tools.Utils;
     31import org.w3c.dom.Node;
     32import org.w3c.dom.NodeList;
     33import org.xml.sax.SAXException;
     34
     35import com.vividsolutions.jts.geom.Coordinate;
     36import com.vividsolutions.jts.geom.Geometry;
     37import com.vividsolutions.jts.geom.GeometryFactory;
     38import com.vividsolutions.jts.geom.LineString;
     39import com.vividsolutions.jts.geom.LinearRing;
     40import com.vividsolutions.jts.geom.Point;
     41import com.vividsolutions.jts.geom.Polygon;
    4242
    4343/**
     
    4646 * @author imis-nkarag
    4747 */
    48 
    4948public class HistoryParser {
    50     private static final String OSM_API = "http://api.openstreetmap.org/api/0.6/";
    51     //private static final String GET_CHANGESET = "http://api.openstreetmap.org/api/0.6/changeset/28851695/download";
     49    private static final String OSM_API = OsmApi.getOsmApi().getBaseUrl();
    5250    private static final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
    5351    private static final CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN;
     
    6260    private final String username;
    6361
     62    /**
     63     * Constructs a new {@code HistoryParser}.
     64     * @param username user name
     65     */
    6466    public HistoryParser(String username) {   
    6567        this.username = username;
     
    8183        try {
    8284            String osmUrl = OSM_API + "changesets?display_name=" + username + "&time=" + timeInterval;
    83            
    84             System.out.println("requesting..\n" + osmUrl);
    85            
    86             URL url = new URL(osmUrl);
    87             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    88             connection.setRequestMethod("GET");
    89             //connection.setRequestProperty("Accept", "application/xml");
    90            
    91             InputStream xml = connection.getInputStream();
    92             //System.out.println("xml" + xml.read());
    93            
    94             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    95             DocumentBuilder db = dbf.newDocumentBuilder();
    96             Document doc = db.parse(xml);
    97             NodeList nodes = doc.getElementsByTagName("changeset");
    98    
    99            
    100             System.out.println("changeset size "+ nodes.getLength());
    101             //System.out.println("changeset ");
     85            InputStream xml = HttpClient.create(new URL(osmUrl)).connect().getContent();
     86            NodeList nodes = Utils.parseSafeDOM(xml).getElementsByTagName("changeset");
     87
     88            Main.debug("changeset size "+ nodes.getLength());
    10289            for (int i = 0; i < nodes.getLength(); i++) {
    103                 //Element element = (Element) nodes.item(i);
    104                 System.out.println("attributes of " + i + "th changeset");
    105                 //for(int j = 0; j < nodes.item(i).getAttributes().getLength(); j++){
    106                     //System.out.println("-  "+ nodes.item(i).getAttributes().item(j));
    107                    
    108                 //}
     90                Main.debug("attributes of " + i + "th changeset");
    10991                String id = nodes.item(i).getAttributes().item(3).toString();
    110                 System.out.println("id:" + nodes.item(i).getAttributes().item(3));
     92                Main.debug("id:" + nodes.item(i).getAttributes().item(3));
    11193                id = stripQuotes(id);
    11294                changesetIDsList.add(id);               
    11395            }
    114            
     96
    11597            for(String id : changesetIDsList){
    11698                getChangesetByID(id);
    11799            }
    118         } catch (MalformedURLException ex) {
    119             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    120         } catch (IOException ex) {
    121             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    122         } catch (ParserConfigurationException | SAXException ex) {
     100        } catch (IOException | ParserConfigurationException | SAXException ex) {
    123101            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    124102        }
     
    128106        try {
    129107            String changesetByIDURL = OSM_API+ "changeset/" + id + "/download";
    130            
    131             System.out.println("requesting..\n" + changesetByIDURL);
    132            
    133             URL url = new URL(changesetByIDURL);
    134             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    135             connection.setRequestMethod("GET");
    136             //connection.setRequestProperty("Accept", "application/xml");
    137        
    138             InputStream xml = connection.getInputStream();
    139            
    140             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    141             DocumentBuilder db = dbf.newDocumentBuilder();
    142             Document doc = db.parse(xml);
    143             //NodeList nodes = doc.getElementsByTagName("create");
    144             //NodeList nodes2 = doc.getChildNodes();
    145             Node osmChange = doc.getFirstChild();
     108            InputStream xml = HttpClient.create(new URL(changesetByIDURL)).connect().getContent();
     109            Node osmChange = Utils.parseSafeDOM(xml).getFirstChild();
    146110 
    147111            //get all nodes first, in order to be able to call all nodes references and create the geometries
     
    155119
    156120                    if(osmObject.getNodeName().equals("node")){
    157                         //System.out.println("node");
    158121                        //node data
    159122                        nodeTmp = new OSMNode();
    160                         //System.out.println("id of node: " + wayChild.getAttributes().getNamedItem("id").getNodeValue());
    161123                        nodeTmp.setID(osmObject.getAttributes().getNamedItem("id").getNodeValue());
    162124
     
    178140                        nodeList.add(nodeTmp);
    179141                        nodesWithIDs.put(nodeTmp.getID(), nodeTmp);
    180 
    181142                    }                       
    182143                }
     
    186147                String changeType = osmChange.getChildNodes().item(i).getNodeName();
    187148                if(!(changeType.equals("#text") || changeType.equals("delete"))){
    188                 //if(!(changeType.equals("#text"))){
    189149                    NodeList changeChilds = osmChange.getChildNodes().item(i).getChildNodes();
    190150
     
    196156                        wayTmp.setID(osmObject.getAttributes().getNamedItem("id").getNodeValue()); 
    197157                        //osmObject.getChildNodes() <-extract tags, then set tags to osm object
    198                         System.out.println("\n\nWAY: " + wayTmp.getID());
    199                         //System.out.println("i " + i + " j " + j + " wayTmp refers: " + wayTmp.getNodeReferences());
     158                        Main.debug("\n\nWAY: " + wayTmp.getID());
    200159                        for(int l=0; l<osmObject.getChildNodes().getLength(); l++){
    201160                            String wayChild = osmObject.getChildNodes().item(l).getNodeName();
     
    208167                            }
    209168                            else if(wayChild.equals("nd")){
    210                                 //System.out.println("nd ref: " + osmObject.getChildNodes().item(j).getAttributes().getNamedItem("ref").getNodeValue());
    211169                                wayTmp.addNodeReference(osmObject.getChildNodes().item(l).getAttributes().getNamedItem("ref").getNodeValue());
    212 
    213170                            }
    214171                        }
     
    216173                        //construct the Way geometry from each node of the node references
    217174                        List<String> references = wayTmp.getNodeReferences();
    218                         //System.out.println("references exist? size: " + references.size()); 
    219175
    220176                        for (String entry: references) {
    221177                           if(nodesWithIDs.containsKey(entry)){
    222                             //System.out.println("nodes with ids, entry " + entry);
    223                             //System.out.println("nodes with ids: " + nodesWithIDs);
    224178                                Geometry geometry = nodesWithIDs.get(entry).getGeometry(); //get the geometry of the node with ID=entry
    225179                                wayTmp.addNodeGeometry(geometry); //add the node geometry in this way
    226                            //}
    227180                           }
    228181                           else{
    229                                System.out.println("nodes with ids, no entry " + entry);
     182                               Main.debug("nodes with ids, no entry " + entry);
    230183                               getNodeFromAPI(entry);
    231184                           }
     
    233186
    234187                        Geometry geom = geometryFactory.buildGeometry(wayTmp.getNodeGeometries());
    235                         //System.out.println("geom: " + geom);
    236188                        if((wayTmp.getNodeGeometries().size()>3) &&
    237189                                wayTmp.getNodeGeometries().get(0).equals(wayTmp.getNodeGeometries()
     
    256208                        //it is an open geometry with more than one nodes, make it linestring
    257209
    258                             LineString lineString =  geometryFactory.createLineString(geom.getCoordinates());
     210                            LineString lineString = geometryFactory.createLineString(geom.getCoordinates());
    259211                            wayTmp.setGeometry(lineString);               
    260212                        }
     
    268220                }
    269221            }                 
    270            
    271         } catch (MalformedURLException ex) {
    272             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    273         } catch (IOException ex) {
    274             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    275         } catch (ParserConfigurationException | SAXException ex) {
     222        } catch (IOException | ParserConfigurationException | SAXException ex) {
    276223            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    277224        }   
     
    279226
    280227    private String stripQuotes(String id) {
    281         id = id.substring(4, id.length()-1);
    282         //System.out.println("id: " + id);
    283         return id;
     228        return id.substring(4, id.length()-1);
    284229    }
    285230
     
    287232        try {
    288233            String osmUrl = OSM_API + "node/" + nodeID;
    289            
    290             System.out.println("requesting..\n" + osmUrl);
    291            
    292             URL url = new URL(osmUrl);
    293             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    294             connection.setRequestMethod("GET");
    295             //connection.setRequestProperty("Accept", "application/xml");
    296            
    297             InputStream xml = connection.getInputStream();
    298             //System.out.println("xml" + xml.read());
    299            
    300             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    301             DocumentBuilder db = dbf.newDocumentBuilder();
    302             Document doc = db.parse(xml);
    303             NodeList nodes = doc.getElementsByTagName("node");
     234            InputStream xml = HttpClient.create(new URL(osmUrl)).connect().getContent();
     235            NodeList nodes = Utils.parseSafeDOM(xml).getElementsByTagName("node");
    304236            String lat = nodes.item(0).getAttributes().getNamedItem("lat").getNodeValue();
    305237            String lon = nodes.item(0).getAttributes().getNamedItem("lon").getNodeValue();
    306             //System.out.println("lat from api " + lat);
    307238           
    308239            nodeTmp = new OSMNode();
     
    327258            nodesWithIDs.put(nodeTmp.getID(), nodeTmp);
    328259           
    329         } catch (MalformedURLException ex) {
    330             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    331         } catch (IOException ex) {
    332             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    333         } catch (ParserConfigurationException | SAXException ex) {
     260        } catch (IOException | ParserConfigurationException | SAXException ex) {
    334261            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
    335262        }
  • applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/OSMParser.java

    r31441 r32320  
    11package org.openstreetmap.josm.plugins.parsers;
    22
    3 import com.vividsolutions.jts.geom.Coordinate;
    4 import com.vividsolutions.jts.geom.Geometry;
    5 import com.vividsolutions.jts.geom.GeometryFactory;
    6 import com.vividsolutions.jts.geom.LineString;
    7 import com.vividsolutions.jts.geom.LinearRing;
    8 import com.vividsolutions.jts.geom.Point;
    9 import com.vividsolutions.jts.geom.Polygon;
    10 import org.openstreetmap.josm.plugins.container.OSMNode;
    11 import org.openstreetmap.josm.plugins.container.OSMRelation;
    12 import org.openstreetmap.josm.plugins.container.OSMWay;
    133import java.io.IOException;
    144import java.util.ArrayList;
     
    188import java.util.logging.Level;
    199import java.util.logging.Logger;
     10
    2011import javax.xml.parsers.ParserConfigurationException;
    21 import javax.xml.parsers.SAXParser;
    22 import javax.xml.parsers.SAXParserFactory;
     12
    2313import org.geotools.geometry.jts.JTS;
    2414import org.geotools.referencing.CRS;
     
    3020import org.opengis.referencing.operation.MathTransform;
    3121import org.opengis.referencing.operation.TransformException;
     22import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.plugins.container.OSMNode;
     24import org.openstreetmap.josm.plugins.container.OSMRelation;
     25import org.openstreetmap.josm.plugins.container.OSMWay;
     26import org.openstreetmap.josm.tools.Utils;
    3227import org.xml.sax.Attributes;
    3328import org.xml.sax.SAXException;
    3429import org.xml.sax.helpers.DefaultHandler;
     30
     31import com.vividsolutions.jts.geom.Coordinate;
     32import com.vividsolutions.jts.geom.Geometry;
     33import com.vividsolutions.jts.geom.GeometryFactory;
     34import com.vividsolutions.jts.geom.LineString;
     35import com.vividsolutions.jts.geom.LinearRing;
     36import com.vividsolutions.jts.geom.Point;
     37import com.vividsolutions.jts.geom.Polygon;
    3538
    3639/**
     
    3942 * @author imis-nkarag
    4043 */
    41 
    4244public class OSMParser extends DefaultHandler {
    4345   
     
    6264   
    6365    public OSMParser(String osmXmlFileName)  {
    64         //System.out.println("creating osmParser..");
    6566        this.osmXmlFileName = osmXmlFileName;       
    6667        nodeList = new ArrayList<>();
     
    7374            Logger.getLogger(OSMParser.class.getName()).log(Level.SEVERE, null, ex);
    7475        }
    75         //System.out.println("osmParser created!");
    7676    }
    7777
    7878    public void parseDocument() {
    79         // parse       
    80         System.out.println("parsing OSM file...");
    81         SAXParserFactory factory = SAXParserFactory.newInstance();
    8279        try {
    83             SAXParser parser = factory.newSAXParser();
    84             parser.parse(osmXmlFileName, this);
    85         } catch (ParserConfigurationException e) {
    86             System.out.println("ParserConfig error " + e);
    87         } catch (SAXException e) {
    88             System.out.println("SAXException : xml not well formed " + e);
    89         } catch (IOException e) {
    90             System.out.println("IO error " + e);
    91         }
    92     //LOG.info("Instances from OSM/XML file parsed!");   
     80            Utils.newSafeSAXParser().parse(osmXmlFileName, this);
     81        } catch (ParserConfigurationException | SAXException | IOException e) {
     82            Main.error(e);
     83        }
    9384    }
    9485
     
    130121                wayTmp.setUser("undefined");
    131122            }
    132             //System.out.println("way user: " + attributes.getValue("user"));
    133123                   
    134124            inWay = true;
     
    211201                wayTmp.setGeometry(point);
    212202            }
    213         wayList.add(wayTmp);
     203            wayList.add(wayTmp);
    214204        }
    215205       
Note: See TracChangeset for help on using the changeset viewer.